Public Member Functions | List of all members
cyclus::Context Class Reference

Detailed Description

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.

the context takes ownership of and manages the lifetime/destruction of all agents constructed with it (including Cloned agents). Agents should generally NEVER be allocated on the stack.
the context takes ownership of the solver and will manage its destruction.

Definition at line 128 of file context.h.

#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)
DatumNewDatum (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 ()
ExchangeSolversolver ()
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)

Constructor & Destructor Documentation

cyclus::Context::Context ( Timer ti,
Recorder rec 

Creates a new context working with the specified timer and datum manager.

The timer does not have to be initialized (yet).

Definition at line 71 of file

cyclus::Context::~Context ( )

Clean up resources including destructing the solver and all agents the context is aware of.

Definition at line 78 of file

Member Function Documentation

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.

namethe prototype name
ma pointer to the agent prototype
overwrite,allowoverwrites to the prototype listing, default: false
ifoverwrite is false and a prototype name has already been added

Definition at line 135 of file

void cyclus::Context::AddPrototype ( std::string  name,
Agent m,
bool  overwrite 

Definition at line 139 of file

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 164 of file

template<class T >
T* cyclus::Context::CreateAgent ( std::string  proto_name)

Create a new agent by cloning the named prototype.

The returned agent is not initialized as a simulation participant.

this method should generally NOT be used by agents.

Definition at line 178 of file context.h.

void cyclus::Context::DelAgent ( Agent m)

Destructs and cleans up m (and it's children recursively).

this method should generally NOT be used by agents.

Definition at line 97 of file

uint64_t cyclus::Context::dt ( )

Returns the duration of a single time step in seconds.

Definition at line 235 of file context.h.

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 172 of file

void cyclus::Context::InitSim ( SimInfo  si)

Initializes the simulation time parameters.

Should only be called once - NOT idempotent.

Definition at line 179 of file

void cyclus::Context::KillSim ( )

Schedules the simulation to be terminated at the end of this timestep.

Definition at line 245 of file

int cyclus::Context::n_prototypes ( std::string  type)
the number of agents of a given prototype currently in the simulation

Definition at line 273 of file context.h.

int cyclus::Context::n_specs ( std::string  impl)
the number of agents of a given implementation currently in the simulation

Definition at line 279 of file context.h.

Datum * cyclus::Context::NewDatum ( std::string  title)

See Recorder::NewDatum documentation.

Definition at line 237 of file

int cyclus::Context::NextTransactionID ( )
the next transaction id

Definition at line 253 of file context.h.

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 229 of file

void cyclus::Context::RegisterTrader ( Trader e)

Registers an agent as a participant in resource exchanges.

Agents should register from their Deploy method.

Definition at line 159 of file context.h.

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 105 of file

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 119 of file

boost::uuids::uuid cyclus::Context::sim_id ( )

See Recorder::sim_id documentation.

Definition at line 131 of file

SimInfo cyclus::Context::sim_info ( ) const

Return static simulation info.

Definition at line 238 of file context.h.

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 241 of file

ExchangeSolver* cyclus::Context::solver ( )

Returns the exchange solver associated with this context.

Definition at line 258 of file context.h.

void cyclus::Context::solver ( ExchangeSolver solver)

sets the solver associated with this context

Definition at line 266 of file context.h.

int cyclus::Context::time ( )

Returns the current simulation timestep.

Definition at line 225 of file

const std::set<Trader*>& cyclus::Context::traders ( ) const
the current set of traders registered for resource exchange.

Definition at line 169 of file context.h.

void cyclus::Context::UnregisterTimeListener ( TimeListener tl)

Removes an agent from receiving tick/tock notifications.

Agents should unregister from their Decommission method.

Definition at line 233 of file

void cyclus::Context::UnregisterTrader ( Trader e)

Unregisters an agent as a participant in resource exchanges.

Definition at line 164 of file context.h.

The documentation for this class was generated from the following files: