Generate complete, cross-platform C++ source code for FMI 2.0 Functional Mockup Units (FMUs) — with a few clicks.

What is this FMI/FMU stuff?

FMU stands for Functional Mockup Unit and FMI for Functional Mockup Interface. The latter is an industry standard for simulation model runtime coupling, and basically defines an API and a meta data description file and directory structure: see the FMI-Standard webpage for details.

Why a code generator?

When you want an efficient/fast FMU slave, there’s probably no way around a native C/C++ implementation. However, implementing the C interface functions, the data handling, input/output variable handling and advanced features like saving and restoring the FMU state is not so simple and straight-forward.

The process of setting up the FMU (core files, modelDescription.xml, directory structure) is pretty similar for most projects and can be automated with a configurable code generator — hence this project.

Features

VariableDefinition
GenerationSucccess
  • Graphical wizard (Python/Qt 6) and command line generator

  • Generates FMI 2.0 FMUs for Model Exchange and Co-Simulation

  • Generates modelDescription.xml, value reference defines and variable handling

  • Generic FMU state serialization (get/set/serialize FMU state) — you only add your model-specific state

  • Re-run the generator to change variables: generated files are updated, your own code stays untouched

  • CMake and qmake (Qt Creator) build files, build and deploy scripts for Linux, macOS and Windows

  • Small, readable code without third-party library dependencies

What FMI Code Generator is not

This is not a Software Development Library/Toolkit for accessing/supporting the FMI interface. Look at the FMU SDK or other projects on fmi-tools if you need something like that.

Actually, the code generated by FMI Code Generator hides most of the messy FMI C function interface (including most of the memory management related to instantiating/deleting slave instances, and the state storage stuff) from the typical (engineering) user.

Quick start

git clone https://github.com/ghorwin/FMICodeGenerator.git
cd FMICodeGenerator
pip install -r requirements.txt
python scripts/main.py

Then continue with:

  • Installation — system requirements per platform

  • User Guide — how to generate, implement, update, build and deploy an FMU

  • Tutorial — step-by-step from the wizard to a working FMU

  • Test scenarios — demonstration models and compliance checking

About the author

I’m working with FMI since 2009, and also authored the co-simulation master tool MasterSim. FMUs generated with the FMI Code Generator and run with MasterSim allow for very efficient simulation coupling (even real-time applications), so give it a try!

License

The FMICodeGenerator is provided under a BSD 3-Clause License. Source code: https://github.com/ghorwin/FMICodeGenerator