Generate and Simulate Standalone FMU in Simulink
Simulink FMU Builder enables you to generate FMUs from your Simulink models and C/C++ code. You can generate Co-Simulation and Model Exchange FMUs that are compatible with FMI 2.0 and 3.0 standards. To learn about FMI and FMU concepts, see Functional Mockup Interface Concepts.
Comparison of FMU with Simulink Alternatives
FMUs provide a way to package your system components into standalone units. Simulink provides alternatives for generating standalone packages from Simulink models or C/C++ code. You can use protected models to generate a standalone package from Simulink models and C MEX S-function to generate standalone S-functions from C/C++ code.
General considerations
This table provides general considerations for choosing a tool to generate your standalone package.
| Working Environment | Simulink Model | C/C++ Code |
|---|---|---|
| Requires Interoperability | Model to FMU | Code to FMU |
| Used only in Simulink | Protected Model | C MEX S-Function |
Generate Ready-to-run Packages for Simulink Models
You can use FMUs or protected models to generate standalone packages from your Simulink models. Use FMUs when you need interoperability with other tools and plan to share the package outside Simulink. Use Simulink protected models when you are modeling, generating, and integrating the components in the Simulink environment and interoperability with other tools is not required. This table provides a detailed comparison between FMU and protected models.
| Feature | FMU | Protected Model |
|---|---|---|
| Tool compatibility | Tool-independent | Simulink only |
| Multi-platform | Yes; can package multiple binaries | No; single-platform |
| Bus interface | Supports non-virtual busses only | Full bus support |
| Advanced Simulink Semantics (for example fixed-point, Simscape solver) | Limited | Full compatibility |
| Simulation fidelity | High for Model Exchange; solver and importer dependent for Co-Simulation | High |
| Intellectual property protection | Protected by compilation (binary files) | Protected by encryption, (password protection), compilation (binary), and obfuscation (source code) |
| Debugging capability | Signal and source-code based debugging | Hidden model details |
Generate Ready-to-run Packages for C/C++ Code
You can use the Code to FMU tool or a C MEX S-function to generate standalone units for your C/C++ code. Use FMUs when you need interoperability with other tools and to share the package outside Simulink. Use a C MEX S-function when you are modeling, generating, and integrating the components entirely within the Simulink environment. This table provides a detailed comparison between FMU and C MEX S-functions.
| Feature | FMU | C MEX S-Function |
|---|---|---|
| Tool Compatibility | Tool-independent | Simulink only |
| Multi-platform | Yes; can package multiple binaries | No; single-platform |
| System Composer integration | Yes | No; can be included in Simulink Subsystem or Model Reference |
| Fixed-point compatibility | No | Yes |
| Simulation fidelity | High for Model Exchange; solver and importer dependent for Co-Simulation | High |
| Modeling and integration complexity | Moderate | Complex |
You can generate Co-Simulation or Model Exchange FMUs for both Simulink models and C/C++ code. To learn more about these FMU types, see FMU Types: Co-Simulation and Model Exchange.
Co-Simulation FMU Solvers: Fixed-Step and Variable-Step
A Co-Simulation FMU that contains both the model and solver can use either a fixed-step or variable-step solver. A fixed-step FMU can run independently of the original modeling environment and does not require additional runtime dependencies. A variable-step co-simulation FMU that is generated from Simulink offers limited Simulink semantics support, does not support cross-compilation, and depends on the MATLAB Runtime (MCR) to execute. As a result, variable-step FMUs are less portable and require the target environment to have the necessary runtime libraries installed.
| Feature | Fixed-Step FMU | Variable-Step FMU |
|---|---|---|
| MATLAB Runtime | Does not require MATLAB Runtime | Requires MATLAB Runtime |
| Cross-platform compilation and simulation | Yes | No |
| Cross-release simulation | Yes | No |
FMUState support | Yes | No |
| Windows 32-bit DLL | Yes | No |
| Multi-Instance support | Yes | No |
Generate FMUs in Simulink
Simulink FMU Builder and Simulink enable you to generate FMU from Simulink models or C/C++ and simulate these in the Simulink environment. Simulink FMU Builder supports generation of FMUs compatible with the FMI 2.0 and FMI 3.0 standards.
For a simple workflow demonstration of generating FMU from your Simulink model, see Generate a Basic Standalone FMU from Simulink Model.
To learn how to generate FMU using your C/C++ code, see Generate a Basic Standalone FMU from C/C++ Code.
Import and Simulate FMUs in Simulink
Simulink provides a wide range of features that enhance the usability and integration of FMUs within its environment. Through support for FMI standards and integration with native Simulink capabilities, you can incorporate FMUs into a model development workflows for simulation, verification, and deployment. This enables FMUs to function as integral components within Simulink based systems, supporting a range of development and testing activities. For more information, see Import, Test, and Simulate FMUs in Simulink.
See Also
Functional Mockup Interface Concepts