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

A class which represents an execution, i.e., a co-simulation run. More...

#include <cosim/execution.hpp>

Public Member Functions

 execution (time_point startTime, std::shared_ptr< algorithm > algo)
 Constructor. More...
 
 execution (const execution &)=delete
 
executionoperator= (const execution &)=delete
 
 execution (execution &&) noexcept
 
executionoperator= (execution &&) noexcept
 
simulator_index add_slave (std::shared_ptr< slave > slave, std::string_view name, duration stepSizeHint=duration::zero())
 Adds a slave to the execution. More...
 
function_index add_function (std::shared_ptr< function > fun)
 Adds a function to the execution.
 
void add_observer (std::shared_ptr< observer > obs)
 Adds an observer to the execution.
 
void add_manipulator (std::shared_ptr< manipulator > man)
 Adds a manipulator to the execution.
 
void connect_variables (variable_id output, variable_id input)
 Connects a simulator output variable to a simulator input variable. More...
 
void connect_variables (variable_id output, function_io_id input)
 Connects a simulator output variable to a function input variable. More...
 
void connect_variables (function_io_id output, variable_id input)
 Connects a function output variable to a simulator input variable. More...
 
time_point current_time () const noexcept
 Returns the current logical time.
 
bool simulate_until (std::optional< time_point > targetTime)
 Advance the co-simulation forward to the given logical time. More...
 
duration step ()
 Advance the co-simulation forward one single step. More...
 
void stop_simulation ()
 Stops the co-simulation temporarily.
 
bool is_running () const noexcept
 Is the simulation loop currently running.
 
const std::shared_ptr< real_time_configget_real_time_config () const
 Returns a pointer to an object containing real time configuration.
 
std::shared_ptr< const real_time_metricsget_real_time_metrics () const
 Returns a pointer to an object containing real time metrics.
 
model_description get_model_description (simulator_index index) const
 Returns the model description for a simulator with the given index.
 
std::vector< variable_idget_modified_variables () const
 Returns a map of currently modified variables.
 
void set_real_initial_value (simulator_index sim, value_reference var, double value)
 Set initial value for a variable of type real. Must be called before simulation is started.
 
void set_integer_initial_value (simulator_index sim, value_reference var, int value)
 Set initial value for a variable of type integer. Must be called before simulation is started.
 
void set_boolean_initial_value (simulator_index sim, value_reference var, bool value)
 Set initial value for a variable of type boolean. Must be called before simulation is started.
 
void set_string_initial_value (simulator_index sim, value_reference var, const std::string &value)
 Set initial value for a variable of type string. Must be called before simulation is started.
 

Detailed Description

A class which represents an execution, i.e., a co-simulation run.

The execution class manages all the entities involved in an execution and provides a high-level API for driving the co-simulation algorithm forward.

Constructor & Destructor Documentation

◆ execution()

cosim::execution::execution ( time_point  startTime,
std::shared_ptr< algorithm algo 
)

Constructor.

Parameters
startTimeThe logical time at which the simulation will start.
algoThe co-simulation algorithm which will be used. One algorithm object may only be used with one execution.

Member Function Documentation

◆ add_slave()

simulator_index cosim::execution::add_slave ( std::shared_ptr< slave slave,
std::string_view  name,
duration  stepSizeHint = duration::zero() 
)

Adds a slave to the execution.

Parameters
slaveThe slave object.
nameAn execution-specific name for the slave.
stepSizeHintThe recommended co-simulation step size for this slave. Whether and how this is taken into account is algorithm dependent. If zero, the algorithm will attempt to choose a sensible default.

◆ connect_variables() [1/3]

void cosim::execution::connect_variables ( function_io_id  output,
variable_id  input 
)

Connects a function output variable to a simulator input variable.

After this, the values of the output variable will be passed to the input value at the co-simulation algorithm's discretion. Different algorithms may handle this in different ways, and could for instance choose to extrapolate or correct the variable value during transfer.

When calling this method, the validity of both variables are checked against the metadata of their respective simulators. If either is found to be invalid (i.e. not found, wrong type or causality, an exception will be thrown.

◆ connect_variables() [2/3]

void cosim::execution::connect_variables ( variable_id  output,
function_io_id  input 
)

Connects a simulator output variable to a function input variable.

After this, the values of the output variable will be passed to the input value at the co-simulation algorithm's discretion. Different algorithms may handle this in different ways, and could for instance choose to extrapolate or correct the variable value during transfer.

When calling this method, the validity of both variables are checked against the metadata of their respective simulators. If either is found to be invalid (i.e. not found, wrong type or causality, an exception will be thrown.

◆ connect_variables() [3/3]

void cosim::execution::connect_variables ( variable_id  output,
variable_id  input 
)

Connects a simulator output variable to a simulator input variable.

After this, the values of the output variable will be passed to the input value at the co-simulation algorithm's discretion. Different algorithms may handle this in different ways, and could for instance choose to extrapolate or correct the variable value during transfer.

When calling this method, the validity of both variables are checked against the metadata of their respective simulators. If either is found to be invalid (i.e. not found, wrong type or causality, an exception will be thrown.

◆ simulate_until()

bool cosim::execution::simulate_until ( std::optional< time_point targetTime)

Advance the co-simulation forward to the given logical time.

Parameters
targetTimeThe logical time at which the co-simulation should pause (optional). If specified, this must always be greater than the value of current_time() at the moment the function is called. If not specified, the co-simulation will continue until stop_simulation() is called.
Returns
true if the co-simulation was advanced to the given time, or false if it was stopped before this. In the latter case, current_time() may be called to determine the actual end time.

◆ step()

duration cosim::execution::step ( )

Advance the co-simulation forward one single step.

Returns
The actual duration of the step. current_time() may be called to determine the actual time after the step completed.

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