commodconverter
 All Classes Namespaces Files Functions Variables Macros
build/CommodConverter/commodconverter.h
Go to the documentation of this file.
1 
2 #line 1 "/Users/khuff/repos/cyclus/commodconverter/src/commodconverter.h"
3 #ifndef CYCLUS_COMMODCONVERTERS_COMMODCONVERTER_H_
4 #define CYCLUS_COMMODCONVERTERS_COMMODCONVERTER_H_
5 
6 #include <string>
7 
8 #include "cyclus.h"
9 
10 // forward declaration
11 namespace commodconverter {
12 class CommodConverter;
13 } // namespace commodconverter
14 
15 
16 namespace commodconverter {
17 /// @class CommodConverter
18 ///
19 /// This Facility is intended to convert a resource from one commodity to
20 /// another. It also has an optional delay parameter. It can therefore be used
21 /// quite easily as a storage facility.
22 /// The CommodConverter class inherits from the Facility class and is
23 /// dynamically loaded by the Agent class when requested.
24 ///
25 /// @section intro Introduction
26 /// This Agent was initially developed to support the fco code-to-code
27 /// comparsion.
28 /// It's very similar to the "NullFacility" of years
29 /// past. Its purpose is to convert a commodity from one commodity to another
30 /// after some period of delay time. This facility is very good for use as a
31 /// storage facility or fuel fabrication.
32 ///
33 /// @section agentparams Agent Parameters
34 /// in_commod is a string naming the commodity that this facility recieves
35 /// out_commod is a string naming the commodity that in_commod is stocks into
36 /// process_time is the number of timesteps between receiving and offering
37 /// in_recipe (optional) describes the incoming resource by recipe
38 /// out_recipe (optional) describes the outgoing resource by recipe
39 ///
40 /// @section optionalparams Optional Parameters
41 /// max_inv_size is the maximum capacity of the inventory storage
42 /// capacity is the maximum processing capacity per timestep
43 ///
44 /// @section detailed Detailed Behavior
45 ///
46 /// Tick:
47 /// Nothing really happens on the tick.
48 ///
49 /// Tock:
50 /// On the tock, any material that has been waiting for long enough (delay
51 /// time) is stocks and placed in the stocks buffer.
52 ///
53 /// Any brand new inventory that was received in this timestep is placed into
54 /// the processing queue to begin waiting.
55 ///
56 /// Making Requests:
57 /// This facility requests all of the in_commod that it can.
58 ///
59 /// Receiving Resources:
60 /// Anything of the in_commod that is received by this facility goes into the
61 /// inventory.
62 ///
63 /// Making Offers:
64 /// Any stocks material in the stocks buffer is offered to the market.
65 ///
66 /// Sending Resources:
67 /// Matched resources are sent immediately.
69  : public cyclus::Facility,
70  public cyclus::toolkit::CommodityProducer {
71  public:
72  /// Constructor for CommodConverter Class
73  /// @param ctx the cyclus context for access to simulation-wide parameters
74  CommodConverter(cyclus::Context* ctx);
75 
76  /// The Prime Directive
77  /// Generates code that handles all input file reading and restart operations
78  /// (e.g., reading from the database, instantiating a new object, etc.).
79  /// @warning The Prime Directive must have a space before it! (A fix will be
80  /// in 2.0 ^TM)
81 #line 81 "/Users/khuff/repos/cyclus/commodconverter/src/commodconverter.h"
82 
84 
85  virtual void InitFrom(cyclus::QueryableBackend* b);
86 
87  virtual void InfileToDb(cyclus::InfileTree* tree, cyclus::DbInit di);
88 
89  virtual cyclus::Agent* Clone();
90 
91  virtual std::string schema();
92 
93  virtual Json::Value annotations();
94 
95  virtual void InitInv(cyclus::Inventories& inv);
96 
97  virtual cyclus::Inventories SnapshotInv();
98 
99  virtual void Snapshot(cyclus::DbInit di);
100 
101  #pragma cyclus note {"doc": "A commodconverter facility converts from one " "commodity to another, with an optional delay."}
102 #line 84 "/Users/khuff/repos/cyclus/commodconverter/src/commodconverter.h"
103 
104  /// A verbose printer for the CommodConverter
105  virtual std::string str();
106 
107  // --- Facility Members ---
108 
109  // --- Agent Members ---
110  virtual void EnterNotify();
111 
112  /// The handleTick function specific to the CommodConverter.
113  /// @param time the time of the tick
114  virtual void Tick();
115 
116  /// The handleTick function specific to the CommodConverter.
117  /// @param time the time of the tock
118  virtual void Tock();
119 
120  /// @brief The CommodConverter request Materials of its given
121  /// commodity.
122  virtual std::set<cyclus::RequestPortfolio<cyclus::Material>::Ptr> GetMatlRequests();
123 
124  /// @brief The CommodConverter place accepted trade Materials in their
125  /// Inventory
126  virtual void AcceptMatlTrades(
127  const std::vector< std::pair<cyclus::Trade<cyclus::Material>,
128  cyclus::Material::Ptr> >& responses);
129 
130  /// @brief Responds to each request for this facility's commodity. If a given
131  /// request is more than this facility's inventory capacity, it will
132  /// offer its minimum of its capacities.
133  virtual std::set<cyclus::BidPortfolio<cyclus::Material>::Ptr>
134  GetMatlBids(cyclus::CommodMap<cyclus::Material>::type&
135  commod_requests);
136 
137  /// @brief respond to each trade with a material of out_commod and out_recipe
138  ///
139  /// @param trades all trades in which this trader is the supplier
140  /// @param responses a container to populate with responses to each trade
141  virtual void GetMatlTrades(
142  const std::vector< cyclus::Trade<cyclus::Material> >& trades,
143  std::vector<std::pair<cyclus::Trade<cyclus::Material>,
144  cyclus::Material::Ptr> >& responses);/* --- *//* --- CommodConverter Members --- *//* --- */
145 #line 132 "/Users/khuff/repos/cyclus/commodconverter/src/commodconverter.h"
146 
147  protected:
148  /// @brief adds a material into the incoming commodity inventory
149  /// @param mat the material to add to the incoming inventory.
150  /// @throws if there is trouble with pushing to the inventory buffer.
151  void AddMat_(cyclus::Material::Ptr mat);
152 
153  /// @brief generates a request for this facility given its current state. The
154  /// quantity of the material will be equal to the remaining inventory size.
155  /// @return a material that this facility will request
156  cyclus::Material::Ptr Request_();
157 
158  /// @brief gathers information about bids
159  /// @param commod_requests the materials that have been requested
160  cyclus::BidPortfolio<cyclus::Material>::Ptr GetBids_(
161  cyclus::CommodMap<cyclus::Material>::type& commod_requests,
162  std::string commod,
163  cyclus::toolkit::ResourceBuff* buffer);
164 
165  /// @brief suggests, based on the buffer, a material response to an offer
166  cyclus::Material::Ptr TradeResponse_(
167  double qty,
168  cyclus::toolkit::ResourceBuff* buffer);
169 
170  /// @brief Move all unprocessed inventory to processing
171  void BeginProcessing_();
172 
173  /// @brief Convert one ready resource in processing
174  void Convert_();
175 
176  /// @brief this facility's commodity-recipe context
177  inline void crctx(const cyclus::toolkit::CommodityRecipeContext& crctx) {
178  crctx_ = crctx;
179  }
180 
181  inline cyclus::toolkit::CommodityRecipeContext crctx() const {
182  return crctx_;
183  }
184 
185  /// @brief returns the time key for ready materials
186  int ready(){ return context()->time() - process_time ; }/* --- Module Members --- */
187 #line 173 "/Users/khuff/repos/cyclus/commodconverter/src/commodconverter.h"
188 
189  #pragma cyclus var {"tooltip":"input commodity", "doc":"commodity accepted by this facility"}
190 #line 178 "/Users/khuff/repos/cyclus/commodconverter/src/commodconverter.h"
191  std::string in_commod;
192 
193  #pragma cyclus var {"tooltip":"output commodity", "doc":"commodity produced by this facility"}
194 #line 182 "/Users/khuff/repos/cyclus/commodconverter/src/commodconverter.h"
195  std::string out_commod;
196 
197  #pragma cyclus var {"default":"", "tooltip":"input recipe", "doc":"recipe accepted by this facility"}
198 #line 187 "/Users/khuff/repos/cyclus/commodconverter/src/commodconverter.h"
199  std::string in_recipe;
200 
201  #pragma cyclus var {"default":"", "tooltip":"output recipe", "doc":"recipe to be generated by this facility"}
202 #line 192 "/Users/khuff/repos/cyclus/commodconverter/src/commodconverter.h"
203  std::string out_recipe;
204 
205  #pragma cyclus var {"default": 0, "tooltip":"process time (timesteps)", "doc":"the time it takes to convert a received commodity (timesteps)."}
206 #line 197 "/Users/khuff/repos/cyclus/commodconverter/src/commodconverter.h"
208 
209  #pragma cyclus var {"default": 1e299, "tooltip":"maximum inventory size (kg)", "doc":"the amount of material that can be in storage at " "one time (kg)."}
210 #line 203 "/Users/khuff/repos/cyclus/commodconverter/src/commodconverter.h"
211  double max_inv_size;
212 
213  #pragma cyclus var{"default": 1e299, "tooltip":"capacity per timestep (kg)", "doc":"the maximumamount that can be processed per timestep (kg)"}
214 #line 208 "/Users/khuff/repos/cyclus/commodconverter/src/commodconverter.h"
215  double capacity;
216 
217  #pragma cyclus var{"default": 0, "tooltip":"cost per kg of production", "doc":"cost per kg of produced out_commod"}
218 #line 213 "/Users/khuff/repos/cyclus/commodconverter/src/commodconverter.h"
219  double cost;
220 
221  cyclus::toolkit::ResourceBuff inventory;
222  cyclus::toolkit::ResourceBuff stocks;
223 
224  /// @brief map from ready time to resource buffers
225  std::map<int, cyclus::toolkit::ResourceBuff> processing;
226 
227  cyclus::toolkit::CommodityRecipeContext crctx_;
228 
229  /// @brief the processing time required for a full process
230  inline void process_time_(int t) { process_time = t; }
231  inline int process_time_() const { return process_time; }
232 
233  /// @brief the maximum amount allowed in inventory
234  inline void max_inv_size_(double c) { max_inv_size = c; }
235  inline double max_inv_size_() const { return max_inv_size; }
236 
237  /// @brief the maximum amount processed per timestep
238  inline void capacity_(double c) { capacity = c; }
239  inline double capacity_() const { return capacity; }
240 
241  /// @brief the cost per unit out_commod
242  inline void cost_(double c) { cost = c; }
243  inline double cost_() const { return cost; }
244 
245  /// @brief the in commodity
246  inline void in_commod_(std::string c) { in_commod = c; }
247  inline std::string in_commod_() const { return in_commod; }
248 
249  /// @brief the out commodity
250  inline void out_commod_(std::string c) { out_commod = c; }
251  inline std::string out_commod_() const { return out_commod; }
252 
253  /// @brief the in recipe
254  inline void in_recipe_(std::string c) { in_recipe = c; }
255  inline std::string in_recipe_() const { return in_recipe; }
256 
257  /// @brief the out recipe
258  inline void out_recipe_(std::string c) { out_recipe = c; }
259  inline std::string out_recipe_() const { return out_recipe; }
260 
261  /// @brief current maximum amount that can be added to processing
262  inline double current_capacity() const {
263  return std::min(capacity, max_inv_size - inventory.quantity()); }
264 
265  friend class CommodConverterTest;
266 };
267 
268 } // namespace commodconverter
269 
270 #endif // CYCLUS_COMMODCONVERTERS_COMMODCONVERTER_H_
double current_capacity() const
current maximum amount that can be added to processing
void capacity_(double c)
the maximum amount processed per timestep
cyclus::BidPortfolio< cyclus::Material >::Ptr GetBids_(cyclus::CommodMap< cyclus::Material >::type &commod_requests, std::string commod, cyclus::toolkit::ResourceBuff *buffer)
gathers information about bids
virtual void InfileToDb(cyclus::InfileTree *tree, cyclus::DbInit di)
virtual void InitFrom(commodconverter::CommodConverter *m)
The Prime Directive Generates code that handles all input file reading and restart operations (e...
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 of out_commod and out_recipe
cyclus::toolkit::CommodityRecipeContext crctx_
cyclus::Material::Ptr TradeResponse_(double qty, cyclus::toolkit::ResourceBuff *buffer)
suggests, based on the buffer, a material response to an offer
virtual std::set< cyclus::RequestPortfolio< cyclus::Material >::Ptr > GetMatlRequests()
The CommodConverter request Materials of its given commodity.
void Convert_()
Convert one ready resource in processing.
void in_commod_(std::string c)
the in commodity
virtual void AcceptMatlTrades(const std::vector< std::pair< cyclus::Trade< cyclus::Material >, cyclus::Material::Ptr > > &responses)
The CommodConverter place accepted trade Materials in their Inventory.
cyclus::toolkit::CommodityRecipeContext crctx() const
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.
void BeginProcessing_()
Move all unprocessed inventory to processing.
virtual std::string str()
A verbose printer for the CommodConverter.
virtual void Tock()
The handleTick function specific to the CommodConverter.
void cost_(double c)
the cost per unit out_commod
void process_time_(int t)
the processing time required for a full process
void AddMat_(cyclus::Material::Ptr mat)
adds a material into the incoming commodity inventory
int ready()
returns the time key for ready materials
virtual void InitInv(cyclus::Inventories &inv)
cyclus::Material::Ptr Request_()
generates a request for this facility given its current state.
CommodConverter(cyclus::Context *ctx)
Constructor for CommodConverter Class.
This Facility is intended to convert a resource from one commodity to another.
virtual void Tick()
The handleTick function specific to the CommodConverter.
void out_commod_(std::string c)
the out commodity
void max_inv_size_(double c)
the maximum amount allowed in inventory
void crctx(const cyclus::toolkit::CommodityRecipeContext &crctx)
this facility's commodity-recipe context
std::map< int, cyclus::toolkit::ResourceBuff > processing
map from ready time to resource buffers