CYCLUS
Loading...
Searching...
No Matches
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.

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

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

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 81 of file context.cc.

◆ ~Context()

cyclus::Context::~Context ( )

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

Definition at line 90 of file context.cc.

Member Function Documentation

◆ AddPackage()

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 194 of file context.cc.

◆ 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.

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

Definition at line 150 of file context.cc.

◆ AddPrototype() [2/2]

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

Definition at line 154 of file context.cc.

◆ 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 179 of file context.cc.

◆ AddTransportUnit()

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 227 of file context.cc.

◆ CreateAgent()

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

Create a new agent by cloning the named prototype.

The returned agent is not initialized as a simulation participant.

Warning
this method should generally NOT be used by agents.

Definition at line 195 of file context.h.

◆ DelAgent()

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

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

Warning
this method should generally NOT be used by agents.

Definition at line 111 of file context.cc.

◆ dt()

uint64_t cyclus::Context::dt ( )
inline

Returns the duration of a single time step in seconds.

Definition at line 304 of file context.h.

◆ GetPackage()

Package::Ptr cyclus::Context::GetPackage ( std::string name)

Retrieve a registered package.

Definition at line 214 of file context.cc.

◆ 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 187 of file context.cc.

◆ GetTransportUnit()

TransportUnit::Ptr cyclus::Context::GetTransportUnit ( std::string name)

Retrieve a registered transport unit.

Definition at line 249 of file context.cc.

◆ InitSim()

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

Initializes the simulation time parameters.

Should only be called once - NOT idempotent.

Definition at line 263 of file context.cc.

◆ KillSim()

void cyclus::Context::KillSim ( )

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

Definition at line 359 of file context.cc.

◆ n_prototypes()

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

Definition at line 348 of file context.h.

◆ n_specs()

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

Definition at line 354 of file context.h.

◆ NewDatum()

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

See Recorder::NewDatum documentation.

Definition at line 351 of file context.cc.

◆ NextTransactionID()

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

Definition at line 328 of file context.h.

◆ random()

int cyclus::Context::random ( )

Definition at line 317 of file context.cc.

◆ random_01()

double cyclus::Context::random_01 ( )

Generates a random number on the range [0,1)].

Definition at line 321 of file context.cc.

◆ random_normal_int()

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 338 of file context.cc.

◆ random_normal_real()

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 333 of file context.cc.

◆ random_uniform_int()

int cyclus::Context::random_uniform_int ( int low,
int high )

Returns a random number from a uniform integer distribution.

Definition at line 325 of file context.cc.

◆ random_uniform_real()

double cyclus::Context::random_uniform_real ( double low,
double high )

Returns a random number from a uniform real distribution.

Definition at line 329 of file context.cc.

◆ RecordPackage()

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 205 of file context.cc.

◆ RecordTransportUnit()

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 239 of file context.cc.

◆ 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 343 of file context.cc.

◆ RegisterTrader()

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

Registers an agent as a participant in resource exchanges.

Agents should register from their Deploy method.

Definition at line 176 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 120 of file context.cc.

◆ 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 134 of file context.cc.

◆ seed()

uint64_t cyclus::Context::seed ( )
inline

Returns the seed for the random number generator.

Definition at line 307 of file context.h.

◆ sim_id()

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

See Recorder::sim_id documentation.

Definition at line 146 of file context.cc.

◆ sim_info()

SimInfo cyclus::Context::sim_info ( ) const
inline

Return static simulation info.

Definition at line 313 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 355 of file context.cc.

◆ solver() [1/2]

ExchangeSolver * cyclus::Context::solver ( )
inline

Returns the exchange solver associated with this context.

Definition at line 333 of file context.h.

◆ solver() [2/2]

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

sets the solver associated with this context

Definition at line 341 of file context.h.

◆ stride()

uint64_t cyclus::Context::stride ( )
inline

Returns the stride for the random number generator.

Definition at line 310 of file context.h.

◆ time()

int cyclus::Context::time ( )
virtual

Returns the current simulation timestep.

Definition at line 313 of file context.cc.

◆ traders()

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

Definition at line 186 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 347 of file context.cc.

◆ UnregisterTrader()

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

Unregisters an agent as a participant in resource exchanges.

Definition at line 181 of file context.h.


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