coral
A C++ library for distributed co-simulation
Public Member Functions | List of all members
coral::slave::Instance Class Referenceabstract

An interface for classes that represent slave instances. More...

#include "coral/slave/instance.hpp"

Inheritance diagram for coral::slave::Instance:
coral::fmi::SlaveInstance coral::slave::LoggingInstance coral::fmi::SlaveInstance1 coral::fmi::SlaveInstance2

Public Member Functions

virtual coral::model::SlaveTypeDescription TypeDescription () const =0
 Returns an object that describes the slave type.
 
virtual void Setup (const std::string &slaveName, const std::string &executionName, coral::model::TimePoint startTime, coral::model::TimePoint stopTime, bool adaptiveStepSize, double relativeTolerance)=0
 Instructs the slave to perform pre-simulation setup and enter initialisation mode. More...
 
virtual void StartSimulation ()=0
 Informs the slave that the initialisation stage ends and the simulation begins.
 
virtual void EndSimulation ()=0
 Informs the slave that the simulation run has ended.
 
virtual bool DoStep (coral::model::TimePoint currentT, coral::model::TimeDuration deltaT)=0
 Performs model calculations for the time step which starts at the time point currentT and has a duration of deltaT. More...
 
virtual double GetRealVariable (coral::model::VariableID variable) const =0
 Returns the value of a real variable. More...
 
virtual int GetIntegerVariable (coral::model::VariableID variable) const =0
 Returns the value of an integer variable. More...
 
virtual bool GetBooleanVariable (coral::model::VariableID variable) const =0
 Returns the value of a boolean variable. More...
 
virtual std::string GetStringVariable (coral::model::VariableID variable) const =0
 Returns the value of a string variable. More...
 
virtual bool SetRealVariable (coral::model::VariableID variable, double value)=0
 Sets the value of a real variable. More...
 
virtual bool SetIntegerVariable (coral::model::VariableID variable, int value)=0
 Sets the value of an integer variable. More...
 
virtual bool SetBooleanVariable (coral::model::VariableID variable, bool value)=0
 Sets the value of a boolean variable. More...
 
virtual bool SetStringVariable (coral::model::VariableID variable, const std::string &value)=0
 Sets the value of a string variable. More...
 

Detailed Description

An interface for classes that represent slave instances.

The function call sequence is as follows:

  1. Setup(): Configure the slave and enter initialisation mode.
  2. Get...Variable(), Set...Variable(): Variable initialisation. The functions may be called multiple times in any order.
  3. StartSimulation(): End initialisation mode, start simulation.
  4. DoStep(), Get...Variable(), Set...Variable(): Simulation. The functions may be called multiple times in any order.
  5. EndSimulation(): End simulation.

Any method may throw an exception, after which the slave instance is considered to be "broken" and no further method calls will be made.

Member Function Documentation

virtual bool coral::slave::Instance::DoStep ( coral::model::TimePoint  currentT,
coral::model::TimeDuration  deltaT 
)
pure virtual

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
true if the model calculations for the given time step were successfully carried out, or false if they were not because the time step was too long.
Note
Currently, retrying a failed time step is not supported, but this is planned for a future version.

Implemented in coral::fmi::SlaveInstance1, coral::fmi::SlaveInstance2, and coral::slave::LoggingInstance.

virtual bool coral::slave::Instance::GetBooleanVariable ( coral::model::VariableID  variable) const
pure virtual

Returns the value of a boolean variable.

Exceptions
std::logic_errorif there is no boolean variable with the given ID.

Implemented in coral::fmi::SlaveInstance1, coral::fmi::SlaveInstance2, and coral::slave::LoggingInstance.

virtual int coral::slave::Instance::GetIntegerVariable ( coral::model::VariableID  variable) const
pure virtual

Returns the value of an integer variable.

Exceptions
std::logic_errorif there is no integer variable with the given ID.

Implemented in coral::fmi::SlaveInstance1, coral::fmi::SlaveInstance2, and coral::slave::LoggingInstance.

virtual double coral::slave::Instance::GetRealVariable ( coral::model::VariableID  variable) const
pure virtual

Returns the value of a real variable.

Exceptions
std::logic_errorif there is no real variable with the given ID.

Implemented in coral::fmi::SlaveInstance1, coral::fmi::SlaveInstance2, and coral::slave::LoggingInstance.

virtual std::string coral::slave::Instance::GetStringVariable ( coral::model::VariableID  variable) const
pure virtual

Returns the value of a string variable.

Exceptions
std::logic_errorif there is no string variable with the given ID.

Implemented in coral::fmi::SlaveInstance1, coral::fmi::SlaveInstance2, and coral::slave::LoggingInstance.

virtual bool coral::slave::Instance::SetBooleanVariable ( coral::model::VariableID  variable,
bool  value 
)
pure virtual

Sets the value of a boolean variable.

Returns
Whether the value was set successfully. This could be false if, for example, the value is out of range.
Exceptions
std::logic_errorIf there is no boolean variable with the given ID.

Implemented in coral::fmi::SlaveInstance1, coral::fmi::SlaveInstance2, and coral::slave::LoggingInstance.

virtual bool coral::slave::Instance::SetIntegerVariable ( coral::model::VariableID  variable,
int  value 
)
pure virtual

Sets the value of an integer variable.

Returns
Whether the value was set successfully. This could be false if, for example, the value is out of range.
Exceptions
std::logic_errorIf there is no integer variable with the given ID.

Implemented in coral::fmi::SlaveInstance1, coral::fmi::SlaveInstance2, and coral::slave::LoggingInstance.

virtual bool coral::slave::Instance::SetRealVariable ( coral::model::VariableID  variable,
double  value 
)
pure virtual

Sets the value of a real variable.

Returns
Whether the value was set successfully. This could be false if, for example, the value is out of range.
Exceptions
std::logic_errorIf there is no real variable with the given ID.

Implemented in coral::fmi::SlaveInstance1, coral::fmi::SlaveInstance2, and coral::slave::LoggingInstance.

virtual bool coral::slave::Instance::SetStringVariable ( coral::model::VariableID  variable,
const std::string value 
)
pure virtual

Sets the value of a string variable.

Returns
Whether the value was set successfully. This could be false if, for example, the value is out of range.
Exceptions
std::logic_errorIf there is no string variable with the given ID.

Implemented in coral::fmi::SlaveInstance1, coral::fmi::SlaveInstance2, and coral::slave::LoggingInstance.

virtual void coral::slave::Instance::Setup ( const std::string slaveName,
const std::string executionName,
coral::model::TimePoint  startTime,
coral::model::TimePoint  stopTime,
bool  adaptiveStepSize,
double  relativeTolerance 
)
pure virtual

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 DoStep() will never be called with a time point outside this interval.)

Parameters
[in]slaveNameThe name of the slave in the current execution. May be empty if this feature is not used.
[in]executionNameThe name of the current execution. May be empty if this feature is not used.
[in]startTimeThe earliest possible time point for the simulation.
[in]stopTimeThe latest possible time point for the simulation. May be infinity if there is no defined stop time.
[in]adaptiveStepSizeWhether the step size is being controlled by error estimation.
[in]relativeToleranceOnly used if adaptiveStepSize == true, and then contains the relative tolerance of the step size controller. The slave may then use this for error estimation in its internal integrator.

Implemented in coral::fmi::SlaveInstance1, coral::fmi::SlaveInstance2, and coral::slave::LoggingInstance.


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