Main Content

Implement an FMU Block

Implement a block and assign a functional mockup unit (FMU) to it. You can then explore the block to see the FMU. This example uses the FMU block with the vehicle FMU.

  1. Create a model and add the FMU block.

    If you have an FMU with source code that is missing the binary for the current platform, you can use the fmudialog.compileFMUSources function to generate binary for the current platform.

  2. In the block dialog box, enter the path name for an FMU file in the FMU name parameter and click OK or Apply. The file extension .fmu is optional.

    The first time you click OK or Apply, the block identifies which FMU mode to set your FMU to, cosimulation or model exchange.

    The block also creates a slprj/_fmu/fmu_name folder and unpacks the contents of the FMU file into this folder, which optionally include:

    • binaries — FMU binary files

    • documentation — FMU documentation HTML files

    • resources — FMU source files

    • sources — FMU source files

    • Other supporting files, such as block mask and description files

The FMU block icon and port labels update to the labels of the corresponding FMU. After you associate the block with an FMU, if you want to change the FMU, right-click the FMU block, and select Block Parameters, and enter a new FMU name in FMU name. The section in this topic use the FMU from the Simplify Interface for Structured Data with FMU Import Block example.

Explore the FMU Block

Double-click the block. Suppose that you entered an FMU named fmuVehicAOB.fmu from your current folder. The FMU block dialog box reflects the FMU parameters defined in the fmuVehicAOB.fmu file.

Parameters Tab

Lists the FMU block parameters. Edit the values as necessary. You can edit the elements of a structure parameter by expanding the tree view.

Simulation Tab

Enables logging and associated customizations.

  • To enter a relative tolerance, select Enable FMU tolerance and set it.

  • To determine the sample time of the block in the model, set Communication step size. To inherit the step size from the Simulink® solver, set to -1. This option is available only if the FMU is a cosimulation FMU.

  • For simulating in event mode, check Enable event mode option. This option is only available if your FMU is used in co-simulation mode and is compatible with FMI 3.0 standards.

  • To enable logging, select the Enable FMU Debug Logging.

  • In Redirect debug logs to, select the destination for the logs.

    • File, saved to slprj\_fmu\_logs_modelname\modelname_blockname.txt

    • Display, displayed in the MATLAB® Command Window.

    If the Enable FMU Debug Logging check box is selected and the Redirect debug logs to parameter is set to Display, you cannot use the FMU block for cosimulation. For more information on cosimulation and multiple cores, see Run Co-Simulation Components on Multiple Cores

  • In the Filter logs by return status, select the check box for the return status you want.

  • If you have an FMU with Linux® binary on Windows® and want to use the Linux binary for simulation, set the Simulate FMU using parameter to linux64. For more information, see Simulate FMU with Linux Binary on Windows (Simulink Compiler).

Input and Output Tabs

These two tabs list the input and output ports that the block defines. The Type Object field lists the bus object or enumeration class for ports that have bus or enumeration types. The FMU block uses the metadata inside the modelDescription.xml file to determine the signal attributes for bus and enumeration type ports.

Set the Type Object field in the Input and Output tabs to Inherit:Auto for enumeration type ports to enable downstream and upstream blocks to inherit signal data.

Set the Type Object field in the Output tab to Auto generate for bus type ports to enable downstream blocks to inherit signal data. Backward inheritance is not supported for bus ports. You need to provide compatible bus type input signal for FMU with bus type input ports.

Use the fmudialog.createBusType function to create a bus objects used by the FMU in the workspace:


Use the fmudialog.createEnumType function to create a enumeration classes used by the FMU in the workspace:


Change Block Input, Output, Parameter and Internal Variable Structures

You can change the layout of FMU block input ports, output ports, and parameters with these parameters:

FMUInputMappingChange hierarchy of input ports.

'Flat' — Separates input into individual signals.

'Structured' — Combines input into a structure of signals (bus).

FMUOutputMappingChange hierarchy of output ports.

'Flat' — Separates output into individual signals.

'Structured' — Combines output into a structure of signals (bus).

FMUParamMappingChange hierarchy of parameters.

'Flat' — Separates parameters into individual parameters, listed by the parameter name and value.

'Structured' — Combines parameters into a structure of parameter values (struct).

FMUInternalMappingChange hierarchy of internal variables

'Flat' — Separates internal variables into individual signals.

'Structured' — Combines internal variables into a structure of signals (bus).

Use the get_param and set_param functions to set these values. For example, assume a block parameter tab with a structure construct:

The parameters are contained in a struct. To list the parameters individually, set the FMUParamMapping property to 'Flat':

set_param(gcb,'FMUParamMapping', 'Flat')

Timing Considerations

You can set the sample time for the FMU block with the Communication step size parameter. This block sample time setting, tC, like all Simulink blocks, must be an integer multiple of the model sample time, tM. Simulink generates an error if the communication step size tC is not a multiple of the model step size tM.

The local step size of the FMU tL, on the other hand, is part of the FMU specification and is known to the FMU only internally. For proper operation, the communication step size, tC must also be an integer multiple of tL. If the model sample time tM or the block sample time tC is incompatible with the FMU local step size tL, the FMU may or may not produce an error at run time, depending on its implementation.

Troubleshooting FMUs

If there are problems with using the FMU:

  • Check the compliance of the FMU with the FMI standard. Use the FMU compliance checker.

  • Select the Enable FMU Debug Logging check box on the FMU block Simulation tab.

  • Contact the FMU supplier.

See Also


Related Topics

External Websites