CYCAMORE
Loading...
Searching...
No Matches
build/cycamore/deploy_inst.h
Go to the documentation of this file.
1
2#line 1 "/cycamore/src/deploy_inst.h"
3#ifndef CYCAMORE_SRC_DEPLOY_INST_H_
4#define CYCAMORE_SRC_DEPLOY_INST_H_
5
6#include <utility>
7#include <set>
8#include <map>
9
10#include "cyclus.h"
11#include "cycamore_version.h"
12
13namespace cycamore {
14
15typedef std::map<int, std::vector<std::string> > BuildSched;
16
17// Builds and manages agents (facilities) according to a manually specified
18// deployment schedule. Deployed agents are automatically decommissioned at
19// the end of their lifetime. The user specifies a list of prototypes for
20// each and corresponding build times, number to build, and (optionally)
21// lifetimes. The same prototype can be specified multiple times with any
22// combination of the same or different build times, build number, and
23// lifetimes.
24class DeployInst :
25 public cyclus::Institution,
26 public cyclus::toolkit::CommodityProducerManager,
27 public cyclus::toolkit::Position {
28 #pragma cyclus note { "doc": "Builds and manages agents (facilities) according to a manually" " specified deployment schedule. Deployed agents are automatically" " decommissioned at the end of their lifetime. Deployed and" " decommissioned agents are registered and unregistered with a" " region. The user specifies a list of prototypes for" " each and corresponding build times, number to build, and (optionally)" " lifetimes. The same prototype can be specified multiple times with" " any combination of the same or different build times, build number," " and lifetimes. " }
29#line 38 "/cycamore/src/deploy_inst.h"
30 public:
31 DeployInst(cyclus::Context* ctx);
32
33 virtual ~DeployInst();
34
35 virtual std::string version() { return CYCAMORE_VERSION; }
36 virtual void InitFrom(cycamore::DeployInst* m) {
37 cyclus::Institution::InitFrom(m);
38 int rawcycpp_shape_prototypes[2] = {-1, -1};
39 cycpp_shape_prototypes = std::vector<int>(rawcycpp_shape_prototypes, rawcycpp_shape_prototypes + 2);
40 int rawcycpp_shape_build_times[2] = {-1, -1};
41 cycpp_shape_build_times = std::vector<int>(rawcycpp_shape_build_times, rawcycpp_shape_build_times + 2);
42 int rawcycpp_shape_n_build[2] = {-1, -1};
43 cycpp_shape_n_build = std::vector<int>(rawcycpp_shape_n_build, rawcycpp_shape_n_build + 2);
44 int rawcycpp_shape_lifetimes[2] = {-1, -1};
45 cycpp_shape_lifetimes = std::vector<int>(rawcycpp_shape_lifetimes, rawcycpp_shape_lifetimes + 2);
46 int rawcycpp_shape_latitude[1] = {-1};
47 cycpp_shape_latitude = std::vector<int>(rawcycpp_shape_latitude, rawcycpp_shape_latitude + 1);
48 int rawcycpp_shape_longitude[1] = {-1};
49 cycpp_shape_longitude = std::vector<int>(rawcycpp_shape_longitude, rawcycpp_shape_longitude + 1);
52 n_build = m->n_build;
54 latitude = m->latitude;
56 };
57#line 44 "/cycamore/src/deploy_inst.h"
58
59 virtual void InitFrom(cyclus::QueryableBackend* b) {
60 cyclus::Institution::InitFrom(b);
61 int rawcycpp_shape_prototypes[2] = {-1, -1};
62 cycpp_shape_prototypes = std::vector<int>(rawcycpp_shape_prototypes, rawcycpp_shape_prototypes + 2);
63 int rawcycpp_shape_build_times[2] = {-1, -1};
64 cycpp_shape_build_times = std::vector<int>(rawcycpp_shape_build_times, rawcycpp_shape_build_times + 2);
65 int rawcycpp_shape_n_build[2] = {-1, -1};
66 cycpp_shape_n_build = std::vector<int>(rawcycpp_shape_n_build, rawcycpp_shape_n_build + 2);
67 int rawcycpp_shape_lifetimes[2] = {-1, -1};
68 cycpp_shape_lifetimes = std::vector<int>(rawcycpp_shape_lifetimes, rawcycpp_shape_lifetimes + 2);
69 int rawcycpp_shape_latitude[1] = {-1};
70 cycpp_shape_latitude = std::vector<int>(rawcycpp_shape_latitude, rawcycpp_shape_latitude + 1);
71 int rawcycpp_shape_longitude[1] = {-1};
72 cycpp_shape_longitude = std::vector<int>(rawcycpp_shape_longitude, rawcycpp_shape_longitude + 1);
73 cyclus::QueryResult qr = b->Query("Info", NULL);
74 prototypes = qr.GetVal<std::vector< std::string > >("prototypes");
75 build_times = qr.GetVal<std::vector< int > >("build_times");
76 n_build = qr.GetVal<std::vector< int > >("n_build");
77 lifetimes = qr.GetVal<std::vector< int > >("lifetimes");
78 latitude = qr.GetVal<double>("latitude");
79 longitude = qr.GetVal<double>("longitude");
80 };
81
82 virtual void InfileToDb(cyclus::InfileTree* tree, cyclus::DbInit di) {
83 cyclus::Institution::InfileToDb(tree, di);
84 int rawcycpp_shape_prototypes[2] = {-1, -1};
85 cycpp_shape_prototypes = std::vector<int>(rawcycpp_shape_prototypes, rawcycpp_shape_prototypes + 2);
86 int rawcycpp_shape_build_times[2] = {-1, -1};
87 cycpp_shape_build_times = std::vector<int>(rawcycpp_shape_build_times, rawcycpp_shape_build_times + 2);
88 int rawcycpp_shape_n_build[2] = {-1, -1};
89 cycpp_shape_n_build = std::vector<int>(rawcycpp_shape_n_build, rawcycpp_shape_n_build + 2);
90 int rawcycpp_shape_lifetimes[2] = {-1, -1};
91 cycpp_shape_lifetimes = std::vector<int>(rawcycpp_shape_lifetimes, rawcycpp_shape_lifetimes + 2);
92 int rawcycpp_shape_latitude[1] = {-1};
93 cycpp_shape_latitude = std::vector<int>(rawcycpp_shape_latitude, rawcycpp_shape_latitude + 1);
94 int rawcycpp_shape_longitude[1] = {-1};
95 cycpp_shape_longitude = std::vector<int>(rawcycpp_shape_longitude, rawcycpp_shape_longitude + 1);
96 cyclus::InfileTree* sub = tree->SubTree("config/*");
97 int i;
98 int n;
99 {
100 cyclus::InfileTree* bub = sub->SubTree("prototypes", 0);
101 cyclus::InfileTree* sub = bub;
102 int n1 = sub->NMatches("val");
103 std::vector< std::string > prototypes_val;
104 prototypes_val.resize(n1);
105 for (int i1 = 0; i1 < n1; ++i1) {
106 std::string elem;
107 {
108 std::string elem_in = cyclus::Query<std::string>(sub, "val", i1);
109 elem = elem_in;
110 }
111 prototypes_val[i1] = elem;
112 }
113 prototypes = prototypes_val;
114 }
115 {
116 cyclus::InfileTree* bub = sub->SubTree("build_times", 0);
117 cyclus::InfileTree* sub = bub;
118 int n1 = sub->NMatches("val");
119 std::vector< int > build_times_val;
120 build_times_val.resize(n1);
121 for (int i1 = 0; i1 < n1; ++i1) {
122 int elem;
123 {
124 int elem_in = cyclus::Query<int>(sub, "val", i1);
125 elem = elem_in;
126 }
127 build_times_val[i1] = elem;
128 }
129 build_times = build_times_val;
130 }
131 {
132 cyclus::InfileTree* bub = sub->SubTree("n_build", 0);
133 cyclus::InfileTree* sub = bub;
134 int n1 = sub->NMatches("val");
135 std::vector< int > n_build_val;
136 n_build_val.resize(n1);
137 for (int i1 = 0; i1 < n1; ++i1) {
138 int elem;
139 {
140 int elem_in = cyclus::Query<int>(sub, "val", i1);
141 elem = elem_in;
142 }
143 n_build_val[i1] = elem;
144 }
145 n_build = n_build_val;
146 }
147 if (sub->NMatches("lifetimes") > 0) {
148 {
149 cyclus::InfileTree* bub = sub->SubTree("lifetimes", 0);
150 cyclus::InfileTree* sub = bub;
151 int n1 = sub->NMatches("val");
152 std::vector< int > lifetimes_val;
153 lifetimes_val.resize(n1);
154 for (int i1 = 0; i1 < n1; ++i1) {
155 int elem;
156 {
157 int elem_in = cyclus::Query<int>(sub, "val", i1);
158 elem = elem_in;
159 }
160 lifetimes_val[i1] = elem;
161 }
162 lifetimes = lifetimes_val;
163 }
164 } else {
165 std::vector< int > lifetimes_tmp;
166 lifetimes_tmp.resize(0);
167 {
168 }
169 lifetimes = lifetimes_tmp;
170 }
171 if (sub->NMatches("latitude") > 0) {
172 {
173 double latitude_val = cyclus::Query<double>(sub, "latitude");
174 latitude = latitude_val;
175 }
176 } else {
177 double latitude_tmp = 0.0;
178 latitude = latitude_tmp;
179 }
180 if (sub->NMatches("longitude") > 0) {
181 {
182 double longitude_val = cyclus::Query<double>(sub, "longitude");
183 longitude = longitude_val;
184 }
185 } else {
186 double longitude_tmp = 0.0;
187 longitude = longitude_tmp;
188 }
189 di.NewDatum("Info")
190 ->AddVal("prototypes", prototypes, &cycpp_shape_prototypes)
191 ->AddVal("build_times", build_times, &cycpp_shape_build_times)
192 ->AddVal("n_build", n_build, &cycpp_shape_n_build)
193 ->AddVal("lifetimes", lifetimes, &cycpp_shape_lifetimes)
194 ->AddVal("latitude", latitude, &cycpp_shape_latitude)
195 ->AddVal("longitude", longitude, &cycpp_shape_longitude)
196 ->Record();
197 };
198
199 virtual cyclus::Agent* Clone() {
200 cycamore::DeployInst* m = new cycamore::DeployInst(context());
201 m->InitFrom(this);
202 return m;
203 };
204
205 virtual std::string schema() {
206 return ""
207 "<interleave>\n"
208 " <element name=\"prototypes\">\n"
209 " <oneOrMore>\n"
210 " <element name=\"val\">\n"
211 " <data type=\"string\"/>\n"
212 " </element>\n"
213 " </oneOrMore>\n"
214 " </element>\n"
215 " <element name=\"build_times\">\n"
216 " <oneOrMore>\n"
217 " <element name=\"val\">\n"
218 " <data type=\"int\"/>\n"
219 " </element>\n"
220 " </oneOrMore>\n"
221 " </element>\n"
222 " <element name=\"n_build\">\n"
223 " <oneOrMore>\n"
224 " <element name=\"val\">\n"
225 " <data type=\"int\"/>\n"
226 " </element>\n"
227 " </oneOrMore>\n"
228 " </element>\n"
229 " <optional>\n"
230 " <element name=\"lifetimes\">\n"
231 " <oneOrMore>\n"
232 " <element name=\"val\">\n"
233 " <data type=\"int\"/>\n"
234 " </element>\n"
235 " </oneOrMore>\n"
236 " </element>\n"
237 " </optional>\n"
238 " <optional>\n"
239 " <element name=\"latitude\">\n"
240 " <data type=\"double\"/>\n"
241 " </element>\n"
242 " </optional>\n"
243 " <optional>\n"
244 " <element name=\"longitude\">\n"
245 " <data type=\"double\"/>\n"
246 " </element>\n"
247 " </optional>\n"
248 "</interleave>\n";
249 };
250
251 virtual Json::Value annotations() {
252 Json::Value root;
253 Json::Reader reader;
254 bool parsed_ok = reader.parse(
255 "{\"name\":\"cycamore::DeployInst\",\"entity\":\"instituti"
256 "on\",\"parents\":[\"cyclus::Institution\",\"cyclus::tool"
257 "kit::CommodityProducerManager\",\"cyclus::toolkit::P"
258 "osition\"],\"all_parents\":[\"cyclus::Agent\",\"cyclus::"
259 "Ider\",\"cyclus::Institution\",\"cyclus::StateWrangler"
260 "\",\"cyclus::TimeListener\",\"cyclus::toolkit::AgentMa"
261 "naged\",\"cyclus::toolkit::CommodityProducerManager\""
262 ",\"cyclus::toolkit::Position\"],\"vars\":{\"prototypes\""
263 ":{\"doc\":\"Ordered list of prototypes to build.\",\"ui"
264 "type\":[\"oneormore\",\"prototype\"],\"uilabel\":[\"Protot"
265 "ypes to deploy\",\"\"],\"type\":[\"std::vector\",\"std::st"
266 "ring\"],\"index\":0,\"shape\":[-1,-"
267 "1],\"alias\":[\"prototypes\",\"val\"],\"tooltip\":[\"protot"
268 "ypes\",\"\"]},\"build_times\":{\"doc\":\"Time step on "
269 "which to deploy agents given in prototype list "
270 "(same order).\",\"uilabel\":[\"Deployment times\",\"\"],\""
271 "type\":[\"std::vector\",\"int\"],\"index\":1,\"shape\":[-"
272 "1,-"
273 "1],\"alias\":[\"build_times\",\"val\"],\"tooltip\":[\"build"
274 "_times\",\"\"]},\"n_build\":{\"doc\":\"Number of each "
275 "prototype given in prototype list that should be "
276 "deployed (same order).\",\"uilabel\":[\"Number to depl"
277 "oy\",\"\"],\"type\":[\"std::vector\",\"int\"],\"index\":2,\"sh"
278 "ape\":[-1,-"
279 "1],\"alias\":[\"n_build\",\"val\"],\"tooltip\":[\"n_build\","
280 "\"\"]},\"lifetimes\":{\"doc\":\"Lifetimes for each "
281 "prototype in prototype list (same order). These "
282 "lifetimes override the lifetimes in the original "
283 "prototype definition. If unspecified, lifetimes "
284 "from the original prototype definitions are used. "
285 "Although a new prototype is created in the "
286 "Prototypes table for each lifetime with the suffix"
287 " '_life_[lifetime]', all deployed agents "
288 "themselves will have the same original prototype "
289 "name (and so will the Agents tables).\",\"default\":["
290 "],\"uilabel\":[\"Lifetimes\",\"\"],\"type\":[\"std::vector\""
291 ",\"int\"],\"index\":3,\"shape\":[-1,-"
292 "1],\"alias\":[\"lifetimes\",\"val\"],\"tooltip\":[\"lifetim"
293 "es\",\"\"]},\"latitude\":{\"default\":0.0,\"uilabel\":\"Geog"
294 "raphical latitude in degrees as a "
295 "double\",\"doc\":\"Latitude of the agent's "
296 "geographical position. The value should be "
297 "expressed in degrees as a double.\",\"type\":\"double\""
298 ",\"index\":4,\"shape\":[-"
299 "1],\"alias\":\"latitude\",\"tooltip\":\"latitude\"},\"longi"
300 "tude\":{\"default\":0.0,\"uilabel\":\"Geographical "
301 "longitude in degrees as a double\",\"doc\":\"Longitude"
302 " of the agent's geographical position. The value "
303 "should be expressed in degrees as a double.\",\"type"
304 "\":\"double\",\"index\":5,\"shape\":[-"
305 "1],\"alias\":\"longitude\",\"tooltip\":\"longitude\"}},\"do"
306 "c\":\"Builds and manages agents (facilities) "
307 "according to a manually specified deployment "
308 "schedule. Deployed agents are automatically "
309 "decommissioned at the end of their lifetime. "
310 "Deployed and decommissioned agents are registered "
311 "and unregistered with a region. The user specifies"
312 " a list of prototypes for each and corresponding "
313 "build times, number to build, and (optionally) "
314 "lifetimes. The same prototype can be specified "
315 "multiple times with any combination of the same or"
316 " different build times, build number, and "
317 "lifetimes. \"}", root);
318 if (!parsed_ok) {
319 throw cyclus::ValueError("failed to parse annotations for cycamore::DeployInst.");
320 }
321 return root;
322 };
323
324 virtual void InitInv(cyclus::Inventories& inv) {
325 };
326
327 virtual cyclus::Inventories SnapshotInv() {
328 cyclus::Inventories invs;
329 return invs;
330 };
331
332 virtual void Snapshot(cyclus::DbInit di) {
333 di.NewDatum("Info")
334 ->AddVal("prototypes", prototypes, &cycpp_shape_prototypes)
335 ->AddVal("build_times", build_times, &cycpp_shape_build_times)
336 ->AddVal("n_build", n_build, &cycpp_shape_n_build)
337 ->AddVal("lifetimes", lifetimes, &cycpp_shape_lifetimes)
338 ->AddVal("latitude", latitude, &cycpp_shape_latitude)
339 ->AddVal("longitude", longitude, &cycpp_shape_longitude)
340 ->Record();
341 };
342#line 46 "/cycamore/src/deploy_inst.h"
343
344 virtual void Build(cyclus::Agent* parent);
345
346 virtual void EnterNotify();
347
348 virtual void BuildNotify(Agent* m);
349 virtual void DecomNotify(Agent* m);
352 void WriteProducerInformation(cyclus::toolkit::CommodityProducer*
353 producer);
354
355 private:
357 void Register_(cyclus::Agent* agent);
358
360 void Unregister_(cyclus::Agent* agent);
361
362 protected:
363 #pragma cyclus var { "doc": "Ordered list of prototypes to build.", "uitype": ("oneormore", "prototype"), "uilabel": "Prototypes to deploy", }
364#line 71 "/cycamore/src/deploy_inst.h"
365 std::vector<std::string> prototypes;
366 std::vector<int> cycpp_shape_prototypes;
367#line 86 "/cycamore/src/deploy_inst.h"
368
369
370 #pragma cyclus var { "doc": "Time step on which to deploy agents given in prototype list " "(same order).", "uilabel": "Deployment times", }
371 std::vector<int> build_times;
372 std::vector<int> cycpp_shape_build_times;
373
374
375 #pragma cyclus var { "doc": "Number of each prototype given in prototype list that should be " "deployed (same order).", "uilabel": "Number to deploy", }
376 std::vector<int> n_build;
377 std::vector<int> cycpp_shape_n_build;
378
379
380
381 #pragma cyclus var { "doc": "Lifetimes for each prototype in prototype list (same order)." " These lifetimes override the lifetimes in the original prototype" " definition." " If unspecified, lifetimes from the original prototype definitions" " are used." " Although a new prototype is created in the Prototypes table for" " each lifetime with the suffix '_life_[lifetime]'," " all deployed agents themselves will have the same original" " prototype name (and so will the Agents tables).", "default": [], "uilabel": "Lifetimes" }
382#line 101 "/cycamore/src/deploy_inst.h"
383 std::vector<int> lifetimes;
384 std::vector<int> cycpp_shape_lifetimes;
385
386#line 102 "/cycamore/src/deploy_inst.h"
387
388 private:
389 #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." }
390#line 110 "/cycamore/src/deploy_inst.h"
391 double latitude;
392 std::vector<int> cycpp_shape_latitude;
393#line 111 "/cycamore/src/deploy_inst.h"
394
395
396 #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." }
397#line 118 "/cycamore/src/deploy_inst.h"
398 double longitude;
399 std::vector<int> cycpp_shape_longitude;
400
401#line 119 "/cycamore/src/deploy_inst.h"
402
403 cyclus::toolkit::Position coordinates;
404
406 void RecordPosition();
407};
408
409} // namespace cycamore
410
411#endif // CYCAMORE_SRC_DEPLOY_INST_H_
#define CYCAMORE_VERSION
void WriteProducerInformation(cyclus::toolkit::CommodityProducer *producer)
write information about a commodity producer to a stream
void Unregister_(cyclus::Agent *agent)
unregister a child
void RecordPosition()
Records an agent's latitude and longitude to the output db.
virtual cyclus::Inventories SnapshotInv()
std::vector< int > cycpp_shape_longitude
std::vector< int > cycpp_shape_lifetimes
virtual Json::Value annotations()
std::vector< int > cycpp_shape_n_build
std::vector< int > cycpp_shape_build_times
DeployInst(cyclus::Context *ctx)
virtual void DecomNotify(Agent *m)
void Register_(cyclus::Agent *agent)
register a child
virtual std::string version()
cyclus::toolkit::Position coordinates
virtual void Build(cyclus::Agent *parent)
virtual void InfileToDb(cyclus::InfileTree *tree, cyclus::DbInit di)
std::vector< int > cycpp_shape_prototypes
virtual void InitFrom(cycamore::DeployInst *m)
virtual cyclus::Agent * Clone()
std::vector< int > cycpp_shape_latitude
std::vector< std::string > prototypes
virtual void Snapshot(cyclus::DbInit di)
virtual void InitInv(cyclus::Inventories &inv)
virtual void BuildNotify(Agent *m)
virtual void InitFrom(cyclus::QueryableBackend *b)
std::map< int, std::vector< std::string > > BuildSched