CYCAMORE
Loading...
Searching...
No Matches
src/enrichment.h
Go to the documentation of this file.
1#ifndef CYCAMORE_SRC_ENRICHMENT_H_
2#define CYCAMORE_SRC_ENRICHMENT_H_
3
4#include <string>
5
6#include "cyclus.h"
7#include "cycamore_version.h"
8
9#pragma cyclus exec from cyclus.system import CY_LARGE_DOUBLE, CY_LARGE_INT, CY_NEAR_ZERO
10
11namespace cycamore {
12
17class SWUConverter : public cyclus::Converter<cyclus::Material> {
18 public:
19 SWUConverter(double feed_commod, double tails) : feed_(feed_commod),
20 tails_(tails) {}
21 virtual ~SWUConverter() {}
22
24 virtual double convert(
25 cyclus::Material::Ptr m,
26 cyclus::Arc const * a = NULL,
27 cyclus::ExchangeTranslationContext<cyclus::Material>
28 const * ctx = NULL) const {
29 cyclus::toolkit::Assays assays(feed_, cyclus::toolkit::UraniumAssayMass(m),
30 tails_);
31 return cyclus::toolkit::SwuRequired(m->quantity(), assays);
32 }
33
35 virtual bool operator==(Converter& other) const {
36 SWUConverter* cast = dynamic_cast<SWUConverter*>(&other);
37 return cast != NULL &&
38 feed_ == cast->feed_ &&
39 tails_ == cast->tails_;
40 }
41
42 private:
43 double feed_, tails_;
44};
45
51class NatUConverter : public cyclus::Converter<cyclus::Material> {
52 public:
53 NatUConverter(double feed_commod, double tails) : feed_(feed_commod),
54 tails_(tails) {}
55 virtual ~NatUConverter() {}
56
57 virtual std::string version() { return CYCAMORE_VERSION; }
58
60 virtual double convert(
61 cyclus::Material::Ptr m,
62 cyclus::Arc const * a = NULL,
63 cyclus::ExchangeTranslationContext<cyclus::Material>
64 const * ctx = NULL) const {
65 cyclus::toolkit::Assays assays(feed_, cyclus::toolkit::UraniumAssayMass(m),
66 tails_);
67 cyclus::toolkit::MatQuery mq(m);
68 std::set<cyclus::Nuc> nucs;
69 nucs.insert(922350000);
70 nucs.insert(922380000);
71
72 double natu_frac = mq.mass_frac(nucs);
73 double natu_req = cyclus::toolkit::FeedQty(m->quantity(), assays);
74 return natu_req / natu_frac;
75 }
76
78 virtual bool operator==(Converter& other) const {
79 NatUConverter* cast = dynamic_cast<NatUConverter*>(&other);
80 return cast != NULL &&
81 feed_ == cast->feed_ &&
82 tails_ == cast->tails_;
83 }
84
85 private:
86 double feed_, tails_;
87};
88
121
122class Enrichment
123 : public cyclus::Facility,
124 public cyclus::toolkit::Position {
125#pragma cyclus note { \
126 "niche": "enrichment facility", \
127 "doc": \
128 "The Enrichment facility is a simple agent that enriches natural " \
129 "uranium in a Cyclus simulation. It does not explicitly compute " \
130 "the physical enrichment process, rather it calculates the SWU " \
131 "required to convert a source uranium recipe (i.e. natural uranium) " \
132 "into a requested enriched recipe (i.e. 4% enriched uranium), given " \
133 "the natural uranium inventory constraint and its SWU capacity " \
134 "constraint." \
135 "\n\n" \
136 "The Enrichment facility requests an input commodity and associated " \
137 "recipe whose quantity is its remaining inventory capacity. All " \
138 "facilities trading the same input commodity (even with different " \
139 "recipes) will offer materials for trade. The Enrichment facility " \
140 "accepts any input materials with enrichments less than its tails assay, "\
141 "as long as some U235 is present, and preference increases with U235 " \
142 "content. If no U235 is present in the offered material, the trade " \
143 "preference is set to -1 and the material is not accepted. Any material " \
144 "components other than U235 and U238 are sent directly to the tails buffer."\
145 "\n\n" \
146 "The Enrichment facility will bid on any request for its output commodity "\
147 "up to the maximum allowed enrichment (if not specified, default is 100%) "\
148 "It bids on either the request quantity, or the maximum quanity allowed " \
149 "by its SWU constraint or natural uranium inventory, whichever is lower. " \
150 "If multiple output commodities with different enrichment levels are " \
151 "requested and the facility does not have the SWU or quantity capacity " \
152 "to meet all requests, the requests are fully, then partially filled " \
153 "in unspecified but repeatable order. A request for the product " \
154 "commodity without an associated requested enriched recipe will not be " \
155 "fulfilled." \
156 "\n\n" \
157 "Accumulated tails inventory is offered for trading as a specifiable " \
158 "output commodity.", \
159}
160 public:
161 // --- Module Members ---
164 Enrichment(cyclus::Context* ctx);
165
167 virtual ~Enrichment();
168
169 virtual void EnterNotify();
170
171 virtual std::string version() { return CYCAMORE_VERSION; }
172
173 #pragma cyclus
174
176 virtual std::string str();
177 // ---
178
179 // --- Facility Members ---
181 virtual void Build(cyclus::Agent* parent);
182 // ---
183
184 // --- Agent Members ---
187
189 virtual void Tick();
190
193
195 virtual void Tock();
196
199 virtual std::set<cyclus::RequestPortfolio<cyclus::Material>::Ptr>
201
205 virtual void AdjustMatlPrefs(cyclus::PrefMap<cyclus::Material>::type& prefs);
206
209 virtual void AcceptMatlTrades(
210 const std::vector< std::pair<cyclus::Trade<cyclus::Material>,
211 cyclus::Material::Ptr> >& responses);
212
216 virtual std::set<cyclus::BidPortfolio<cyclus::Material>::Ptr>
217 GetMatlBids(cyclus::CommodMap<cyclus::Material>::type&
218 commod_requests);
219
225 virtual void GetMatlTrades(
226 const std::vector< cyclus::Trade<cyclus::Material> >& trades,
227 std::vector<std::pair<cyclus::Trade<cyclus::Material>,
228 cyclus::Material::Ptr> >& responses);
229 // ---
230
235 bool ValidReq(const cyclus::Material::Ptr mat);
236
237 inline void SetMaxInventorySize(double size) {
238 max_feed_inventory = size;
239 inventory.capacity(size);
240 }
241
242 inline void SwuCapacity(double capacity) {
243 swu_capacity = capacity;
245 }
246
247 inline double SwuCapacity() const { return swu_capacity; }
248
249 inline const cyclus::toolkit::ResBuf<cyclus::Material>& Tails() const {
250 return tails;
251 }
252
253 private:
254 // Code Injection:
255 #include "toolkit/position.cycpp.h"
256
259 void AddMat_(cyclus::Material::Ptr mat);
260
263 cyclus::Material::Ptr Request_();
264
271 cyclus::Material::Ptr Offer_(cyclus::Material::Ptr req);
272
273 cyclus::Material::Ptr Enrich_(cyclus::Material::Ptr mat, double qty);
274
276 double FeedAssay();
277
279 void RecordEnrichment_(double natural_u, double swu);
280
281 #pragma cyclus var { \
282 "tooltip": "feed commodity", \
283 "doc": "feed commodity that the enrichment facility accepts", \
284 "uilabel": "Feed Commodity", \
285 "uitype": "incommodity" \
286 }
287 std::string feed_commod;
288
289 #pragma cyclus var { \
290 "tooltip": "feed recipe", \
291 "doc": "recipe for enrichment facility feed commodity", \
292 "uilabel": "Feed Recipe", \
293 "uitype": "inrecipe" \
294 }
295 std::string feed_recipe;
296
297 #pragma cyclus var { \
298 "tooltip": "product commodity", \
299 "doc": "product commodity that the enrichment facility generates", \
300 "uilabel": "Product Commodity", \
301 "uitype": "outcommodity" \
302 }
303 std::string product_commod;
304
305 #pragma cyclus var { \
306 "tooltip": "tails commodity", \
307 "doc": "tails commodity supplied by enrichment facility", \
308 "uilabel": "Tails Commodity", \
309 "uitype": "outcommodity" \
310 }
311 std::string tails_commod;
312
313 #pragma cyclus var { \
314 "default": 0.003, "tooltip": "tails assay", \
315 "uilabel": "Tails Assay", \
316 "uitype": "range", \
317 "range": [0.0, 0.003], \
318 "doc": "tails assay from the enrichment process", \
319 }
320 double tails_assay;
321
322 #pragma cyclus var { \
323 "default": 0, "tooltip": "initial uranium reserves (kg)", \
324 "uilabel": "Initial Feed Inventory", \
325 "doc": "amount of natural uranium stored at the enrichment " \
326 "facility at the beginning of the simulation (kg)" \
327 }
328 double initial_feed;
329
330 #pragma cyclus var { \
331 "default": CY_LARGE_DOUBLE, "tooltip": "max inventory of feed material (kg)", \
332 "uilabel": "Maximum Feed Inventory", \
333 "uitype": "range", \
334 "range": [0.0, CY_LARGE_DOUBLE], \
335 "doc": "maximum total inventory of natural uranium in " \
336 "the enrichment facility (kg)" \
337 }
338 double max_feed_inventory;
339
340 #pragma cyclus var { \
341 "default": 1.0, \
342 "tooltip": "maximum allowed enrichment fraction", \
343 "doc": "maximum allowed weight fraction of U235 in product", \
344 "uilabel": "Maximum Allowed Enrichment", \
345 "uitype": "range", \
346 "range": [0.0,1.0], \
347 "schema": '<optional>' \
348 ' <element name="max_enrich">' \
349 ' <data type="double">' \
350 ' <param name="minInclusive">0</param>' \
351 ' <param name="maxInclusive">1</param>' \
352 ' </data>' \
353 ' </element>' \
354 ' </optional>' \
355 }
356 double max_enrich;
357
358 #pragma cyclus var { \
359 "default": 1, \
360 "userlevel": 10, \
361 "tooltip": "Rank Material Requests by U235 Content", \
362 "uilabel": "Prefer feed with higher U235 content", \
363 "doc": "turn on preference ordering for input material " \
364 "so that EF chooses higher U235 content first" \
365 }
366 bool order_prefs;
367
368 #pragma cyclus var { \
369 "default": CY_LARGE_DOUBLE, \
370 "tooltip": "SWU capacity (kgSWU/timestep)", \
371 "uilabel": "SWU Capacity", \
372 "uitype": "range", \
373 "range": [0.0, CY_LARGE_DOUBLE], \
374 "doc": "separative work unit (SWU) capacity of enrichment " \
375 "facility (kgSWU/timestep) " \
376 }
377 double swu_capacity;
378
380
381 #pragma cyclus var { 'capacity': 'max_feed_inventory' }
382 cyclus::toolkit::ResBuf<cyclus::Material> inventory; // natural u
383 #pragma cyclus var {}
384 cyclus::toolkit::ResBuf<cyclus::Material> tails; // depleted u
385
386 // used to total intra-timestep swu and natu usage for meeting requests -
387 // these help enable time series generation.
388 double intra_timestep_swu_;
390
391 friend class EnrichmentTest;
392 // ---
393
394};
395
396} // namespace cycamore
397
398#endif // CYCAMORE_SRC_ENRICHMENT_FACILITY_H_
#define CYCAMORE_VERSION
void SwuCapacity(double capacity)
cyclus::Material::Ptr Enrich_(cyclus::Material::Ptr mat, double qty)
cyclus::Material::Ptr Offer_(cyclus::Material::Ptr req)
Generates a material offer for a given request.
void SetMaxInventorySize(double size)
virtual void EnterNotify()
virtual void Tock()
Each facility is prompted to its end-of-time-step stuff on the tock of the timer.
const cyclus::toolkit::ResBuf< cyclus::Material > & Tails() const
cyclus::toolkit::ResBuf< cyclus::Material > tails
bool ValidReq(const cyclus::Material::Ptr mat)
Determines if a particular material is a valid request to respond to.
virtual std::set< cyclus::RequestPortfolio< cyclus::Material >::Ptr > GetMatlRequests()
The Enrichment request Materials of its given commodity.
cyclus::Material::Ptr Request_()
generates a request for this facility given its current state.
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...
double SwuCapacity() const
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.
double FeedAssay()
calculates the feed assay based on the unenriched inventory
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 void Tick()
Each facility is prompted to do its beginning-of-time-step stuff at the tick of the timer.
virtual std::string str()
Print information about this agent.
void RecordEnrichment_(double natural_u, double swu)
records and enrichment with the cyclus::Recorder
virtual std::string version()
virtual ~Enrichment()
Destructor for the Enrichment class.
virtual void Build(cyclus::Agent *parent)
perform module-specific tasks when entering the simulation
Enrichment(cyclus::Context *ctx)
Constructor for the Enrichment class.
cyclus::toolkit::ResBuf< cyclus::Material > inventory
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...
void AddMat_(cyclus::Material::Ptr mat)
adds a material into the natural uranium inventory
virtual std::string version()
virtual bool operator==(Converter &other) const
NatUConverter(double feed_commod, double tails)
virtual double convert(cyclus::Material::Ptr m, cyclus::Arc const *a=NULL, cyclus::ExchangeTranslationContext< cyclus::Material > const *ctx=NULL) const
provides a conversion for the amount of natural Uranium required
The SWUConverter is a simple Converter class for material to determine the amount of SWU required for...
virtual double convert(cyclus::Material::Ptr m, cyclus::Arc const *a=NULL, cyclus::ExchangeTranslationContext< cyclus::Material > const *ctx=NULL) const
provides a conversion for the SWU required
SWUConverter(double feed_commod, double tails)
virtual bool operator==(Converter &other) const