Guy on Simulink

Simulink & Model-Based Design

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the Original version of the page.

Simulink and the Functional Mock-up Interface Standard 4

Posted by Guy Rouleau,

Today, I want to cover the current state of support of Functional Mock-up Units (FMU) in Simulink.

Background

From the FMI standard website, FMI is:

Functional Mock-up Interface (FMI) is a tool independent standard to support both model exchange and co-simulation of dynamic models using a combination of xml-files and compiled C-code.

This standard has been gaining popularity over the past few years, and we added support in Simulink to import and export FMUs.

Disclaimer: The FMI standard is one of many options available for co-simulation between Simulink and other tools. As with most standards, it comes with a set of constraints. If your requirements do not fit within those constraints and you want more flexibility, I recommend writing an S-Function as I described in this post: Communicating with an External Application for Co-Simulation. With an S-Function, you have full control over the co-simulation interface.

FMU Import

In R2017b, the FMU block was introduced. This block supports FMI standards 1.0 and 2.0, in both Co-Simulation mode (where the FMU contains its own local solver) and Model Exchange mode (where the FMU states are integrated by the Simulink solver).

FMU block

I recommend looking at the FMU Importing section of the documentation to get started with that.

FMU Import Enhancements

In R2018a, we added two significant enhancements to the FMU block. The first one is numerical compensation.

Co-Simulation FMUs typically represent continuous phenomena, but their interface must be discrete and this can introduce numerical inaccuracies. To reduce those inaccuracies, numerical compensation can help. When a port has numerical compensation enabled, you will see the following icon next to it:

Numerical compensation

The second enhancement to the FMU block is that it can now run on different cores. As you can imagine, this can result in significant performance improvements if componentized properly.

One thing to note is that those two features also work with hand-written C-Mex S-Functions. If you want to write a co-simulation interface for a third-party tool without going through the FMU standard, keep that in mind!

Export a Model as a Tool-Coupling FMU

In R2018b, we added support in the other direction. It is now possible to export a model as a Tool-Coupling FMU and include it in other tools.

To begin, your Simulink model must be in a Simulink Project. In the Share menu, you will notice a new FMU entry:

Share FMU

Note that the Simulink Project should be configured to load and put on the path everything that the model needs. This is typically done through project startup tasks.

Using the Exported Tool-Coupling FMU

To use the FMU, you need a dedicated MATLAB session. For that, you have two options.

The first option is to manually start MATLAB and execute shareMATLABForFMUCoSim. When the other tool utilizing the FMU will begin executing, you should see the Simulink project and model open and start.

The second option is to start a dedicated MATLAB session from the operating system to run in the background. On Windows OS, you can execute a batch file from a DOS prompt to start as many dedicated MATLAB session as needed. See the documentation for the location and syntax of this batch file.

Debugging Tip

Before importing an FMU in Simulink, I recommend running it through the FMU Compliance Checker, to ensure that the FMU is valid.

If you have problems utilizing an FMU exported from Simulink in another tool, I recommend trying to import it first in a seperate MATLAB session using the FMU Import block. In the block, enable debugging to get as much information as possible:

Debugging FMU

If you select to send the debug log to "Display" as in the image above, the info will show up in the Simulink Diagnostic Viewer.

Now it's your turn

Are you using the FMU technology to co-simulate with different tools? Let us know which ones in the comment below.

4 CommentsOldest to Newest

Gareth Thomas replied on : 1 of 4
This is a very useful functionality. FMU is a hot topic and it is nice to see MathWorks empowering their users to leverage this. I am glad you wrote about this Guy, as I missed this in the Release notes the first them. I typically use this page for Simulink: What's New in Simulink and it is not there:(
Christian Bertsch replied on : 2 of 4
Hi Guy, thanks for this nice overview on FMI support in ML/SL. Mathworks has made good progress! Regarding your disclaimer: there are also cases where it is the other way round and FMI-features cannot be mapped to S-Functions. (One example is the definition of direct feedthough. In FMI for Model Exchange you can define the full matrix of direct feedhrough dependencies from inputs to outputs. In S-Functions, direct feedthrough is a property of inputs only, which leads to the false detection of artificial algebraic loops in many cases. Would be great, if Mathworks could implement this FMI feature!) Best regards, Christian
Sampath Vanimisetti replied on : 3 of 4
Thanks Guy! Nice overview. What are the licensing limitation of using an exported FMU from Simulink? If other blocksets are used, does the running Matlab session have to provide for all the necessary licenses?