CYCAMORE
Loading...
Searching...
No Matches
build/cycamore/mixer.h
Go to the documentation of this file.
1
2#line 1 "/cycamore/src/mixer.h"
3#ifndef CYCAMORE_SRC_MIXER_H_
4#define CYCAMORE_SRC_MIXER_H_
5
6#include <string>
7#include "cycamore_version.h"
8#include "cyclus.h"
9
10#pragma cyclus exec from cyclus.system import CY_LARGE_DOUBLE, CY_LARGE_INT, CY_NEAR_ZERO
11
12namespace cycamore {
13
19class Mixer
20 : public cyclus::Facility,
21 public cyclus::toolkit::Position {
22#pragma cyclus note { "niche": "mixing facility", "doc": "Mixer mixes N streams with fixed, static, user-specified" " ratios into a single output stream. The Mixer has N input" " inventories: one for each streams to be mixed, and one output" " stream. The supplying of mixed material is constrained by " " available inventory of mixed material quantities.", }
23#line 28 "/cycamore/src/mixer.h"
24
25 friend class MixerTest;
26
27 public:
28 Mixer(cyclus::Context* ctx);
29 virtual ~Mixer(){};
30
31 virtual void Tick();
32 virtual void Tock(){};
33 virtual void EnterNotify();
34
35 virtual void AcceptMatlTrades(
36 const std::vector<std::pair<cyclus::Trade<cyclus::Material>,
37 cyclus::Material::Ptr> >& responses);
38
39 virtual std::set<cyclus::RequestPortfolio<cyclus::Material>::Ptr>
41 virtual cyclus::Agent* Clone() {
42 cycamore::Mixer* m = new cycamore::Mixer(context());
43 m->InitFrom(this);
44 return m;
45 };
46#line 45 "/cycamore/src/mixer.h"
47
48 virtual void InitFrom(cycamore::Mixer* m) {
49 cyclus::Facility::InitFrom(m);
50 int rawcycpp_shape_streams_[8] = {-1, -1, -1, -1, -1, -1, -1, -1};
51 cycpp_shape_streams_ = std::vector<int>(rawcycpp_shape_streams_, rawcycpp_shape_streams_ + 8);
52 int rawcycpp_shape_out_commod[1] = {-1};
53 cycpp_shape_out_commod = std::vector<int>(rawcycpp_shape_out_commod, rawcycpp_shape_out_commod + 1);
54 int rawcycpp_shape_out_buf_size[1] = {-1};
55 cycpp_shape_out_buf_size = std::vector<int>(rawcycpp_shape_out_buf_size, rawcycpp_shape_out_buf_size + 1);
56 int rawcycpp_shape_output[2] = {-1, -1};
57 cycpp_shape_output = std::vector<int>(rawcycpp_shape_output, rawcycpp_shape_output + 2);
58 int rawcycpp_shape_throughput[1] = {-1};
59 cycpp_shape_throughput = std::vector<int>(rawcycpp_shape_throughput, rawcycpp_shape_throughput + 1);
60 int rawcycpp_shape_latitude[1] = {-1};
61 cycpp_shape_latitude = std::vector<int>(rawcycpp_shape_latitude, rawcycpp_shape_latitude + 1);
62 int rawcycpp_shape_longitude[1] = {-1};
63 cycpp_shape_longitude = std::vector<int>(rawcycpp_shape_longitude, rawcycpp_shape_longitude + 1);
64 streams_ = m->streams_;
65 out_commod = m->out_commod;
66 out_buf_size = m->out_buf_size;
67 throughput = m->throughput;
68 latitude = m->latitude;
69 longitude = m->longitude;
70 output.capacity(m->output.capacity());
71 };
72
73 virtual void InfileToDb(cyclus::InfileTree* tree, cyclus::DbInit di) {
74 cyclus::Facility::InfileToDb(tree, di);
75 int rawcycpp_shape_streams_[8] = {-1, -1, -1, -1, -1, -1, -1, -1};
76 cycpp_shape_streams_ = std::vector<int>(rawcycpp_shape_streams_, rawcycpp_shape_streams_ + 8);
77 int rawcycpp_shape_out_commod[1] = {-1};
78 cycpp_shape_out_commod = std::vector<int>(rawcycpp_shape_out_commod, rawcycpp_shape_out_commod + 1);
79 int rawcycpp_shape_out_buf_size[1] = {-1};
80 cycpp_shape_out_buf_size = std::vector<int>(rawcycpp_shape_out_buf_size, rawcycpp_shape_out_buf_size + 1);
81 int rawcycpp_shape_output[2] = {-1, -1};
82 cycpp_shape_output = std::vector<int>(rawcycpp_shape_output, rawcycpp_shape_output + 2);
83 int rawcycpp_shape_throughput[1] = {-1};
84 cycpp_shape_throughput = std::vector<int>(rawcycpp_shape_throughput, rawcycpp_shape_throughput + 1);
85 int rawcycpp_shape_latitude[1] = {-1};
86 cycpp_shape_latitude = std::vector<int>(rawcycpp_shape_latitude, rawcycpp_shape_latitude + 1);
87 int rawcycpp_shape_longitude[1] = {-1};
88 cycpp_shape_longitude = std::vector<int>(rawcycpp_shape_longitude, rawcycpp_shape_longitude + 1);
89 cyclus::InfileTree* sub = tree->SubTree("config/*");
90 int i;
91 int n;
92 {
93 cyclus::InfileTree* bub = sub->SubTree("in_streams", 0);
94 cyclus::InfileTree* sub = bub;
95 int n1 = sub->NMatches("stream");
96 std::vector< std::pair< std::pair< double, double >, std::map< std::string, double > > > streams__val;
97 streams__val.resize(n1);
98 for (int i1 = 0; i1 < n1; ++i1) {
99 std::pair< std::pair< double, double >, std::map< std::string, double > > elem;
100 {
101 cyclus::InfileTree* bub = sub->SubTree("stream", i1);
102 cyclus::InfileTree* sub = bub;
103 std::pair< double, double > firsti1;
104 {
105 cyclus::InfileTree* bub = sub->SubTree("info", 0);
106 cyclus::InfileTree* sub = bub;
107 double first0;
108 {
109 double first0_in = cyclus::Query<double>(sub, "mixing_ratio", 0);
110 first0 = first0_in;
111 }
112 double second0;
113 {
114 double second0_in = cyclus::Query<double>(sub, "buf_size", 0);
115 second0 = second0_in;
116 }
117 std::pair< double, double > firsti1_in(first0, second0);
118 firsti1 = firsti1_in;
119 }
120 std::map< std::string, double > secondi1;
121 {
122 cyclus::InfileTree* bub = sub->SubTree("commodities", 0);
123 cyclus::InfileTree* sub = bub;
124 int n2 = sub->NMatches("item");
125 std::map< std::string, double > secondi1_in;
126 for (int i2 = 0; i2 < n2; ++i2) {
127 std::string key;
128 {
129 std::string key_in = cyclus::Query<std::string>(sub, "item/commodity", i2);
130 key = key_in;
131 }
132 double val;
133 {
134 double val_in = cyclus::Query<double>(sub, "item/pref", i2);
135 val = val_in;
136 }
137 secondi1_in[key] = val;
138 }
139 secondi1 = secondi1_in;
140 }
141 std::pair< std::pair< double, double >, std::map< std::string, double > > elem_in(firsti1, secondi1);
142 elem = elem_in;
143 }
144 streams__val[i1] = elem;
145 }
146 streams_ = streams__val;
147 }
148 {
149 std::string out_commod_val = cyclus::Query<std::string>(sub, "out_commod");
150 out_commod = out_commod_val;
151 }
152 if (sub->NMatches("out_buf_size") > 0) {
153 {
154 double out_buf_size_val = cyclus::Query<double>(sub, "out_buf_size");
155 out_buf_size = out_buf_size_val;
156 }
157 } else {
158 double out_buf_size_tmp = 1e+299;
159 out_buf_size = out_buf_size_tmp;
160 }
161 if (sub->NMatches("throughput") > 0) {
162 {
163 double throughput_val = cyclus::Query<double>(sub, "throughput");
164 throughput = throughput_val;
165 }
166 } else {
167 double throughput_tmp = 1e+299;
168 throughput = throughput_tmp;
169 }
170 if (sub->NMatches("latitude") > 0) {
171 {
172 double latitude_val = cyclus::Query<double>(sub, "latitude");
173 latitude = latitude_val;
174 }
175 } else {
176 double latitude_tmp = 0.0;
177 latitude = latitude_tmp;
178 }
179 if (sub->NMatches("longitude") > 0) {
180 {
181 double longitude_val = cyclus::Query<double>(sub, "longitude");
182 longitude = longitude_val;
183 }
184 } else {
185 double longitude_tmp = 0.0;
186 longitude = longitude_tmp;
187 }
188 di.NewDatum("Info")
189 ->AddVal("streams_", streams_, &cycpp_shape_streams_)
190 ->AddVal("out_commod", out_commod, &cycpp_shape_out_commod)
191 ->AddVal("out_buf_size", out_buf_size, &cycpp_shape_out_buf_size)
192 ->AddVal("throughput", throughput, &cycpp_shape_throughput)
193 ->AddVal("latitude", latitude, &cycpp_shape_latitude)
194 ->AddVal("longitude", longitude, &cycpp_shape_longitude)
195 ->Record();
196 };
197
198 virtual void InitFrom(cyclus::QueryableBackend* b) {
199 cyclus::Facility::InitFrom(b);
200 int rawcycpp_shape_streams_[8] = {-1, -1, -1, -1, -1, -1, -1, -1};
201 cycpp_shape_streams_ = std::vector<int>(rawcycpp_shape_streams_, rawcycpp_shape_streams_ + 8);
202 int rawcycpp_shape_out_commod[1] = {-1};
203 cycpp_shape_out_commod = std::vector<int>(rawcycpp_shape_out_commod, rawcycpp_shape_out_commod + 1);
204 int rawcycpp_shape_out_buf_size[1] = {-1};
205 cycpp_shape_out_buf_size = std::vector<int>(rawcycpp_shape_out_buf_size, rawcycpp_shape_out_buf_size + 1);
206 int rawcycpp_shape_output[2] = {-1, -1};
207 cycpp_shape_output = std::vector<int>(rawcycpp_shape_output, rawcycpp_shape_output + 2);
208 int rawcycpp_shape_throughput[1] = {-1};
209 cycpp_shape_throughput = std::vector<int>(rawcycpp_shape_throughput, rawcycpp_shape_throughput + 1);
210 int rawcycpp_shape_latitude[1] = {-1};
211 cycpp_shape_latitude = std::vector<int>(rawcycpp_shape_latitude, rawcycpp_shape_latitude + 1);
212 int rawcycpp_shape_longitude[1] = {-1};
213 cycpp_shape_longitude = std::vector<int>(rawcycpp_shape_longitude, rawcycpp_shape_longitude + 1);
214 cyclus::QueryResult qr = b->Query("Info", NULL);
215 streams_ = qr.GetVal<std::vector< std::pair< std::pair< double, double >, std::map< std::string, double > > > >("streams_");
216 out_commod = qr.GetVal<std::string>("out_commod");
217 out_buf_size = qr.GetVal<double>("out_buf_size");
218 throughput = qr.GetVal<double>("throughput");
219 latitude = qr.GetVal<double>("latitude");
220 longitude = qr.GetVal<double>("longitude");
221 output.capacity(out_buf_size);
222 };
223
224 virtual std::string schema() {
225 return ""
226 "<interleave>\n"
227 " <element name=\"in_streams\">\n"
228 " <oneOrMore>\n"
229 " <element name=\"stream\">\n"
230 " <interleave>\n"
231 " <element name=\"info\">\n"
232 " <interleave>\n"
233 " <element name=\"mixing_ratio\">\n"
234 " <data type=\"double\"/>\n"
235 " </element>\n"
236 " <element name=\"buf_size\">\n"
237 " <data type=\"double\"/>\n"
238 " </element>\n"
239 " </interleave>\n"
240 " </element>\n"
241 " <element name=\"commodities\">\n"
242 " <oneOrMore>\n"
243 " <element name=\"item\">\n"
244 " <interleave>\n"
245 " <element name=\"commodity\">\n"
246 " <data type=\"string\"/>\n"
247 " </element>\n"
248 " <element name=\"pref\">\n"
249 " <data type=\"double\"/>\n"
250 " </element>\n"
251 " </interleave>\n"
252 " </element>\n"
253 " </oneOrMore>\n"
254 " </element>\n"
255 " </interleave>\n"
256 " </element>\n"
257 " </oneOrMore>\n"
258 " </element>\n"
259 " <element name=\"out_commod\">\n"
260 " <data type=\"string\"/>\n"
261 " </element>\n"
262 " <optional>\n"
263 " <element name=\"out_buf_size\">\n"
264 " <data type=\"double\"/>\n"
265 " </element>\n"
266 " </optional>\n"
267 " <optional>\n"
268 " <element name=\"throughput\">\n"
269 " <data type=\"double\"/>\n"
270 " </element>\n"
271 " </optional>\n"
272 " <optional>\n"
273 " <element name=\"latitude\">\n"
274 " <data type=\"double\"/>\n"
275 " </element>\n"
276 " </optional>\n"
277 " <optional>\n"
278 " <element name=\"longitude\">\n"
279 " <data type=\"double\"/>\n"
280 " </element>\n"
281 " </optional>\n"
282 "</interleave>\n";
283 };
284
285 virtual Json::Value annotations() {
286 Json::Value root;
287 Json::Reader reader;
288 bool parsed_ok = reader.parse(
289 "{\"name\":\"cycamore::Mixer\",\"entity\":\"facility\",\"par"
290 "ents\":[\"cyclus::Facility\",\"cyclus::toolkit::Positi"
291 "on\"],\"all_parents\":[\"cyclus::Agent\",\"cyclus::Facil"
292 "ity\",\"cyclus::Ider\",\"cyclus::StateWrangler\",\"cyclu"
293 "s::TimeListener\",\"cyclus::Trader\",\"cyclus::toolkit"
294 "::Position\"],\"vars\":{\"streams_\":{\"alias\":[\"in_stre"
295 "ams\",[\"stream\",[\"info\",\"mixing_ratio\",\"buf_size\"],"
296 "[[\"commodities\",\"item\"],\"commodity\",\"pref\"]]],\"uit"
297 "ype\":[\"oneormore\",[\"pair\",[\"pair\",\"double\",\"double"
298 "\"],[\"oneormore\",\"incommodity\",\"double\"]]],\"uilabel"
299 "\":[\"streams_\",[\"\",[\"\",\"\",\"\"],[[\"\",\"\"],\"\",\"\"]]],\"do"
300 "c\":\"\",\"type\":[\"std::vector\",[\"std::pair\",[\"std::pa"
301 "ir\",\"double\",\"double\"],[\"std::map\",\"std::string\",\""
302 "double\"]]],\"index\":0,\"shape\":[-1,-1,-1,-1,-1,-1,-"
303 "1,-"
304 "1],\"tooltip\":[\"streams_\",[\"\",[\"\",\"\",\"\"],[[\"\",\"\"],\""
305 "\",\"\"]]]},\"in_streams\":\"streams_\",\"out_commod\":{\"do"
306 "c\":\"Commodity on which to offer/supply mixed fuel "
307 "material.\",\"uilabel\":\"Output Commodity\",\"uitype\":\""
308 "outcommodity\",\"type\":\"std::string\",\"index\":2,\"shap"
309 "e\":[-"
310 "1],\"alias\":\"out_commod\",\"tooltip\":\"out_commod\"},\"o"
311 "ut_buf_size\":{\"doc\":\"Maximum amount of mixed "
312 "material that can be stored. If full, the facility"
313 " halts operation until space becomes "
314 "available.\",\"uilabel\":\"Maximum Leftover Inventory\""
315 ",\"default\":1e+299,\"uitype\":\"range\",\"range\":[0.0,1e"
316 "+299],\"units\":\"kg\",\"type\":\"double\",\"index\":3,\"shap"
317 "e\":[-"
318 "1],\"alias\":\"out_buf_size\",\"tooltip\":\"out_buf_size\""
319 "},\"output\":{\"capacity\":\"out_buf_size\",\"type\":[\"cyc"
320 "lus::toolkit::ResBuf\",\"cyclus::Material\"],\"index\":"
321 "4,\"shape\":[-1,-"
322 "1]},\"throughput\":{\"default\":1e+299,\"doc\":\"Maximum "
323 "number of kg of fuel material that can be mixed "
324 "per time step.\",\"uilabel\":\"Maximum Throughput\",\"ui"
325 "type\":\"range\",\"range\":[0.0,1e+299],\"units\":\"kg\",\"t"
326 "ype\":\"double\",\"index\":5,\"shape\":[-"
327 "1],\"alias\":\"throughput\",\"tooltip\":\"throughput\"},\"l"
328 "atitude\":{\"default\":0.0,\"uilabel\":\"Geographical "
329 "latitude in degrees as a double\",\"doc\":\"Latitude "
330 "of the agent's geographical position. The value "
331 "should be expressed in degrees as a double.\",\"type"
332 "\":\"double\",\"index\":6,\"shape\":[-"
333 "1],\"alias\":\"latitude\",\"tooltip\":\"latitude\"},\"longi"
334 "tude\":{\"default\":0.0,\"uilabel\":\"Geographical "
335 "longitude in degrees as a double\",\"doc\":\"Longitude"
336 " of the agent's geographical position. The value "
337 "should be expressed in degrees as a double.\",\"type"
338 "\":\"double\",\"index\":7,\"shape\":[-"
339 "1],\"alias\":\"longitude\",\"tooltip\":\"longitude\"}},\"ni"
340 "che\":\"mixing facility\",\"doc\":\"Mixer mixes N "
341 "streams with fixed, static, user-specified ratios "
342 "into a single output stream. The Mixer has N input"
343 " inventories: one for each streams to be mixed, "
344 "and one output stream. The supplying of mixed "
345 "material is constrained by available inventory of"
346 " mixed material quantities.\"}", root);
347 if (!parsed_ok) {
348 throw cyclus::ValueError("failed to parse annotations for cycamore::Mixer.");
349 }
350 return root;
351 };
352
353 virtual void Snapshot(cyclus::DbInit di) {
354 di.NewDatum("Info")
355 ->AddVal("streams_", streams_, &cycpp_shape_streams_)
356 ->AddVal("out_commod", out_commod, &cycpp_shape_out_commod)
357 ->AddVal("out_buf_size", out_buf_size, &cycpp_shape_out_buf_size)
358 ->AddVal("throughput", throughput, &cycpp_shape_throughput)
359 ->AddVal("latitude", latitude, &cycpp_shape_latitude)
360 ->AddVal("longitude", longitude, &cycpp_shape_longitude)
361 ->Record();
362 };
363#line 53 "/cycamore/src/mixer.h"
364 // the following pragmas are ommitted and the functions are written
365 // manually in order to handle the vector of resource buffers:
366 //
367 // #pragma cyclus snapshotinv
368 // #pragma cyclus initinv
369
370 virtual cyclus::Inventories SnapshotInv();
371 virtual void InitInv(cyclus::Inventories& inv);
372
373 protected:
374#pragma cyclus var { "alias": ["in_streams", [ "stream", [ "info", "mixing_ratio", "buf_size"], [ "commodities", "commodity", "pref"]]], "uitype": ["oneormore", [ "pair", ["pair", "double", "double"], ["oneormore", "incommodity", "double"]]], "uilabel": "", "doc": "", }
375#line 69 "/cycamore/src/mixer.h"
376 std::vector<std::pair<std::pair<double, double>, std::map<std::string, double> > > streams_;
377 std::vector<int> cycpp_shape_streams_;
378
379#line 70 "/cycamore/src/mixer.h"
380
381 std::vector<std::map<std::string, double> > in_commods;
382 std::vector<double> in_buf_sizes;
383 std::vector<double> mixing_ratios;
384
385 // custom SnapshotInv and InitInv and EnterNotify are used to persist this
386 // state var.
387 std::map<std::string, cyclus::toolkit::ResBuf<cyclus::Material> > streambufs;
388
389
390#pragma cyclus var { "doc" : "Commodity on which to offer/supply mixed fuel material.", "uilabel" : "Output Commodity", "uitype" : "outcommodity", }
391#line 83 "/cycamore/src/mixer.h"
392 std::string out_commod;
393 std::vector<int> cycpp_shape_out_commod;
394#line 84 "/cycamore/src/mixer.h"
395
396
397#pragma cyclus var { "doc" : "Maximum amount of mixed material that can be stored." " If full, the facility halts operation until space becomes" " available.", "uilabel": "Maximum Leftover Inventory", "default": CY_LARGE_DOUBLE, "uitype": "range", "range": [0.0, CY_LARGE_DOUBLE], "units": "kg", }
398#line 95 "/cycamore/src/mixer.h"
400 std::vector<int> cycpp_shape_out_buf_size;
401
402#line 96 "/cycamore/src/mixer.h"
403
404#pragma cyclus var { "capacity" : "out_buf_size", }
405 cyclus::toolkit::ResBuf<cyclus::Material> output;
406 std::vector<int> cycpp_shape_output;
407#line 99 "/cycamore/src/mixer.h"
408
409
410#pragma cyclus var { "default": CY_LARGE_DOUBLE, "doc": "Maximum number of kg of fuel material that can be mixed per time step.", "uilabel": "Maximum Throughput", "uitype": "range", "range": [0.0, CY_LARGE_DOUBLE], "units": "kg", }
411#line 108 "/cycamore/src/mixer.h"
413 std::vector<int> cycpp_shape_throughput;
414
415#line 109 "/cycamore/src/mixer.h"
416
417 // intra-time-step state - no need to be a state var
418 // map<request, inventory name>
419 std::map<cyclus::Request<cyclus::Material>*, std::string> req_inventories_;
420
422 cyclus::toolkit::MatlSellPolicy sell_policy;
423
424 private:
425 #pragma cyclus var { "default": 0.0, "uilabel": "Geographical latitude in degrees as a double", "doc": "Latitude of the agent's geographical position. The value should " "be expressed in degrees as a double." }
426#line 124 "/cycamore/src/mixer.h"
427 double latitude;
428 std::vector<int> cycpp_shape_latitude;
429#line 125 "/cycamore/src/mixer.h"
430
431
432 #pragma cyclus var { "default": 0.0, "uilabel": "Geographical longitude in degrees as a double", "doc": "Longitude of the agent's geographical position. The value should " "be expressed in degrees as a double." }
433#line 132 "/cycamore/src/mixer.h"
434 double longitude;
435 std::vector<int> cycpp_shape_longitude;
436
437#line 133 "/cycamore/src/mixer.h"
438
439 cyclus::toolkit::Position coordinates;
440
442 void RecordPosition();
443};
444
445} // namespace cycamore
446
447#endif // CYCAMORE_SRC_MIXER_H_
Mixer mixes N streams with fixed, static, user-specified ratios into a single output stream.
std::map< std::string, cyclus::toolkit::ResBuf< cyclus::Material > > streambufs
std::map< cyclus::Request< cyclus::Material > *, std::string > req_inventories_
std::vector< int > cycpp_shape_out_buf_size
std::vector< double > mixing_ratios
void RecordPosition()
Records an agent's latitude and longitude to the output db.
virtual void EnterNotify()
std::vector< int > cycpp_shape_latitude
cyclus::toolkit::MatlSellPolicy sell_policy
virtual void InitFrom(cyclus::QueryableBackend *b)
virtual cyclus::Inventories SnapshotInv()
virtual void InitInv(cyclus::Inventories &inv)
virtual void InitFrom(cycamore::Mixer *m)
std::vector< int > cycpp_shape_longitude
Mixer(cyclus::Context *ctx)
cyclus::toolkit::Position coordinates
std::vector< int > cycpp_shape_output
virtual cyclus::Agent * Clone()
cyclus::toolkit::ResBuf< cyclus::Material > output
std::vector< std::map< std::string, double > > in_commods
virtual void InfileToDb(cyclus::InfileTree *tree, cyclus::DbInit di)
std::vector< int > cycpp_shape_streams_
virtual std::string schema()
virtual std::set< cyclus::RequestPortfolio< cyclus::Material >::Ptr > GetMatlRequests()
std::vector< double > in_buf_sizes
virtual void AcceptMatlTrades(const std::vector< std::pair< cyclus::Trade< cyclus::Material >, cyclus::Material::Ptr > > &responses)
std::vector< int > cycpp_shape_throughput
std::vector< int > cycpp_shape_out_commod
std::vector< std::pair< std::pair< double, double >, std::map< std::string, double > > > streams_
virtual Json::Value annotations()
virtual void Snapshot(cyclus::DbInit di)