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 130 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

◆ Context()

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

◆ ~Context()

cyclus::Context::~Context ( )

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

Definition at line 79 of file

Member Function Documentation

◆ AddPrototype() [1/2]

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

◆ AddPrototype() [2/2]

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

Definition at line 141 of file

◆ AddRecipe()

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

◆ CreateAgent()

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 180 of file context.h.

◆ DelAgent()

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

◆ dt()

uint64_t cyclus::Context::dt ( )

Returns the duration of a single time step in seconds.

Definition at line 238 of file context.h.

◆ GetRecipe()

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

◆ InitSim()

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

Initializes the simulation time parameters.

Should only be called once - NOT idempotent.

Definition at line 181 of file

◆ KillSim()

void cyclus::Context::KillSim ( )

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

Definition at line 247 of file

◆ n_prototypes()

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

Definition at line 276 of file context.h.

◆ n_specs()

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

Definition at line 282 of file context.h.

◆ NewDatum()

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

See Recorder::NewDatum documentation.

Definition at line 239 of file

◆ NextTransactionID()

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

Definition at line 256 of file context.h.

◆ RegisterTimeListener()

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

◆ RegisterTrader()

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 161 of file context.h.

◆ SchedBuild()

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

◆ SchedDecom()

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

◆ sim_id()

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

See Recorder::sim_id documentation.

Definition at line 133 of file

◆ sim_info()

SimInfo cyclus::Context::sim_info ( ) const

Return static simulation info.

Definition at line 241 of file context.h.

◆ Snapshot()

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

◆ solver() [1/2]

ExchangeSolver* cyclus::Context::solver ( )

Returns the exchange solver associated with this context.

Definition at line 261 of file context.h.

◆ solver() [2/2]

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

sets the solver associated with this context

Definition at line 269 of file context.h.

◆ time()

int cyclus::Context::time ( )

Returns the current simulation timestep.

Definition at line 227 of file

◆ traders()

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

Definition at line 171 of file context.h.

◆ UnregisterTimeListener()

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

◆ UnregisterTrader()

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

Unregisters an agent as a participant in resource exchanges.

Definition at line 166 of file context.h.

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