Main Content

Use Multi-Instance FMU for Simultaneous Simulations

This example demonstrates how to generate and simulate an Functional Mock Up Unit (FMU) compatible with multi-instantiation in Simulink®. You can export Simulink models with fixed-step solvers to standalone FMUs, which can be reused in multiple instances in Simulink. This enables the FMU to be used within For Each Subsystems in Simulink for simultaneous simulations.

In the first section of this example, a multi-instantiable FMU is generated from a Simulink model. In the second section, this FMU is imported back to Simulink and used within a For Each subsystem for simultaneous simulations with different input signals.

Generate Multi-Instance FMU

Open the suspensionModel_halfCar model. This is a simplified mathematical model of a vehicle's front and rear suspension system which can be used to study it's ride characteristics. The two inputs to this model are the pitch moment induced due to the vehicle's acceleration and the change in the road height that it travels on. For more information about this model, see Automotive Suspension.

suspension_model = 'suspensionModel_halfCar';
suspensionModel_data;
open_system(suspension_model);

Use the exportToFMU function with supportMultiInstance argument set to on to export this model as an FMU compatible with multi-instantiation.

exportToFMU(suspension_model,'FMUType','CS','FMIVersion','3.0','SupportMultiInstance','on');
Setting System Target to FMU 'Co-Simulation' for model 'suspensionModel_halfCar'.
Setting Hardware Implementation > Device Type to 'MATLAB Host' for model 'suspensionModel_halfCar'.
### 'GenerateComments' is disabled for 'Co-Simulation' FMU Export.
### 'CodeInterfacePackaging' is disabled for 'Co-Simulation' FMU Export.
### 'MultiInstanceErrorCode' is disabled for 'Co-Simulation' FMU Export.

Build Summary

Top model targets:

Model                    Build Reason                                         Status                        Build Duration
==========================================================================================================================
suspensionModel_halfCar  Information cache folder or artifacts were missing.  Code generated and compiled.  0h 0m 15.57s  

1 of 1 models built (0 models already up to date)
Build duration: 0h 0m 16.301s
### Model was successfully exported to 'Co-Simulation' FMU: '/tmp/Bdoc24b_2725827_1537762/tp4c9e9c2a/simulinkcompiler-ex33808161/suspensionModel_halfCar.fmu'.

You can also use the FMU Export dialog to generate the FMU. In to the Simulation tab on the Simulink toolstrip, click drop-down button for Save. Select Standalone FMU.... to open the FMU Export dialog. Open the Advanced tab within the dialog and select the Support multiple instantiation per process check box. Click Create to generate the FMU.

In the generated FMU, the canBeInstantiatedOnlyOncePerProcess flag in the modelDescription.xml file is set to false.

Import and Simulate FMU in a For Each Subsystem

Open the suspension_simulation model that imports the FMU into Simulink and implements it within a For Each Subsystem. The suspension model is simultaneously given three different road profiles as input. You can use For Each subsystem to perform simultaneous simulations for various FMU inputs or parameters. For more information about For Each Subsystem, see Repeat an Algorithm Using a For-Each Subsystem

suspension_model_sim = 'suspension_simulation.slx';
open_system(suspension_model_sim);

Simulate the model and observe the system response for the three different road profiles.

sim(suspension_model_sim);
open_system('suspension_simulation/Scope');

See Also

Related Topics