CYCLUS
Loading...
Searching...
No Matches
sim_init.cc
Go to the documentation of this file.
1#include "sim_init.h"
2
4#include "greedy_solver.h"
5#include "platform.h"
6#include "prog_solver.h"
7#include "region.h"
8
9namespace cyclus {
10
11class Dummy : public Region {
12 public:
13 Dummy(Context* ctx) : Region(ctx) {}
14 Dummy* Clone() { return NULL; }
15};
16
17SimInit::SimInit() : rec_(NULL), ctx_(NULL) {}
18
20 if (ctx_ != NULL) {
21 delete ctx_;
22 }
23}
24
27 rec_ = &tmprec; // use dummy recorder to avoid re-recording
28 InitBase(b, r->sim_id(), 0);
29 ctx_->rec_ = r; // switch back before running sim
30}
31
32void SimInit::Restart(QueryableBackend* b, boost::uuids::uuid sim_id, int t) {
33 Warn<EXPERIMENTAL_WARNING>("restart capability is not finalized and fully"
34 " tested. Its behavior may change in future"
35 " releases.");
36 rec_ = new Recorder();
37 InitBase(b, sim_id, t);
38 si_.parent_sim = sim_id;
39 si_.parent_type = "restart";
40 si_.branch_time = t;
41 ctx_->InitSim(si_); // explicitly force this to show up in the new simulations output db
42}
43
44void SimInit::Branch(QueryableBackend* b, boost::uuids::uuid prev_sim_id,
45 int t, boost::uuids::uuid new_sim_id) {
46 throw Error("simulation branching feature not implemented");
47}
48
49void SimInit::InitBase(QueryableBackend* b, boost::uuids::uuid simid, int t) {
50 ctx_ = new Context(&ti_, rec_);
51
52 std::vector<Cond> conds;
53 conds.push_back(Cond("SimId", "==", simid));
54 b_ = new CondInjector(b, conds);
55 t_ = t;
56 simid_ = simid;
57
58 // this sequence is imporant!!!
59 LoadInfo();
60 LoadRecipes();
61 LoadPackages();
62 LoadTransportUnits();
63 LoadSolverInfo();
64 LoadPrototypes();
65 LoadInitialAgents();
66 LoadInventories();
67 LoadBuildSched();
68 LoadDecomSched();
69 LoadNextIds();
70
71 // delete all buffered data that we don't want to be re-recorded in the
72 // output db
73 rec_->Flush();
74}
75
77 ctx->NewDatum("Snapshots")
78 ->AddVal("Time", ctx->time())
79 ->Record();
80
81 // snapshot all agent internal state
82 std::set<Agent*> mlist = ctx->agent_list_;
83 std::set<Agent*>::iterator it;
84 for (it = mlist.begin(); it != mlist.end(); ++it) {
85 Agent* m = *it;
86 if (m->enter_time() != -1) {
88 }
89 }
90
91 // snapshot all next ids
92 ctx->NewDatum("NextIds")
93 ->AddVal("Time", ctx->time())
94 ->AddVal("Object", std::string("Agent"))
95 ->AddVal("NextId", Agent::next_id_)
96 ->Record();
97 ctx->NewDatum("NextIds")
98 ->AddVal("Time", ctx->time())
99 ->AddVal("Object", std::string("Transaction"))
100 ->AddVal("NextId", ctx->trans_id_)
101 ->Record();
102 ctx->NewDatum("NextIds")
103 ->AddVal("Time", ctx->time())
104 ->AddVal("Object", std::string("Composition"))
105 ->AddVal("NextId", Composition::next_id_)
106 ->Record();
107 ctx->NewDatum("NextIds")
108 ->AddVal("Time", ctx->time())
109 ->AddVal("Object", std::string("ResourceState"))
110 ->AddVal("NextId", Resource::nextstate_id_)
111 ->Record();
112 ctx->NewDatum("NextIds")
113 ->AddVal("Time", ctx->time())
114 ->AddVal("Object", std::string("ResourceObj"))
115 ->AddVal("NextId", Resource::nextobj_id_)
116 ->Record();
117 ctx->NewDatum("NextIds")
118 ->AddVal("Time", ctx->time())
119 ->AddVal("Object", std::string("Product"))
120 ->AddVal("NextId", Product::next_qualid_)
121 ->Record();
122}
123
125 // call manually without agent impl injected to keep all Agent state in a
126 // single, consolidated db table
127 m->Agent::Snapshot(DbInit(m, true));
128
129 m->Snapshot(DbInit(m));
131 Context* ctx = m->context();
132
133 Inventories::iterator it;
134 for (it = invs.begin(); it != invs.end(); ++it) {
135 std::string name = it->first;
136 std::vector<Resource::Ptr> inv = it->second;
137 for (int i = 0; i < inv.size(); ++i) {
138 ctx->NewDatum("AgentStateInventories")
139 ->AddVal("AgentId", m->id())
140 ->AddVal("SimTime", ctx->time())
141 ->AddVal("InventoryName", name)
142 ->AddVal("ResourceId", inv[i]->state_id())
143 ->Record();
144 }
145 }
146}
147
148void SimInit::LoadInfo() {
149 QueryResult qr = b_->Query("Info", NULL);
150 int dur = qr.GetVal<int>("Duration");
151 int y0 = qr.GetVal<int>("InitialYear");
152 int m0 = qr.GetVal<int>("InitialMonth");
153 std::string h = qr.GetVal<std::string>("Handle");
154 QueryResult dq = b_->Query("DecayMode", NULL);
155 std::string d = dq.GetVal<std::string>("Decay");
156 si_ = SimInfo(dur, y0, m0, h, d);
157
158 si_.seed = qr.GetVal<int>("Seed");
159 si_.stride = qr.GetVal<int>("Stride");
160
161 si_.parent_sim = qr.GetVal<boost::uuids::uuid>("ParentSimId");
162
163 qr = b_->Query("TimeStepDur", NULL);
164 // TODO: when the backends support uint64_t, the int template here
165 // should be updated to uint64_t.
166 si_.dt = qr.GetVal<int>("DurationSecs");
167
168 qr = b_->Query("Epsilon", NULL);
169 si_.eps = qr.GetVal<double>("GenericEpsilon");
170 si_.eps_rsrc = qr.GetVal<double>("ResourceEpsilon");
171
172 qr = b_->Query("InfoExplicitInv", NULL);
173 si_.explicit_inventory = qr.GetVal<bool>("RecordInventory");
174 si_.explicit_inventory_compact = qr.GetVal<bool>("RecordInventoryCompact");
175
176 ctx_->InitSim(si_);
177}
178
179void SimInit::LoadRecipes() {
180 QueryResult qr;
181 try {
182 qr = b_->Query("Recipes", NULL);
183 } catch (std::exception err) {
184 return;
185 } // table doesn't exist (okay)
186
187 for (int i = 0; i < qr.rows.size(); ++i) {
188 std::string recipe = qr.GetVal<std::string>("Recipe", i);
189 int stateid = qr.GetVal<int>("QualId", i);
190 Composition::Ptr c = LoadComposition(b_, stateid);
191 ctx_->AddRecipe(recipe, c);
192 }
193}
194
195void SimInit::LoadPackages() {
196 QueryResult qr;
197 try {
198 qr = b_->Query("Packages", NULL);
199 } catch (std::exception err) {
200 return;
201 } // table doesn't exist (okay)
202
203 for (int i = 0; i < qr.rows.size(); ++i) {
204 std::string name = qr.GetVal<std::string>("PackageName", i);
205 double fill_min = qr.GetVal<double>("FillMin", i);
206 double fill_max = qr.GetVal<double>("FillMax", i);
207 std::string strategy = qr.GetVal<std::string>("Strategy", i);
208
209 if (name != Package::unpackaged_name()) {
210 ctx_->AddPackage(name, fill_min, fill_max, strategy);
211 }
212 else {
214 }
215 }
216}
217
218void SimInit::LoadTransportUnits() {
219 QueryResult qr;
220 try {
221 qr = b_->Query("TransportUnits", NULL);
222 } catch (std::exception err) {
223 return;
224 } // table doesn't exist (okay)
225
226 for (int i = 0; i < qr.rows.size(); ++i) {
227 std::string name = qr.GetVal<std::string>("TransportUnitName", i);
228 int fill_min = qr.GetVal<int>("FillMin", i);
229 int fill_max = qr.GetVal<int>("FillMax", i);
230 std::string strategy = qr.GetVal<std::string>("Strategy", i);
231
232 if (name != TransportUnit::unrestricted_name()) {
233 ctx_->AddTransportUnit(name, fill_min, fill_max, strategy);
234 }
235 else {
237 }
238 }
239}
240
241void* SimInit::LoadPreconditioner(std::string name) {
242 using std::map;
243 using std::string;
244 void* precon = NULL;
246 try {
247 QueryResult qr = b_->Query("CommodPriority", NULL);
248 for (int i = 0; i < qr.rows.size(); ++i) {
249 std::string commod = qr.GetVal<string>("Commodity", i);
250 double order = qr.GetVal<double>("SolutionOrder", i);
251 commod_order[commod] = order;
252 }
253 } catch (std::exception err) {
254 return NULL;
255 } // table doesn't exist (okay)
256
257 // actually create and return the preconditioner
258 if (name == "greedy") {
259 precon = new GreedyPreconditioner(commod_order,
261 } else {
262 throw ValueError("The name of the preconditioner was not recognized, "
263 "got '" + name + "'.");
264 }
265 return precon;
266}
267
268ExchangeSolver* SimInit::LoadGreedySolver(bool exclusive,
269 std::set<std::string> tables) {
270 using std::set;
271 using std::string;
272 ExchangeSolver* solver;
273 void* precon = NULL;
274 string precon_name = string("greedy");
275
276 string solver_info = string("GreedySolverInfo");
277 if (0 < tables.count(solver_info)) {
278 QueryResult qr = b_->Query(solver_info, NULL);
279 if (qr.rows.size() > 0) {
280 precon_name = qr.GetVal<string>("Preconditioner");
281 }
282 }
283
284 precon = LoadPreconditioner(precon_name);
285 if (precon == NULL) {
286 solver = new GreedySolver(exclusive);
287 } else {
288 solver = new GreedySolver(exclusive,
289 reinterpret_cast<GreedyPreconditioner*>(precon));
290 }
291 return solver;
292}
293
294ExchangeSolver* SimInit::LoadCoinSolver(bool exclusive,
295 std::set<std::string> tables) {
296#if CYCLUS_HAS_COIN
297 ExchangeSolver* solver;
298 double timeout;
299 bool verbose, mps;
300
301 std::string solver_info = "CoinSolverInfo";
302 if (0 < tables.count(solver_info)) {
303 QueryResult qr = b_->Query(solver_info, NULL);
304 timeout = qr.GetVal<double>("Timeout");
305 verbose = qr.GetVal<bool>("Verbose");
306 mps = qr.GetVal<bool>("Mps");
307 }
308
309 // set timeout to default if input value is non-positive
311 solver = new ProgSolver("cbc", timeout, exclusive, verbose, mps);
312 return solver;
313#else
314 throw cyclus::Error("Cyclus was not compiled with COIN support, cannot load solver.");
315#endif
316}
317
318void SimInit::LoadSolverInfo() {
319 using std::set;
320 using std::string;
321 // context will delete solver
322 ExchangeSolver* solver;
323 string solver_name;
324 bool exclusive_orders;
325
326 // load in possible Solver info, needs to be optional to
327 // maintain backwards compatibility, defaults above.
328 set<string> tables = b_->Tables();
329 string solver_info = string("SolverInfo");
330 if (0 < tables.count(solver_info)) {
331 QueryResult qr = b_->Query(solver_info, NULL);
332 if (qr.rows.size() > 0) {
333 solver_name = qr.GetVal<string>("Solver");
334 exclusive_orders = qr.GetVal<bool>("ExclusiveOrders");
335 }
336 }
337
338 if (solver_name == "greedy") {
339 solver = LoadGreedySolver(exclusive_orders, tables);
340 } else if (solver_name == "coin-or") {
341 solver = LoadCoinSolver(exclusive_orders, tables);
342 } else {
343 throw ValueError("The name of the solver was not recognized, "
344 "got '" + solver_name + "'.");
345 }
346
347 ctx_->solver(solver);
348}
349
350void SimInit::LoadPrototypes() {
351 QueryResult qr = b_->Query("Prototypes", NULL);
352 for (int i = 0; i < qr.rows.size(); ++i) {
353 std::string proto = qr.GetVal<std::string>("Prototype", i);
354 int agentid = qr.GetVal<int>("AgentId", i);
355 std::string impl = qr.GetVal<std::string>("Spec", i);
356 AgentSpec spec(impl);
357
358 Agent* m = DynamicModule::Make(ctx_, spec);
359 m->id_ = agentid;
360
361 // note that we don't filter by SimTime here because prototypes remain
362 // static over the life of the simulation and we only snapshot them once
363 // when the simulation is initialized.
364 std::vector<Cond> conds;
365 conds.push_back(Cond("AgentId", "==", agentid));
366 CondInjector ci(b_, conds);
367 PrefixInjector pi(&ci, "AgentState");
368
369 // call manually without agent impl injected
370 m->Agent::InitFrom(&pi);
371
372 pi = PrefixInjector(&ci, "AgentState" + spec.Sanitize());
373 m->InitFrom(&pi);
374 ctx_->AddPrototype(proto, m);
375 }
376}
377
378void SimInit::LoadInitialAgents() {
379 // DO NOT call the agents' Build methods because the agents might modify the
380 // state of their children and/or the simulation in ways that are only meant
381 // to be done once; remember that we are initializing agents from a
382 // simulation that was already started.
383
384 // find all agents that are alive at the current timestep
385 std::vector<Cond> conds;
386 conds.push_back(Cond("EnterTime", "<=", t_));
387 QueryResult qentry = b_->Query("AgentEntry", &conds);
388 std::map<int, int> parentmap; // map<agentid, parentid>
389 std::map<int, Agent*> unbuilt; // map<agentid, agent_ptr>
390 for (int i = 0; i < qentry.rows.size(); ++i) {
391 if (t_ > 0 && qentry.GetVal<int>("EnterTime", i) == t_) {
392 // agent is scheduled to be built already
393 continue;
394 }
395 int id = qentry.GetVal<int>("AgentId", i);
396 std::vector<Cond> conds;
397 conds.push_back(Cond("AgentId", "==", id));
398 conds.push_back(Cond("ExitTime", "<", t_));
399 try {
400 QueryResult qexit = b_->Query("AgentExit", &conds);
401 if (qexit.rows.size() != 0) {
402 continue; // agent was decomissioned before t_ - skip
403 }
404 } catch (std::exception err) {} // table doesn't exist (okay)
405
406 // if the agent wasn't decommissioned before t_ create and init it
407
408 std::string proto = qentry.GetVal<std::string>("Prototype", i);
409 std::string impl = qentry.GetVal<std::string>("Spec", i);
410 AgentSpec spec(impl);
411 Agent* m = DynamicModule::Make(ctx_, spec);
412
413 // agent-kernel init
414 m->prototype_ = proto;
415 m->id_ = id;
416 m->enter_time_ = qentry.GetVal<int>("EnterTime", i);
417 unbuilt[id] = m;
418 parentmap[id] = qentry.GetVal<int>("ParentId", i);
419
420 // agent-custom init
421 conds.pop_back();
422 conds.push_back(Cond("SimTime", "==", t_));
423 CondInjector ci(b_, conds);
424 PrefixInjector pi(&ci, "AgentState");
425 m->Agent::InitFrom(&pi);
426 pi = PrefixInjector(&ci, "AgentState" + spec.Sanitize());
427 m->InitFrom(&pi);
428 }
429
430 // construct agent hierarchy starting at roots (no parent) down
431 std::map<int, Agent*>::iterator it = unbuilt.begin();
432 std::vector<Agent*> enter_list;
433 while (unbuilt.size() > 0) {
434 int id = it->first;
435 Agent* m = it->second;
436 int parentid = parentmap[id];
437
438 if (parentid == -1) { // root agent
439 m->Connect(NULL);
440 agents_[id] = m;
441 ++it;
442 unbuilt.erase(id);
443 enter_list.push_back(m);
444 } else if (agents_.count(parentid) > 0) { // parent is built
445 m->Connect(agents_[parentid]);
446 agents_[id] = m;
447 ++it;
448 unbuilt.erase(id);
449 enter_list.push_back(m);
450 } else { // parent not built yet
451 ++it;
452 }
453 if (it == unbuilt.end()) {
454 it = unbuilt.begin();
455 }
456 }
457
458 // notify all agents that they are active in a simulation AFTER the
459 // parent-child hierarchy has been reconstructed.
460 for (int i = 0; i < enter_list.size(); ++i) {
461 enter_list[i]->EnterNotify();
462 }
463}
464
465void SimInit::LoadInventories() {
466 std::map<int, Agent*>::iterator it;
467 for (it = agents_.begin(); it != agents_.end(); ++it) {
468 Agent* m = it->second;
469 std::vector<Cond> conds;
470 conds.push_back(Cond("SimTime", "==", t_));
471 conds.push_back(Cond("AgentId", "==", m->id()));
472 QueryResult qr;
473 try {
474 qr = b_->Query("AgentStateInventories", &conds);
475 } catch (std::exception err) {return;} // table doesn't exist (okay)
476
478 for (int i = 0; i < qr.rows.size(); ++i) {
479 std::string inv_name = qr.GetVal<std::string>("InventoryName", i);
480 int state_id = qr.GetVal<int>("ResourceId", i);
481 invs[inv_name].push_back(LoadResource(ctx_, b_, state_id));
482 }
483 m->InitInv(invs);
484 }
485}
486
487void SimInit::LoadBuildSched() {
488 std::vector<Cond> conds;
489 conds.push_back(Cond("BuildTime", ">", t_));
490 QueryResult qr;
491 try {
492 qr = b_->Query("BuildSchedule", &conds);
493 } catch (std::exception err) {return;} // table doesn't exist (okay)
494
495 for (int i = 0; i < qr.rows.size(); ++i) {
496 int t = qr.GetVal<int>("BuildTime", i);
497 int parentid = qr.GetVal<int>("ParentId", i);
498 std::string proto = qr.GetVal<std::string>("Prototype", i);
499 ctx_->SchedBuild(agents_[parentid], proto, t);
500 }
501}
502
503void SimInit::LoadDecomSched() {
504 std::vector<Cond> conds;
505 conds.push_back(Cond("DecomTime", ">=", t_));
506 QueryResult qr;
507 try {
508 qr = b_->Query("DecomSchedule", &conds);
509 } catch (std::exception err) {return;} // table doesn't exist (okay)
510
511 for (int i = 0; i < qr.rows.size(); ++i) {
512 int t = qr.GetVal<int>("DecomTime", i);
513 int agentid = qr.GetVal<int>("AgentId", i);
514 ctx_->SchedDecom(agents_[agentid], t);
515 }
516}
517
518void SimInit::LoadNextIds() {
519 std::vector<Cond> conds;
520 conds.push_back(Cond("Time", "==", t_));
521 QueryResult qr = b_->Query("NextIds", &conds);
522 for (int i = 0; i < qr.rows.size(); ++i) {
523 std::string obj = qr.GetVal<std::string>("Object", i);
524 if (obj == "Agent") {
525 Agent::next_id_ = qr.GetVal<int>("NextId", i);
526 } else if (obj == "Transaction") {
527 ctx_->trans_id_ = qr.GetVal<int>("NextId", i);
528 } else if (obj == "Composition") {
529 Composition::next_id_ = qr.GetVal<int>("NextId", i);
530 } else if (obj == "ResourceState") {
531 Resource::nextstate_id_ = qr.GetVal<int>("NextId", i);
532 } else if (obj == "ResourceObj") {
533 Resource::nextobj_id_ = qr.GetVal<int>("NextId", i);
534 } else if (obj == "Product") {
535 Product::next_qualid_ = qr.GetVal<int>("NextId", i);
536 } else {
537 throw IOError("Unexpected value in NextIds table: " + obj);
538 }
539 }
540}
541
543 Timer ti;
545 Context ctx(&ti, &rec);
546
547 // manually make this "untracked" to prevent segfaulting and other such
548 // terrors because the created context is destructed by SimInit at the end
549 // of this function.
550 Material::Ptr m = ResCast<Material>(SimInit::LoadResource(&ctx, b, resid));
551 m->tracker_.DontTrack();
552 m->ctx_ = NULL;
553 return m;
554}
555
557 Timer ti;
559 Context ctx(&ti, &rec);
560
561 // manually make this "untracked" to prevent segfaulting and other such
562 // terrors because the created context is destructed by SimInit at the end
563 // of this function.
564 Product::Ptr p = ResCast<Product>(SimInit::LoadResource(&ctx, b, resid));
565 p->tracker_.DontTrack();
566 p->ctx_ = NULL;
567 return p;
568}
569
570Resource::Ptr SimInit::LoadResource(Context* ctx, QueryableBackend* b, int state_id) {
571 std::vector<Cond> conds;
572 conds.push_back(Cond("ResourceId", "==", state_id));
573 QueryResult qr = b->Query("Resources", &conds);
574 ResourceType type = qr.GetVal<ResourceType>("Type");
575 int obj_id = qr.GetVal<int>("ObjId");
576
578 if (type == Material::kType) {
579 r = LoadMaterial(ctx, b, state_id);
580 } else if (type == Product::kType) {
581 r = LoadProduct(ctx, b, state_id);
582 } else {
583 throw IOError("Invalid resource type in output database: " + type);
584 }
585
586 r->state_id_ = state_id;
587 r->obj_id_ = obj_id;
588 return r;
589}
590
591Material::Ptr SimInit::LoadMaterial(Context* ctx, QueryableBackend* b, int state_id) {
592 // get special material object state
593 std::vector<Cond> conds;
594 conds.push_back(Cond("ResourceId", "==", state_id));
595 QueryResult qr = b->Query("MaterialInfo", &conds);
596 int prev_decay = qr.GetVal<int>("PrevDecayTime");
597
598 // get general resource object info
599 conds.clear();
600 conds.push_back(Cond("ResourceId", "==", state_id));
601 qr = b->Query("Resources", &conds);
602 double qty = qr.GetVal<double>("Quantity");
603 int stateid = qr.GetVal<int>("QualId");
604
605 // create the composition and material
606 Composition::Ptr comp = LoadComposition(b, stateid);
607 Agent* dummy = new Dummy(ctx);
609 mat->prev_decay_time_ = prev_decay;
610 ctx->DelAgent(dummy);
611
612 return mat;
613}
614
615Composition::Ptr SimInit::LoadComposition(QueryableBackend* b, int stateid) {
616 std::vector<Cond> conds;
617 conds.push_back(Cond("QualId", "==", stateid));
618 QueryResult qr = b->Query("Compositions", &conds);
619 CompMap cm;
620 for (int i = 0; i < qr.rows.size(); ++i) {
621 int nucid = qr.GetVal<int>("NucId", i);
622 double mass_frac = qr.GetVal<double>("MassFrac", i);
623 cm[nucid] = mass_frac;
624 }
626 c->recorded_ = true;
627 c->id_ = stateid;
628 return c;
629}
630
631Product::Ptr SimInit::LoadProduct(Context* ctx, QueryableBackend* b, int state_id) {
632 // get general resource object info
633 std::vector<Cond> conds;
634 conds.push_back(Cond("ResourceId", "==", state_id));
635 QueryResult qr = b->Query("Resources", &conds);
636 double qty = qr.GetVal<double>("Quantity");
637 int stateid = qr.GetVal<int>("QualId");
638
639 // get special Product internal state
640 conds.clear();
641 conds.push_back(Cond("QualId", "==", stateid));
642 qr = b->Query("Products", &conds);
643 std::string quality = qr.GetVal<std::string>("Quality");
644
645 // set static quality-stateid map to have same vals as db
646 Product::qualids_[quality] = stateid;
647
648 Agent* dummy = new Dummy(ctx);
649 Product::Ptr r = Product::Create(dummy, qty, quality);
650 ctx->DelAgent(dummy);
651 return r;
652}
653
654} // namespace cyclus
a holding class for information related to a TradeExecutor
The abstract base class used by all types of agents that live and interact in a simulation.
Definition agent.h:49
Context * context() const
Returns this agent's simulation context.
Definition agent.h:367
virtual const int id() const
The agent instance's unique ID within a simulation.
Definition agent.h:352
virtual void Snapshot(DbInit di)=0
Snapshots agent-internal state to the database via the DbInit var di.
Definition agent.cc:52
const int enter_time() const
Returns the time step at which this agent's Build function was called (-1 if the agent has never been...
Definition agent.h:381
virtual Inventories SnapshotInv()=0
Snapshots an agent's resource inventories to the database.
static Ptr CreateFromMass(CompMap v)
Creates a new composition from v with its components having appropriate mass-based ratios.
boost::shared_ptr< Composition > Ptr
Definition composition.h:43
Wrapper class for QueryableBackends that injects a set of Cond's into every query before being execut...
Represents a condition used to filter rows returned by a query.
A simulation context provides access to necessary simulation-global functions and state.
Definition context.h:145
void SchedBuild(Agent *parent, std::string proto_name, int t=-1)
Schedules the named prototype to be built for the specified parent at timestep t.
Definition context.cc:120
Datum * NewDatum(std::string title)
See Recorder::NewDatum documentation.
Definition context.cc:351
ExchangeSolver * solver()
Returns the exchange solver associated with this context.
Definition context.h:333
void AddPrototype(std::string name, Agent *m)
Adds a prototype to a simulation-wide accessible list, a prototype can not be added more than once.
Definition context.cc:150
void AddRecipe(std::string name, Composition::Ptr c)
Adds a composition recipe to a simulation-wide accessible list.
Definition context.cc:179
void AddTransportUnit(std::string name, int fill_min=0, int fill_max=std::numeric_limits< int >::max(), std::string strategy="first")
Adds a transport unit type to a simulation-wide accessible list.
Definition context.cc:227
void RecordTransportUnit(TransportUnit::Ptr)
Records transport unit information.
Definition context.cc:239
void AddPackage(std::string name, double fill_min=0, double fill_max=std::numeric_limits< double >::max(), std::string strategy="first")
Adds a package type to a simulation-wide accessible list.
Definition context.cc:194
virtual int time()
Returns the current simulation timestep.
Definition context.cc:313
void RecordPackage(Package::Ptr)
Records package information.
Definition context.cc:205
void SchedDecom(Agent *m, int time=-1)
Schedules the given Agent to be decommissioned at the specified timestep t.
Definition context.cc:134
void InitSim(SimInfo si)
Initializes the simulation time parameters.
Definition context.cc:263
Datum * AddVal(const char *field, boost::spirit::hold_any val, std::vector< int > *shape=NULL)
Add an arbitrary field-value pair to the datum.
Definition datum.cc:22
void Record()
Record this datum to its Recorder.
Definition datum.cc:35
DbInit provides an interface for agents to record data to the output db that automatically injects th...
Definition db_init.h:14
Dummy * Clone()
Returns a newly created/allocated prototype that is an exact copy of this.
Definition sim_init.cc:14
Dummy(Context *ctx)
Definition sim_init.cc:13
static Agent * Make(Context *ctx, AgentSpec spec)
Returns a newly constructed agent for the given module spec.
A generic mechanism to manually manage exceptions.
Definition error.h:12
static const ResourceType kType
Definition material.h:76
boost::shared_ptr< Material > Ptr
Definition material.h:75
static Ptr Create(Agent *creator, double quantity, Composition::Ptr c, std::string package_name=Package::unpackaged_name())
Creates a new material resource that is "live" and tracked.
Definition material.cc:17
static Ptr & unpackaged()
Definition package.cc:24
static std::string unpackaged_name()
Definition package.h:68
static Ptr Create(Agent *creator, double quantity, std::string quality, std::string package_name=Package::unpackaged_name())
Creates a new product that is "live" and tracked.
Definition product.cc:15
boost::shared_ptr< Product > Ptr
Definition product.h:24
static const ResourceType kType
Definition product.h:25
static const int kDefaultTimeout
Definition prog_solver.h:21
Meta data and results of a query.
T GetVal(std::string field, int row=0)
Convenience method for retrieving a value from a specific row and named field (column).
Interface implemented by backends that support rudimentary querying.
virtual QueryResult Query(std::string table, std::vector< Cond > *conds)=0
Return a set of rows from the specificed table that match all given conditions.
virtual std::set< std::string > Tables()=0
Return a set of all table names currently in the database.
Collects and manages output data generation for the cyclus core and agents during a simulation.
Definition recorder.h:45
void Flush()
Flushes all buffered Datum objects and flushes all registered backends.
Definition recorder.cc:92
The Region class is the abstract class/interface used by all region agents.
Definition region.h:60
boost::shared_ptr< Resource > Ptr
Definition resource.h:27
Container for a static simulation-global parameters that both describe the simulation and affect its ...
Definition context.h:45
boost::uuids::uuid parent_sim
id for the parent simulation if any
Definition context.h:97
std::string parent_type
One of "init", "branch", "restart" indicating the relationship of this simulation to its parent simul...
Definition context.h:101
int branch_time
timestep at which simulation branching occurs if any
Definition context.h:104
static Product::Ptr BuildProduct(QueryableBackend *b, int resid)
Convenience function for reconstructing an untracked product object with the given resource state id ...
Definition sim_init.cc:556
void Restart(QueryableBackend *b, boost::uuids::uuid sim_id, int t)
EXPERIMENTAL (might not work properly).
Definition sim_init.cc:32
void Init(Recorder *r, QueryableBackend *b)
Initialize a simulation with data from b for simulation id in r.
Definition sim_init.cc:25
static void SnapAgent(Agent *m)
Records a snapshot of the agent's current internal state into the simulation's output database.
Definition sim_init.cc:124
static void Snapshot(Context *ctx)
Records a snapshot of the current state of the simulation being managed by ctx into the simulation's ...
Definition sim_init.cc:76
static Material::Ptr BuildMaterial(QueryableBackend *b, int resid)
Convenience function for reconstructing an untracked material object with the given resource state id...
Definition sim_init.cc:542
void Branch(QueryableBackend *b, boost::uuids::uuid prev_sim_id, int t, boost::uuids::uuid new_sim_id)
NOT IMPLEMENTED.
Definition sim_init.cc:44
Controls simulation timestepping and inter-timestep phases.
Definition timer.h:22
static std::string unrestricted_name()
Definition package.h:166
static Ptr & unrestricted()
Definition package.cc:131
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
std::map< Nuc, double > CompMap
a raw definition of nuclides and corresponding (dimensionless quantities).
Definition composition.h:17
std::map< std::string, std::vector< Resource::Ptr > > Inventories
map<inventory_name, vector<resources_in_inventory> >.
Definition agent.h:38
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters
std::string ResourceType
Definition resource.h:17
int id(int nuc)
Definition pyne.cc:2716
std::string name(int nuc)
Definition pyne.cc:2940
double b(int nuc)
Computes the scattering length [cm] from the coherent and incoherent components.
Definition pyne.cc:11180
const double pi
pi = 3.14159265359
Definition pyne.cc:10356