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
26 Recorder tmprec;
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) {
34 "restart capability is not finalized and fully"
35 " tested. Its behavior may change in future"
36 " releases.");
37 rec_ = new Recorder();
38 InitBase(b, sim_id, t);
39 si_.parent_sim = sim_id;
40 si_.parent_type = "restart";
41 si_.branch_time = t;
42 ctx_->InitSim(si_); // explicitly force this to show up in the new
43 // simulations output db
44}
45
46void SimInit::Branch(QueryableBackend* b, boost::uuids::uuid prev_sim_id, int t,
47 boost::uuids::uuid new_sim_id) {
48 throw Error("simulation branching feature not implemented");
49}
50
51void SimInit::InitBase(QueryableBackend* b, boost::uuids::uuid simid, int t) {
52 ctx_ = new Context(&ti_, rec_);
53
54 std::vector<Cond> conds;
55 conds.push_back(Cond("SimId", "==", simid));
56 b_ = new CondInjector(b, conds);
57 t_ = t;
58 simid_ = simid;
59
60 // this sequence is imporant!!!
61 LoadInfo();
62 LoadRecipes();
63 LoadPackages();
64 LoadTransportUnits();
65 LoadSolverInfo();
66 LoadPrototypes();
67 LoadInitialAgents();
68 LoadInventories();
69 LoadBuildSched();
70 LoadDecomSched();
71 LoadNextIds();
72
73 // delete all buffered data that we don't want to be re-recorded in the
74 // output db
75 rec_->Flush();
76}
77
79 ctx->NewDatum("Snapshots")->AddVal("Time", ctx->time())->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));
130 Inventories invs = m->SnapshotInv();
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 } else {
212 ctx_->RecordPackage(Package::unpackaged());
213 }
214 }
215}
216
217void SimInit::LoadTransportUnits() {
218 QueryResult qr;
219 try {
220 qr = b_->Query("TransportUnits", NULL);
221 } catch (std::exception err) {
222 return;
223 } // table doesn't exist (okay)
224
225 for (int i = 0; i < qr.rows.size(); ++i) {
226 std::string name = qr.GetVal<std::string>("TransportUnitName", i);
227 int fill_min = qr.GetVal<int>("FillMin", i);
228 int fill_max = qr.GetVal<int>("FillMax", i);
229 std::string strategy = qr.GetVal<std::string>("Strategy", i);
230
231 if (name != TransportUnit::unrestricted_name()) {
232 ctx_->AddTransportUnit(name, fill_min, fill_max, strategy);
233 } else {
234 ctx_->RecordTransportUnit(TransportUnit::unrestricted());
235 }
236 }
237}
238
239void* SimInit::LoadPreconditioner(std::string name) {
240 using std::map;
241 using std::string;
242 void* precon = NULL;
243 map<string, double> commod_order;
244 try {
245 QueryResult qr = b_->Query("CommodPriority", NULL);
246 for (int i = 0; i < qr.rows.size(); ++i) {
247 std::string commod = qr.GetVal<string>("Commodity", i);
248 double order = qr.GetVal<double>("SolutionOrder", i);
249 commod_order[commod] = order;
250 }
251 } catch (std::exception err) {
252 return NULL;
253 } // table doesn't exist (okay)
254
255 // actually create and return the preconditioner
256 if (name == "greedy") {
257 precon =
258 new GreedyPreconditioner(commod_order, GreedyPreconditioner::REVERSE);
259 } else {
260 throw ValueError(
261 "The name of the preconditioner was not recognized, "
262 "got '" +
263 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
310 timeout = timeout <= 0 ? ProgSolver::kDefaultTimeout : timeout;
311 solver = new ProgSolver("cbc", timeout, exclusive, verbose, mps);
312 return solver;
313#else
314 throw cyclus::Error(
315 "Cyclus was not compiled with COIN support, cannot load solver.");
316#endif
317}
318
319void SimInit::LoadSolverInfo() {
320 using std::set;
321 using std::string;
322 // context will delete solver
323 ExchangeSolver* solver;
324 string solver_name;
325 bool exclusive_orders;
326
327 // load in possible Solver info, needs to be optional to
328 // maintain backwards compatibility, defaults above.
329 set<string> tables = b_->Tables();
330 string solver_info = string("SolverInfo");
331 if (0 < tables.count(solver_info)) {
332 QueryResult qr = b_->Query(solver_info, NULL);
333 if (qr.rows.size() > 0) {
334 solver_name = qr.GetVal<string>("Solver");
335 exclusive_orders = qr.GetVal<bool>("ExclusiveOrders");
336 }
337 }
338
339 if (solver_name == "greedy") {
340 solver = LoadGreedySolver(exclusive_orders, tables);
341 } else if (solver_name == "coin-or") {
342 solver = LoadCoinSolver(exclusive_orders, tables);
343 } else {
344 throw ValueError(
345 "The name of the solver was not recognized, "
346 "got '" +
347 solver_name + "'.");
348 }
349
350 ctx_->solver(solver);
351}
352
353void SimInit::LoadPrototypes() {
354 QueryResult qr = b_->Query("Prototypes", NULL);
355 for (int i = 0; i < qr.rows.size(); ++i) {
356 std::string proto = qr.GetVal<std::string>("Prototype", i);
357 int agentid = qr.GetVal<int>("AgentId", i);
358 std::string impl = qr.GetVal<std::string>("Spec", i);
359 AgentSpec spec(impl);
360
361 Agent* m = DynamicModule::Make(ctx_, spec);
362 m->id_ = agentid;
363
364 // note that we don't filter by SimTime here because prototypes remain
365 // static over the life of the simulation and we only snapshot them once
366 // when the simulation is initialized.
367 std::vector<Cond> conds;
368 conds.push_back(Cond("AgentId", "==", agentid));
369 CondInjector ci(b_, conds);
370 PrefixInjector pi(&ci, "AgentState");
371
372 // call manually without agent impl injected
373 m->Agent::InitFrom(&pi);
374
375 pi = PrefixInjector(&ci, "AgentState" + spec.Sanitize());
376 m->InitFrom(&pi);
377 ctx_->AddPrototype(proto, m);
378 }
379}
380
381void SimInit::LoadInitialAgents() {
382 // DO NOT call the agents' Build methods because the agents might modify the
383 // state of their children and/or the simulation in ways that are only meant
384 // to be done once; remember that we are initializing agents from a
385 // simulation that was already started.
386
387 // find all agents that are alive at the current timestep
388 std::vector<Cond> conds;
389 conds.push_back(Cond("EnterTime", "<=", t_));
390 QueryResult qentry = b_->Query("AgentEntry", &conds);
391 std::map<int, int> parentmap; // map<agentid, parentid>
392 std::map<int, Agent*> unbuilt; // map<agentid, agent_ptr>
393 for (int i = 0; i < qentry.rows.size(); ++i) {
394 if (t_ > 0 && qentry.GetVal<int>("EnterTime", i) == t_) {
395 // agent is scheduled to be built already
396 continue;
397 }
398 int id = qentry.GetVal<int>("AgentId", i);
399 std::vector<Cond> conds;
400 conds.push_back(Cond("AgentId", "==", id));
401 conds.push_back(Cond("ExitTime", "<", t_));
402 try {
403 QueryResult qexit = b_->Query("AgentExit", &conds);
404 if (qexit.rows.size() != 0) {
405 continue; // agent was decomissioned before t_ - skip
406 }
407 } catch (std::exception err) {
408 } // table doesn't exist (okay)
409
410 // if the agent wasn't decommissioned before t_ create and init it
411
412 std::string proto = qentry.GetVal<std::string>("Prototype", i);
413 std::string impl = qentry.GetVal<std::string>("Spec", i);
414 AgentSpec spec(impl);
415 Agent* m = DynamicModule::Make(ctx_, spec);
416
417 // agent-kernel init
418 m->prototype_ = proto;
419 m->id_ = id;
420 m->enter_time_ = qentry.GetVal<int>("EnterTime", i);
421 unbuilt[id] = m;
422 parentmap[id] = qentry.GetVal<int>("ParentId", i);
423
424 // agent-custom init
425 conds.pop_back();
426 conds.push_back(Cond("SimTime", "==", t_));
427 CondInjector ci(b_, conds);
428 PrefixInjector pi(&ci, "AgentState");
429 m->Agent::InitFrom(&pi);
430 pi = PrefixInjector(&ci, "AgentState" + spec.Sanitize());
431 m->InitFrom(&pi);
432 }
433
434 // construct agent hierarchy starting at roots (no parent) down
435 std::map<int, Agent*>::iterator it = unbuilt.begin();
436 std::vector<Agent*> enter_list;
437 while (unbuilt.size() > 0) {
438 int id = it->first;
439 Agent* m = it->second;
440 int parentid = parentmap[id];
441
442 if (parentid == -1) { // root agent
443 m->Connect(NULL);
444 agents_[id] = m;
445 ++it;
446 unbuilt.erase(id);
447 enter_list.push_back(m);
448 } else if (agents_.count(parentid) > 0) { // parent is built
449 m->Connect(agents_[parentid]);
450 agents_[id] = m;
451 ++it;
452 unbuilt.erase(id);
453 enter_list.push_back(m);
454 } else { // parent not built yet
455 ++it;
456 }
457 if (it == unbuilt.end()) {
458 it = unbuilt.begin();
459 }
460 }
461
462 // notify all agents that they are active in a simulation AFTER the
463 // parent-child hierarchy has been reconstructed.
464 for (int i = 0; i < enter_list.size(); ++i) {
465 enter_list[i]->EnterNotify();
466 }
467}
468
469void SimInit::LoadInventories() {
470 std::map<int, Agent*>::iterator it;
471 for (it = agents_.begin(); it != agents_.end(); ++it) {
472 Agent* m = it->second;
473 std::vector<Cond> conds;
474 conds.push_back(Cond("SimTime", "==", t_));
475 conds.push_back(Cond("AgentId", "==", m->id()));
476 QueryResult qr;
477 try {
478 qr = b_->Query("AgentStateInventories", &conds);
479 } catch (std::exception err) {
480 return;
481 } // table doesn't exist (okay)
482
483 Inventories invs;
484 for (int i = 0; i < qr.rows.size(); ++i) {
485 std::string inv_name = qr.GetVal<std::string>("InventoryName", i);
486 int state_id = qr.GetVal<int>("ResourceId", i);
487 invs[inv_name].push_back(LoadResource(ctx_, b_, state_id));
488 }
489 m->InitInv(invs);
490 }
491}
492
493void SimInit::LoadBuildSched() {
494 std::vector<Cond> conds;
495 conds.push_back(Cond("BuildTime", ">", t_));
496 QueryResult qr;
497 try {
498 qr = b_->Query("BuildSchedule", &conds);
499 } catch (std::exception err) {
500 return;
501 } // table doesn't exist (okay)
502
503 for (int i = 0; i < qr.rows.size(); ++i) {
504 int t = qr.GetVal<int>("BuildTime", i);
505 int parentid = qr.GetVal<int>("ParentId", i);
506 std::string proto = qr.GetVal<std::string>("Prototype", i);
507 ctx_->SchedBuild(agents_[parentid], proto, t);
508 }
509}
510
511void SimInit::LoadDecomSched() {
512 std::vector<Cond> conds;
513 conds.push_back(Cond("DecomTime", ">=", t_));
514 QueryResult qr;
515 try {
516 qr = b_->Query("DecomSchedule", &conds);
517 } catch (std::exception err) {
518 return;
519 } // table doesn't exist (okay)
520
521 for (int i = 0; i < qr.rows.size(); ++i) {
522 int t = qr.GetVal<int>("DecomTime", i);
523 int agentid = qr.GetVal<int>("AgentId", i);
524 ctx_->SchedDecom(agents_[agentid], t);
525 }
526}
527
528void SimInit::LoadNextIds() {
529 std::vector<Cond> conds;
530 conds.push_back(Cond("Time", "==", t_));
531 QueryResult qr = b_->Query("NextIds", &conds);
532 for (int i = 0; i < qr.rows.size(); ++i) {
533 std::string obj = qr.GetVal<std::string>("Object", i);
534 if (obj == "Agent") {
535 Agent::next_id_ = qr.GetVal<int>("NextId", i);
536 } else if (obj == "Transaction") {
537 ctx_->trans_id_ = qr.GetVal<int>("NextId", i);
538 } else if (obj == "Composition") {
539 Composition::next_id_ = qr.GetVal<int>("NextId", i);
540 } else if (obj == "ResourceState") {
541 Resource::nextstate_id_ = qr.GetVal<int>("NextId", i);
542 } else if (obj == "ResourceObj") {
543 Resource::nextobj_id_ = qr.GetVal<int>("NextId", i);
544 } else if (obj == "Product") {
545 Product::next_qualid_ = qr.GetVal<int>("NextId", i);
546 } else {
547 throw IOError("Unexpected value in NextIds table: " + obj);
548 }
549 }
550}
551
553 Timer ti;
554 Recorder rec;
555 Context ctx(&ti, &rec);
556
557 // manually make this "untracked" to prevent segfaulting and other such
558 // terrors because the created context is destructed by SimInit at the end
559 // of this function.
560 Material::Ptr m = ResCast<Material>(SimInit::LoadResource(&ctx, b, resid));
561 m->tracker_.DontTrack();
562 m->ctx_ = NULL;
563 return m;
564}
565
567 Timer ti;
568 Recorder rec;
569 Context ctx(&ti, &rec);
570
571 // manually make this "untracked" to prevent segfaulting and other such
572 // terrors because the created context is destructed by SimInit at the end
573 // of this function.
574 Product::Ptr p = ResCast<Product>(SimInit::LoadResource(&ctx, b, resid));
575 p->tracker_.DontTrack();
576 p->ctx_ = NULL;
577 return p;
578}
579
580Resource::Ptr SimInit::LoadResource(Context* ctx, QueryableBackend* b,
581 int state_id) {
582 std::vector<Cond> conds;
583 conds.push_back(Cond("ResourceId", "==", state_id));
584 QueryResult qr = b->Query("Resources", &conds);
585 ResourceType type = qr.GetVal<ResourceType>("Type");
586 int obj_id = qr.GetVal<int>("ObjId");
587
589 if (type == Material::kType) {
590 r = LoadMaterial(ctx, b, state_id);
591 } else if (type == Product::kType) {
592 r = LoadProduct(ctx, b, state_id);
593 } else {
594 throw IOError("Invalid resource type in output database: " + type);
595 }
596
597 r->state_id_ = state_id;
598 r->obj_id_ = obj_id;
599 return r;
600}
601
602Material::Ptr SimInit::LoadMaterial(Context* ctx, QueryableBackend* b,
603 int state_id) {
604 // get special material object state
605 std::vector<Cond> conds;
606 conds.push_back(Cond("ResourceId", "==", state_id));
607 QueryResult qr = b->Query("MaterialInfo", &conds);
608 int prev_decay = qr.GetVal<int>("PrevDecayTime");
609
610 // get general resource object info
611 conds.clear();
612 conds.push_back(Cond("ResourceId", "==", state_id));
613 qr = b->Query("Resources", &conds);
614 double qty = qr.GetVal<double>("Quantity");
615 int stateid = qr.GetVal<int>("QualId");
616
617 // create the composition and material
618 Composition::Ptr comp = LoadComposition(b, stateid);
619 Agent* dummy = new Dummy(ctx);
620 Material::Ptr mat = Material::Create(dummy, qty, comp);
621 mat->prev_decay_time_ = prev_decay;
622 ctx->DelAgent(dummy);
623
624 return mat;
625}
626
627Composition::Ptr SimInit::LoadComposition(QueryableBackend* b, int stateid) {
628 std::vector<Cond> conds;
629 conds.push_back(Cond("QualId", "==", stateid));
630 QueryResult qr = b->Query("Compositions", &conds);
631 CompMap cm;
632 for (int i = 0; i < qr.rows.size(); ++i) {
633 int nucid = qr.GetVal<int>("NucId", i);
634 double mass_frac = qr.GetVal<double>("MassFrac", i);
635 cm[nucid] = mass_frac;
636 }
638 c->recorded_ = true;
639 c->id_ = stateid;
640 return c;
641}
642
643Product::Ptr SimInit::LoadProduct(Context* ctx, QueryableBackend* b,
644 int state_id) {
645 // get general resource object info
646 std::vector<Cond> conds;
647 conds.push_back(Cond("ResourceId", "==", state_id));
648 QueryResult qr = b->Query("Resources", &conds);
649 double qty = qr.GetVal<double>("Quantity");
650 int stateid = qr.GetVal<int>("QualId");
651
652 // get special Product internal state
653 conds.clear();
654 conds.push_back(Cond("QualId", "==", stateid));
655 qr = b->Query("Products", &conds);
656 std::string quality = qr.GetVal<std::string>("Quality");
657
658 // set static quality-stateid map to have same vals as db
659 Product::qualids_[quality] = stateid;
660
661 Agent* dummy = new Dummy(ctx);
662 Product::Ptr r = Product::Create(dummy, qty, quality);
663 ctx->DelAgent(dummy);
664 return r;
665}
666
667} // namespace cyclus
The abstract base class used by all types of agents that live and interact in a simulation.
Definition agent.h:50
Context * context() const
Returns this agent's simulation context.
Definition agent.h:364
virtual const int id() const
The agent instance's unique ID within a simulation.
Definition agent.h:349
virtual void Snapshot(DbInit di)=0
Snapshots agent-internal state to the database via the DbInit var di.
Definition agent.cc:51
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:378
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:146
Datum * NewDatum(std::string title)
See Recorder::NewDatum documentation.
Definition context.cc:351
virtual int time()
Returns the current simulation timestep.
Definition context.cc:314
void InitSim(SimInfo si)
Initializes the simulation time parameters.
Definition context.cc:267
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:21
void Record()
Record this datum to its Recorder.
Definition datum.cc:34
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
a very simple interface for solving translated resource exchanges
static const ResourceType kType
Definition material.h:76
static Ptr Create(Agent *creator, double quantity, Composition::Ptr c, std::string package_name=Package::unpackaged_name(), double unit_value=kUnsetUnitValue)
Creates a new material resource that is "live" and tracked.
Definition material.cc:17
boost::shared_ptr< Material > Ptr
Definition material.h:75
static Ptr & unpackaged()
Definition package.cc:23
static std::string unpackaged_name()
Definition package.h:68
boost::shared_ptr< Product > Ptr
Definition product.h:23
static const ResourceType kType
Definition product.h:24
static Ptr Create(Agent *creator, double quantity, std::string quality, std::string package_name=Package::unpackaged_name(), double unit_value=kUnsetUnitValue)
Creates a new product that is "live" and tracked.
Definition product.cc:15
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.
Collects and manages output data generation for the cyclus core and agents during a simulation.
Definition recorder.h:45
boost::uuids::uuid sim_id()
returns the unique id associated with this cyclus simulation.
Definition recorder.cc:50
void Flush()
Flushes all buffered Datum objects and flushes all registered backends.
Definition recorder.cc:93
Region(Context *ctx)
Default constructor for Region Class.
Definition region.cc:20
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:49
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:566
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:78
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:552
void Branch(QueryableBackend *b, boost::uuids::uuid prev_sim_id, int t, boost::uuids::uuid new_sim_id)
NOT IMPLEMENTED.
Definition sim_init.cc:46
Controls simulation timestepping and inter-timestep phases.
Definition timer.h:22
static std::string unrestricted_name()
Definition package.h:161
static Ptr & unrestricted()
Definition package.cc:133
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::vector< typename T::Ptr > ResCast(std::vector< Resource::Ptr > rs)
Casts a vector of Resources into a vector of a specific resource type T.
Definition resource.h:135
std::map< std::string, std::vector< Resource::Ptr > > Inventories
map<inventory_name, vector<resources_in_inventory> >.
Definition agent.h:39
std::string ResourceType
Definition resource.h:17
void Warn(const std::string &msg)
Issue a warning with the approriate message, accoring to the current warning settings.
Definition error.h:108
int id(int nuc)
Definition pyne.cc:1019
std::string name(int nuc)
Definition pyne.cc:1239
double b(int nuc)
Computes the scattering length [cm] from the coherent and incoherent components.
Definition pyne.cc:8819
const double pi
pi = 3.14159265359
Definition pyne.cc:8017