Importing the FMU Co-Simulation component
We show you how to use the blocks. FMU Import to add external models in FMU format to the Engee canvas.
Description of the model
The Co-Simulation mode in the FMU (Functional Mock-up Unit) components is designed to combine several models developed in different modeling tools into a single time-synchronized system.
This mode allows you to connect models created in different environments (MATLAB/Simulink, Dymola, OpenModelica, etc.), without having to rewrite their code.
Each FMU operates as a "black box" with its own solver.
In this example, our "external" model is in the file fmuVanDerPol.fmu, which we will place in the FMU Import block, and after configuring we will get graphs from the model that lies in it.
We suggest examining the FMU file. To do this, install several libraries and call the command info(fmu).
Pkg.add( ["FMI"] )
using FMI
fmu = loadFMU( "fmuVanDerPol.fmu" )
info(fmu)
Configuring the block
In this information, we need to find the names of the input and output ports and the names of the parameters in order to create and configure the interface of the block correctly.
This model has no inputs, there are two outputs (Out1 and Out2) and there is a parameter mu. In addition, we do not see the time step settings that the solver of this model is waiting for.
We found out empirically that the size of the calculated step of this FMU model should not be lower
0.1 с. The global step size of the entire simulation can be arbitrary.
Let's run the model for execution and build graphs.:
model_name = "fmu_co_simulation";
model_name in [m.name for m in engee.get_all_models()] ? engee.open(model_name) : engee.load( "$(@__DIR__)/$(model_name).engee");
res = engee.run( model_name );
plot( res["x"].time, [res["x"].value res["dx"].value], label=["x" "dx"],
lw=3, size=(600,300) )
When do you choose Co-Simulation instead of Model Exchange?
Model Exchange (ME) requires a single solver for the entire system and is suitable if all models can work with a single solver.
Co-Simulation (CS) selects when:
- The models use different solvers,
- There is a legacy code or proprietary simulators.,
- Distributed execution is required (for example, HIL testing).
Conclusion
Co-Simulation FMU is a powerful tool for integrating heterogeneous models without the need to completely rewrite them, but with a compromise in the form of controlled synchronization and potential sampling errors.