liveBook · Manning

Functional mock-up unit

As explained in Digital Twins in Action

A functional mock-up unit is a portable package containing a compiled model and, depending on its type, a numerical solver for execution in an FMI-compliant environment.

A functional mock-up unit (FMU) is a portable zip package containing a compiled simulation model. It follows the open Functional Mock-up Interface (FMI) standard, allowing an FMI-compliant environment to run a model outside the tool used to develop it. This makes an FMU useful when a production digital twin must run simulations as part of a larger system rather than inside a modeling GUI. section 9.3.3

Choose the FMU type according to who will supply the numerical solver:

  • A model exchange FMU leaves the solver to the simulation environment. section 9.3.3
  • A co-simulation FMU includes a solver; the environment sets inputs and advances time. section 9.3.3
# Download the model
curl -L https://github.com/digital-twins-in-action/book/blob/main/code/
ch09/WaterTankDrainage.mo > WaterTankDrainage.mo

# Launch OpenModelica container
docker run -it -v "$(pwd):/app" openmodelica/openmodelica:v1.25.5-gui

# Inside the container, start the shell and build the FMU
OMShell-terminal

>>> installPackage(Modelica) # Install the Modelica Standard Library

>>> loadModel(Modelica)      # Load it into the environment

>>> loadFile("/app/WaterTankDrainage.mo") # Load the tank model

>>> buildModelFMU(WaterTankDrainage, modelType="cs") # Build
co-simulation FMU

This build sequence loads a Modelica water-tank drainage model in OpenModelica and uses buildModelFMU with modelType="cs" to create a co-simulation FMU. section 9.3.3

Run the drainage model from Python

Install numpy and fmpy, then call simulate_fmu on WaterTankDrainage.fmu. Set tank.level_start to 2, request tank.level as output, and stop at 15,000 simulated seconds. The example runs roughly 4.1 hours of drainage in a few seconds of real time. The package includes platform binaries by default: an FMU built for 64-bit Linux can run on a matching platform, not necessarily on every machine that supports FMI. section 9.3.3

An FMU can also supply predictions inside a sensor-fusion workflow. In a room-temperature example, a thermal model accounts for HVAC settings and external temperature; an unscented Kalman filter uses the FMU in its predict stage while combining noisy readings from five IoT sensors. The illustrated Python temperature class describes the thermal step, rather than the FMU packaging process. section 9.3.4

How Digital Twins in Action covers it

How deep it goes
Defines both solver variants and demonstrates building and running an FMU, without detailing numerical solver internals.
Examples
Uses a water-tank drainage FMU run through FMPy and a room-temperature FMU paired with noisy IoT sensor readings.
What it assumes
Introduces FMI and FMU types while using an existing Modelica tank model for the build exercise.
What you can do after
Apply it via OpenModelica and FMPy to build and run a co-simulation FMU on a compatible platform.
How it connects
Links FMI, model exchange, co-simulation, Modelica, digital twins, and unscented Kalman filters.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Digital Twins in Action. The section links point to the parts of the book it draws on.