class SimulationManager

Overview

Manages simulation execution. More…

#include <simulation_manager.h>

class SimulationManager: public PtrTemplates {
public:
    // enums

    enum SimState;

    // structs

    struct RequestResult;

    // construction

    SimulationManager(const jsonSharedPtr& simulationConfig);
    SimulationManager();

    // methods

    static void validateConfig(jsonSharedPtr& config);
    RequestResult initializeSimulation();
    RequestResult resetSimulation();
    RequestResult stopSimulation();
    RequestResult runSimulationUntilDoneOrTimeout();
    virtual bool hasSimulationTimedOut() const = 0;
    RequestResult runSimulation(unsigned numIterations);
    RequestResult shutdownSimulation();
    SimState currentState();
    std::string printSimState(const SimState& simState);
    SimulationDataManager& getSimulationDataManager();
};

// direct descendants

class EventLoopSimManager;
class FTILoopSimManager;

Inherited Members

public:
    // typedefs

    typedef std::shared_ptr<T> shared_ptr;
    typedef std::shared_ptr<const T> const_shared_ptr;
    typedef std::unique_ptr<T> unique_ptr;
    typedef std::unique_ptr<const T> const_unique_ptr;

Detailed Documentation

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

Construction

SimulationManager(const jsonSharedPtr& simulationConfig)

Constructor.

Parameters:

simulationConfig

Simulation configuration

Methods

static void validateConfig(jsonSharedPtr& config)

Validates config against Simulation schema.

Parameters:

config

Pointer to a config

RequestResult initializeSimulation()

Initialize the simulation.

Returns:

Simulation state after processing the request

RequestResult resetSimulation()

Reset the currently running simulation.

Returns:

Simulation state after processing the request

RequestResult 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

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.

Returns:

Simulation state after processing the request

RequestResult runSimulation(unsigned numIterations)

Run the Simulation for specified amount of timesteps.

Parameters:

numIterations

Number of iterations (i.e timesteps) to run simulation

Returns:

Simulation state after processing the request

RequestResult shutdownSimulation()

Shuts down the simulation.

Returns:

Simulation state after processing the request

SimState currentState()

returns the current state of the simulation

std::string printSimState(const SimState& simState)

returns a simulation state as a string