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::UraniumAssay(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::UraniumAssay(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 : public cyclus::Facility {
119 #pragma cyclus note { \
120  "niche": "enrichment facility", \
121  "doc": \
122  "The Enrichment facility is a simple agent that enriches natural " \
123  "uranium in a Cyclus simulation. It does not explicitly compute " \
124  "the physical enrichment process, rather it calculates the SWU " \
125  "required to convert an source uranium recipe (i.e. natural uranium) " \
126  "into a requested enriched recipe (i.e. 4% enriched uranium), given " \
127  "the natural uranium inventory constraint and its SWU capacity " \
128  "constraint." \
129  "\n\n" \
130  "The Enrichment facility requests an input commodity and associated " \
131  "recipe whose quantity is its remaining inventory capacity. All " \
132  "facilities trading the same input commodity (even with different " \
133  "recipes) will offer materials for trade. The Enrichment facility " \
134  "accepts any input materials with enrichments less than its tails assay, "\
135  "as long as some U235 is present, and preference increases with U235 " \
136  "content. If no U235 is present in the offered material, the trade " \
137  "preference is set to -1 and the material is not accepted. Any material " \
138  "components other than U235 and U238 are sent directly to the tails buffer."\
139  "\n\n" \
140  "The Enrichment facility will bid on any request for its output commodity "\
141  "up to the maximum allowed enrichment (if not specified, default is 100%) "\
142  "It bids on either the request quantity, or the maximum quanity allowed " \
143  "by its SWU constraint or natural uranium inventory, whichever is lower. " \
144  "If multiple output commodities with different enrichment levels are " \
145  "requested and the facility does not have the SWU or quantity capacity " \
146  "to meet all requests, the requests are fully, then partially filled " \
147  "in unspecified but repeatable order." \
148  "\n\n" \
149  "Accumulated tails inventory is offered for trading as a specifiable " \
150  "output commodity.", \
151 }
152  public:
153  // --- Module Members ---
156  Enrichment(cyclus::Context* ctx);
157 
159  virtual ~Enrichment();
160 
161  virtual std::string version() { return CYCAMORE_VERSION; }
162 
163  #pragma cyclus
164 
166  virtual std::string str();
167  // ---
168 
169  // --- Facility Members ---
171  virtual void Build(cyclus::Agent* parent);
172  // ---
173 
174  // --- Agent Members ---
177 
179  virtual void Tick();
180 
183 
185  virtual void Tock();
186 
189  virtual std::set<cyclus::RequestPortfolio<cyclus::Material>::Ptr>
190  GetMatlRequests();
191 
195  virtual void AdjustMatlPrefs(cyclus::PrefMap<cyclus::Material>::type& prefs);
196 
199  virtual void AcceptMatlTrades(
200  const std::vector< std::pair<cyclus::Trade<cyclus::Material>,
201  cyclus::Material::Ptr> >& responses);
202 
206  virtual std::set<cyclus::BidPortfolio<cyclus::Material>::Ptr>
207  GetMatlBids(cyclus::CommodMap<cyclus::Material>::type&
208  commod_requests);
209 
215  virtual void GetMatlTrades(
216  const std::vector< cyclus::Trade<cyclus::Material> >& trades,
217  std::vector<std::pair<cyclus::Trade<cyclus::Material>,
218  cyclus::Material::Ptr> >& responses);
219  // ---
220 
225  bool ValidReq(const cyclus::Material::Ptr mat);
226 
227  inline void SetMaxInventorySize(double size) {
228  max_feed_inventory = size;
229  inventory.capacity(size);
230  }
231 
232  inline void SwuCapacity(double capacity) {
233  swu_capacity = capacity;
234  current_swu_capacity = swu_capacity;
235  }
236 
237  inline double SwuCapacity() const { return swu_capacity; }
238 
239  inline const cyclus::toolkit::ResBuf<cyclus::Material>& Tails() const {
240  return tails;
241  }
242 
243  private:
246  void AddMat_(cyclus::Material::Ptr mat);
247 
250  cyclus::Material::Ptr Request_();
251 
258  cyclus::Material::Ptr Offer_(cyclus::Material::Ptr req);
259 
260  cyclus::Material::Ptr Enrich_(cyclus::Material::Ptr mat, double qty);
261 
263  double FeedAssay();
264 
266  void RecordEnrichment_(double natural_u, double swu);
267 
268  #pragma cyclus var { \
269  "tooltip": "feed commodity", \
270  "doc": "feed commodity that the enrichment facility accepts", \
271  "uilabel": "Feed Commodity", \
272  "uitype": "incommodity" \
273  }
274  std::string feed_commod;
275 
276  #pragma cyclus var { \
277  "tooltip": "feed recipe", \
278  "doc": "recipe for enrichment facility feed commodity", \
279  "uilabel": "Feed Recipe", \
280  "uitype": "recipe" \
281  }
282  std::string feed_recipe;
283 
284  #pragma cyclus var { \
285  "tooltip": "product commodity", \
286  "doc": "product commodity that the enrichment facility generates", \
287  "uilabel": "Product Commodity", \
288  "uitype": "outcommodity" \
289  }
290  std::string product_commod;
291 
292  #pragma cyclus var { \
293  "tooltip": "tails commodity", \
294  "doc": "tails commodity supplied by enrichment facility", \
295  "uilabel": "Tails Commodity", \
296  "uitype": "outcommodity" \
297  }
298  std::string tails_commod;
299 
300  #pragma cyclus var { \
301  "default": 0.003, "tooltip": "tails assay", \
302  "uilabel": "Tails Assay", \
303  "doc": "tails assay from the enrichment process", \
304  }
305  double tails_assay;
306 
307  #pragma cyclus var { \
308  "default": 0, "tooltip": "initial uranium reserves (kg)", \
309  "uilabel": "Initial Feed Inventory", \
310  "doc": "amount of natural uranium stored at the enrichment " \
311  "facility at the beginning of the simulation (kg)" \
312  }
313  double initial_feed;
314 
315  #pragma cyclus var { \
316  "default": 1e299, "tooltip": "max inventory of feed material (kg)", \
317  "uilabel": "Maximum Feed Inventory", \
318  "uitype": "range", \
319  "range": [0.0, 1e299], \
320  "doc": "maximum total inventory of natural uranium in " \
321  "the enrichment facility (kg)" \
322  }
323  double max_feed_inventory;
324 
325  #pragma cyclus var { \
326  "default": 1.0, \
327  "tooltip": "maximum allowed enrichment fraction", \
328  "doc": "maximum allowed weight fraction of U235 in product", \
329  "uilabel": "Maximum Allowed Enrichment", \
330  "schema": '<optional>' \
331  ' <element name="max_enrich">' \
332  ' <data type="double">' \
333  ' <param name="minInclusive">0</param>' \
334  ' <param name="maxInclusive">1</param>' \
335  ' </data>' \
336  ' </element>' \
337  ' </optional>' \
338  }
339  double max_enrich;
340 
341  #pragma cyclus var { \
342  "default": 1, \
343  "userlevel": 10, \
344  "tooltip": "Rank Material Requests by U235 Content", \
345  "uilabel": "Prefer feed with higher U235 content", \
346  "doc": "turn on preference ordering for input material " \
347  "so that EF chooses higher U235 content first" \
348  }
349  bool order_prefs;
350 
351  #pragma cyclus var { \
352  "default": 1e299, \
353  "tooltip": "SWU capacity (kgSWU/month)", \
354  "uilabel": "SWU Capacity", \
355  "uitype": "range", \
356  "range": [0.0, 1e299], \
357  "doc": "separative work unit (SWU) capacity of enrichment " \
358  "facility (kgSWU/timestep) " \
359  }
360  double swu_capacity;
361 
362  double current_swu_capacity;
363 
364  #pragma cyclus var { 'capacity': 'max_feed_inventory' }
365  cyclus::toolkit::ResBuf<cyclus::Material> inventory; // natural u
366  #pragma cyclus var {}
367  cyclus::toolkit::ResBuf<cyclus::Material> tails; // depleted u
368 
369  // used to total intra-timestep swu and natu usage for meeting requests -
370  // these help enable time series generation.
371  double intra_timestep_swu_;
372  double intra_timestep_feed_;
373 
374  friend class EnrichmentTest;
375  // ---
376 };
377 
378 } // namespace cycamore
379 
380 #endif // CYCAMORE_SRC_ENRICHMENT_FACILITY_H_
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
void SetMaxInventorySize(double size)
SWUConverter(double feed_commod, double tails)
The NatUConverter is a simple Converter class for material to determine the amount of natural uranium...
virtual bool operator==(Converter &other) const
cycamore::GrowthRegion string
void SwuCapacity(double capacity)
const cyclus::toolkit::ResBuf< cyclus::Material > & Tails() const
NatUConverter(double feed_commod, double tails)
virtual bool operator==(Converter &other) const
double SwuCapacity() const
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 std::string version()
virtual std::string version()
The Enrichment facility is a simple Agent that enriches natural uranium in a Cyclus simulation...
The SWUConverter is a simple Converter class for material to determine the amount of SWU required for...