FMU Block Calling Sequences
During simulation of models containing FMU blocks, as Simulink® passes through different Simulink engine phases, the FMU blocks call FMU Co-Simulation and Model Exchange methods
for FMI Versions 1.0 and 2.0 (fmi* and fmi2* methods).
This topic presents the FMI Standard call
sequences in those phases.
This topic uses:
fmiSetXXX(FMI Version 1.0) andfmi2SetXXX(FMI Version 2.0) to represent any of the methods:fmiSetReal/fmi2SetReal,fmiSetInteger/fmi2SetInteger,fmiSetBoolean/fmi2SetBoolean, orfmiSetString/fmi2SetString.fmiGetXXX(FMI Version 1.0) andfmi2GetXXX(FMI Version 2.0) to represent any of the methods:fmiGetReal/fmi2GetReal,fmiGetInteger/fmi2GetInteger,fmiGetBoolean/fmi2GetBoolean, orfmiGetString/fmi2GetString.
Co-Simulation Call Sequence for FMI Version 1.0
These are the call orders for the FMI methods that the S-function callback methods call.
Setup Phase
At the end of compilation, the FMU block performs setup activities by calling these FMI methods:
fmiGetTypesPlatformfmiGetVersionfmiInstantiateModelfmiSetTimeFor variables with start values,
fmiSetXXX
Initialization Phase
At the start of simulation, the FMU block sets up internal states and performs other
initialization activities by calling the fmiSetXXX
methods for tunable parameters.
Output Phase
During this phase, the FMU block computes outputs at the current time step by calling these FMI methods:
If the call is the first step:
fmiSetXXXfmiInitializeIf an event occurs,
fmiEventUpdate
If the call is not the first step:
fmiSetTimefmiSetXXX(for input)fmiSetContinuousStatesfmiCompletedIntegratorStepIf an event occurs,
fmiEventUpdate
For output,
fmiGetXXX
Update Phase
The FMU block computes states at the current time step and performs other major time
step activities by calling the fmiSetXXX methods for
input.
Derivatives Phase
The FMU block computes derivatives of the FMU continuous states by calling these FMI methods:
fmiSetTimefmiSetContinuousStatesfmiGetDerivatives
Zero-Crossing Signal Phase
The FMU block computes the zero-crossing vector from the FMU event indicator by calling these FMI functions:
fmiSetTimefmiSetContinuousStatesfmiGetEventIndicators
Termination Phase
At the end of simulation, the FMU block performs activities before terminating the simulation by calling these FMI methods:
fmiTerminatefmiFreeModelInstance
Model Exchange Call Sequence for FMI Version 1.0
These are the call orders for the FMI methods that the S-function callback methods call.
Setup Phase
At the end of compilation, the FMU block performs setup activities by calling these FMI functions:
fmiGetTypesPlatformfmiGetVersionfmiInstantiateModelfmiSetTimeFor variables with start values,
fmiSetXXX
Initialization Phase
At the start of simulation, the FMU block sets up internal states and performs other
initialization activities by calling these fmiSetXXX
methods for tunable parameters.
Output Phase
The FMU block computes outputs at the current time step by calling these FMI functions:
If the call is the first step:
fmiSetXXXfmiInitializeIf an event occurs,
fmiEventUpdate
If the call is not the first step,
fmiDoStep,For output,
fmiGetXXX
Update Phase
The FMU block computes states at the current time step and performs other major time
step activities by calling the fmiSetXXX methods for
input.
Termination Phase
At the end of simulation, the FMU block performs activities before terminating the simulation. This method calls these methods:
fmiTerminatefmiFreeModelInstance
Co-Simulation Call Sequence for FMI Version 2.0
These are the call orders for the FMI methods that the S-function callback methods call.
Setup Phase
At the end of compilation, the FMU block performs setup activities by calling these FMI methods:
fmi2GetTypesPlatformfmi2GetVersionfmi2InstantiateFor variables with start values,
fmi2SetXXX
Initialization Phase
At the start of simulation, the FMU block sets up internal states and performs other initialization activities by calling these FMI methods:
For variables with start values,
fmi2SetXXXfmi2SetupExperiment
Output Phase
During this phase, the FMU block computes outputs at the current time step by calling these FMI methods:
If the call is the first step:
fmi2EnterInitializationModeFor input,
fmi2SetXXXfmi2ExitInitializationMode
If the call is not the first step,
fmi2DoStepFor output,
fmi2GetXXX
Update Phase
During this phase, the FMU block computes states at the current time step and performs
other major time step activities. This method calls the
fmi2SetXXX for input.
Termination Phase
At the end of simulation, the FMU block performs activities before terminating the simulation by calling these methods:
fmi2Terminatefmi2FreeModelInstance
Model Exchange Call Sequence for FMI Version 2.0
These are the call orders for the FMI methods that the S-function callback methods call.
Setup Phase
At the end of compilation, the FMU block performs setup activities by calling these FMI methods:
fmi2GetTypesPlatformfmi2GetVersionfmi2InstantiateFor variables with start values,
fmi2SetXXX
Initialization Phase
At the start of simulation, the FMU block sets up internal states and performs other initialization activities by calling these FMI methods.
For tunable parameters,
fmi2SetXXXfmi2SetupExperiment
Output Phase
The FMU block computes outputs at the current time step by calling these FMI methods:
If the call is the first step:
fmi2EnterIntializationModeFor input,
fmi2SetXXXfmi2ExitIntializationMode
If the call is not the first step:
fmi2SetTimeFor continuous input,
fmi2SetXXXfmi2SetContinuousStatesfmi2SetContinuousStatesfmi2CompletedIntegratorStepIf an event occurs:
fmi2EnterEventModeFor input,
fmi2SetXXXfmi2NewDiscreteStatesfmi2EnterContinuousTimeModeIf an event occurs:
fmi2EnterEventModeFor input,
fmi2SetXXXfmi2NewDiscreteStatesfmi2EnterContinuousTimeMode
For output,
fmi2GetXXX
Update Phase
The FMU block computes states at the current time step and performs other major time
step activities by calling the fmi2SetXXX methods
for input.
Derivatives Phase
The FMU block computes derivatives of the FMU continuous states by calling these FMI methods:
fmi2SetTimefmi2SetContinuousStatesfmi2GetEventIndicators
Zero-Crossing Signal Phase
The FMU block computes the zero-crossing vector from the FMU event indicator by calling these FMI methods:
fmi2SetTimefmi2SetContinuousStatesfmi2GetEventIndicators
Termination Phase
At the end of simulation, the FMU block performs activities before terminating the simulation by calling these methods:
fmi2Terminatefmi2FreeInstance
Co-Simulation Call Sequence for FMI Version 3.0
These are the call orders for the FMI methods that the S-function callback methods call.
Setup Phase
At the end of compilation, the FMU block performs setup activities by calling these FMI methods:
fmi3GetTypesPlatformfmi3GetVersionfmi3InstantiateCoSimulationFor variables with start values,
fmi3SetXXX
Initialization Phase
At the start of simulation, the FMU block sets up internal states and performs other initialization activities by calling the following:
For variables with start values,
fmi3SetXXX
Output Phase
During this phase, the FMU block computes outputs at the current time step by calling these FMI methods:
If the call is the first step:
fmi3EnterInitializationModeFor input,
fmi3SetXXXfmi3ExitInitializationMode
If the call is not the first step,
fmi3DoStepIf an event occurs:
fmi3EnterEventModeSet continuous and discrete inputs:
fmi3SetXXXfmi3UpdateDiscreteStates
For output,
fmi3GetXXX
Update Phase
During this phase, the FMU block computes states at the current time step and performs
other major time step activities. This method calls the
fmi3SetXXX for input.
If FMU is in event mode, then enter step mode using
fmi3EnterStepMode function.
Termination Phase
At the end of simulation, the FMU block performs activities before terminating the simulation by calling these methods:
fmi3Terminatefmi3FreeModelInstance
Model Exchange Call Sequence for FMI Version 3.0
These are the call orders for the FMI methods that the S-function callback methods call.
Setup Phase
At the end of compilation, the FMU block performs setup activities by calling these FMI methods:
fmi3GetTypesPlatformfmi3GetVersionfmi3InstantiateModelExchangeFor variables with start values,
fmi3SetXXX
Initialization Phase
At the start of simulation, the FMU block sets up internal states and performs other initialization activities by calling the following:
For tunable parameters,
fmi3SetXXX
Output Phase
The FMU block computes outputs at the current time step by calling these FMI methods:
If the call is the first step:
fmi3EnterIntializationModeFor input,
fmi3SetXXXfmi3ExitIntializationMode
If the call is not the first step:
fmi3SetTimeFor continuous input,
fmi3SetXXXfmi3SetContinuousStatesfmi3SetContinuousStatesfmi3CompletedIntegratorStepIf an event occurs:
fmi3EnterEventModeFor input,
fmi3SetXXXfmi3NewDiscreteStatesfmi3EnterContinuousTimeModeIf an event occurs:
fmi3EnterEventModeFor input,
fmi3SetXXXfmi3NewDiscreteStatesfmi3EnterContinuousTimeMode
For output,
fmi3GetXXX
Update Phase
The FMU block computes states at the current time step and performs other major time
step activities by calling the fmi2SetXXX methods
for input.
Derivatives Phase
The FMU block computes derivatives of the FMU continuous states by calling these FMI methods:
fmi2SetTimefmi2SetContinuousStatesfmi2GetEventIndicators
Zero-Crossing Signal Phase
The FMU block computes the zero-crossing vector from the FMU event indicator by calling these FMI methods:
fmi3SetTimefmi3SetContinuousStatesfmi3GetEventIndicators
Termination Phase
At the end of simulation, the FMU block performs activities before terminating the simulation by calling these methods:
fmi3Terminatefmi3FreeInstance