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

An interface for co-simulation algorithms. More...

#include <cosim/algorithm/algorithm.hpp>

Inheritance diagram for cosim::algorithm:
cosim::fixed_step_algorithm

Public Member Functions

virtual void add_simulator (simulator_index index, simulator *sim, duration stepSizeHint)=0
 Adds a simulator to the co-simulation. More...
 
virtual void remove_simulator (simulator_index index)=0
 Removes a simulator from the co-simulation. More...
 
virtual void add_function (function_index index, function *fun)=0
 Adds a function to the co-simulation. More...
 
virtual void connect_variables (variable_id output, variable_id input)=0
 Connects a simulator output variable to a simulator input variable. More...
 
virtual void connect_variables (variable_id output, function_io_id input)=0
 Connects a simulator output variable to a function input variable. More...
 
virtual void connect_variables (function_io_id output, variable_id input)=0
 Connects a function output variable to a simulator input variable. More...
 
virtual void disconnect_variable (variable_id input)=0
 Breaks any previously established connection to input variable input. More...
 
virtual void disconnect_variable (function_io_id input)=0
 Breaks any previously established connection to input variable input. More...
 
virtual void setup (time_point startTime, std::optional< time_point > stopTime)=0
 Performs initial setup. More...
 
virtual void initialize ()=0
 Initializes the co-simulation. More...
 
virtual std::pair< duration, std::unordered_set< simulator_index > > do_step (time_point currentT)=0
 Performs a single macro time step. More...
 

Detailed Description

An interface for co-simulation algorithms.

A co-simulation algorithm is responsible for connecting variables (i.e., transferring output values to the right input variables) and stepping simulators.

Some of the functions in this interface are guaranteed to be called in a fixed order:

  1. setup()
  2. initialize()
  3. do_step() (possibly repeatedly)

Member Function Documentation

◆ add_function()

virtual void cosim::algorithm::add_function ( function_index  index,
function fun 
)
pure virtual

Adds a function to the co-simulation.

Parameters
indexA numerical index that will be used to identify the function in other function calls.
funA pointer to an object that is used to access the function. Note that the algorithm does not have resource ownership of the object it points to (i.e., should not try to delete it).

Implemented in cosim::fixed_step_algorithm.

◆ add_simulator()

virtual void cosim::algorithm::add_simulator ( simulator_index  index,
simulator sim,
duration  stepSizeHint 
)
pure virtual

Adds a simulator to the co-simulation.

Parameters
indexA numerical index that will be used to identify the simulator in other function calls.
simA pointer to an object that is used to control the simulator. Note that the algorithm does not have resource ownership of the object it points to (i.e., should not try to delete it).
stepSizeHintThe recommended co-simulation step size for this simulator. The algorithm is free to choose whether and how this is taken into account. The algorithm is also responsible for selecting a sensible default if this is zero.

Implemented in cosim::fixed_step_algorithm.

◆ connect_variables() [1/3]

virtual void cosim::algorithm::connect_variables ( function_io_id  output,
variable_id  input 
)
pure virtual

Connects a function output variable to a simulator input variable.

After this, the algorithm is responsible for acquiring the value of the output variable and assigning it to the input variable after the function is calculated.

Parameters
outputA reference to the output variable.
inputA reference to the input variable.

Implemented in cosim::fixed_step_algorithm.

◆ connect_variables() [2/3]

virtual void cosim::algorithm::connect_variables ( variable_id  output,
function_io_id  input 
)
pure virtual

Connects a simulator output variable to a function input variable.

After this, the algorithm is responsible for acquiring the value of the output variable and assigning it to the input variable before the function is calculated.

Parameters
outputA reference to the output variable.
inputA reference to the input variable.

Implemented in cosim::fixed_step_algorithm.

◆ connect_variables() [3/3]

virtual void cosim::algorithm::connect_variables ( variable_id  output,
variable_id  input 
)
pure virtual

Connects a simulator output variable to a simulator input variable.

After this, the algorithm is responsible for acquiring the value of the output variable and assigning it to the input variable at communication points.

Parameters
outputA reference to the output variable.
inputA reference to the input variable.

Implemented in cosim::fixed_step_algorithm.

◆ disconnect_variable() [1/2]

virtual void cosim::algorithm::disconnect_variable ( function_io_id  input)
pure virtual

Breaks any previously established connection to input variable input.

Implemented in cosim::fixed_step_algorithm.

◆ disconnect_variable() [2/2]

virtual void cosim::algorithm::disconnect_variable ( variable_id  input)
pure virtual

Breaks any previously established connection to input variable input.

Implemented in cosim::fixed_step_algorithm.

◆ do_step()

virtual std::pair< duration, std::unordered_set< simulator_index > > cosim::algorithm::do_step ( time_point  currentT)
pure virtual

Performs a single macro time step.

The actual time step length is determined by the algorithm, but it may not exceed maxDeltaT if specified.

This function is guaranteed to be called after initialize(). The first time it is called, currentT will be equal to the startTime argument passed to setup().

Parameters
currentTThe starting point of the time step.
Returns
The actual time step length, which must be less than or equal to maxDeltaT, if specified.

Implemented in cosim::fixed_step_algorithm.

◆ initialize()

virtual void cosim::algorithm::initialize ( )
pure virtual

Initializes the co-simulation.

Typically, this function will set the initial values of simulator variables, possibly performing iterative initialization to steady-state values for some of them.

This function is guaranteed to be called after setup() and before the first do_step() call.

Implemented in cosim::fixed_step_algorithm.

◆ remove_simulator()

virtual void cosim::algorithm::remove_simulator ( simulator_index  index)
pure virtual

Removes a simulator from the co-simulation.

Parameters
indexThe index of a simulator that has previously been added to the co-simulation with add_simulator().

Implemented in cosim::fixed_step_algorithm.

◆ setup()

virtual void cosim::algorithm::setup ( time_point  startTime,
std::optional< time_point stopTime 
)
pure virtual

Performs initial setup.

This function is guaranteed to be called before initialize().

Parameters
startTimeThe logical time at which the simulation will start. (The first time do_step() is called, its currentT argument will have the same value.)
stopTimeThe logical time at which the simulation will end. If specified, the algorithm will not be stepped beyond this point.

Implemented in cosim::fixed_step_algorithm.


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