CYCLUS
|
MockSim is a helper for running full simulations entirely in-code to test archetypes/agents without having to deal with input files, output database files, and other pieces of the full Cyclus stack.
This is especially convenient for writing unit-like tests (e.g. using gtest) for your archetype's in-simulation behavior. Initialize the MockSim indicating the archetype you want to test and the simulation duration. Then add any number of sources and/or sinks to transact with your agent. They can have specific recipes (or not) and their deployment and lifetime (before decommissioning) can be specified too. Here is an example using the agents:Source archetype in Cyclus as the tested agent:
Querying the results can be accomplished by getting a reference to the in-memory database generated. Not all data that is present in normal full-stack simulations is available. However, most of the key core tables are fully available. Namely, the Transactions, Composition, Resources, ResCreators, AgentEntry, and AgentExit tables are available. Any custom-tables created by the tested archetype will also be available. Here is a sample query and test you might write if using the googletest framework:
Definition at line 132 of file mock_sim.h.
#include <mock_sim.h>
Public Member Functions | |
void | AddRecipe (std::string name, Composition::Ptr c) |
MockAgent | AddSink (std::string commod) |
MockAgent | AddSource (std::string commod) |
Context * | context () |
SqliteBack & | db () |
void | DummyProto (std::string name) |
void | DummyProto (std::string name, std::string commod, double capacity) |
Material::Ptr | GetMaterial (int resid) |
Product::Ptr | GetProduct (int resid) |
MockSim (AgentSpec spec, std::string config, int duration) | |
MockSim (AgentSpec spec, std::string config, int duration, int lifetime) | |
MockSim (int duration) | |
int | Run () |
~MockSim () | |
Public Attributes | |
Agent * | agent |
cyclus::MockSim::MockSim | ( | int | duration | ) |
Creates and initializes a new empty mock simulation environment where duration is the length of the simulation in time steps.
An agent must be specified before running an empty-constructed MockSim (i.e. manually construct an agent using MockSim::context() and setting MockSim::agent.
Definition at line 115 of file mock_sim.cc.
Creates and initializes a new mock simulation environment to test the archetype identified by spec.
config should contain the archetype-specific xml snippet excluding the wrapping "<config>" and "<[AgentName]>" tags. duration is the length of the simulation in time steps.
Definition at line 124 of file mock_sim.cc.
Creates and initializes a new mock simulation environment to test the archetype identified by spec.
config should contain the archetype-specific xml snippet excluding the wrapping "<config>" and "<[AgentName]>" tags. duration is the length of the simulation in time steps. 'lifetime' is the lifetime of the agent being tested.
Definition at line 143 of file mock_sim.cc.
cyclus::MockSim::~MockSim | ( | ) |
Definition at line 193 of file mock_sim.cc.
void cyclus::MockSim::AddRecipe | ( | std::string | name, |
Composition::Ptr | c ) |
AddRecipe adds a recipe to the mock simulation environment (i.e.
to the simulation context). Any recipes that your archetype expects to find in the simulation context must be added this way; if the xml configuration snippet for the archetype being tested contains a recipe name, add it with this function.
Definition at line 211 of file mock_sim.cc.
MockAgent cyclus::MockSim::AddSink | ( | std::string | commod | ) |
AddSink adds a sink facility that can request+receive material from the archetype being tested.
commod specifies the commodity the sink will request on. AddSink can be called multiple times to generate many sinks for the simulation. The returned MockAgent object has several functions that can be called to configure the sink's behavior further. Don't forget to call the MockAgent object's "Finalize" function when you are done configuring it. MockAgent's functions support chaining:
Definition at line 205 of file mock_sim.cc.
MockAgent cyclus::MockSim::AddSource | ( | std::string | commod | ) |
AddSource adds a source facility that can offer/provide material to the archetype being tested.
commod specifies the commodity the source will offer on. AddSource can be called multiple times to generate many sources for the simulation. The returned MockAgent object has several functions that can be called to configure the source's behavior further. Don't forget to call the MockAgent object's "Finalize" function when you are done configuring it. MockAgent's functions support chaining:
Definition at line 199 of file mock_sim.cc.
|
inline |
Returns the context for the mock simulation environment.
Definition at line 227 of file mock_sim.h.
SqliteBack & cyclus::MockSim::db | ( | ) |
Returns the underlying in-memory database containing results for the simulation.
Run must be called before the database will contain anything.
Definition at line 236 of file mock_sim.cc.
void cyclus::MockSim::DummyProto | ( | std::string | name | ) |
Adds a dummy prototype to the simulation that can be used by institutions and other agents for deployment/decommission testing.
Definition at line 165 of file mock_sim.cc.
Adds a dummy prototype to the simulation that can be used by institutions and other agents for demand-driven deployment testing.
Definition at line 179 of file mock_sim.cc.
Material::Ptr cyclus::MockSim::GetMaterial | ( | int | resid | ) |
Reconstructs a material object from the simulation results database with the given resource state id.
Definition at line 228 of file mock_sim.cc.
Product::Ptr cyclus::MockSim::GetProduct | ( | int | resid | ) |
Reconstructs a product object from the simulation results database with the given resource state id.
Definition at line 232 of file mock_sim.cc.
int cyclus::MockSim::Run | ( | ) |
Runs the simulation.
This can only be called once. After the simulation has been run, this MockSim object CANNOT be reused to run other simulations. Run returns the agent ID for the agent being tested for use in queries.
Definition at line 215 of file mock_sim.cc.
Agent* cyclus::MockSim::agent |
the agent being tested by the mock simulation environment.
Definition at line 230 of file mock_sim.h.