FMU Co-Simulation
Demonstration of integrating Functional Mock-up Units (FMU) as PathSim blocks.
What is an FMU?
The Functional Mock-up Interface (FMI) is an open standard for model exchange and co-simulation. An FMU is a ZIP archive containing:
- Model equations (compiled binaries)
- XML description of variables and metadata
- Optional resources and documentation
PathSim supports FMI 2.0 and FMI 3.0 co-simulation FMUs through the FMPy library.
The Coupled Clutches Model
This example uses a coupled clutches system, which is a classic benchmark from the FMI standard examples. The system consists of:
- Multiple rotating inertias
- Clutches connecting the inertias
- An input torque driving the system
The FMU has:
- 1 input: Torque applied to the first clutch
- 4 outputs: Angular velocities of the four rotating masses
This example demonstrates the CoSimulationFMU block, which wraps an FMU for integration with PathSim's simulation environment.
Import and Setup
Note that FMPy must be installed to use FMU blocks:
pip install fmpy
First, let's import the required classes:
FMU Path
We need to provide the path to the FMU file. In this example, we use the coupled clutches FMU:
Create the FMU Block
The CoSimulationFMU block handles all the FMI protocol details: - Instantiates the FMU - Manages initialization and termination - Synchronizes inputs and outputs - Performs co-simulation steps at the specified dt
System Setup
We create a sinusoidal torque input to drive the system and a scope to record all signals:
Connections
The FMU block behaves like any other PathSim block. We connect: - The source to the FMU input (torque) - The FMU outputs (4 angular velocities) to the scope - The input signal is also recorded for reference
Simulation
The simulation timestep is set smaller than the FMU communication step size. PathSim automatically handles the scheduling of FMU co-simulation steps:
Results
Let's plot the input torque and the angular velocities of all four clutches:
Analysis: Phase Space
We can examine the relationship between the angular velocities in phase space:
FMU Integration Details
Communication Step Size
The FMU performs internal integration steps with its own solver. The dt parameter specifies how often PathSim exchanges data with the FMU:
- Smaller
dt: More frequent data exchange, higher accuracy, slower simulation - Larger
dt: Less frequent exchange, faster simulation, potentially lower accuracy
PathSim vs FMU Timestep
PathSim can use a different (typically smaller) timestep than the FMU communication interval. This allows:
- Smooth integration with other PathSim blocks
- Fine-grained logging and event detection
- The FMU only performs co-simulation steps at its specified
dt
Event Handling
The FMU block uses PathSim's event scheduling system to trigger co-simulation steps at regular intervals. You can see the scheduled events:
Key Features of CoSimulationFMU
- Supports FMI 2.0 and FMI 3.0 standards
- Automatic metadata extraction and port configuration
- Configurable communication step size
- Event-based synchronization with PathSim
- Full reset and re-initialization support