CYCAMORE
Loading...
Searching...
No Matches
build/cycamore/growth_region.h
Go to the documentation of this file.
1
2#line 1 "/cycamore/src/growth_region.h"
3#ifndef CYCAMORE_SRC_GROWTH_REGION_H_
4#define CYCAMORE_SRC_GROWTH_REGION_H_
5
6#include <string>
7#include <utility>
8#include <vector>
9
10#include "cyclus.h"
11#include "cycamore_version.h"
12
13// forward declarations
14namespace cycamore {
15class GrowthRegion;
16} // namespace cycamore
17
18// forward includes
19#include "growth_region_tests.h"
20
21namespace cycamore {
22
24typedef std::vector<
25 std::pair<int, std::pair<std::string, std::string> > > Demand;
26
40class GrowthRegion : public cyclus::Region,
41 public cyclus::toolkit::Position {
42 friend class GrowthRegionTests;
43 public:
45 GrowthRegion(cyclus::Context* ctx);
46
48 virtual ~GrowthRegion();
49
50 virtual std::string version() { return CYCAMORE_VERSION; }
52 cyclus::Region::InitFrom(m);
53 int rawcycpp_shape_commodity_demand[8] = {-1, -1, -1, -1, -1, -1, -1, -1};
54 cycpp_shape_commodity_demand = std::vector<int>(rawcycpp_shape_commodity_demand, rawcycpp_shape_commodity_demand + 8);
55 int rawcycpp_shape_latitude[1] = {-1};
56 cycpp_shape_latitude = std::vector<int>(rawcycpp_shape_latitude, rawcycpp_shape_latitude + 1);
57 int rawcycpp_shape_longitude[1] = {-1};
58 cycpp_shape_longitude = std::vector<int>(rawcycpp_shape_longitude, rawcycpp_shape_longitude + 1);
59 commodity_demand = m->commodity_demand;
60 latitude = m->latitude;
61 longitude = m->longitude;
62 };
63#line 49 "/cycamore/src/growth_region.h"
64
65 virtual void InitFrom(cyclus::QueryableBackend* b) {
66 cyclus::Region::InitFrom(b);
67 int rawcycpp_shape_commodity_demand[8] = {-1, -1, -1, -1, -1, -1, -1, -1};
68 cycpp_shape_commodity_demand = std::vector<int>(rawcycpp_shape_commodity_demand, rawcycpp_shape_commodity_demand + 8);
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 commodity_demand = qr.GetVal<std::map< std::string, std::vector< std::pair< int, std::pair< std::string, std::string > > > > >("commodity_demand");
75 latitude = qr.GetVal<double>("latitude");
76 longitude = qr.GetVal<double>("longitude");
77 };
78#line 51 "/cycamore/src/growth_region.h"
79
80 virtual void InfileToDb(cyclus::InfileTree* tree, cyclus::DbInit di) {
81 cyclus::Region::InfileToDb(tree, di);
82 int rawcycpp_shape_commodity_demand[8] = {-1, -1, -1, -1, -1, -1, -1, -1};
83 cycpp_shape_commodity_demand = std::vector<int>(rawcycpp_shape_commodity_demand, rawcycpp_shape_commodity_demand + 8);
84 int rawcycpp_shape_latitude[1] = {-1};
85 cycpp_shape_latitude = std::vector<int>(rawcycpp_shape_latitude, rawcycpp_shape_latitude + 1);
86 int rawcycpp_shape_longitude[1] = {-1};
87 cycpp_shape_longitude = std::vector<int>(rawcycpp_shape_longitude, rawcycpp_shape_longitude + 1);
88 cyclus::InfileTree* sub = tree->SubTree("config/*");
89 int i;
90 int n;
91 {
92 cyclus::InfileTree* bub = sub->SubTree("growth", 0);
93 cyclus::InfileTree* sub = bub;
94 int n1 = sub->NMatches("item");
95 std::map< std::string, std::vector< std::pair< int, std::pair< std::string, std::string > > > > commodity_demand_val;
96 for (int i1 = 0; i1 < n1; ++i1) {
97 std::string key;
98 {
99 std::string key_in = cyclus::Query<std::string>(sub, "item/commod", i1);
100 key = key_in;
101 }
102 std::vector< std::pair< int, std::pair< std::string, std::string > > > val;
103 {
104 cyclus::InfileTree* bub = sub->SubTree("item/piecewise_function", i1);
105 cyclus::InfileTree* sub = bub;
106 int n2 = sub->NMatches("piece");
107 std::vector< std::pair< int, std::pair< std::string, std::string > > > val_in;
108 val_in.resize(n2);
109 for (int i2 = 0; i2 < n2; ++i2) {
110 std::pair< int, std::pair< std::string, std::string > > elem;
111 {
112 cyclus::InfileTree* bub = sub->SubTree("piece", i2);
113 cyclus::InfileTree* sub = bub;
114 int firsti2;
115 {
116 int firsti2_in = cyclus::Query<int>(sub, "start", 0);
117 firsti2 = firsti2_in;
118 }
119 std::pair< std::string, std::string > secondi2;
120 {
121 cyclus::InfileTree* bub = sub->SubTree("function", 0);
122 cyclus::InfileTree* sub = bub;
123 std::string first0;
124 {
125 std::string first0_in = cyclus::Query<std::string>(sub, "type", 0);
126 first0 = first0_in;
127 }
128 std::string second0;
129 {
130 std::string second0_in = cyclus::Query<std::string>(sub, "params", 0);
131 second0 = second0_in;
132 }
133 std::pair< std::string, std::string > secondi2_in(first0, second0);
134 secondi2 = secondi2_in;
135 }
136 std::pair< int, std::pair< std::string, std::string > > elem_in(firsti2, secondi2);
137 elem = elem_in;
138 }
139 val_in[i2] = elem;
140 }
141 val = val_in;
142 }
143 commodity_demand_val[key] = val;
144 }
145 commodity_demand = commodity_demand_val;
146 }
147 if (sub->NMatches("latitude") > 0) {
148 {
149 double latitude_val = cyclus::Query<double>(sub, "latitude");
150 latitude = latitude_val;
151 }
152 } else {
153 double latitude_tmp = 0.0;
154 latitude = latitude_tmp;
155 }
156 if (sub->NMatches("longitude") > 0) {
157 {
158 double longitude_val = cyclus::Query<double>(sub, "longitude");
159 longitude = longitude_val;
160 }
161 } else {
162 double longitude_tmp = 0.0;
163 longitude = longitude_tmp;
164 }
165 di.NewDatum("Info")
166 ->AddVal("commodity_demand", commodity_demand, &cycpp_shape_commodity_demand)
167 ->AddVal("latitude", latitude, &cycpp_shape_latitude)
168 ->AddVal("longitude", longitude, &cycpp_shape_longitude)
169 ->Record();
170 };
171
172 virtual cyclus::Agent* Clone() {
174 m->InitFrom(this);
175 return m;
176 };
177
178 virtual std::string schema() {
179 return ""
180 "<interleave>\n"
181 " <element name=\"growth\">\n"
182 " <oneOrMore>\n"
183 " <element name=\"item\">\n"
184 " <interleave>\n"
185 " <element name=\"commod\">\n"
186 " <data type=\"string\"/>\n"
187 " </element>\n"
188 " <element name=\"piecewise_function\">\n"
189 " <oneOrMore>\n"
190 " <element name=\"piece\">\n"
191 " <interleave>\n"
192 " <element name=\"start\">\n"
193 " <data type=\"int\"/>\n"
194 " </element>\n"
195 " <element name=\"function\">\n"
196 " <interleave>\n"
197 " <element name=\"type\">\n"
198 " <data type=\"string\"/>\n"
199 " </element>\n"
200 " <element name=\"params\">\n"
201 " <data type=\"string\"/>\n"
202 " </element>\n"
203 " </interleave>\n"
204 " </element>\n"
205 " </interleave>\n"
206 " </element>\n"
207 " </oneOrMore>\n"
208 " </element>\n"
209 " </interleave>\n"
210 " </element>\n"
211 " </oneOrMore>\n"
212 " </element>\n"
213 " <optional>\n"
214 " <element name=\"latitude\">\n"
215 " <data type=\"double\"/>\n"
216 " </element>\n"
217 " </optional>\n"
218 " <optional>\n"
219 " <element name=\"longitude\">\n"
220 " <data type=\"double\"/>\n"
221 " </element>\n"
222 " </optional>\n"
223 "</interleave>\n";
224 };
225
226 virtual Json::Value annotations() {
227 Json::Value root;
228 Json::Reader reader;
229 bool parsed_ok = reader.parse(
230 "{\"name\":\"cycamore::GrowthRegion\",\"entity\":\"region\""
231 ",\"parents\":[\"cyclus::Region\",\"cyclus::toolkit::Pos"
232 "ition\"],\"all_parents\":[\"cyclus::Agent\",\"cyclus::Id"
233 "er\",\"cyclus::Region\",\"cyclus::StateWrangler\",\"cycl"
234 "us::TimeListener\",\"cyclus::toolkit::Position\"],\"va"
235 "rs\":{\"commodity_demand\":{\"alias\":[[\"growth\",\"item\""
236 "],\"commod\",[\"piecewise_function\",[\"piece\",\"start\","
237 "[\"function\",\"type\",\"params\"]]]],\"uitype\":[\"oneormo"
238 "re\",\"string\",[\"oneormore\",[\"pair\",\"int\",[\"pair\",\"s"
239 "tring\",\"string\"]]]],\"uilabel\":[[\"Growth Demand Cur"
240 "ves\",\"\"],\"\",[\"\",[\"\",\"\",[\"\",\"\",\"\"]]]],\"doc\":\"Namepl"
241 "ate capacity demand functions.\\n\\nEach demand type"
242 " must be for a commodity for which capacity can be"
243 " built (e.g., 'power' from cycamore::Reactors). "
244 "Any archetype that implements the "
245 "cyclus::toolkit::CommodityProducer interface can "
246 "interact with the GrowthRegion in the "
247 "manner.\\n\\nDemand functions are defined as "
248 "piecewise functions. Each piece must be provided a"
249 " starting time and function description. Each "
250 "function description is comprised of a function "
251 "type and associated parameters. \\n\\n * Start "
252 "times are inclusive. For a start time :math:`t_0`,"
253 " the demand function is evaluated on :math:`[t_0, "
254 "\\\\infty)`.\\n\\n * Supported function types are "
255 "based on the "
256 "`cyclus::toolkit::BasicFunctionFactory types <http"
257 "://fuelcycle.org/cyclus/api/classcyclus_1_1toolkit"
258 "_1_1BasicFunctionFactory.html#a2f3806305d99a745ab5"
259 "7c300e54a603d>`_. \\n\\n * The type name is the "
260 "lower-case name of the function (e.g., 'linear', "
261 "'exponential', etc.).\\n\\n * The parameters "
262 "associated with each function type can be found on"
263 " their respective documentation pages.\",\"type\":[\"s"
264 "td::map\",\"std::string\",[\"std::vector\",[\"std::pair\""
265 ",\"int\",[\"std::pair\",\"std::string\",\"std::string\"]]]"
266 "],\"index\":0,\"shape\":[-1,-1,-1,-1,-1,-1,-1,-"
267 "1],\"tooltip\":[[\"commodity_demand\",\"\"],\"\",[\"\",[\"\",\""
268 "\",[\"\",\"\",\"\"]]]]},\"growth\":\"commodity_demand\",\"lati"
269 "tude\":{\"default\":0.0,\"uilabel\":\"Geographical "
270 "latitude in degrees as a double\",\"doc\":\"Latitude "
271 "of the agent's geographical position. The value "
272 "should be expressed in degrees as a double.\",\"type"
273 "\":\"double\",\"index\":2,\"shape\":[-"
274 "1],\"alias\":\"latitude\",\"tooltip\":\"latitude\"},\"longi"
275 "tude\":{\"default\":0.0,\"uilabel\":\"Geographical "
276 "longitude in degrees as a double\",\"doc\":\"Longitude"
277 " of the agent's geographical position. The value "
278 "should be expressed in degrees as a double.\",\"type"
279 "\":\"double\",\"index\":3,\"shape\":[-"
280 "1],\"alias\":\"longitude\",\"tooltip\":\"longitude\"}},\"do"
281 "c\":\"A region that governs a scenario in which "
282 "there is growth in demand for a commodity. \"}", root);
283 if (!parsed_ok) {
284 throw cyclus::ValueError("failed to parse annotations for cycamore::GrowthRegion.");
285 }
286 return root;
287 };
288
289 virtual void InitInv(cyclus::Inventories& inv) {
290 };
291
292 virtual cyclus::Inventories SnapshotInv() {
293 cyclus::Inventories invs;
294 return invs;
295 };
296
297 virtual void Snapshot(cyclus::DbInit di) {
298 di.NewDatum("Info")
299 ->AddVal("commodity_demand", commodity_demand, &cycpp_shape_commodity_demand)
300 ->AddVal("latitude", latitude, &cycpp_shape_latitude)
301 ->AddVal("longitude", longitude, &cycpp_shape_longitude)
302 ->Record();
303 };
304
305 #pragma cyclus note {"doc": "A region that governs a scenario in which " "there is growth in demand for a commodity. "}
306#line 54 "/cycamore/src/growth_region.h"
307
313 virtual void Tick();
314
316 virtual void EnterNotify();
317
319 virtual void DecomNotify(Agent* m);
320
321 inline cyclus::toolkit::SupplyDemandManager* sdmanager() {
322 return &sdmanager_;
323 }
324
325 protected:
326 #pragma cyclus var { "alias": ["growth", "commod", ["piecewise_function", ["piece", "start", ["function", "type", "params"]]]], "uitype": ["oneormore", "string", ["oneormore", ["pair", "int", ["pair", "string", "string"]]]], "uilabel": "Growth Demand Curves", "doc": "Nameplate capacity demand functions." "\n\n" "Each demand type must be for a commodity for which capacity can be built " "(e.g., 'power' from cycamore::Reactors). Any archetype that implements the " "cyclus::toolkit::CommodityProducer interface can interact with the " "GrowthRegion in the manner." "\n\n" "Demand functions are defined as piecewise functions. Each piece must " "be provided a starting time and function description. Each function " "description is comprised of a function type and associated parameters. " "\n\n" " * Start times are inclusive. For a start time :math:`t_0`, the demand " "function is evaluated on :math:`[t_0, \infty)`." "\n\n" " * Supported function types are based on the " "`cyclus::toolkit::BasicFunctionFactory " "types <http://fuelcycle.org/cyclus/api/classcyclus_1_1toolkit_1_1BasicFunctionFactory.html#a2f3806305d99a745ab57c300e54a603d>`_. " "\n\n" " * The type name is the lower-case name of the function (e.g., " "'linear', 'exponential', etc.)." "\n\n" " * The parameters associated with each function type can be found on their " "respective documentation pages.", }
327 std::map<std::string, std::vector<std::pair<int, std::pair<std::string, std::string> > > > commodity_demand;
329 // must match Demand typedef
330#line 106 "/cycamore/src/growth_region.h"
331
332#if CYCLUS_HAS_COIN
334 cyclus::toolkit::BuildingManager buildmanager_;
335#endif
336
338 cyclus::toolkit::SupplyDemandManager sdmanager_;
339
341 void Register_(cyclus::Agent* agent);
342
344 void Unregister_(cyclus::Agent* agent);
345
348 void AddCommodityDemand_(std::string commod, Demand& demand);
349
354 void OrderBuilds(cyclus::toolkit::Commodity& commodity, double unmetdemand);
355
356 private:
357 #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." }
358#line 138 "/cycamore/src/growth_region.h"
359 double latitude;
360 std::vector<int> cycpp_shape_latitude;
361#line 139 "/cycamore/src/growth_region.h"
362
363
364 #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." }
365#line 146 "/cycamore/src/growth_region.h"
366 double longitude;
367 std::vector<int> cycpp_shape_longitude;
368
369#line 147 "/cycamore/src/growth_region.h"
370
371 cyclus::toolkit::Position coordinates;
372
374 void RecordPosition();
375};
376} // namespace cycamore
377
378#endif // CYCAMORE_SRC_GROWTH_REGION_H_
#define CYCAMORE_VERSION
This region determines if there is a need to meet a certain capacity (as defined via input) at each t...
void RecordPosition()
Records an agent's latitude and longitude to the output db.
virtual cyclus::Inventories SnapshotInv()
cyclus::toolkit::SupplyDemandManager * sdmanager()
virtual void InitFrom(cycamore::GrowthRegion *m)
void Unregister_(cyclus::Agent *agent)
unregister a child
std::vector< int > cycpp_shape_commodity_demand
virtual void Snapshot(cyclus::DbInit di)
GrowthRegion(cyclus::Context *ctx)
The default constructor for the GrowthRegion.
virtual void EnterNotify()
enter the simulation and register any children present
virtual void InitInv(cyclus::Inventories &inv)
virtual void DecomNotify(Agent *m)
unregister a child
cyclus::toolkit::SupplyDemandManager sdmanager_
manager for Supply and demand
virtual void Tick()
On each tick, the GrowthRegion queries its supply demand manager to determine if there exists some de...
virtual cyclus::Agent * Clone()
cyclus::toolkit::Position coordinates
void OrderBuilds(cyclus::toolkit::Commodity &commodity, double unmetdemand)
orders builds given a commodity and an unmet demand for production capacity of that commodity
virtual ~GrowthRegion()
The default destructor for the GrowthRegion.
std::map< std::string, std::vector< std::pair< int, std::pair< std::string, std::string > > > > commodity_demand
virtual void InfileToDb(cyclus::InfileTree *tree, cyclus::DbInit di)
void Register_(cyclus::Agent *agent)
register a child
void AddCommodityDemand_(std::string commod, Demand &demand)
add a demand for a commodity on which this region request that facilities be built
virtual void InitFrom(cyclus::QueryableBackend *b)
std::vector< std::pair< int, std::pair< std::string, std::string > > > Demand
A container of (time, (demand type, demand parameters))