CYCAMORE
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 namespace cycamore {
10 
15 class SWUConverter : public cyclus::Converter<cyclus::Material> {
16  public:
17  SWUConverter(double feed_commod, double tails) : feed_(feed_commod),
18  tails_(tails) {}
19  virtual ~SWUConverter() {}
20 
22  virtual double convert(
23  cyclus::Material::Ptr m,
24  cyclus::Arc const * a = NULL,
25  cyclus::ExchangeTranslationContext<cyclus::Material>
26  const * ctx = NULL) const {
27  cyclus::toolkit::Assays assays(feed_, cyclus::toolkit::UraniumAssayMass(m),
28  tails_);
29  return cyclus::toolkit::SwuRequired(m->quantity(), assays);
30  }
31 
33  virtual bool operator==(Converter& other) const {
34  SWUConverter* cast = dynamic_cast<SWUConverter*>(&other);
35  return cast != NULL &&
36  feed_ == cast->feed_ &&
37  tails_ == cast->tails_;
38  }
39 
40  private:
41  double feed_, tails_;
42 };
43 
49 class NatUConverter : public cyclus::Converter<cyclus::Material> {
50  public:
51  NatUConverter(double feed_commod, double tails) : feed_(feed_commod),
52  tails_(tails) {}
53  virtual ~NatUConverter() {}
54 
55  virtual std::string version() { return CYCAMORE_VERSION; }
56 
58  virtual double convert(
59  cyclus::Material::Ptr m,
60  cyclus::Arc const * a = NULL,
61  cyclus::ExchangeTranslationContext<cyclus::Material>
62  const * ctx = NULL) const {
63  cyclus::toolkit::Assays assays(feed_, cyclus::toolkit::UraniumAssayMass(m),
64  tails_);
65  cyclus::toolkit::MatQuery mq(m);
66  std::set<cyclus::Nuc> nucs;
67  nucs.insert(922350000);
68  nucs.insert(922380000);
69 
70  double natu_frac = mq.mass_frac(nucs);
71  double natu_req = cyclus::toolkit::FeedQty(m->quantity(), assays);
72  return natu_req / natu_frac;
73  }
74 
76  virtual bool operator==(Converter& other) const {
77  NatUConverter* cast = dynamic_cast<NatUConverter*>(&other);
78  return cast != NULL &&
79  feed_ == cast->feed_ &&
80  tails_ == cast->tails_;
81  }
82 
83  private:
84  double feed_, tails_;
85 };
86 
117 
118 class Enrichment
119  : public cyclus::Facility,
120  public cyclus::toolkit::Position {
121 #pragma cyclus note { \
122  "niche": "enrichment facility", \
123  "doc": \
124  "The Enrichment facility is a simple agent that enriches natural " \
125  "uranium in a Cyclus simulation. It does not explicitly compute " \
126  "the physical enrichment process, rather it calculates the SWU " \
127  "required to convert an source uranium recipe (i.e. natural uranium) " \
128  "into a requested enriched recipe (i.e. 4% enriched uranium), given " \
129  "the natural uranium inventory constraint and its SWU capacity " \
130  "constraint." \
131  "\n\n" \
132  "The Enrichment facility requests an input commodity and associated " \
133  "recipe whose quantity is its remaining inventory capacity. All " \
134  "facilities trading the same input commodity (even with different " \
135  "recipes) will offer materials for trade. The Enrichment facility " \
136  "accepts any input materials with enrichments less than its tails assay, "\
137  "as long as some U235 is present, and preference increases with U235 " \
138  "content. If no U235 is present in the offered material, the trade " \
139  "preference is set to -1 and the material is not accepted. Any material " \
140  "components other than U235 and U238 are sent directly to the tails buffer."\
141  "\n\n" \
142  "The Enrichment facility will bid on any request for its output commodity "\
143  "up to the maximum allowed enrichment (if not specified, default is 100%) "\
144  "It bids on either the request quantity, or the maximum quanity allowed " \
145  "by its SWU constraint or natural uranium inventory, whichever is lower. " \
146  "If multiple output commodities with different enrichment levels are " \
147  "requested and the facility does not have the SWU or quantity capacity " \
148  "to meet all requests, the requests are fully, then partially filled " \
149  "in unspecified but repeatable order." \
150  "\n\n" \
151  "Accumulated tails inventory is offered for trading as a specifiable " \
152  "output commodity.", \
153 }
154  public:
155  // --- Module Members ---
158  Enrichment(cyclus::Context* ctx);
159 
161  virtual ~Enrichment();
162 
163  virtual std::string version() { return CYCAMORE_VERSION; }
164 
165  #pragma cyclus
166 
168  virtual std::string str();
169  // ---
170 
171  // --- Facility Members ---
173  virtual void Build(cyclus::Agent* parent);
174  // ---
175 
176  // --- Agent Members ---
179 
181  virtual void Tick();
182 
185 
187  virtual void Tock();
188 
191  virtual std::set<cyclus::RequestPortfolio<cyclus::Material>::Ptr>
192  GetMatlRequests();
193 
197  virtual void AdjustMatlPrefs(cyclus::PrefMap<cyclus::Material>::type& prefs);
198 
201  virtual void AcceptMatlTrades(
202  const std::vector< std::pair<cyclus::Trade<cyclus::Material>,
203  cyclus::Material::Ptr> >& responses);
204 
208  virtual std::set<cyclus::BidPortfolio<cyclus::Material>::Ptr>
209  GetMatlBids(cyclus::CommodMap<cyclus::Material>::type&
210  commod_requests);
211 
217  virtual void GetMatlTrades(
218  const std::vector< cyclus::Trade<cyclus::Material> >& trades,
219  std::vector<std::pair<cyclus::Trade<cyclus::Material>,
220  cyclus::Material::Ptr> >& responses);
221  // ---
222 
227  bool ValidReq(const cyclus::Material::Ptr mat);
228 
229  inline void SetMaxInventorySize(double size) {
230  max_feed_inventory = size;
231  inventory.capacity(size);
232  }
233 
234  inline void SwuCapacity(double capacity) {
235  swu_capacity = capacity;
236  current_swu_capacity = swu_capacity;
237  }
238 
239  inline double SwuCapacity() const { return swu_capacity; }
240 
241  inline const cyclus::toolkit::ResBuf<cyclus::Material>& Tails() const {
242  return tails;
243  }
244 
245  private:
248  void AddMat_(cyclus::Material::Ptr mat);
249 
252  cyclus::Material::Ptr Request_();
253 
260  cyclus::Material::Ptr Offer_(cyclus::Material::Ptr req);
261 
262  cyclus::Material::Ptr Enrich_(cyclus::Material::Ptr mat, double qty);
263 
265  double FeedAssay();
266 
268  void RecordEnrichment_(double natural_u, double swu);
269 
271  void RecordPosition();
272 
273  #pragma cyclus var { \
274  "tooltip": "feed commodity", \
275  "doc": "feed commodity that the enrichment facility accepts", \
276  "uilabel": "Feed Commodity", \
277  "uitype": "incommodity" \
278  }
279  std::string feed_commod;
280 
281  #pragma cyclus var { \
282  "tooltip": "feed recipe", \
283  "doc": "recipe for enrichment facility feed commodity", \
284  "uilabel": "Feed Recipe", \
285  "uitype": "inrecipe" \
286  }
287  std::string feed_recipe;
288 
289  #pragma cyclus var { \
290  "tooltip": "product commodity", \
291  "doc": "product commodity that the enrichment facility generates", \
292  "uilabel": "Product Commodity", \
293  "uitype": "outcommodity" \
294  }
295  std::string product_commod;
296 
297  #pragma cyclus var { \
298  "tooltip": "tails commodity", \
299  "doc": "tails commodity supplied by enrichment facility", \
300  "uilabel": "Tails Commodity", \
301  "uitype": "outcommodity" \
302  }
303  std::string tails_commod;
304 
305  #pragma cyclus var { \
306  "default": 0.003, "tooltip": "tails assay", \
307  "uilabel": "Tails Assay", \
308  "uitype": "range", \
309  "range": [0.0, 0.003], \
310  "doc": "tails assay from the enrichment process", \
311  }
312  double tails_assay;
313 
314  #pragma cyclus var { \
315  "default": 0, "tooltip": "initial uranium reserves (kg)", \
316  "uilabel": "Initial Feed Inventory", \
317  "doc": "amount of natural uranium stored at the enrichment " \
318  "facility at the beginning of the simulation (kg)" \
319  }
320  double initial_feed;
321 
322  #pragma cyclus var { \
323  "default": 1e299, "tooltip": "max inventory of feed material (kg)", \
324  "uilabel": "Maximum Feed Inventory", \
325  "uitype": "range", \
326  "range": [0.0, 1e299], \
327  "doc": "maximum total inventory of natural uranium in " \
328  "the enrichment facility (kg)" \
329  }
330  double max_feed_inventory;
331 
332  #pragma cyclus var { \
333  "default": 1.0, \
334  "tooltip": "maximum allowed enrichment fraction", \
335  "doc": "maximum allowed weight fraction of U235 in product", \
336  "uilabel": "Maximum Allowed Enrichment", \
337  "uitype": "range", \
338  "range": [0.0,1.0], \
339  "schema": '<optional>' \
340  ' <element name="max_enrich">' \
341  ' <data type="double">' \
342  ' <param name="minInclusive">0</param>' \
343  ' <param name="maxInclusive">1</param>' \
344  ' </data>' \
345  ' </element>' \
346  ' </optional>' \
347  }
348  double max_enrich;
349 
350  #pragma cyclus var { \
351  "default": 1, \
352  "userlevel": 10, \
353  "tooltip": "Rank Material Requests by U235 Content", \
354  "uilabel": "Prefer feed with higher U235 content", \
355  "doc": "turn on preference ordering for input material " \
356  "so that EF chooses higher U235 content first" \
357  }
358  bool order_prefs;
359 
360  #pragma cyclus var { \
361  "default": 1e299, \
362  "tooltip": "SWU capacity (kgSWU/month)", \
363  "uilabel": "SWU Capacity", \
364  "uitype": "range", \
365  "range": [0.0, 1e299], \
366  "doc": "separative work unit (SWU) capacity of enrichment " \
367  "facility (kgSWU/timestep) " \
368  }
369  double swu_capacity;
370 
371  double current_swu_capacity;
372 
373  #pragma cyclus var { 'capacity': 'max_feed_inventory' }
374  cyclus::toolkit::ResBuf<cyclus::Material> inventory; // natural u
375  #pragma cyclus var {}
376  cyclus::toolkit::ResBuf<cyclus::Material> tails; // depleted u
377 
378  // used to total intra-timestep swu and natu usage for meeting requests -
379  // these help enable time series generation.
380  double intra_timestep_swu_;
381  double intra_timestep_feed_;
382 
383  friend class EnrichmentTest;
384  // ---
385 
386  #pragma cyclus var { \
387  "default": 0.0, \
388  "uilabel": "Geographical latitude in degrees as a double", \
389  "doc": "Latitude of the agent's geographical position. The value should " \
390  "be expressed in degrees as a double." \
391  }
392  double latitude;
393 
394  #pragma cyclus var { \
395  "default": 0.0, \
396  "uilabel": "Geographical longitude in degrees as a double", \
397  "doc": "Longitude of the agent's geographical position. The value should " \
398  "be expressed in degrees as a double." \
399  }
400  double longitude;
401 
402  cyclus::toolkit::Position coordinates;
403 };
404 
405 } // namespace cycamore
406 
407 #endif // CYCAMORE_SRC_ENRICHMENT_FACILITY_H_
virtual bool operator==(Converter &other) const
void SetMaxInventorySize(double size)
double longitude
SWUConverter(double feed_commod, double tails)
The NatUConverter is a simple Converter class for material to determine the amount of natural uranium...
const cyclus::toolkit::ResBuf< cyclus::Material > & Tails() const
cycamore::GrowthRegion string
void SwuCapacity(double capacity)
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
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
virtual bool operator==(Converter &other) const
NatUConverter(double feed_commod, double tails)
cyclus::toolkit::Position coordinates
virtual std::string version()
virtual std::string version()
The Enrichment facility is a simple Agent that enriches natural uranium in a Cyclus simulation...
void RecordPosition()
Records an agent&#39;s latitude and longitude to the output db.
double SwuCapacity() const
The SWUConverter is a simple Converter class for material to determine the amount of SWU required for...