Today, I want to cover the current state of support of Functional Mock-up Units (FMU) in Simulink.
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.
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).
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:
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:
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.
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:
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.
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.