Main Content

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) and fmi2SetXXX (FMI Version 2.0) to represent any of the methods: fmiSetReal/fmi2SetReal, fmiSetInteger/fmi2SetInteger, fmiSetBoolean/fmi2SetBoolean, or fmiSetString/fmi2SetString.

  • fmiGetXXX (FMI Version 1.0) and fmi2GetXXX (FMI Version 2.0) to represent any of the methods: fmiGetReal/fmi2GetReal, fmiGetInteger/fmi2GetInteger, fmiGetBoolean/fmi2GetBoolean, or fmiGetString/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:

  1. fmiGetTypesPlatform

  2. fmiGetVersion

  3. fmiInstantiateModel

  4. fmiSetTime

  5. For 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:

  1. If the call is the first step:

    1. fmiSetXXX

    2. fmiInitialize

    3. If an event occurs, fmiEventUpdate

  2. If the call is not the first step:

    1. fmiSetTime

    2. fmiSetXXX (for input)

    3. fmiSetContinuousStates

    4. fmiCompletedIntegratorStep

    5. If an event occurs, fmiEventUpdate

  3. 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:

  1. fmiSetTime

  2. fmiSetContinuousStates

  3. fmiGetDerivatives

Zero-Crossing Signal Phase

The FMU block computes the zero-crossing vector from the FMU event indicator by calling these FMI functions:

  1. fmiSetTime

  2. fmiSetContinuousStates

  3. fmiGetEventIndicators

Termination Phase

At the end of simulation, the FMU block performs activities before terminating the simulation by calling these FMI methods:

  1. fmiTerminate

  2. fmiFreeModelInstance

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:

  1. fmiGetTypesPlatform

  2. fmiGetVersion

  3. fmiInstantiateModel

  4. fmiSetTime

  5. For 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:

  1. If the call is the first step:

    1. fmiSetXXX

    2. fmiInitialize

    3. If an event occurs, fmiEventUpdate

  2. If the call is not the first step, fmiDoStep,

  3. 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:

  1. fmiTerminate

  2. fmiFreeModelInstance

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:

  1. fmi2GetTypesPlatform

  2. fmi2GetVersion

  3. fmi2Instantiate

  4. For 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:

  1. For variables with start values, fmi2SetXXX

  2. fmi2SetupExperiment

Output Phase

During this phase, the FMU block computes outputs at the current time step by calling these FMI methods:

  1. If the call is the first step:

    1. fmi2EnterInitializationMode

    2. For input, fmi2SetXXX

    3. fmi2ExitInitializationMode

  2. If the call is not the first step, fmi2DoStep

  3. For 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:

  1. fmi2Terminate

  2. fmi2FreeModelInstance

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:

  1. fmi2GetTypesPlatform

  2. fmi2GetVersion

  3. fmi2Instantiate

  4. For 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.

  1. For tunable parameters, fmi2SetXXX

  2. fmi2SetupExperiment

Output Phase

The FMU block computes outputs at the current time step by calling these FMI methods:

  1. If the call is the first step:

    1. fmi2EnterIntializationMode

    2. For input, fmi2SetXXX

    3. fmi2ExitIntializationMode

  2. If the call is not the first step:

    1. fmi2SetTime

    2. For continuous input, fmi2SetXXX

    3. fmi2SetContinuousStates

    4. fmi2SetContinuousStates

    5. fmi2CompletedIntegratorStep

    6. If an event occurs:

      1. fmi2EnterEventMode

      2. For input, fmi2SetXXX

      3. fmi2NewDiscreteStates

      4. fmi2EnterContinuousTimeMode

      5. If an event occurs:

        1. fmi2EnterEventMode

        2. For input, fmi2SetXXX

        3. fmi2NewDiscreteStates

        4. fmi2EnterContinuousTimeMode

  3. 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:

  1. fmi2SetTime

  2. fmi2SetContinuousStates

  3. fmi2GetEventIndicators

Zero-Crossing Signal Phase

The FMU block computes the zero-crossing vector from the FMU event indicator by calling these FMI methods:

  1. fmi2SetTime

  2. fmi2SetContinuousStates

  3. fmi2GetEventIndicators

Termination Phase

At the end of simulation, the FMU block performs activities before terminating the simulation by calling these methods:

  1. fmi2Terminate

  2. fmi2FreeInstance

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:

  1. fmi3GetTypesPlatform

  2. fmi3GetVersion

  3. fmi3InstantiateCoSimulation

  4. For 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:

  1. 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:

  1. If the call is the first step:

    1. fmi3EnterInitializationMode

    2. For input, fmi3SetXXX

    3. fmi3ExitInitializationMode

  2. If the call is not the first step, fmi3DoStep

  3. If an event occurs:

    1. fmi3EnterEventMode

    2. Set continuous and discrete inputs: fmi3SetXXX

    3. fmi3UpdateDiscreteStates

  4. 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:

  1. fmi3Terminate

  2. fmi3FreeModelInstance

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:

  1. fmi3GetTypesPlatform

  2. fmi3GetVersion

  3. fmi3InstantiateModelExchange

  4. For 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:

  1. For tunable parameters, fmi3SetXXX

Output Phase

The FMU block computes outputs at the current time step by calling these FMI methods:

  1. If the call is the first step:

    1. fmi3EnterIntializationMode

    2. For input, fmi3SetXXX

    3. fmi3ExitIntializationMode

  2. If the call is not the first step:

    1. fmi3SetTime

    2. For continuous input, fmi3SetXXX

    3. fmi3SetContinuousStates

    4. fmi3SetContinuousStates

    5. fmi3CompletedIntegratorStep

    6. If an event occurs:

      1. fmi3EnterEventMode

      2. For input, fmi3SetXXX

      3. fmi3NewDiscreteStates

      4. fmi3EnterContinuousTimeMode

      5. If an event occurs:

        1. fmi3EnterEventMode

        2. For input, fmi3SetXXX

        3. fmi3NewDiscreteStates

        4. fmi3EnterContinuousTimeMode

  3. 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:

  1. fmi2SetTime

  2. fmi2SetContinuousStates

  3. fmi2GetEventIndicators

Zero-Crossing Signal Phase

The FMU block computes the zero-crossing vector from the FMU event indicator by calling these FMI methods:

  1. fmi3SetTime

  2. fmi3SetContinuousStates

  3. fmi3GetEventIndicators

Termination Phase

At the end of simulation, the FMU block performs activities before terminating the simulation by calling these methods:

  1. fmi3Terminate

  2. fmi3FreeInstance

See Also

External Websites