Engee documentation
Notebook

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.

image.png

We suggest examining the FMU file. To do this, install several libraries and call the command info(fmu).

In [ ]:
Pkg.add( ["FMI"] )
using FMI
fmu = loadFMU( "fmuVanDerPol.fmu" )
info(fmu)
#################### Begin information for FMU ####################
	Model name:			myvdp
	FMI-Version:			2.0
	GUID:				{a50ebd80-9a0f-b492-4bf4-893f9611b1a5}
	Generation tool:		[Unknown generation tool]
	Generation time:		2018-09-26T19:47:29Z
	Var. naming conv.:		structured
	Event indicators:		0
	Inputs:				0
	Outputs:			2
		0 ["Out1"]
		1 ["Out2"]
	States:				0
	Parameters:			1
		2 ["mu"]
	Supports Co-Simulation:		true
		Model identifier:	myvdp
		Get/Set State:		true
		Serialize State:	true
		Dir. Derivatives:	false
		Var. com. steps:	false
		Input interpol.:	false
		Max order out. der.:	nothing
	Supports Model-Exchange:	false
##################### End information for 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.

image.png

Let's run the model for execution and build graphs.:

In [ ]:
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) )
Out[0]:

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.

Blocks used in example