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