libcosim 0.8.2
C++ library for distributed co-simulation
Public Member Functions | Friends | List of all members
cosim::fmi::v2::slave_instance Class Reference

An FMI 2.0 co-simulation slave instance. More...

#include <cosim/fmi/v2/fmu.hpp>

Inheritance diagram for cosim::fmi::v2::slave_instance:
cosim::fmi::slave_instance cosim::slave

Public Member Functions

 slave_instance (const slave_instance &)=delete
 
slave_instanceoperator= (const slave_instance &)=delete
 
 slave_instance (slave_instance &&)=delete
 
slave_instanceoperator= (slave_instance &&)=delete
 
void setup (time_point startTime, std::optional< time_point > stopTime, std::optional< double > relativeTolerance) override
 Instructs the slave to perform pre-simulation setup and enter initialisation mode. More...
 
void start_simulation () override
 Informs the slave that the initialisation stage ends and the simulation begins. More...
 
void end_simulation () override
 Informs the slave that the simulation run has ended. More...
 
step_result do_step (time_point currentT, duration deltaT) override
 Performs model calculations for the time step which starts at the time point currentT and has a duration of deltaT. More...
 
void get_real_variables (gsl::span< const value_reference > variables, gsl::span< double > values) const override
 Retrieves the values of real variables. More...
 
void get_integer_variables (gsl::span< const value_reference > variables, gsl::span< int > values) const override
 Retrieves the values of integer variables. More...
 
void get_boolean_variables (gsl::span< const value_reference > variables, gsl::span< bool > values) const override
 Retrieves the values of boolean variables. More...
 
void get_string_variables (gsl::span< const value_reference > variables, gsl::span< std::string > values) const override
 Retrieves the values of string variables. More...
 
void set_real_variables (gsl::span< const value_reference > variables, gsl::span< const double > values) override
 Sets the values of real variables. More...
 
void set_integer_variables (gsl::span< const value_reference > variables, gsl::span< const int > values) override
 Sets the values of integer variables. More...
 
void set_boolean_variables (gsl::span< const value_reference > variables, gsl::span< const bool > values) override
 Sets the values of boolean variables. More...
 
void set_string_variables (gsl::span< const value_reference > variables, gsl::span< const std::string > values) override
 Sets the values of string variables. More...
 
std::shared_ptr< fmi::fmufmu () const override
 Returns a reference to the FMU of which this is an instance. More...
 
std::shared_ptr< v2::fmuv2_fmu () const
 Returns the same object as fmu(), only statically typed as a v2::fmu().
 
fmi2_import_t * fmilib_handle () const
 Returns the underlying C API handle (for FMI Library)
 
- Public Member Functions inherited from cosim::fmi::slave_instance
cosim::model_description model_description () const final override
 Returns a model description. More...
 

Friends

std::shared_ptr< slave_instancefmu::instantiate_v2_slave (std::string_view)
 

Detailed Description

An FMI 2.0 co-simulation slave instance.

Constructor & Destructor Documentation

◆ ~slave_instance()

cosim::fmi::v2::slave_instance::~slave_instance ( )
virtualnoexcept

Reimplemented from cosim::fmi::slave_instance.

Member Function Documentation

◆ do_step()

step_result cosim::fmi::v2::slave_instance::do_step ( time_point  currentT,
duration  deltaT 
)
overridevirtual

Performs model calculations for the time step which starts at the time point currentT and has a duration of deltaT.

If this is not the first time step, it can be assumed that the previous time step ended at currentT. It can also be assumed that currentT is greater than or equal to the start time, and currentT+deltaT is less than or equal to the stop time, specified in the setup() call.

Returns
Whether the step completed successfully or not. (Non-recoverable problems must be signaled with an exception.)
Note
Currently, retrying a failed time step is not supported, but this is planned for a future version.

Implements cosim::slave.

◆ end_simulation()

void cosim::fmi::v2::slave_instance::end_simulation ( )
overridevirtual

Informs the slave that the simulation run has ended.

Implements cosim::slave.

◆ fmu()

std::shared_ptr< fmi::fmu > cosim::fmi::v2::slave_instance::fmu ( ) const
inlineoverridevirtual

Returns a reference to the FMU of which this is an instance.

Implements cosim::fmi::slave_instance.

◆ get_boolean_variables()

void cosim::fmi::v2::slave_instance::get_boolean_variables ( gsl::span< const value_reference variables,
gsl::span< bool >  values 
) const
overridevirtual

