Compiling Linux FMUs with Dymola

FMUs are ideal for performing large-scale simulation studies on computing clusters. Since computing clusters usually run on Linux, the FMUs must also be compiled for Linux. We show you how to generate cross-compiled Linux FMUs with Dymola.

Stefan Rauscher

Stefan Rauscher

|

December 12, 2022

FMU for Linux

©zannagap / 123RF.com

What do FMI and FMU mean?

The Functional Mock-Up Interface (FMI) is a standardized interface that enables the exchange of models between different simulation tools. Functional Mock-Up Units (FMUs) are compiled models that conform to the FMI standard. For example, a model created in Dymola can be exported as an FMU and used in Simulink to test controllers.

Create Linux FMUs with Windows?

FMUs are usually in the form of compiled code¹. FMUs are therefore, similar to the well-known executables (.exe), executable programs that are bound to a specific operating system. An FMU compiled on Windows can only be executed on Windows and not on Linux. Linux would not "understand" the Windows FMU. To create a Linux FMU with Dymola, the FMU previously had to be created on Linux. This meant that a Linux distribution and a Linux version of Dymola were required.

Since version 2022, Dymola supports what is known as cross-compilation. Cross-compilation makes it possible to compile FMUs on Windows that can run on both Windows and Linux. This increases the user-friendliness considerably.

Installation guide for cross compilation in Dymola

Even though Dymola natively supports cross-compilation since version 2022, additional programs must be installed before first use:

  • First, Windows Subsystem for Linux (WSL) must be installed. To do this, start the command prompt as administrator and execute the following command:
    wsl --install -d Ubuntu

    The PC must be restarted afterwards. Here you can find more information about the installation of WSL.
  • After the restart, WSL should open automatically in the form of a command prompt. If WSL does not open automatically, it must be started manually. When WSL is started for the first time, the user is prompted to create an account and password (note: the password is not displayed on the command line).
  • Several packages must be installed in WSL. To do this, the following commands are executed one after the other:
    sudo apt update
    sudo apt upgrade
    sudo apt install gcc g++ zip dos2unix

    The WSL window can be closed after the successful execution of the commands.
  • Finally, the cross-compiler can be tested. To do this, Dymola is started and the Linux cross-compiler is selected under Simulation\Setup\Compiler tab. With Verify Compiler the test of the cross-compiler is executed:
  • A successful test is confirmed by Dymola as follows (Important: The compiler must be reset to the original setting afterwards!):

If you get an error message instead of the pictured message, WSL may not have write permissions. To grant WSL write permissions, the wsl.conf file must be edited:

  • Open the wsl.conf file in WSL:
    sudo vim /etc/wsl.conf
  • Entering the letter i activates the edit mode. The following text must be written to the file:
    [automount]
    options = "metadata"
  • Afterwards, the editing mode can be terminated by pressing Esc. The command
    :wq
    saves and closes the file. After that the PC must be restarted.

For more information, please refer to the Dymola user manual.

Compiling a Linux FMU

To create a Linux FMU, the option Cross compile for Linux must be selected in the Export FMU window (Simulatation\Translate\FMU):

If you open the FMU afterwards (FMUs are packaged as .zip files), you will see three folders in the binaries directory:

This shows that the FMU has been compiled for 32-bit and 64-bit Windows (win32 and win64) as well as 64-bit Linux (linux64). The FMU can thus be executed on Windows as well as on 64-bit Linux.

¹ Exception: So-called source code FMUs. Source code FMUs are not compiled, but are available in the form of C code. Source code FMUs are thus not bound to an operating system.

Stefan Rauscher

M.Sc.

Stefan Rauscher

Simulation & Optimization

TLK Energy

Stefan Rauscher studied mechanical engineering at the RWTH Aachen University, specializing in energy engineering. He joined TLK Energy in 2018 and has since then been intensively involved in the simulation, control and optimization of thermal systems. He also regularly leads training on the simulation of thermal systems using the model library TIL.

More blog posts: