FMI Modes & Compatibility
CoModel integrates FMUs exported from external tools into the MTK modeling workflow through the FMI standard. Understanding the differences between FMI versions and simulation modes helps you pick a suitable solver strategy and avoid common compatibility errors.
FMI Version Support
| FMI version | Support | Modes | Notes |
|---|---|---|---|
| FMI 2.0.x | ✅ Fully supported | CS + ME | The most widely used FMU format in industry today |
| FMI 3.0.x | ✅ Fully supported | CS + ME | The latest generation of the standard, with richer variable types |
| FMI 1.0 | ❌ Not supported | — | Obsolete; export as FMI 2.0/3.0 instead |
| Scheduled Execution (SE) | ❌ Not yet supported | SE | New in FMI 3.0; not implemented in the current version |
Comparing CS and ME Modes
The simulation mode of an FMU determines how the external solver cooperates with the solver inside the FMU:
| Mode | Full name | Solving | Ports and states exposed | Typical use |
|---|---|---|---|---|
| CS | Co-Simulation | The FMU carries its own internal solver; the external side only drives time stepping | Input / Output only | Black-box models, high-quality third-party solvers, loosely coupled systems |
| ME | Model Exchange | The FMU provides state derivatives; the external solver integrates everything | State variables and derivatives exposed | Deep coupling with MTK models, uniform accuracy |
CS Mode Characteristics
- The FMU integrates each step internally; the external MTK solver acts as the time driver.
- The data exchange frequency is controlled by
communication_step_size. - An explicit solver (e.g.
Tsit5()) is usually sufficient on the external side. - Suits cases where the solver inside the FMU already handles stiffness or events robustly.
ME Mode Characteristics
- The FMU's state derivatives and the MTK equations are compiled into a single DAE system.
- When FMU outputs participate in algebraic equations, the solver has to handle a mixed Jacobian.
- Because the FMU's C library interface cannot accept Julia
Dualnumbers, algebraic coupling requires a finite-difference Jacobian (Rodas5P(autodiff = AutoFiniteDiff())). - Suits cases where the FMU and the physics model need tight coupling and unified error control.
Mode Selection Strategy
When you upload an FMU, CS is preselected as the default simulation mode. After parsing, CoModel corrects the choice automatically based on what the FMU actually supports—when the selected mode is unsupported, it falls back to a supported mode (CS preferred). The default mode cannot yet be switched manually on the page.
| Modes the FMU supports | Effective mode | Reason |
|---|---|---|
| CS only | CS | The only choice |
| ME only | ME | The only choice |
| CS + ME | The option selected at upload (default CS) | Simpler; stiffness and events handled internally; no states exposed |
Platform Compatibility Constraints
Using an FMU in CoModel requires meeting these platform constraints:
| Constraint | Requirement |
|---|---|
| OS binaries | .so files under binaries/linux64/ must be present |
| Input / Output types | Only Real (floating-point) signal ports |
| Discrete variables and events | Discrete events inside the FMU are not supported in ME mode |
| Automatic differentiation | The FMU C library does not accept Dual numbers; ForwardDiff must be off when algebraic coupling is present |
| File size | ≤ 100 MB per FMU, ≤ 500 MB total per user |
TODO (platform compatibility): this section currently describes only the constraints of the Linux x86_64 service. Once Windows (win64, binaries/win64/.dll) and macOS (darwin64, binaries/darwin64/.dylib) compatibility support lands, update this section and the Linux note in FMU Upload & Component Library: binary directories and shared-library suffixes, whether the glibc version constraint applies, the linux64/glibc compatibility check message, and similar hints.
Recommended Solvers
The table below summarizes recommended solvers for different FMI versions, modes, and the presence of IO algebraic coupling:
| Scenario | FMI version | Mode | IO algebraic coupling | Recommended solver | Key settings |
|---|---|---|---|---|---|
| Standalone | FMI2 | CS | No | Tsit5() |
tstops aligned to the communication grid |
| Standalone | FMI2 | ME | No | Tsit5() |
tstops aligned to the communication grid |
| Standalone | FMI3 | CS | No | Tsit5() |
tstops; use_scc=false |
| Standalone | FMI3 | ME | No | Tsit5() |
tstops; use_scc=false |
| IO-connected | FMI2 | CS | Yes | Rodas5P(autodiff=AutoFiniteDiff()) |
tstops; components need reinitializealg=BrownFullBasicInit() |
| IO-connected | FMI2 | ME | Yes | Rodas5P(autodiff=AutoFiniteDiff()) |
tstops; ForwardDiff disabled |
| IO-connected | FMI3 | CS | Yes | Rodas5P(autodiff=AutoFiniteDiff()) |
tstops; use_scc=false; reinitializealg |
| IO-connected | FMI3 | ME | Yes | Rodas5P(autodiff=AutoFiniteDiff()) |
tstops; use_scc=false |
Two rules apply to every FMU simulation:
tstopsmust align with the communication grid—a standalone CS FMU may expose no continuous states at all, and withouttstopsthe solver crosses the entire simulation interval in one step (the CoModel platform always injects them for FMU models); FMI 3.0 models always getuse_scc=falsewhen theODEProblemis constructed (strongly connected component tearing disabled, consistent with the verified FMI3 templates). Solver tiering itself depends only on whether IO algebraic coupling is present.In the CoModel simulation settings, when the solver is set to auto the platform makes a recommendation based on the model's composition:
Rodas5Pfor models containing FMUs (with IO algebraic coupling,Rodas5P(autodiff=AutoFiniteDiff())is applied automatically at run time), andTsit5for AI models. Advanced users can override this manually.
Code Example: CS Mode
The following is a standalone FMI 2.0 CS mode example:
using ModelingToolkit, ModelingToolkitBase
using FMI
using OrdinaryDiffEq
using OrdinaryDiffEqCore: BrownFullBasicInit
using ModelingToolkit: t_nounits as t, D_nounits as D
using ModelingToolkitBase: MissingGuessValue
import ModelingToolkit as MTK
fmu = loadFMU("/path/to/model.fmu"; type = :CS)
@mtkcompile sys = MTK.FMIComponent(
Val(2);
fmu,
type = :CS,
communication_step_size = 1.0e-3,
reinitializealg = BrownFullBasicInit(),
)
op = [sys.mass__s => 0.5, sys.mass__v => 0.0] # in CS mode FMU variables are discrete holds, passed in via op
prob = ODEProblem(
sys, op, (0.0, 10.0);
warn_initialize_determined = false,
missing_guess_value = MissingGuessValue.Constant(0.0),
)
# Align tstops with the communication grid: a standalone CS FMU may have no continuous states,
# without tstops the solver crosses the whole interval in one step (the CoModel platform always injects tstops for FMU models)
sol = solve(prob, Tsit5(); reltol = 1.0e-6, abstol = 1.0e-6,
tstops = 0.0:1.0e-3:10.0)
println(sol[sys.mass__s][end])
unloadFMU(fmu)
Code Example: ME Mode
The following is an FMI 2.0 ME mode example with IO algebraic coupling:
using ModelingToolkit, ModelingToolkitBase
using FMI
using OrdinaryDiffEq
using ADTypes: AutoFiniteDiff
using ModelingToolkit: t_nounits as t, D_nounits as D
import ModelingToolkit as MTK
fmu = loadFMU("/path/to/model.fmu"; type = :ME)
@named fmu_comp = MTK.FMIComponent(Val(2); fmu, type = :ME)
@variables a(t) = 1.0 b(t) = 0.5 alg_z(t) [guess = 1.0]
@mtkcompile sys = System(
[
fmu_comp.a ~ a,
fmu_comp.b ~ b,
D(a) ~ t,
D(b) ~ fmu_comp.out + fmu_comp.c,
alg_z^2 ~ fmu_comp.out + fmu_comp.value,
],
t;
systems = [fmu_comp],
)
prob = ODEProblem(
sys,
[
sys.fmu_comp.c => 0.0,
sys.a => 1.0,
sys.b => 0.5,
sys.fmu_comp.value => 2.0,
],
(0.0, 1.0),
)
sol = solve(prob, Rodas5P(autodiff = AutoFiniteDiff());
abstol = 1.0e-8, reltol = 1.0e-8,
tstops = 0.0:1.0e-3:1.0)
println(sol[sys.fmu_comp.out][end])
unloadFMU(fmu)
In CoModel this code is generated automatically from the FMU nodes and their parameters on the canvas; you never write it by hand. Understanding how it works still helps when troubleshooting simulation failures.
Common Compatibility Errors
The full text of parsing/simulation errors appears in the Status column of the FMU list (hover to read it) or in the simulation log. Typical cases:
| Typical error | Likely cause | Fix |
|---|---|---|
| Parsing failed: unsupported FMI version | The FMU is FMI 1.0 or corrupted | Re-export as FMI 2.0/3.0 |
| Parsing failed: SE interface only | The FMU supports neither CS nor ME | Include CS or ME interfaces when exporting |
| Cannot load .so / binary not found | binaries/linux64/ missing |
Export Linux x86_64 binaries |
| Dual number is not supported | An implicit solver passed Dual numbers into the FMU |
Use Rodas5P(autodiff=AutoFiniteDiff()) |
| instance already exists | The previous simulation did not clean up the FMU handle | Re-upload, or wait for the worker to restart |
Next Steps
- To upload FMU files, read FMU Upload & Component Library.
- To drag, connect, and run simulations on the canvas, read Using FMUs on the Canvas.