2#line 1 "/cycamore/src/separations.cc"
6using cyclus::Composition;
7using cyclus::toolkit::ResBuf;
8using cyclus::toolkit::MatVec;
14 : cyclus::Facility(ctx),
20 cyclus::Inventories invs;
26 leftover.Push(invs[
"leftover-inv-name"]);
27 invs[
"feed-inv-name"] =
feed.PopNRes(
feed.count());
28 feed.Push(invs[
"feed-inv-name"]);
30 std::map<std::string, ResBuf<Material> >::iterator it;
32 invs[it->first] = it->second.PopNRes(it->second.count());
33 it->second.Push(invs[it->first]);
40 leftover.Push(inv[
"leftover-inv-name"]);
41 feed.Push(inv[
"feed-inv-name"]);
43 cyclus::Inventories::iterator it;
44 for (it = inv.begin(); it != inv.end(); ++it) {
49typedef std::pair<double, std::map<int, double> >
Stream;
53 cyclus::Facility::EnterNotify();
54 std::map<int, double> efficiency_;
56 StreamSet::iterator it;
57 std::map<int, double>::iterator it2;
60 std::string name = it->first;
61 Stream stream = it->second;
62 double cap = stream.first;
67 for (it2 = stream.second.begin(); it2 != stream.second.end(); it2++) {
68 efficiency_[it2->first] += it2->second;
73 std::vector<int> eff_pb_;
74 for (it2 = efficiency_.begin(); it2 != efficiency_.end(); it2++) {
75 if (it2->second > 1) {
76 eff_pb_.push_back(it2->first);
80 if (eff_pb_.size() > 0) {
82 ss <<
"In " << prototype() <<
", ";
83 ss <<
"the following nuclide(s) have a cumulative separation efficiency "
85 for (
int i = 0; i < eff_pb_.size(); i++) {
86 ss <<
"\n " << eff_pb_[i];
87 if (i < eff_pb_.size() - 1) {
94 throw cyclus::ValueError(ss.str());
105 using cyclus::toolkit::RecordTimeSeries;
106 if (
feed.count() == 0) {
110 Material::Ptr mat =
feed.Pop(pop_qty, cyclus::eps_rsrc());
111 double orig_qty = mat->quantity();
113 StreamSet::iterator it;
115 std::map<std::string, Material::Ptr> stagedsep;
116 Record(
"Separating", orig_qty,
"feed");
119 std::string name = it->first;
121 double frac =
streambufs[name].space() / stagedsep[name]->quantity();
122 if (frac < maxfrac) {
127 std::map<std::string, Material::Ptr>::iterator itf;
128 for (itf = stagedsep.begin(); itf != stagedsep.end(); ++itf) {
129 std::string name = itf->first;
130 Material::Ptr m = itf->second;
131 if (m->quantity() > 0) {
132 double qty = m->quantity();
133 if (m->quantity() > mat->quantity()) {
134 qty = mat->quantity();
137 mat->ExtractComp(qty * maxfrac, m->comp()));
138 Record(
"Separated", qty * maxfrac, name);
140 cyclus::toolkit::RecordTimeSeries<double>(
"supply"+name,
this,
145 if (mat->quantity() > 0) {
152 feed.Push(mat->ExtractQty((1 - maxfrac) * orig_qty));
153 if (mat->quantity() > 0) {
158 cyclus::toolkit::RecordTimeSeries<double>(
"supply"+
leftover_commod,
this,
165Material::Ptr
SepMaterial(std::map<int, double> effs, Material::Ptr mat) {
166 using cyclus::CompMap;
168 CompMap cm = mat->comp()->mass();
169 cyclus::compmath::Normalize(&cm, mat->quantity());
173 CompMap::iterator it;
174 for (it = cm.begin(); it != cm.end(); ++it) {
176 int elem = (nuc / 10000000) * 10000000;
178 if (effs.count(nuc) > 0) {
180 }
else if (effs.count(elem) > 0) {
186 double qty = it->second;
187 double sepqty = qty * eff;
188 sepcomp[nuc] = sepqty;
192 Composition::Ptr c = Composition::CreateFromMass(sepcomp);
193 return Material::CreateUntracked(tot_qty, c);
196std::set<cyclus::RequestPortfolio<Material>::Ptr>
198 using cyclus::RequestPortfolio;
199 using cyclus::toolkit::RecordTimeSeries;
200 std::set<RequestPortfolio<Material>::Ptr> ports;
202 int t = context()->time();
203 int t_exit = exit_time();
206 std::vector<double>::iterator result;
209 cyclus::toolkit::RecordTimeSeries<double>(
"demand"+
feed_commods[maxindx],
211 if (t_exit >= 0 && (
feed.quantity() >= (t_exit - t) *
throughput)) {
213 }
else if (
feed.space() < cyclus::eps_rsrc()) {
217 bool exclusive =
false;
218 RequestPortfolio<Material>::Ptr port(
new RequestPortfolio<Material>());
220 Material::Ptr m = cyclus::NewBlankMaterial(
feed.space());
222 Composition::Ptr c = context()->GetRecipe(
feed_recipe);
223 m = Material::CreateUntracked(
feed.space(), c);
226 std::vector<Request<Material>*> reqs;
230 reqs.push_back(port->AddRequest(m,
this, commod, pref, exclusive));
232 port->AddMutualReqs(reqs);
239 const std::vector<cyclus::Trade<Material> >& trades,
240 std::vector<std::pair<cyclus::Trade<Material>, Material::Ptr> >&
244 std::vector<Trade<Material> >::const_iterator it;
245 for (
int i = 0; i < trades.size(); i++) {
246 std::string commod = trades[i].request->commodity();
248 double amt = std::min(
leftover.quantity(), trades[i].amt);
249 Material::Ptr m =
leftover.Pop(amt, cyclus::eps_rsrc());
250 responses.push_back(std::make_pair(trades[i], m));
252 double amt = std::min(
streambufs[commod].quantity(), trades[i].amt);
253 Material::Ptr m =
streambufs[commod].Pop(amt, cyclus::eps_rsrc());
254 responses.push_back(std::make_pair(trades[i], m));
256 throw cyclus::ValueError(
"invalid commodity " + commod +
257 " on trade matched to prototype " + prototype());
263 const std::vector<std::pair<cyclus::Trade<Material>, Material::Ptr> >&
265 std::vector<std::pair<cyclus::Trade<Material>,
266 Material::Ptr> >::const_iterator trade;
268 for (trade = responses.begin(); trade != responses.end(); ++trade) {
269 feed.Push(trade->second);
274 cyclus::CommodMap<Material>::type& commod_requests) {
275 using cyclus::BidPortfolio;
276 bool exclusive =
false;
277 std::set<BidPortfolio<Material>::Ptr> ports;
280 std::map<std::string, ResBuf<Material> >::iterator it;
282 std::string commod = it->first;
283 std::vector<Request<Material>*>& reqs = commod_requests[commod];
284 if (reqs.size() == 0) {
286 }
else if (
streambufs[commod].quantity() < cyclus::eps_rsrc()) {
293 BidPortfolio<Material>::Ptr port(
new BidPortfolio<Material>());
295 for (
int j = 0; j < reqs.size(); j++) {
296 Request<Material>* req = reqs[j];
298 for (
int k = 0; k < mats.size(); k++) {
299 Material::Ptr m = mats[k];
300 tot_bid += m->quantity();
304 if (m->quantity() > cyclus::eps_rsrc()) {
305 port->AddBid(req, m,
this, exclusive);
308 if (tot_bid >= req->target()->quantity()) {
314 double tot_qty =
streambufs[commod].quantity();
315 cyclus::CapacityConstraint<Material> cc(tot_qty);
316 port->AddConstraint(cc);
321 std::vector<Request<Material>*>& reqs = commod_requests[
leftover_commod];
322 if (reqs.size() > 0 &&
leftover.quantity() >= cyclus::eps_rsrc()) {
326 BidPortfolio<Material>::Ptr port(
new BidPortfolio<Material>());
328 for (
int j = 0; j < reqs.size(); j++) {
329 Request<Material>* req = reqs[j];
331 for (
int k = 0; k < mats.size(); k++) {
332 Material::Ptr m = mats[k];
333 tot_bid += m->quantity();
337 if (m->quantity() > cyclus::eps_rsrc()) {
338 port->AddBid(req, m,
this, exclusive);
341 if (tot_bid >= req->target()->quantity()) {
347 cyclus::CapacityConstraint<Material> cc(
leftover.quantity());
348 port->AddConstraint(cc);
362 std::map<std::string, ResBuf<Material> >::iterator it;
364 if (it->second.count() > 0) {
373 std::string specification = this->spec();
375 ->NewDatum(
"AgentPosition")
376 ->AddVal(
"Spec", specification)
377 ->AddVal(
"Prototype", this->prototype())
378 ->AddVal(
"AgentId",
id())
386 ->NewDatum(
"SeparationEvents")
387 ->AddVal(
"AgentId",
id())
388 ->AddVal(
"Time", context()->time())
389 ->AddVal(
"Event", name)
390 ->AddVal(
"Value", val)
391 ->AddVal(
"Type", type)
Separations processes feed material into one or more streams containing specific elements and/or nucl...
std::string leftover_commod
std::map< std::string, std::pair< double, std::map< int, double > > > streams_
virtual void GetMatlTrades(const std::vector< cyclus::Trade< cyclus::Material > > &trades, std::vector< std::pair< cyclus::Trade< cyclus::Material >, cyclus::Material::Ptr > > &responses)
virtual void AcceptMatlTrades(const std::vector< std::pair< cyclus::Trade< cyclus::Material >, cyclus::Material::Ptr > > &responses)
cyclus::toolkit::ResBuf< cyclus::Material > feed
virtual std::set< cyclus::RequestPortfolio< cyclus::Material >::Ptr > GetMatlRequests()
virtual cyclus::Inventories SnapshotInv()
virtual void InitInv(cyclus::Inventories &inv)
cyclus::toolkit::ResBuf< cyclus::Material > leftover
std::map< std::string, cyclus::toolkit::ResBuf< cyclus::Material > > streambufs
virtual bool CheckDecommissionCondition()
virtual void EnterNotify()
void Record(std::string name, double val, std::string type)
std::vector< double > feed_commod_prefs
void RecordPosition()
Records an agent's latitude and longitude to the output db.
virtual std::set< cyclus::BidPortfolio< cyclus::Material >::Ptr > GetMatlBids(cyclus::CommodMap< cyclus::Material >::type &commod_requests)
std::vector< std::string > feed_commods
Separations(cyclus::Context *ctx)
Material::Ptr SepMaterial(std::map< int, double > effs, Material::Ptr mat)
std::pair< double, std::map< int, double > > Stream
std::map< std::string, Stream > StreamSet
cyclus::toolkit::Position coordinates
cyclus::Agent * ConstructSeparations(cyclus::Context *ctx)