This directory is a small collection of FMI and Open Simulation Platform (OSP) examples. It contains C++ FMU sources, a PythonFMU model, and an OSP system description that connects generated FMUs.
osp-examples/
|-- .git/ Git metadata for this examples checkout
|-- cpp-fmus/ C++ FMU project based on CPPFMU
|-- PythonFMU/ PythonFMU resistor model and build files
`-- system/ OSP system structure and FMU files
The C++ FMU project contains:
CMakeLists.txtandcmake/for configuring and packaging FMUs.src/with the example FMU implementations.cppfmu/with the CPPFMU framework submodule.fmi/with FMI headers and support files.tools/with utilities such asMergeFMUs.cmake.build.ps1for the Windows build workflow.fail/,mock/,null/, andvector/with example FMU sources.
Build it from this directory with CMake:
Set-Location cpp-fmus
git submodule update --init --recursive
cmake -S . -B build
cmake --build buildThe generated FMUs are placed in the build/ directory. The project README
also documents optional FMI compliance checks and merging platform-specific
FMUs.
This directory contains a PythonFMU resistor example:
demoslave.pydefines theResistorFMI 2.0 co-simulation slave.requirements.txtlists the model dependencies.build.ps1contains thepythonfmu buildcommand.
Build the example from this directory after installing PythonFMU:
Set-Location PythonFMU
pythonfmu build -f demoslave.py requirements.txtImportant
When loading a PythonFMU in a non-Python host on Linux, set LD_PRELOAD to
the full path of the shared library for the Python runtime that will execute
the FMU before starting the host process. The library must match the
Python version and architecture available on the target system; PythonFMU
does not bundle Python.
For example, launch the host with:
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libpython3.11.so cosim run path/to/systemReplace the example path and version with the libpython library installed
on your system. Setting LD_PRELOAD after the host has already started is
too late. This Linux-specific step is needed for non-Python hosts; it is not
required when the host process is Python itself.
On Windows, LD_PRELOAD does not exist. Instead, make the directory
containing the matching Python DLL (python3.dll or a versioned DLL such as
python311.dll) available on PATH before starting the non-Python host:
$env:PATH = "C:\Path\To\Python311;$env:PATH"
.\cosim.exe run path\to\systemUse a Python DLL with the same version and architecture as the environment that will execute the FMU. If the DLL is already discoverable by the host, no additional environment change is required.
This is a runnable OSP system example:
OspSystemStructure.xmlselects fixed-step execution with a base step of0.01seconds.Resistor.fmuis the PythonFMU resistor model.vector.fmusupplies the voltage inputs and receives the resistor currents.
The connections in the system structure are:
vector.output[0] -> resistor.positive_pin_v
vector.output[1] -> resistor.negative_pin_v
resistor.positive_pin_i -> vector.input[0]
resistor.negative_pin_i -> vector.input[1]
Pass system/ to an OSP-compatible co-simulation runner to execute it and
write simulation results.
| Tool | Purpose | Link |
|---|---|---|
| libcosim | C++ co-simulation library and OSP execution engine. | GitHub repository |
libcosim-cli / cosim |
Command-line tool for running OSP/SSP simulations and inspecting FMUs. The upstream repository is named cosim-cli. |
GitHub repository |
| libcosimpy | Python wrapper for libcosim through the C API. | GitHub repository |
| libcosimc | C API wrapping a subset of libcosim. | GitHub repository |
| cosim-demo-app | Server-client demo application demonstrating libcosim features. | GitHub repository |
| demo-cases | OSP co-simulation cases with OspSystemStructure.xml and SSP SystemStructure.ssd configurations. |
GitHub repository |
| PythonFMU | Builds Python model code into FMI 2.0 co-simulation FMUs. | GitHub repository / PyPI package |