Retrieves the values of boolean variables.

On return, the values array will be filled with the values of the variables specified in variables, in the same order.

Precondition
variables.size() == values.size()

Implements cosim::slave.

◆ get_integer_variables()

void cosim::fmi::v2::slave_instance::get_integer_variables ( gsl::span< const value_reference variables,
gsl::span< int >  values 
) const
overridevirtual

Retrieves the values of integer variables.

On return, the values array will be filled with the values of the variables specified in variables, in the same order.

Precondition
variables.size() == values.size()

Implements cosim::slave.

◆ get_real_variables()

void cosim::fmi::v2::slave_instance::get_real_variables ( gsl::span< const value_reference variables,
gsl::span< double >  values 
) const
overridevirtual

Retrieves the values of real variables.

On return, the values array will be filled with the values of the variables specified in variables, in the same order.

Precondition
variables.size() == values.size()

Implements cosim::slave.

◆ get_string_variables()

void cosim::fmi::v2::slave_instance::get_string_variables ( gsl::span< const value_reference variables,
gsl::span< std::string values 
) const
overridevirtual

Retrieves the values of string variables.

On return, the values array will be filled with the values of the variables specified in variables, in the same order.

Precondition
variables.size() == values.size()

Implements cosim::slave.

◆ set_boolean_variables()

void cosim::fmi::v2::slave_instance::set_boolean_variables ( gsl::span< const value_reference variables,
gsl::span< const bool >  values 
)
overridevirtual

Sets the values of boolean variables.

This will set the value of each variable specified in the variables array to the value given in the corresponding element of values.

The function may throw nonfatal_bad_value to indicate that one or more values were out of range or invalid, but that these values have been accepted or ignored so the simulation can proceed.

Precondition
variables.size() == values.size()

Implements cosim::slave.

◆ set_integer_variables()

void cosim::fmi::v2::slave_instance::set_integer_variables ( gsl::span< const value_reference variables,
gsl::span< const int >  values 
)
overridevirtual

Sets the values of integer variables.

This will set the value of each variable specified in the variables array to the value given in the corresponding element of values.

The function may throw nonfatal_bad_value to indicate that one or more values were out of range or invalid, but that these values have been accepted or ignored so the simulation can proceed.

Precondition
variables.size() == values.size()

Implements cosim::slave.

◆ set_real_variables()

void cosim::fmi::v2::slave_instance::set_real_variables ( gsl::span< const value_reference variables,
gsl::span< const double >  values 
)
overridevirtual

Sets the values of real variables.

This will set the value of each variable specified in the variables array to the value given in the corresponding element of values.

The function may throw nonfatal_bad_value to indicate that one or more values were out of range or invalid, but that these values have been accepted or ignored so the simulation can proceed.

Precondition
variables.size() == values.size()

Implements cosim::slave.

◆ set_string_variables()

void cosim::fmi::v2::slave_instance::set_string_variables ( gsl::span< const value_reference variables,
gsl::span< const std::string values 
)
overridevirtual

Sets the values of string variables.

This will set the value of each variable specified in the variables array to the value given in the corresponding element of values.

The function may throw nonfatal_bad_value to indicate that one or more values were out of range or invalid, but that these values have been accepted or ignored so the simulation can proceed.

Precondition
variables.size() == values.size()

Implements cosim::slave.

◆ setup()

void cosim::fmi::v2::slave_instance::setup ( time_point  startTime,
std::optional< time_point stopTime,
std::optional< double >  relativeTolerance 
)
overridevirtual

Instructs the slave to perform pre-simulation setup and enter initialisation mode.

This function is called when the slave has been added to an execution. The arguments startTime and stopTime represent the time interval inside which the slave's model equations are required to be valid. (In other words, it is guaranteed that do_step() will never be called with a time point outside this interval.)

Parameters
[in]startTimeThe earliest possible time point for the simulation.
[in]stopTimeThe latest possible time point for the simulation. May be left unspecified if there is no defined stop time.
[in]relativeToleranceIf specified, this contains the relative tolerance of the step size controller. The slave may then use this for error control in its internal integrator.

Implements cosim::slave.

◆ start_simulation()

void cosim::fmi::v2::slave_instance::start_simulation ( )
overridevirtual

Informs the slave that the initialisation stage ends and the simulation begins.

Implements cosim::slave.


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