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 std::string version() { return CYCAMORE_VERSION; }
170
171 #pragma cyclus
172
174 virtual std::string str();
175 // ---
176
177 // --- Facility Members ---
179 virtual void Build(cyclus::Agent* parent);
180 // ---
181
182 // --- Agent Members ---
185
187 virtual void Tick();
188
191
193 virtual void Tock();
194
197 virtual std::set<cyclus::RequestPortfolio<cyclus::Material>::Ptr>
199
203 virtual void AdjustMatlPrefs(cyclus::PrefMap<cyclus::Material>::type& prefs);
204
207 virtual void AcceptMatlTrades(
208 const std::vector< std::pair<cyclus::Trade<cyclus::Material>,
209 cyclus::Material::Ptr> >& responses);
210
214 virtual std::set<cyclus::BidPortfolio<cyclus::Material>::Ptr>
215 GetMatlBids(cyclus::CommodMap<cyclus::Material>::type&
216 commod_requests);
217
223 virtual void GetMatlTrades(
224 const std::vector< cyclus::Trade<cyclus::Material> >& trades,
225 std::vector<std::pair<cyclus::Trade<cyclus::Material>,
226 cyclus::Material::Ptr> >& responses);
227 // ---
228
233 bool ValidReq(const cyclus::Material::Ptr mat);
234
235 inline void SetMaxInventorySize(double size) {
236 max_feed_inventory = size;
237 inventory.capacity(size);
238 }
239
240 inline void SwuCapacity(double capacity) {
241 swu_capacity = capacity;
243 }
244
245 inline double SwuCapacity() const { return swu_capacity; }
246
247 inline const cyclus::toolkit::ResBuf<cyclus::Material>& Tails() const {
248 return tails;
249 }
250
251 private:
254 void AddMat_(cyclus::Material::Ptr mat);
255
258 cyclus::Material::Ptr Request_();
259
266 cyclus::Material::Ptr Offer_(cyclus::Material::Ptr req);
267
268 cyclus::Material::Ptr Enrich_(cyclus::Material::Ptr mat, double qty);
269
271 double FeedAssay();
272
274 void RecordEnrichment_(double natural_u, double swu);
275
278
279 #pragma cyclus var { \
280 "tooltip": "feed commodity", \
281 "doc": "feed commodity that the enrichment facility accepts", \
282 "uilabel": "Feed Commodity", \
283 "uitype": "incommodity" \
284 }
285 std::string feed_commod;
286
287 #pragma cyclus var { \
288 "tooltip": "feed recipe", \
289 "doc": "recipe for enrichment facility feed commodity", \
290 "uilabel": "Feed Recipe", \
291 "uitype": "inrecipe" \
292 }
293 std::string feed_recipe;
294
295 #pragma cyclus var { \
296 "tooltip": "product commodity", \
297 "doc": "product commodity that the enrichment facility generates", \
298 "uilabel": "Product Commodity", \
299 "uitype": "outcommodity" \
300 }
301 std::string product_commod;
302
303 #pragma cyclus var { \
304 "tooltip": "tails commodity", \
305 "doc": "tails commodity supplied by enrichment facility", \
306 "uilabel": "Tails Commodity", \
307 "uitype": "outcommodity" \
308 }
309 std::string tails_commod;
310
311 #pragma cyclus var { \
312 "default": 0.003, "tooltip": "tails assay", \
313 "uilabel": "Tails Assay", \
314 "uitype": "range", \
315 "range": [0.0, 0.003], \
316 "doc": "tails assay from the enrichment process", \
317 }
318 double tails_assay;
319
320 #pragma cyclus var { \
321 "default": 0, "tooltip": "initial uranium reserves (kg)", \
322 "uilabel": "Initial Feed Inventory", \
323 "doc": "amount of natural uranium stored at the enrichment " \
324 "facility at the beginning of the simulation (kg)" \
325 }
326 double initial_feed;
327
328 #pragma cyclus var { \
329 "default": CY_LARGE_DOUBLE, "tooltip": "max inventory of feed material (kg)", \
330 "uilabel": "Maximum Feed Inventory", \
331 "uitype": "range", \
332 "range": [0.0, CY_LARGE_DOUBLE], \
333 "doc": "maximum total inventory of natural uranium in " \
334 "the enrichment facility (kg)" \
335 }
336 double max_feed_inventory;
337
338 #pragma cyclus var { \
339 "default": 1.0, \
340 "tooltip": "maximum allowed enrichment fraction", \
341 "doc": "maximum allowed weight fraction of U235 in product", \
342 "uilabel": "Maximum Allowed Enrichment", \
343 "uitype": "range", \
344 "range": [0.0,1.0], \
345 "schema": '<optional>' \
346 ' <element name="max_enrich">' \
347 ' <data type="double">' \
348 ' <param name="minInclusive">0</param>' \
349 ' <param name="maxInclusive">1</param>' \
350 ' </data>' \
351 ' </element>' \
352 ' </optional>' \
353 }
354 double max_enrich;
355
356 #pragma cyclus var { \
357 "default": 1, \
358 "userlevel": 10, \
359 "tooltip": "Rank Material Requests by U235 Content", \
360 "uilabel": "Prefer feed with higher U235 content", \
361 "doc": "turn on preference ordering for input material " \
362 "so that EF chooses higher U235 content first" \
363 }
364 bool order_prefs;
365
366 #pragma cyclus var { \
367 "default": CY_LARGE_DOUBLE, \
368 "tooltip": "SWU capacity (kgSWU/timestep)", \
369 "uilabel": "SWU Capacity", \
370 "uitype": "range", \
371 "range": [0.0, CY_LARGE_DOUBLE], \
372 "doc": "separative work unit (SWU) capacity of enrichment " \
373 "facility (kgSWU/timestep) " \
374 }
375 double swu_capacity;
376
378
379 #pragma cyclus var { 'capacity': 'max_feed_inventory' }
380 cyclus::toolkit::ResBuf<cyclus::Material> inventory; // natural u
381 #pragma cyclus var {}
382 cyclus::toolkit::ResBuf<cyclus::Material> tails; // depleted u
383
384 // used to total intra-timestep swu and natu usage for meeting requests -
385 // these help enable time series generation.
386 double intra_timestep_swu_;
388
389 friend class EnrichmentTest;
390 // ---
391
392 #pragma cyclus var { \
393 "default": 0.0, \
394 "uilabel": "Geographical latitude in degrees as a double", \
395 "doc": "Latitude of the agent's geographical position. The value should " \
396 "be expressed in degrees as a double." \
397 }
398 double latitude;
399
400 #pragma cyclus var { \
401 "default": 0.0, \
402 "uilabel": "Geographical longitude in degrees as a double", \
403 "doc": "Longitude of the agent's geographical position. The value should " \
404 "be expressed in degrees as a double." \
405 }
406 double longitude;
407
408 cyclus::toolkit::Position coordinates;
409};
410
411} // namespace cycamore
412
413#endif // CYCAMORE_SRC_ENRICHMENT_FACILITY_H_
#define CYCAMORE_VERSION
void RecordPosition()
Records an agent's latitude and longitude to the output db.
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 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.
cyclus::toolkit::Position coordinates
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
The NatUConverter is a simple Converter class for material to determine the amount of natural uranium...
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