libcosim 0.9.0
C++ library for distributed co-simulation
|
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 | |
execution & | operator= (const execution &)=delete |
execution (execution &&) noexcept | |
execution & | operator= (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_config > | get_real_time_config () const |
Returns a pointer to an object containing real time configuration. | |
std::shared_ptr< const real_time_metrics > | get_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_id > | get_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. | |
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.
cosim::execution::execution | ( | time_point | startTime, |
std::shared_ptr< algorithm > | algo | ||
) |
Constructor.
startTime | The logical time at which the simulation will start. |
algo | The co-simulation algorithm which will be used. One algorithm object may only be used with one execution . |
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.
slave | The slave object. |
name | An execution-specific name for the slave. |
stepSizeHint | The 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. |
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 simulator
s. If either is found to be invalid (i.e. not found, wrong type or causality, an exception will be thrown.
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 simulator
s. If either is found to be invalid (i.e. not found, wrong type or causality, an exception will be thrown.
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 simulator
s. If either is found to be invalid (i.e. not found, wrong type or causality, an exception will be thrown.
bool cosim::execution::simulate_until | ( | std::optional< time_point > | targetTime | ) |
Advance the co-simulation forward to the given logical time.
targetTime | The 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. |
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. duration cosim::execution::step | ( | ) |
Advance the co-simulation forward one single step.
current_time()
may be called to determine the actual time after the step completed.