CYCLUS
sim_init.h
Go to the documentation of this file.
1 #ifndef CYCLUS_SRC_SIM_INIT_H_
2 #define CYCLUS_SRC_SIM_INIT_H_
3 
4 #include <boost/uuid/uuid_io.hpp>
5 
6 #include "query_backend.h"
7 #include "context.h"
8 #include "timer.h"
9 #include "recorder.h"
10 
11 namespace cyclus {
12 
13 class Context;
14 
15 /// Handles initialization of a simulation from the output database. After
16 /// calling Init, Restart, or Branch, the initialized Context, Timer, and
17 /// Recorder can be retrieved.
18 ///
19 /// @warning the Init, Restart, and Branch methods are NOT idempotent. Only one
20 /// simulation should ever be initialized per SimInit object.
21 ///
22 /// @warning the SimInit class manages the memory of the initialized Context,
23 /// Timer, and Recorder.
24 class SimInit {
25  public:
26  SimInit();
27 
28  ~SimInit();
29 
30  /// Initialize a simulation with data from b for simulation id in r. SimInit
31  /// does not take ownership of the recorder or backend. the configured
32  /// context's recorder is set to r.
33  void Init(Recorder* r, QueryableBackend* b);
34 
35  /// EXPERIMENTAL (might not work properly). Restarts a simulation from time t
36  /// with data from b identified by simid. The newly configured simulation
37  /// will run with a new simulation id.
38  void Restart(QueryableBackend* b, boost::uuids::uuid sim_id, int t);
39 
40  /// NOT IMPLEMENTED. Initializes a simulation branched from prev_sim_id at
41  /// time t with diverging state described in new_sim_id.
42  ///
43  /// TODO(rwcarlsen): implement
44  void Branch(QueryableBackend* b, boost::uuids::uuid prev_sim_id, int t,
45  boost::uuids::uuid new_sim_id);
46 
47  /// Records a snapshot of the current state of the simulation being managed by
48  /// ctx into the simulation's output database.
49  static void Snapshot(Context* ctx);
50 
51  /// Records a snapshot of the agent's current internal state into the
52  /// simulation's output database. Note that this should generally not be
53  /// called directly.
54  static void SnapAgent(Agent* m);
55 
56  /// Returns the initialized context. Note that either Init, Restart, or Branch
57  /// must be called first.
58  Context* context() { return ctx_; }
59 
60  /// Returns the initialized recorder with registered backends. Note that
61  /// either Init, Restart, or Branch must be called first.
62  Recorder* recorder() { return rec_; }
63 
64  /// Returns the initialized timer. Note that either Init, Restart, or Branch
65  /// must be called first.
66  Timer* timer() { return &ti_; }
67 
68  /// Convenience function for reconstructing an untracked material object with
69  /// the given resource state id from a database backend b. Particularly
70  /// useful for running mock simulations/tests.
71  static Material::Ptr BuildMaterial(QueryableBackend* b, int resid);
72 
73  /// Convenience function for reconstructing an untracked product object with
74  /// the given resource state id from a database backend b. Particularly
75  /// useful for running mock simulations/tests.
76  static Product::Ptr BuildProduct(QueryableBackend* b, int resid);
77 
78  private:
79  void InitBase(QueryableBackend* b, boost::uuids::uuid simid, int t);
80 
81  void LoadInfo();
82  void LoadRecipes();
83  void LoadSolverInfo();
84  void LoadPrototypes();
85  void LoadInitialAgents();
86  void LoadInventories();
87  void LoadBuildSched();
88  void LoadDecomSched();
89  void LoadNextIds();
90 
91  void* LoadPreconditioner(std::string name);
92  ExchangeSolver* LoadGreedySolver(bool exclusive, std::set<std::string> tables);
93  ExchangeSolver* LoadCoinSolver(bool exclusive, std::set<std::string> tables);
94  static Resource::Ptr LoadResource(Context* ctx, QueryableBackend* b, int resid);
95  static Material::Ptr LoadMaterial(Context* ctx, QueryableBackend* b, int resid);
96  static Product::Ptr LoadProduct(Context* ctx, QueryableBackend* b, int resid);
97  static Composition::Ptr LoadComposition(QueryableBackend* b, int stateid);
98 
99  // std::map<AgentId, Agent*>
100  std::map<int, Agent*> agents_;
101 
102  Context* ctx_;
103  Recorder* rec_;
104  Timer ti_;
105  boost::uuids::uuid simid_;
106  SimInfo si_;
107  QueryableBackend* b_;
108  int t_;
109 };
110 
111 } // namespace cyclus
112 
113 #endif // CYCLUS_SRC_SIM_INIT_H_
Timer * timer()
Returns the initialized timer.
Definition: sim_init.h:66
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
boost::shared_ptr< Material > Ptr
Definition: material.h:75
std::string name(int nuc)
Definition: pyne.cc:2940
Context * context()
Returns the initialized context.
Definition: sim_init.h:58
boost::shared_ptr< Product > Ptr
Definition: product.h:24
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
void Restart(QueryableBackend *b, boost::uuids::uuid sim_id, int t)
EXPERIMENTAL (might not work properly).
Definition: sim_init.cc:32
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
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
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
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
a very simple interface for solving translated resource exchanges
Handles initialization of a simulation from the output database.
Definition: sim_init.h:24
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
Recorder * recorder()
Returns the initialized recorder with registered backends.
Definition: sim_init.h:62
Controls simulation timestepping and inter-timestep phases.
Definition: timer.h:22