Main Content

Eliminate Single Step Delay in Co-Simulation FMU Using Event Mode

A functional mockup unit (FMU) exhibits a single step delay of output in Simulink® when it is used in co-simulation mode. This is due to the delay in communication between the local FMU solver and Simulink solver. This example shows how to export a Simulink model to a standalone co-simulation FMU that is compatible with FMI 3.0 standard and leverage the event mode of the FMU in Simulink to eliminate the single step delay caused during co-simulation. This method works for FMUs that were created from a Simulink model and contain only direct feedthrough blocks.

Export Simulink Model to Co-Simulation FMU 3.0

Open the ifThen example model.

This model has two inputs, Source Signal and Control Signal. The value of the output is determined by the value of the Control Signal. The Transmitted Signal value is equal to the Source Signal value if the Control Signal value is greater than zero. Otherwise the Transmitted Signal is equal to the Baseline Value.

In the Simulink Toolstrip, on Simulation tab, click the drop-down button for Save button arrow. In the * Export Model To* section, click Standalone FMU In the FMU Export dialog box, for FMI Version select 3.0 and specify save location for the generated FMU.

Click Create to export to FMU. You need a Simulink Compiler license and installation of the FMU Builder for Simulink support package for exporting Simulink models to an FMU. You can find the ifThen.fmu file in the location that you specified.

You can also use the exportToFMU function to export the Simulink model to a co-simulation FMU.

Integrate FMU Into Simulink

Once the FMU is generated, you can integrate it into the top model FMUEventModeComparision to compare the performance of the FMU with and without event mode.

From the Simulation tab, select Enable Event Mode check box to simulate the FMU with Event Mode.

The FMU without Event Mode shows a single step delay during simulation.