libcosim 0.9.0
C++ library for distributed co-simulation
Public Member Functions | List of all members
cosim::simulator Class Referenceabstract

A simulator interface for co-simulation algorithms. More...

#include <cosim/algorithm/simulator.hpp>

Inheritance diagram for cosim::simulator:
cosim::manipulable cosim::observable

Public Member Functions

virtual void set_real (value_reference reference, double value)=0
 Sets the value of a real variable. More...
 
virtual void set_integer (value_reference reference, int value)=0
 Sets the value of an integer variable. More...
 
virtual void set_boolean (value_reference reference, bool value)=0
 Sets the value of a boolean variable. More...
 
virtual void set_string (value_reference reference, std::string_view value)=0
 Sets the value of a string variable. More...
 
virtual void setup (time_point startTime, std::optional< time_point > stopTime, std::optional< double > relativeTolerance)=0
 Performs pre-simulation setup and enters initialisation mode. More...
 
virtual const std::unordered_set< value_reference > & get_modified_real_variables () const =0
 Returns all value references of real type that currently have an active modifier.
 
virtual const std::unordered_set< value_reference > & get_modified_integer_variables () const =0
 Returns all value references of integer type that currently have an active modifier.
 
virtual const std::unordered_set< value_reference > & get_modified_boolean_variables () const =0
 Returns all value references of boolean type that currently have an active modifier.
 
virtual const std::unordered_set< value_reference > & get_modified_string_variables () const =0
 Returns all value references of string type that currently have an active modifier.
 
virtual void do_iteration ()=0
 Updates the simulator with new input values and makes it calculate new output values, without advancing logical time. More...
 
virtual void start_simulation ()=0
 Signals to the simulator that the initialization phase is complete and that stepping will begin. More...
 
virtual step_result do_step (time_point currentT, duration deltaT)=0
 Performs a single time step. More...
 
- Public Member Functions inherited from cosim::manipulable
virtual void expose_for_setting (variable_type, value_reference)=0
 Exposes a variable for assignment with set_xxx(). More...
 
virtual void set_real_input_modifier (value_reference reference, std::function< double(double, duration)> modifier)=0
 Sets a modifier for the value of a real input variable. More...
 
virtual void set_integer_input_modifier (value_reference reference, std::function< int(int, duration)> modifier)=0
 Sets a modifier for the value of an integer input variable. More...
 
virtual void set_boolean_input_modifier (value_reference reference, std::function< bool(bool, duration)> modifier)=0
 Sets a modifier for the value of a boolean input variable. More...
 
virtual void set_string_input_modifier (value_reference reference, std::function< std::string(std::string_view, duration)> modifier)=0
 Sets a modifier for the value of a string input variable. More...
 
virtual void set_real_output_modifier (value_reference reference, std::function< double(double, duration)> modifier)=0
 Sets a modifier for the value of a real output variable. More...
 
virtual void set_integer_output_modifier (value_reference reference, std::function< int(int, duration)> modifier)=0
 Sets a modifier for the value of an integer output variable. More...
 
virtual void set_boolean_output_modifier (value_reference reference, std::function< bool(bool, duration)> modifier)=0
 Sets a modifier for the value of a boolean output variable. More...
 
virtual void set_string_output_modifier (value_reference reference, std::function< std::string(std::string_view, duration)> modifier)=0
 Sets a modifier for the value of a string output variable. More...
 
- Public Member Functions inherited from cosim::observable
virtual std::string name () const =0
 Returns the entity's name.
 
virtual cosim::model_description model_description () const =0
 Returns a description of the entity.
 
virtual void expose_for_getting (variable_type, value_reference)=0
 Exposes a variable for retrieval with get_xxx(). More...
 
virtual double get_real (value_reference) const =0
 Returns the value of a real variable. More...
 
virtual int get_integer (value_reference) const =0
 Returns the value of an integer variable. More...
 
virtual bool get_boolean (value_reference) const =0
 Returns the value of a boolean variable. More...
 
virtual std::string_view get_string (value_reference) const =0
 Returns the value of a string variable. More...
 

Detailed Description

A simulator interface for co-simulation algorithms.

This is the simulator interface exposed to algorithm implementers, and is used to control one "sub-simulator" in a co-simulation.

Member Function Documentation

◆ do_iteration()

virtual void cosim::simulator::do_iteration ( )
pure virtual

Updates the simulator with new input values and makes it calculate new output values, without advancing logical time.

This function can be used in the initialisation phase, after setup() has been called and before the call to start_simulation(). It enables iterative initialisation of the system. The purpose could be to propagate initial values between simulators and/or bring the system to a steady state.

◆ do_step()

virtual step_result cosim::simulator::do_step ( time_point  currentT,
duration  deltaT 
)
pure virtual

Performs a single time step.

This causes the simulator to perform its computations for the logical time interval from currentT to currentT+deltaT.

Parameters
currentTThe starting point of the time step.
deltaTThe length of the time step. Must be positive.

◆ set_boolean()

virtual void cosim::simulator::set_boolean ( value_reference  reference,
bool  value 
)
pure virtual

Sets the value of a boolean variable.

The variable must previously have been exposed with expose_for_setting().

◆ set_integer()

virtual void cosim::simulator::set_integer ( value_reference  reference,
int  value 
)
pure virtual

Sets the value of an integer variable.

The variable must previously have been exposed with expose_for_setting().

◆ set_real()

virtual void cosim::simulator::set_real ( value_reference  reference,
double  value 
)
pure virtual

Sets the value of a real variable.

The variable must previously have been exposed with expose_for_setting().

◆ set_string()

virtual void cosim::simulator::set_string ( value_reference  reference,
std::string_view  value 
)
pure virtual

Sets the value of a string variable.

The variable must previously have been exposed with expose_for_setting().

◆ setup()

virtual void cosim::simulator::setup ( time_point  startTime,
std::optional< time_point stopTime,
std::optional< double >  relativeTolerance 
)
pure virtual

Performs pre-simulation setup and enters initialisation mode.

This function must be called exactly once, before initialisation and simulation can begin (i.e. before the first time either of do_iteration() or do_step() are called).

Parameters
startTimeThe logical time at which the simulation will start. (The first time do_step() is called, its currentT argument must have the same value.)
stopTimeThe logical time at which the simulation will end. If specified, the simulator may not be stepped beyond this point.
relativeToleranceA suggested relative tolerance for the internal error estimation of the simulator's solver. This should be specified if the co-simulation algorithm itself uses error estimation to determine the length of communication intervals. If the simulator's solver doesn't use error estimation, it will just ignore this parameter.

◆ start_simulation()

virtual void cosim::simulator::start_simulation ( )
pure virtual

Signals to the simulator that the initialization phase is complete and that stepping will begin.

This function must be called at the end of the initialisation phase, after any call to do_iteration() and before the first do_step() call.


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