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);
60 latitude = m->latitude;
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 " <a:documentation>Latitude of the agent's geographical position. The value should be expressed in degrees as a double.</a:documentation>\n"
216 " <data type=\"double\"/>\n"
217 " </element>\n"
218 " </optional>\n"
219 " <optional>\n"
220 " <element name=\"longitude\">\n"
221 " <a:documentation>Longitude of the agent's geographical position. The value should be expressed in degrees as a double.</a:documentation>\n"
222 " <data type=\"double\"/>\n"
223 " </element>\n"
224 " </optional>\n"
225 "</interleave>\n";
226 };
227
228 virtual Json::Value annotations() {
229 Json::Value root;
230 Json::Reader reader;
231 bool parsed_ok = reader.parse(
232 "{\"name\":\"cycamore::GrowthRegion\",\"entity\":\"region\""
233 ",\"parents\":[\"cyclus::Region\",\"cyclus::toolkit::Pos"
234 "ition\"],\"all_parents\":[\"EconomicEntity\",\"cyclus::A"
235 "gent\",\"cyclus::Ider\",\"cyclus::Region\",\"cyclus::Sta"
236 "teWrangler\",\"cyclus::TimeListener\",\"cyclus::toolki"
237 "t::Position\"],\"vars\":{\"commodity_demand\":{\"alias\":"
238 "[[\"growth\",\"item\"],\"commod\",[\"piecewise_function\","
239 "[\"piece\",\"start\",[\"function\",\"type\",\"params\"]]]],\""
240 "uitype\":[\"oneormore\",\"string\",[\"oneormore\",[\"pair\""
241 ",\"int\",[\"pair\",\"string\",\"string\"]]]],\"uilabel\":[[\""
242 "Growth Demand Curves\",\"\"],\"\",[\"\",[\"\",\"\",[\"\",\"\",\"\"]"
243 "]]],\"doc\":\"Nameplate capacity demand "
244 "functions.\\n\\nEach demand type must be for a "
245 "commodity for which capacity can be built (e.g., "
246 "'power' from cycamore::Reactors). Any archetype "
247 "that implements the "
248 "cyclus::toolkit::CommodityProducer interface can "
249 "interact with the GrowthRegion in the "
250 "manner.\\n\\nDemand functions are defined as "
251 "piecewise functions. Each piece must be provided a"
252 " starting time and function description. Each "
253 "function description is comprised of a function "
254 "type and associated parameters. \\n\\n * Start "
255 "times are inclusive. For a start time :math:`t_0`,"
256 " the demand function is evaluated on :math:`[t_0, "
257 "\\\\infty)`.\\n\\n * Supported function types are "
258 "based on the "
259 "`cyclus::toolkit::BasicFunctionFactory types <http"
260 "://fuelcycle.org/cyclus/api/classcyclus_1_1toolkit"
261 "_1_1BasicFunctionFactory.html#a2f3806305d99a745ab5"
262 "7c300e54a603d>`_. \\n\\n * The type name is the "
263 "lower-case name of the function (e.g., 'linear', "
264 "'exponential', etc.).\\n\\n * The parameters "
265 "associated with each function type can be found on"
266 " their respective documentation pages.\",\"type\":[\"s"
267 "td::map\",\"std::string\",[\"std::vector\",[\"std::pair\""
268 ",\"int\",[\"std::pair\",\"std::string\",\"std::string\"]]]"
269 "],\"index\":0,\"shape\":[-1,-1,-1,-1,-1,-1,-1,-"
270 "1],\"tooltip\":[[\"commodity_demand\",\"\"],\"\",[\"\",[\"\",\""
271 "\",[\"\",\"\",\"\"]]]]},\"growth\":\"commodity_demand\",\"lati"
272 "tude\":{\"default\":0.0,\"uilabel\":\"Geographical "
273 "latitude in degrees as a double\",\"doc\":\"Latitude "
274 "of the agent's geographical position. The value "
275 "should be expressed in degrees as a double.\",\"type"
276 "\":\"double\",\"index\":2,\"shape\":[-"
277 "1],\"alias\":\"latitude\",\"tooltip\":\"latitude\"},\"longi"
278 "tude\":{\"default\":0.0,\"uilabel\":\"Geographical "
279 "longitude in degrees as a double\",\"doc\":\"Longitude"
280 " of the agent's geographical position. The value "
281 "should be expressed in degrees as a double.\",\"type"
282 "\":\"double\",\"index\":3,\"shape\":[-"
283 "1],\"alias\":\"longitude\",\"tooltip\":\"longitude\"}},\"do"
284 "c\":\"A region that governs a scenario in which "
285 "there is growth in demand for a commodity. \"}", root);
286 if (!parsed_ok) {
287 throw cyclus::ValueError("failed to parse annotations for cycamore::GrowthRegion.");
288 }
289 return root;
290 };
291
292 virtual void InitInv(cyclus::Inventories& inv) {
293 };
294
295 virtual cyclus::Inventories SnapshotInv() {
296 cyclus::Inventories invs;
297 return invs;
298 };
299
300 virtual void Snapshot(cyclus::DbInit di) {
301 di.NewDatum("Info")
302 ->AddVal("commodity_demand", commodity_demand, &cycpp_shape_commodity_demand)
303 ->AddVal("latitude", latitude, &cycpp_shape_latitude)
304 ->AddVal("longitude", longitude, &cycpp_shape_longitude)
305 ->Record();
306 };
307
308 #pragma cyclus note {"doc": "A region that governs a scenario in which " "there is growth in demand for a commodity. "}
309#line 54 "/cycamore/src/growth_region.h"
310
316 virtual void Tick();
317
319 virtual void EnterNotify();
320
322 virtual void DecomNotify(Agent* m);
323
324 inline cyclus::toolkit::SupplyDemandManager* sdmanager() {
325 return &sdmanager_;
326 }
327
328 protected:
329 #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.", }
330 std::map<std::string, std::vector<std::pair<int, std::pair<std::string, std::string> > > > commodity_demand;
332 // must match Demand typedef
333#line 106 "/cycamore/src/growth_region.h"
334
335#if CYCLUS_HAS_COIN
337 cyclus::toolkit::BuildingManager buildmanager_;
338#endif
339
341 cyclus::toolkit::SupplyDemandManager sdmanager_;
342
344 void Register_(cyclus::Agent* agent);
345
347 void Unregister_(cyclus::Agent* agent);
348
351 void AddCommodityDemand_(std::string commod, Demand& demand);
352
357 void OrderBuilds(cyclus::toolkit::Commodity& commodity, double unmetdemand);
358
359 private:
360 #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." }
361#line 138 "/cycamore/src/growth_region.h"
362 double latitude;
363 std::vector<int> cycpp_shape_latitude;
364#line 139 "/cycamore/src/growth_region.h"
365
366
367 #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." }
368#line 146 "/cycamore/src/growth_region.h"
369 double longitude;
370 std::vector<int> cycpp_shape_longitude;
371
372#line 147 "/cycamore/src/growth_region.h"
373
374 cyclus::toolkit::Position coordinates;
375
377 void RecordPosition();
378};
379} // namespace cycamore
380
381#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))