CYCLUS
Loading...
Searching...
No Matches
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
11namespace cyclus {
12
13class 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.
24class 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.
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.
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.
77
78 private:
79 void InitBase(QueryableBackend* b, boost::uuids::uuid simid, int t);
80
81 void LoadInfo();
82 void LoadRecipes();
83 void LoadPackages();
84 void LoadTransportUnits();
85 void LoadSolverInfo();
86 void LoadPrototypes();
87 void LoadInitialAgents();
88 void LoadInventories();
89 void LoadBuildSched();
90 void LoadDecomSched();
91 void LoadNextIds();
92
93 void* LoadPreconditioner(std::string name);
94 ExchangeSolver* LoadGreedySolver(bool exclusive, std::set<std::string> tables);
95 ExchangeSolver* LoadCoinSolver(bool exclusive, std::set<std::string> tables);
96 static Resource::Ptr LoadResource(Context* ctx, QueryableBackend* b, int resid);
97 static Material::Ptr LoadMaterial(Context* ctx, QueryableBackend* b, int resid);
98 static Product::Ptr LoadProduct(Context* ctx, QueryableBackend* b, int resid);
99 static Composition::Ptr LoadComposition(QueryableBackend* b, int stateid);
100
101 // std::map<AgentId, Agent*>
102 std::map<int, Agent*> agents_;
103
104 Context* ctx_;
105 Recorder* rec_;
106 Timer ti_;
107 boost::uuids::uuid simid_;
108 SimInfo si_;
110 int t_;
111};
112
113} // namespace cyclus
114
115#endif // CYCLUS_SRC_SIM_INIT_H_
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
boost::shared_ptr< Composition > Ptr
Definition composition.h:43
A simulation context provides access to necessary simulation-global functions and state.
Definition context.h:145
a very simple interface for solving translated resource exchanges
boost::shared_ptr< Material > Ptr
Definition material.h:75
boost::shared_ptr< Product > Ptr
Definition product.h:24
Interface implemented by backends that support rudimentary querying.
Collects and manages output data generation for the cyclus core and agents during a simulation.
Definition recorder.h:45
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
Handles initialization of a simulation from the output database.
Definition sim_init.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: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
Timer * timer()
Returns the initialized timer.
Definition sim_init.h:66
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
Recorder * recorder()
Returns the initialized recorder with registered backends.
Definition sim_init.h:62
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
Context * context()
Returns the initialized context.
Definition sim_init.h:58
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
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters