CYCLUS
|
A simulation context provides access to necessary simulation-global functions and state.
All code that writes to the output database, needs to know simulation time, creates/builds facilities, and/or uses loaded composition recipes will need a context pointer. In general, all global state should be accessed through a simulation context.
#include <context.h>
Public Member Functions | |
void | AddRecipe (std::string name, Composition::Ptr c) |
Context (Timer *ti, Recorder *rec) | |
template<class T > | |
T * | CreateAgent (std::string proto_name) |
void | DelAgent (Agent *m) |
uint64_t | dt () |
Composition::Ptr | GetRecipe (std::string name) |
void | InitSim (SimInfo si) |
void | KillSim () |
int | n_prototypes (std::string type) |
int | n_specs (std::string impl) |
Datum * | NewDatum (std::string title) |
int | NextTransactionID () |
void | RegisterTimeListener (TimeListener *tl) |
void | RegisterTrader (Trader *e) |
void | SchedBuild (Agent *parent, std::string proto_name, int t=-1) |
void | SchedDecom (Agent *m, int time=-1) |
boost::uuids::uuid | sim_id () |
SimInfo | sim_info () const |
void | Snapshot () |
ExchangeSolver * | solver () |
void | solver (ExchangeSolver *solver) |
virtual int | time () |
const std::set< Trader * > & | traders () const |
void | UnregisterTimeListener (TimeListener *tl) |
void | UnregisterTrader (Trader *e) |
~Context () | |
void | AddPrototype (std::string name, Agent *m) |
void | AddPrototype (std::string name, Agent *m, bool overwrite) |
Creates a new context working with the specified timer and datum manager.
The timer does not have to be initialized (yet).
Definition at line 72 of file context.cc.
cyclus::Context::~Context | ( | ) |
Clean up resources including destructing the solver and all agents the context is aware of.
Definition at line 79 of file context.cc.
void cyclus::Context::AddPrototype | ( | std::string | name, |
Agent * | m | ||
) |
Adds a prototype to a simulation-wide accessible list, a prototype can not be added more than once.
name | the prototype name |
m | a pointer to the agent prototype |
overwrite,allow | overwrites to the prototype listing, default: false |
if | overwrite is false and a prototype name has already been added |
Definition at line 137 of file context.cc.
void cyclus::Context::AddPrototype | ( | std::string | name, |
Agent * | m, | ||
bool | overwrite | ||
) |
Definition at line 141 of file context.cc.
void cyclus::Context::AddRecipe | ( | std::string | name, |
Composition::Ptr | c | ||
) |
Adds a composition recipe to a simulation-wide accessible list.
Agents should NOT add their own recipes.
Definition at line 166 of file context.cc.
|
inline |
void cyclus::Context::DelAgent | ( | Agent * | m | ) |
Destructs and cleans up m (and it's children recursively).
Definition at line 98 of file context.cc.
|
inline |
Composition::Ptr cyclus::Context::GetRecipe | ( | std::string | name | ) |
Retrieve a registered recipe.
This is intended for retrieving compositions loaded from an input file(s) at the start of a simulation and NOT for communicating compositions between facilities during the simulation.
Definition at line 174 of file context.cc.
void cyclus::Context::InitSim | ( | SimInfo | si | ) |
Initializes the simulation time parameters.
Should only be called once - NOT idempotent.
Definition at line 181 of file context.cc.
void cyclus::Context::KillSim | ( | ) |
Schedules the simulation to be terminated at the end of this timestep.
Definition at line 247 of file context.cc.
|
inline |
|
inline |
Datum * cyclus::Context::NewDatum | ( | std::string | title | ) |
See Recorder::NewDatum documentation.
Definition at line 239 of file context.cc.
|
inline |
void cyclus::Context::RegisterTimeListener | ( | TimeListener * | tl | ) |
Registers an agent to receive tick/tock notifications every timestep.
Agents should register from their Deploy method.
Definition at line 231 of file context.cc.
|
inline |
void cyclus::Context::SchedBuild | ( | Agent * | parent, |
std::string | proto_name, | ||
int | t = -1 |
||
) |
Schedules the named prototype to be built for the specified parent at timestep t.
The default t=-1 results in the build being scheduled for the next build phase (i.e. the start of the next timestep).
Definition at line 107 of file context.cc.
void cyclus::Context::SchedDecom | ( | Agent * | m, |
int | time = -1 |
||
) |
Schedules the given Agent to be decommissioned at the specified timestep t.
The default t=-1 results in the decommission being scheduled for the next decommission phase (i.e. the end of the current timestep).
Definition at line 121 of file context.cc.
boost::uuids::uuid cyclus::Context::sim_id | ( | ) |
See Recorder::sim_id documentation.
Definition at line 133 of file context.cc.
|
inline |
void cyclus::Context::Snapshot | ( | ) |
Schedules a snapshot of simulation state to output database to occur at the beginning of the next timestep.
Definition at line 243 of file context.cc.
|
inline |
|
inline |
|
virtual |
Returns the current simulation timestep.
Definition at line 227 of file context.cc.
|
inline |
void cyclus::Context::UnregisterTimeListener | ( | TimeListener * | tl | ) |
Removes an agent from receiving tick/tock notifications.
Agents should unregister from their Decommission method.
Definition at line 235 of file context.cc.
|
inline |