Creating and exporting FMU
Advanced example: creation of a source-code FMU for real-time target
The aim of this example is to prepare a model for export as an FMU for Co-simulation that can be executed on a real-time platform. Open the driveline model located in the tutorial subdirectory of the Simcenter Amesim root directory. Enter Simulation mode and pull down the Simulate > Run > Run parameters menu command. In the Run Parameters dialog box (see figure below), ensure that the Integrator type radio button is set to Standard integrator. This means that the variable step size solver is used for simulating the model.
Figure 76: the Run Parameters dialog box, with Standard integrator selected
Run a simulation, and plot the variable wsig@rotaryspeedsensor (see figure below).
Figure 77: Plot of the wsig@rotaryspeedsensor variable
In the plot window, pull down the Tools > Hold curve menu command (see figure below).
Figure 78: The Hold curve dialog box
Click OK to hold the current curve obtained by running the simulation with the variable step-size solver. In order to be executed on a real-time target, the model needs to be exported as an FMU for Co-simulation that embeds a fixed step solver. The next task is to select the appropriate fixed step solver and to set a value of the step size that ensures that the discretization error is still acceptable with respect to the variable step solver simulation. Now re-open the Run Parameters dialog box, and set the Integrator type to Fixed step integrator (see figure below).
Figure 79: the Run Parameters dialog box with the Fixed step integrator selected
Click the Fixed step options tab, and set the Step to use parameter to 0.001 s (see figure below).
Figure 80: The Fixed step options tab of the Run Parameters dialog box, with Step to use set to 0.001
Click OK, and run a simulation. Look at the plot window (see figure below). It shows the plot of the wsig@rotaryspeedsensor variable obtained with the two different numerical solvers:
The standard integrator, variable step-size solver (as the hold curve)
The fixed step integrator, with a step of 0.001 s (as the current curve)
Figure 81: Simulation results obtained with a fixed step size of 0.001 s (red line) and a variable step size solver (dashed line)
It can be seen that at certain time values, for example 7.3 s, an error of about 1% exists between the two simulations. Re-open the Run Parameters and change the step size to 0.0001 s (see figure below).
Figure 82: The Fixed step options tab of the Run Parameters dialog box, with Step to use set to 0.0001 s
Restart the simulation and look at the results (see the figure below). This time, the error is less than 0.05%.
Figure 83: Simulation results obtained with a fixed step size of 0.0001 s (red line) and a variable step size solver (dashed line)
With these solver settings, the model is ready to be exported to a real-time platform. In Sketch mode, modify the model according to the example shown in section Simple example: exporting a model containing input and output ports :
remove the signal source connected to the torque source (torquecon [TORQC]) on the left
remove the signal sink connected to the rotary speed sensor (rotaryspeedsensor [MECSRSS0A])
Pull down the Interfaces > Create interface block menu command. In the Interface Icon Creation dialog box, specify the following:
select Functional Mock-up Interface (FMI) as type of interface in the list box
set the number of inputs to 1 using the spin buttons
set the number of outputs to 1 using the spin buttons
type speed as the name of the block input in the left text area, just after
1
type torque as the name of the block output in the right text area, in front of 1 >
in the three text areas in the middle of the dialog box, enter the label Functional Mock-up Interface for Co-simulation block
The Interface Icon Creation dialog box should look like the figure Figure 70. Click the OK button and drop the block onto the sketch. Once it is done, its output can be connected to the input of the torque source (torquecon [TORQC]), and its input to the output of the rotary speed sensor (rotaryspeedsensor [MECSRSS0A]), as shown in the example in Simple example: exporting a model containing input and output ports. Enter Simulation mode, and pull down the Interfaces > FMU export assistant menu command and set the following elements:
FMU type and version is Co-simulation 2.0
Visibility level is Low
Embed tables is selected
FMU for real-time is selected
A path is given as the Output directory
Figure 84: The first step of the FMU Export Assistant, with the FMU for real-time option enabled
Proceed to next step, and choose a real-time target, for example dSPACE SCALEXIO (see figure below).
Figure 85: The second step of the FMU Export Assistant. Selecting a real-time target platform in the drop down list
Click the Generate button. It starts the actual export process. Status is reported in the Messages tab. No compilation takes place since this is a source-code FMU.
Figure 86: Last step of the FMU Export Assistant
The FMU is ready to be imported by a real-time environment that is able to compile the source code. Indeed if look you inside the FMU, there is a documentation directory:
Figure 87: Documentation directory
In this directory, a file called readme.txt was created during the export process. It summarizes the information needed for building the FMU. The name of the main C source file to be compiled is listed, as well as the name of the pre-compiled runtime library needed for linking. All these files are available in the sources directory of the FMU.
Copy
FMU Creation date: 2017-09-26 16:03:24 GMT
Simcenter Amesim 16.0.0 - DEV - 24/09/17 19:07 - 67013-62949 2017
FMU for co-simulation 2.0
This source code FMU has been designed to be compiled and run for real-time target dSPACE SCALEXIO
C file to compile: driveline.c
Library to link: libAMESim_RT_r1600_scalexio.a
Refer to the user’s manual of the real-time target for details about how to import, build and execute the platform-specific binary object that can be created from the source-code FMU.
Source: https://docs.sw.siemens.com/en-US/doc/254352342/PL20250521841123434.amesim_collection.Functional_Mockup_Interface/xid1223902 · retrieved 2026-07-17