Functional Mock-up Interface - FMI

The new standard for model exchange and co-simulation with Functional Mockup Interface (FMI) allows export of pre-compiled models, i.e., C-code or binary code, from a tool for import in another tool, and vice versa. The FMI standard is Modelica independent. Import and export works both between different Modelica tools, or between certain non-Modelica tools. OpenModelica supports FMI 1.0 & 2.0,

  • Model Exchange
  • Co-Simulation (under development)

FMI Export

To export the FMU use the OpenModelica command translateModelFMU(ModelName) from command line interface, OMShell, OMNotebook or MDT. The export FMU command is also integrated with OMEdit. Select FMI > Export FMU the FMU package is generated in the current directory of omc. You can use the cd() command to see the current location. You can set which version of FMI to export through OMEdit settings, see section FMI.

To export the bouncing ball example to an FMU, use the following commands:

>>> loadFile(getInstallationDirectoryPath() + "/share/doc/omc/testmodels/")
>>> translateModelFMU(BouncingBall)
>>> system("unzip -l BouncingBall.fmu | egrep -v 'sources|files' | tail -n+3 | grep -o '[A-Za-z._0-9/]*$' > BB.log")

After the command execution is complete you will see that a file BouncingBall.fmu has been created. Its contents varies depending on the current platform. On the machine generating this documentation, the contents in Listing 3 are generated (along with the C source code).

Listing 2 BouncingBall FMU contents

A log file for FMU creation is also generated named ModelName_FMU.log. If there are some errors while creating FMU they will be shown in the command line window and logged in this log file as well.

By default an FMU that can be used for both Model Exchange and Co-Simulation is generated. We only support FMI 2.0 for Co-Simulation FMUs.

Currently the Co-Simulation FMU supports only the forward Euler solver with root finding which does an Euler step of communicationStepSize in fmi2DoStep. Events are checked for before and after the call to fmi2GetDerivatives.

FMI Import

To import the FMU package use the OpenModelica command importFMU,

>>> list(OpenModelica.Scripting.importFMU, interfaceOnly=true)
function importFMU
  input String filename "the fmu file name";
  input String workdir = "<default>" "The output directory for imported FMU files. <default> will put the files to current working directory.";
  input Integer loglevel = 3 "loglevel_nothing=0;loglevel_fatal=1;loglevel_error=2;loglevel_warning=3;loglevel_info=4;loglevel_verbose=5;loglevel_debug=6";
  input Boolean fullPath = false "When true the full output path is returned otherwise only the file name.";
  input Boolean debugLogging = false "When true the FMU's debug output is printed.";
  input Boolean generateInputConnectors = true "When true creates the input connector pins.";
  input Boolean generateOutputConnectors = true "When true creates the output connector pins.";
  output String generatedFileName "Returns the full path of the generated file.";
end importFMU;

The command could be used from command line interface, OMShell, OMNotebook or MDT. The importFMU command is also integrated with OMEdit. Select FMI > Import FMU the FMU package is extracted in the directory specified by workdir, since the workdir parameter is optional so if its not specified then the current directory of omc is used. You can use the cd() command to see the current location.

The implementation supports FMI for Model Exchange 1.0 & 2.0 and FMI for Co-Simulation 1.0 stand-alone. The support for FMI Co-Simulation is still under development.

The FMI Import is currently a prototype. The prototype has been tested in OpenModelica with several examples. It has also been tested with example FMUs from FMUSDK and Dymola. A more fullfleged version for FMI Import will be released in the near future.

When importing the model into OMEdit, roughly the following commands will be executed:

>>> imported_fmu_mo_file:=importFMU("BouncingBall.fmu")
>>> loadFile(imported_fmu_mo_file)

The imported FMU can then be simulated like any normal model:

>>> simulate(BouncingBall_me_FMU, stopTime=3.0)
record SimulationResult
    resultFile = "«DOCHOME»/BouncingBall_me_FMU_res.mat",
    simulationOptions = "startTime = 0.0, stopTime = 3.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'BouncingBall_me_FMU', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
    messages = "LOG_SUCCESS       | info    | The initialization finished successfully without homotopy method.
LOG_SUCCESS       | info    | The simulation finished successfully.
    timeFrontend = 0.022066726,
    timeBackend = 0.011164605,
    timeSimCode = 0.04247485500000001,
    timeTemplates = 0.030049798,
    timeCompile = 0.622289045,
    timeSimulation = 0.042200013,
    timeTotal = 0.770371366
end SimulationResult;

Figure 32 Height of the bouncing ball, simulated through an FMU.