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