Skip to content

Commit

Permalink
Merge pull request #360 from rwcarlsen/sep-life
Browse files Browse the repository at this point in the history
Better end-of-life behavior for separations:
  • Loading branch information
mbmcgarry committed Aug 26, 2015
2 parents 888a8a2 + fee222d commit 2c90840
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 16 deletions.
53 changes: 37 additions & 16 deletions src/separations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,26 +150,32 @@ std::set<cyclus::RequestPortfolio<Material>::Ptr>
Separations::GetMatlRequests() {
using cyclus::RequestPortfolio;
std::set<RequestPortfolio<Material>::Ptr> ports;
bool exclusive = false;

if (feed.space() > cyclus::eps()) {
RequestPortfolio<Material>::Ptr port(new RequestPortfolio<Material>());
int t = context()->time();
int t_exit = exit_time();
if (t_exit >= 0 && (feed.quantity() >= (t_exit - t) * throughput)) {
return ports; // already have enough feed for remainder of life
} else if (feed.space() < cyclus::eps()) {
return ports;
}

Material::Ptr m = cyclus::NewBlankMaterial(feed.space());
if (!feed_recipe.empty()) {
Composition::Ptr c = context()->GetRecipe(feed_recipe);
m = Material::CreateUntracked(feed.space(), c);
}
bool exclusive = false;
RequestPortfolio<Material>::Ptr port(new RequestPortfolio<Material>());

std::vector<cyclus::Request<Material>*> reqs;
for (int i = 0; i < feed_commods.size(); i++) {
std::string commod = feed_commods[i];
double pref = feed_commod_prefs[i];
reqs.push_back(port->AddRequest(m, this, commod, pref, exclusive));
}
port->AddMutualReqs(reqs);
ports.insert(port);
Material::Ptr m = cyclus::NewBlankMaterial(feed.space());
if (!feed_recipe.empty()) {
Composition::Ptr c = context()->GetRecipe(feed_recipe);
m = Material::CreateUntracked(feed.space(), c);
}

std::vector<cyclus::Request<Material>*> reqs;
for (int i = 0; i < feed_commods.size(); i++) {
std::string commod = feed_commods[i];
double pref = feed_commod_prefs[i];
reqs.push_back(port->AddRequest(m, this, commod, pref, exclusive));
}
port->AddMutualReqs(reqs);
ports.insert(port);

return ports;
}
Expand Down Expand Up @@ -281,6 +287,21 @@ std::set<cyclus::BidPortfolio<Material>::Ptr> Separations::GetMatlBids(

void Separations::Tock() {}

bool Separations::CheckDecommissionCondition() {
if (leftover.count() > 0) {
return false;
}

std::map<std::string, ResBuf<Material> >::iterator it;
for (it = streambufs.begin(); it != streambufs.end(); ++it) {
if (it->second.count() > 0) {
return false;
}
}

return true;
}

extern "C" cyclus::Agent* ConstructSeparations(cyclus::Context* ctx) {
return new Separations(ctx);
}
Expand Down
2 changes: 2 additions & 0 deletions src/separations.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class Separations : public cyclus::Facility {
std::vector<std::pair<cyclus::Trade<cyclus::Material>,
cyclus::Material::Ptr> >& responses);

virtual bool CheckDecommissionCondition();

#pragma cyclus clone
#pragma cyclus initfromcopy
#pragma cyclus infiletodb
Expand Down
59 changes: 59 additions & 0 deletions src/separations_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,64 @@ TEST(SeparationsTests, SepMixElemAndNuclide) {
EXPECT_DOUBLE_EQ(0, mq.mass("Pu240"));
}

TEST(SeparationsTests, Retire) {
std::string config =
"<streams>"
" <item>"
" <commod>stream1</commod>"
" <info>"
" <buf_size>-1</buf_size>"
" <efficiencies>"
" <item><comp>U235</comp> <eff>1.0</eff></item>"
" </efficiencies>"
" </info>"
" </item>"
"</streams>"
""
"<leftover_commod>waste</leftover_commod>"
"<throughput>100</throughput>"
"<feedbuf_size>100</feedbuf_size>"
"<feed_commods> <val>feed</val> </feed_commods>"
;

CompMap m;
m[id("u235")] = 0.1;
m[id("u238")] = 0.9;
Composition::Ptr c = Composition::CreateFromMass(m);

int simdur = 5;
int life = 2;

cyclus::MockSim sim(cyclus::AgentSpec(":cycamore:Separations"),
config, simdur, life);
sim.AddSource("feed").recipe("recipe1").Finalize();
sim.AddSink("stream1").capacity(100).Finalize();
sim.AddSink("waste").capacity(70).Finalize();
sim.AddRecipe("recipe1", c);
int id = sim.Run();

// Separations should stop requesting material at its lifetime
// (it is smart enough to not request material on its last timestep because
// it knows it won't be able to process it)
std::vector<Cond> conds;
conds.push_back(Cond("ReceiverId", "==", id));
QueryResult qr = sim.db().Query("Transactions", &conds);
EXPECT_EQ(life - 1, qr.rows.size())
<< "failed to stop ordering near retirement";

// Separations should discharge all material before decomissioning
conds.clear();
conds.push_back(Cond("SenderId", "==", id));
qr = sim.db().Query("Transactions", &conds);
double tot_mat = 0;
for (int i = 0; i < qr.rows.size(); i++) {
cyclus::Material::Ptr m = sim.GetMaterial(qr.GetVal<int>("ResourceId", i));
tot_mat += m->quantity();
}
EXPECT_EQ(100, tot_mat)
<< "total material traded away does not equal total material separated";
EXPECT_EQ(3.0, qr.rows.size())
<< "failed to discharge all material before decomissioning";
}
} // namespace cycamore

0 comments on commit 2c90840

Please sign in to comment.