10 #include <boost/lexical_cast.hpp> 16 : cyclus::Facility(ctx),
36 ss << cyclus::Facility::str() <<
" with enrichment facility parameters:" 47 using cyclus::Material;
49 Facility::Build(parent);
55 LOG(cyclus::LEV_DEBUG2,
"EnrFac") <<
"Enrichment " 56 <<
" entering the simuluation: ";
57 LOG(cyclus::LEV_DEBUG2,
"EnrFac") <<
str();
69 using cyclus::toolkit::RecordTimeSeries;
70 LOG(cyclus::LEV_INFO4,
"EnrFac") << prototype() <<
" used " 73 LOG(cyclus::LEV_INFO4,
"EnrFac") << prototype() <<
" used " 80 std::set<cyclus::RequestPortfolio<cyclus::Material>::Ptr>
82 using cyclus::Material;
83 using cyclus::RequestPortfolio;
84 using cyclus::Request;
86 std::set<RequestPortfolio<Material>::Ptr> ports;
87 RequestPortfolio<Material>::Ptr port(
new RequestPortfolio<Material>());
89 double amt = mat->quantity();
91 if (amt > cyclus::eps_rsrc()) {
100 bool SortBids(cyclus::Bid<cyclus::Material>* i,
101 cyclus::Bid<cyclus::Material>* j) {
102 cyclus::Material::Ptr mat_i = i->offer();
103 cyclus::Material::Ptr mat_j = j->offer();
105 cyclus::toolkit::MatQuery mq_i(mat_i);
106 cyclus::toolkit::MatQuery mq_j(mat_j);
108 return ((mq_i.mass(922350000) / mq_i.qty()) <=
109 (mq_j.mass(922350000) / mq_j.qty()));
115 cyclus::PrefMap<cyclus::Material>::type& prefs) {
117 using cyclus::Material;
118 using cyclus::Request;
124 cyclus::PrefMap<cyclus::Material>::type::iterator reqit;
127 for (reqit = prefs.begin(); reqit != prefs.end(); ++reqit) {
128 std::vector<Bid<Material>*> bids_vector;
129 std::map<Bid<Material>*,
double>::iterator mit;
130 for (mit = reqit->second.begin(); mit != reqit->second.end(); ++mit) {
131 Bid<Material>* bid = mit->first;
132 bids_vector.push_back(bid);
134 std::sort(bids_vector.begin(), bids_vector.end(),
SortBids);
137 double n_bids = bids_vector.size();
140 for (
int bidit = 0; bidit < bids_vector.size(); bidit++) {
141 int new_pref = bidit + 1;
145 cyclus::Material::Ptr mat = bids_vector[bidit]->offer();
146 cyclus::toolkit::MatQuery mq(mat);
147 if (mq.mass(922350000) == 0) {
153 (reqit->second)[bids_vector[bidit]] = new_pref;
160 const std::vector<std::pair<cyclus::Trade<cyclus::Material>,
161 cyclus::Material::Ptr> >& responses) {
164 std::vector<std::pair<cyclus::Trade<cyclus::Material>,
165 cyclus::Material::Ptr> >::const_iterator it;
166 for (it = responses.begin(); it != responses.end(); ++it) {
173 cyclus::CommodMap<cyclus::Material>::type& out_requests) {
175 using cyclus::BidPortfolio;
176 using cyclus::CapacityConstraint;
177 using cyclus::Converter;
178 using cyclus::Material;
179 using cyclus::Request;
180 using cyclus::toolkit::MatVec;
181 using cyclus::toolkit::RecordTimeSeries;
183 std::set<BidPortfolio<Material>::Ptr> ports;
187 if ((out_requests.count(tails_commod) > 0) && (
tails.quantity() > 0)) {
188 BidPortfolio<Material>::Ptr tails_port(
new BidPortfolio<Material>());
190 std::vector<Request<Material>*>& tails_requests =
192 std::vector<Request<Material>*>::iterator it;
193 for (it = tails_requests.begin(); it != tails_requests.end(); ++it) {
198 for (
int k = 0; k < mats.size(); k++) {
199 Material::Ptr m = mats[k];
200 Request<Material>* req = *it;
201 tails_port->AddBid(req, m,
this);
206 CapacityConstraint<Material> tails_constraint(
tails.quantity());
207 tails_port->AddConstraint(tails_constraint);
208 LOG(cyclus::LEV_INFO5,
"EnrFac") << prototype()
209 <<
" adding tails capacity constraint of " 211 ports.insert(tails_port);
214 if ((out_requests.count(product_commod) > 0) && (
inventory.quantity() > 0)) {
215 BidPortfolio<Material>::Ptr commod_port(
new BidPortfolio<Material>());
217 std::vector<Request<Material>*>& commod_requests =
219 std::vector<Request<Material>*>::iterator it;
220 for (it = commod_requests.begin(); it != commod_requests.end(); ++it) {
221 Request<Material>* req = *it;
222 Material::Ptr mat = req->target();
223 double request_enrich = cyclus::toolkit::UraniumAssayMass(mat);
226 (cyclus::AlmostEq(request_enrich,
max_enrich)))) {
227 Material::Ptr offer =
Offer_(req->target());
228 commod_port->AddBid(req, offer,
this);
235 CapacityConstraint<Material> natu(
inventory.quantity(), nc);
236 commod_port->AddConstraint(swu);
237 commod_port->AddConstraint(natu);
239 LOG(cyclus::LEV_INFO5,
"EnrFac")
240 << prototype() <<
" adding a swu constraint of " << swu.capacity();
241 LOG(cyclus::LEV_INFO5,
"EnrFac")
242 << prototype() <<
" adding a natu constraint of " << natu.capacity();
243 ports.insert(commod_port);
250 cyclus::toolkit::MatQuery q(mat);
251 double u235 = q.atom_frac(922350000);
252 double u238 = q.atom_frac(922380000);
253 return (u238 > 0 && u235 / (u235 + u238) >
tails_assay);
258 const std::vector<cyclus::Trade<cyclus::Material> >& trades,
259 std::vector<std::pair<cyclus::Trade<cyclus::Material>,
260 cyclus::Material::Ptr> >& responses) {
261 using cyclus::Material;
267 std::vector<Trade<Material>>::const_iterator it;
268 for (it = trades.begin(); it != trades.end(); ++it) {
269 double qty = it->amt;
270 std::string commod_type = it->bid->request()->commodity();
271 Material::Ptr response;
274 if (commod_type == tails_commod) {
275 LOG(cyclus::LEV_INFO5,
"EnrFac")
276 << prototype() <<
" just received an order" 278 double pop_qty = std::min(qty,
tails.quantity());
279 response =
tails.Pop(pop_qty, cyclus::eps_rsrc());
281 LOG(cyclus::LEV_INFO5,
"EnrFac")
282 << prototype() <<
" just received an order" 284 response =
Enrich_(it->bid->offer(), qty);
286 responses.push_back(std::make_pair(*it, response));
289 if (cyclus::IsNegative(
tails.quantity())) {
290 std::stringstream ss;
291 ss <<
"is being asked to provide more than its current inventory.";
292 throw cyclus::ValueError(Agent::InformErrorMsg(ss.str()));
295 throw cyclus::ValueError(
"EnrFac " + prototype() +
296 " is being asked to provide more than" +
297 " its SWU capacity.");
304 cyclus::CompMap cm = mat->comp()->atom();
305 bool extra_u =
false;
306 bool other_elem =
false;
307 for (cyclus::CompMap::const_iterator it = cm.begin(); it != cm.end(); ++it) {
308 if (pyne::nucname::znum(it->first) == 92) {
309 if (pyne::nucname::anum(it->first) != 235 &&
310 pyne::nucname::anum(it->first) != 238 && it->second > 0) {
313 }
else if (it->second > 0) {
318 cyclus::Warn<cyclus::VALUE_WARNING>(
319 "More than 2 isotopes of U. " 320 "Istopes other than U-235, U-238 are sent directly to tails.");
323 cyclus::Warn<cyclus::VALUE_WARNING>(
324 "Non-uranium elements are " 325 "sent directly to tails.");
328 LOG(cyclus::LEV_INFO5,
"EnrFac") << prototype() <<
" is initially holding " 333 }
catch (cyclus::Error& e) {
334 e.msg(Agent::InformErrorMsg(e.msg()));
338 LOG(cyclus::LEV_INFO5,
"EnrFac")
339 << prototype() <<
" added " << mat->quantity() <<
" of " <<
feed_commod 340 <<
" to its inventory, which is holding " <<
inventory.quantity()
347 return cyclus::Material::CreateUntracked(qty,
353 cyclus::toolkit::MatQuery q(mat);
354 cyclus::CompMap comp;
355 comp[922350000] = q.atom_frac(922350000);
356 comp[922380000] = q.atom_frac(922380000);
357 return cyclus::Material::CreateUntracked(
358 mat->quantity(), cyclus::Composition::CreateFromAtom(comp));
363 using cyclus::Material;
364 using cyclus::ResCast;
365 using cyclus::toolkit::Assays;
366 using cyclus::toolkit::UraniumAssayMass;
367 using cyclus::toolkit::SwuRequired;
368 using cyclus::toolkit::FeedQty;
369 using cyclus::toolkit::TailsQty;
373 double swu_req = SwuRequired(qty, assays);
374 double natu_req = FeedQty(qty, assays);
379 Material::Ptr natu_matl =
inventory.Pop(pop_qty, cyclus::eps_rsrc());
382 cyclus::toolkit::MatQuery mq(natu_matl);
383 std::set<cyclus::Nuc> nucs;
384 nucs.insert(922350000);
385 nucs.insert(922380000);
386 double natu_frac = mq.mass_frac(nucs);
387 double feed_req = natu_req / natu_frac;
393 if (cyclus::AlmostEq(feed_req,
inventory.quantity())) {
396 r =
inventory.Pop(feed_req, cyclus::eps_rsrc());
398 }
catch (cyclus::Error& e) {
400 std::stringstream ss;
401 ss <<
" tried to remove " << feed_req <<
" from its inventory of size " 403 <<
" and the conversion of the material into natu is " 405 throw cyclus::ValueError(Agent::InformErrorMsg(ss.str()));
410 cyclus::Composition::Ptr comp = mat->comp();
411 Material::Ptr response = r->ExtractComp(qty, comp);
420 LOG(cyclus::LEV_INFO5,
"EnrFac") << prototype()
421 <<
" has performed an enrichment: ";
422 LOG(cyclus::LEV_INFO5,
"EnrFac") <<
" * Feed Qty: " << feed_req;
423 LOG(cyclus::LEV_INFO5,
"EnrFac") <<
" * Feed Assay: " 424 << assays.Feed() * 100;
425 LOG(cyclus::LEV_INFO5,
"EnrFac") <<
" * Product Qty: " << qty;
426 LOG(cyclus::LEV_INFO5,
"EnrFac") <<
" * Product Assay: " 427 << assays.Product() * 100;
428 LOG(cyclus::LEV_INFO5,
"EnrFac") <<
" * Tails Qty: " 429 << TailsQty(qty, assays);
430 LOG(cyclus::LEV_INFO5,
"EnrFac") <<
" * Tails Assay: " 431 << assays.Tails() * 100;
432 LOG(cyclus::LEV_INFO5,
"EnrFac") <<
" * SWU: " << swu_req;
433 LOG(cyclus::LEV_INFO5,
"EnrFac") <<
" * Current SWU capacity: " 441 using cyclus::Context;
444 LOG(cyclus::LEV_DEBUG1,
"EnrFac") << prototype()
445 <<
" has enriched a material:";
446 LOG(cyclus::LEV_DEBUG1,
"EnrFac") <<
" * Amount: " << natural_u;
447 LOG(cyclus::LEV_DEBUG1,
"EnrFac") <<
" * SWU: " << swu;
449 Context* ctx = Agent::context();
450 ctx->NewDatum(
"Enrichments")
451 ->AddVal(
"AgentId",
id())
452 ->AddVal(
"Time", ctx->time())
453 ->AddVal(
"Natural_Uranium", natural_u)
459 using cyclus::Material;
465 cyclus::Material::Ptr fission_matl =
466 inventory.Pop(pop_qty, cyclus::eps_rsrc());
468 return cyclus::toolkit::UraniumAssayMass(fission_matl);
475 ->NewDatum(
"AgentPosition")
476 ->AddVal(
"Spec", specification)
477 ->AddVal(
"Prototype", this->prototype())
478 ->AddVal(
"AgentId",
id())
double FeedAssay()
calculates the feed assay based on the unenriched inventory
cyclus::Material::Ptr Offer_(cyclus::Material::Ptr req)
Generates a material offer for a given request.
virtual ~Enrichment()
Destructor for the Enrichment class.
virtual void Build(cyclus::Agent *parent)
perform module-specific tasks when entering the simulation
virtual void Tick()
Each facility is prompted to do its beginning-of-time-step stuff at the tick of the timer...
void RecordPosition()
Records an agent's latitude and longitude to the output db.
bool SortBids(cyclus::Bid< cyclus::Material > *i, cyclus::Bid< cyclus::Material > *j)
double intra_timestep_swu_
cyclus::Agent * ConstructEnrichment(cyclus::Context *ctx)
virtual void AdjustMatlPrefs(cyclus::PrefMap< cyclus::Material >::type &prefs)
The Enrichment adjusts preferences for offers of natural uranium it has received to maximize U-235 co...
virtual void AcceptMatlTrades(const std::vector< std::pair< cyclus::Trade< cyclus::Material >, cyclus::Material::Ptr > > &responses)
The Enrichment place accepted trade Materials in their Inventory.
bool ValidReq(const cyclus::Material::Ptr mat)
Determines if a particular material is a valid request to respond to.
cyclus::Material::Ptr Request_()
generates a request for this facility given its current state.
double current_swu_capacity
cyclus::Material::Ptr Enrich_(cyclus::Material::Ptr mat, double qty)
cycamore::GrowthRegion string
virtual std::set< cyclus::BidPortfolio< cyclus::Material >::Ptr > GetMatlBids(cyclus::CommodMap< cyclus::Material >::type &commod_requests)
Responds to each request for this facility's commodity.
virtual std::string str()
Print information about this agent.
cyclus::toolkit::Position coordinates
Enrichment(cyclus::Context *ctx)
Constructor for the Enrichment class.
void AddMat_(cyclus::Material::Ptr mat)
adds a material into the natural uranium inventory
virtual void Tock()
Each facility is prompted to its end-of-time-step stuff on the tock of the timer. ...
double SwuCapacity() const
virtual std::set< cyclus::RequestPortfolio< cyclus::Material >::Ptr > GetMatlRequests()
The Enrichment request Materials of its given commodity.
virtual void GetMatlTrades(const std::vector< cyclus::Trade< cyclus::Material > > &trades, std::vector< std::pair< cyclus::Trade< cyclus::Material >, cyclus::Material::Ptr > > &responses)
respond to each trade with a material enriched to the appropriate level given this facility's invento...
std::string product_commod
double intra_timestep_feed_
cyclus::toolkit::ResBuf< cyclus::Material > tails
void RecordEnrichment_(double natural_u, double swu)
records and enrichment with the cyclus::Recorder
cyclus::toolkit::ResBuf< cyclus::Material > inventory