NRP Core  1.4.1
SimulationManager Class Referenceabstract

Manages simulation execution. More...

#include <simulation_manager.h>

Inheritance diagram for SimulationManager:
PtrTemplates< SimulationManager > EventLoopSimManager FTILoopSimManager

Classes

struct  RequestResult
 Helper structure for storing request result and error messages. More...
 

Public Types

enum  SimState {
  SimState::Created, SimState::Initialized, SimState::Running, SimState::Stopped,
  SimState::Failed, SimState::NotSet
}
 States the simulation can be in. More...
 
- Public Types inherited from PtrTemplates< SimulationManager >
using shared_ptr = std::shared_ptr< SimulationManager >
 
using const_shared_ptr = std::shared_ptr< const SimulationManager >
 
using unique_ptr = std::unique_ptr< SimulationManager >
 
using const_unique_ptr = std::unique_ptr< const SimulationManager >
 

Public Member Functions

 SimulationManager (const jsonSharedPtr &simulationConfig)
 Constructor. More...
 
 SimulationManager ()=delete
 
virtual ~SimulationManager ()=default
 
RequestResult initializeSimulation ()
 Initialize the simulation. More...
 
RequestResult resetSimulation ()
 Reset the currently running simulation. More...
 
RequestResult stopSimulation ()
 Request to stop the simulation if it was running, if it wasn't the call has no effect. More...
 
RequestResult runSimulationUntilDoneOrTimeout ()
 Runs the simulation until a separate thread stops it or simTimeout (defined in SimulationConfig) is reached. If simTimeout is zero or negative, ignore it. More...
 
virtual bool hasSimulationTimedOut () const =0
 
RequestResult runSimulation (unsigned numIterations)
 Run the Simulation for specified amount of timesteps. More...
 
RequestResult shutdownSimulation ()
 Shuts down the simulation. More...
 
SimState currentState ()
 returns the current state of the simulation More...
 
std::string printSimState (const SimState &simState)
 returns a simulation state as a string More...
 
SimulationDataManagergetSimulationDataManager ()
 

Static Public Member Functions

static void validateConfig (jsonSharedPtr &config)
 Validates config against Simulation schema. More...
 

Protected Member Functions

virtual void initializeCB ()=0
 Initialize the simulation. More...
 
virtual bool resetCB ()=0
 Resets the simulation, returns true if the simulation was reset false otherwise. More...
 
virtual void stopCB ()=0
 Forward request to stop the simulation. More...
 
virtual bool runUntilDoneOrTimeoutCB ()=0
 Run the simulation. More...
 
virtual bool runCB (unsigned numIterations)=0
 Run the simulation. More...
 
virtual void shutdownCB ()=0
 Shutdown the simulation. More...
 

Protected Attributes

jsonSharedPtr _simConfig
 Simulation Configuration. More...
 
SimulationDataManager _simulationDataManager
 
SimulationTime _simTimeout = SimulationTime::zero()
 

Detailed Description

Manages simulation execution.

Maintain the current state of the simulation and process control requests according to this state.

Control request methods are processed sequentially guarded by a lock, with the exception of "stopSimulation", which can be processed in parallel.

Control requests are forwarded to Implementations of this interface via a set of callbacks. Exceptions occurring in these callbacks are handled by SimulationManager by transitioning the simulation to state "Failed", from which the only possible action is to shutdown the simulation.

Calling a control request from the wrong state triggers an exception

Member Enumeration Documentation

◆ SimState

States the simulation can be in.

Enumerator
Created 
Initialized 
Running 
Stopped 
Failed 
NotSet 

Constructor & Destructor Documentation

◆ SimulationManager() [1/2]

SimulationManager::SimulationManager ( const jsonSharedPtr simulationConfig)

Constructor.

Parameters
simulationConfigSimulation configuration

◆ SimulationManager() [2/2]

SimulationManager::SimulationManager ( )
delete

◆ ~SimulationManager()

virtual SimulationManager::~SimulationManager ( )
virtualdefault

Member Function Documentation

◆ currentState()

SimulationManager::SimState SimulationManager::currentState ( )

returns the current state of the simulation

◆ getSimulationDataManager()

SimulationDataManager & SimulationManager::getSimulationDataManager ( )

◆ hasSimulationTimedOut()

virtual bool SimulationManager::hasSimulationTimedOut ( ) const
pure virtual

Implemented in FTILoopSimManager, and EventLoopSimManager.

◆ initializeCB()

virtual void SimulationManager::initializeCB ( )
protectedpure virtual

Initialize the simulation.

◆ initializeSimulation()

SimulationManager::RequestResult SimulationManager::initializeSimulation ( )

Initialize the simulation.

Returns
Simulation state after processing the request

◆ printSimState()

std::string SimulationManager::printSimState ( const SimState simState)

returns a simulation state as a string

◆ resetCB()

virtual bool SimulationManager::resetCB ( )
protectedpure virtual

Resets the simulation, returns true if the simulation was reset false otherwise.

◆ resetSimulation()

SimulationManager::RequestResult SimulationManager::resetSimulation ( )

Reset the currently running simulation.

Returns
Simulation state after processing the request

◆ runCB()

virtual bool SimulationManager::runCB ( unsigned  numIterations)
protectedpure virtual

Run the simulation.

◆ runSimulation()

SimulationManager::RequestResult SimulationManager::runSimulation ( unsigned  numIterations)

Run the Simulation for specified amount of timesteps.

Parameters
numIterationsNumber of iterations (i.e timesteps) to run simulation
Returns
Simulation state after processing the request

◆ runSimulationUntilDoneOrTimeout()

SimulationManager::RequestResult SimulationManager::runSimulationUntilDoneOrTimeout ( )

Runs the simulation until a separate thread stops it or simTimeout (defined in SimulationConfig) is reached. If simTimeout is zero or negative, ignore it.

Returns
Simulation state after processing the request

◆ runUntilDoneOrTimeoutCB()

virtual bool SimulationManager::runUntilDoneOrTimeoutCB ( )
protectedpure virtual

Run the simulation.

◆ shutdownCB()

virtual void SimulationManager::shutdownCB ( )
protectedpure virtual

Shutdown the simulation.

◆ shutdownSimulation()

SimulationManager::RequestResult SimulationManager::shutdownSimulation ( )

Shuts down the simulation.

Returns
Simulation state after processing the request

◆ stopCB()

virtual void SimulationManager::stopCB ( )
protectedpure virtual

Forward request to stop the simulation.

◆ stopSimulation()

SimulationManager::RequestResult SimulationManager::stopSimulation ( )

Request to stop the simulation if it was running, if it wasn't the call has no effect.

It is not blocking, i.e. it is not guaranteed that the simulation is in state "Stopped" after the call returns. The simulation will stop after the the "runSimulation" request that started it returns.

Returns
Simulation state after processing the request

◆ validateConfig()

void SimulationManager::validateConfig ( jsonSharedPtr config)
static

Validates config against Simulation schema.

Parameters
configPointer to a config

Member Data Documentation

◆ _simConfig

jsonSharedPtr SimulationManager::_simConfig
protected

Simulation Configuration.

◆ _simTimeout

SimulationTime SimulationManager::_simTimeout = SimulationTime::zero()
protected

◆ _simulationDataManager

SimulationDataManager SimulationManager::_simulationDataManager
protected

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