![]() |
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 | AddPackage (std::string name, double fill_min=0, double fill_max=std::numeric_limits< double >::max(), std::string strategy="first") |
void | AddRecipe (std::string name, Composition::Ptr c) |
void | AddTransportUnit (std::string name, int fill_min=0, int fill_max=std::numeric_limits< int >::max(), std::string strategy="first") |
Context (Timer *ti, Recorder *rec) | |
template<class T > | |
T * | CreateAgent (std::string proto_name) |
void | DelAgent (Agent *m) |
uint64_t | dt () |
Package::Ptr | GetPackage (std::string name) |
Composition::Ptr | GetRecipe (std::string name) |
TransportUnit::Ptr | GetTransportUnit (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 () |
int | random () |
double | random_01 () |
int | random_normal_int (double mean, double std_dev, int low=0, int high=std::numeric_limits< int >::max()) |
double | random_normal_real (double mean, double std_dev, double low=0, double high=std::numeric_limits< double >::max()) |
int | random_uniform_int (int low, int high) |
double | random_uniform_real (double low, double high) |
void | RecordPackage (Package::Ptr) |
void | RecordTransportUnit (TransportUnit::Ptr) |
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) |
uint64_t | seed () |
boost::uuids::uuid | sim_id () |
SimInfo | sim_info () const |
void | Snapshot () |
ExchangeSolver * | solver () |
void | solver (ExchangeSolver *solver) |
uint64_t | stride () |
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 85 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 94 of file context.cc.
void cyclus::Context::AddPackage | ( | std::string | name, |
double | fill_min = 0, | ||
double | fill_max = std::numeric_limits<double>::max(), | ||
std::string | strategy = "first" ) |
Adds a package type to a simulation-wide accessible list.
Agents should NOT add their own packages.
Definition at line 204 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 160 of file context.cc.
void cyclus::Context::AddPrototype | ( | std::string | name, |
Agent * | m, | ||
bool | overwrite ) |
Definition at line 164 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 189 of file context.cc.
void cyclus::Context::AddTransportUnit | ( | std::string | name, |
int | fill_min = 0, | ||
int | fill_max = std::numeric_limits<int>::max(), | ||
std::string | strategy = "first" ) |
Adds a transport unit type to a simulation-wide accessible list.
Agents should NOT add their own transport units.
Definition at line 237 of file context.cc.
|
inline |
void cyclus::Context::DelAgent | ( | Agent * | m | ) |
Destructs and cleans up m (and it's children recursively).
Definition at line 115 of file context.cc.
|
inline |
Package::Ptr cyclus::Context::GetPackage | ( | std::string | name | ) |
Retrieve a registered package.
Definition at line 224 of file context.cc.
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 197 of file context.cc.
TransportUnit::Ptr cyclus::Context::GetTransportUnit | ( | std::string | name | ) |
Retrieve a registered transport unit.
Definition at line 259 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 273 of file context.cc.
void cyclus::Context::KillSim | ( | ) |
Schedules the simulation to be terminated at the end of this timestep.
Definition at line 369 of file context.cc.
|
inline |
|
inline |
Datum * cyclus::Context::NewDatum | ( | std::string | title | ) |
See Recorder::NewDatum documentation.
Definition at line 361 of file context.cc.
|
inline |
int cyclus::Context::random | ( | ) |
Definition at line 327 of file context.cc.
double cyclus::Context::random_01 | ( | ) |
Generates a random number on the range [0,1)].
Definition at line 331 of file context.cc.
int cyclus::Context::random_normal_int | ( | double | mean, |
double | std_dev, | ||
int | low = 0, | ||
int | high = std::numeric_limits<int>::max() ) |
Returns a random number from a lognormal distribution.
Definition at line 348 of file context.cc.
double cyclus::Context::random_normal_real | ( | double | mean, |
double | std_dev, | ||
double | low = 0, | ||
double | high = std::numeric_limits<double>::max() ) |
Returns a random number from a normal distribution.
Definition at line 343 of file context.cc.
int cyclus::Context::random_uniform_int | ( | int | low, |
int | high ) |
Returns a random number from a uniform integer distribution.
Definition at line 335 of file context.cc.
double cyclus::Context::random_uniform_real | ( | double | low, |
double | high ) |
Returns a random number from a uniform real distribution.
Definition at line 339 of file context.cc.
void cyclus::Context::RecordPackage | ( | Package::Ptr | pkg | ) |
Records package information.
Should be used first on unpackaged, then to record user-declared packages
Definition at line 215 of file context.cc.
void cyclus::Context::RecordTransportUnit | ( | TransportUnit::Ptr | tu | ) |
Records transport unit information.
Should be used first on unrestricted, then to record user-declared transport units
Definition at line 249 of file context.cc.
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 353 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 124 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 141 of file context.cc.
|
inline |
boost::uuids::uuid cyclus::Context::sim_id | ( | ) |
See Recorder::sim_id documentation.
Definition at line 156 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 365 of file context.cc.
|
inline |
|
inline |
|
inline |
|
virtual |
Returns the current simulation timestep.
Definition at line 323 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 357 of file context.cc.
|
inline |