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
