export simulink models to functional mock-up units
export models
export simulink® models to functional mockup unit (fmu) that supports co-simulation in fmi version 2.0. to check that the exported block is still a valid simulink model, you can also direct the software to import the fmu back to a simulink model as part of the export process.
requirements include:
simulink compiler™
a writable folder into which to place the exported fmu.
exported models can have:
input and output data types:
double
,int32
,boolean
,string
matrices
bus signals
tunable parameters which can be model arguments, base workspace, or data dictionary variables.
unit and description.
when you export a model as a standalone fmu, certain metadata from simulink is also exported with the fmu. the metadata includes:
model description
signal unit
parameter unit
signal description
parameter description
standalone fmu
simulink models can be exported to standalone co-simulation fmu in version 2.0. the generated fmu package contains the following files:
modeldescription.xml
model.png (optional)
binaries\win64\modelname.dll
, orbinaries\linux64\modelname.so
, orbinaries\darwin64\modelname.dylib
you might experience an expected time delay in the exported fmu for co-simulation mode.
fmu variables
fmu modeldescription.xml
file contains interfacing variables
converted from simulink model:
variables with
causality=’input’
: converted from root inport blockvariables with
causality=’output’
: converted from root outport blockvariables with
causality=’parameter’
: converted from referenced runtime tunable parametersindependent variable
‘time’
to generate fmu input and output, define root inport and outport blocks in simulink model. the name of the generated variable is converted from root inport or
outport block name, by removing special and blank characters and avoiding duplicates. if
input/output signal carries unit information, it is exported as unit
attribute of the fmu variable. if the input/output block has a non-empty description
information under block properties > general ,
it is exported as description
attribute of the fmu variable.
the following input and output data types are supported:
double
(real in fmi)int32
(integer in fmi)boolean
(boolean in fmi)string
(string in fmi)
if model root inport or outport block is a non-virtual bus, individual bus elements
will be expanded to variables using structured naming convention (‘.’)
.
if model root inport or outport block is array or matrix,, individual scalar elements will
be expanded to variables using array naming convention (‘[]’)
.
to export referenced variables as fmu parameter, you can:
define a variable.
define a simulink parameter object.
ensure that the variable and the parameter object is directly references by tunable parameters of simulink blocks. in fmu export dialog, expand parameter details... to configure each parameter. you can:
unselect exported option to hide a parameter
modify exported name so the parameter is displayed with a different name on fmu interface. do not use special characters and duplicate names.
set
unit
anddescription
of fmu parameter variable by clicking on parameter name, and directly modifying the parameter objectif the fmu parameter is
simulink.parameter
, click the hyperlink to modify theunit
anddescription
of the variable.if fmu parameter is a regular matlab variable, clicking the hyperlink opens model explorer. you can convert matlab variable to a
simulink.parameter
so that it can carryunit
anddescription
.unit
anddescription
of fmu parameter variable cannot be updated directly in fmu export dialog. you can configureunit
anddescription
through model explorer, double-clickingsimulink.parameter
in base workspace, etc.
the following parameter data types are supported:
double
(real in fmi)int32
(integer in fmi)boolean
or logical (boolean in fmi)
if referenced parameter is a struct
, individual
struct
members will be expanded to variables using structured naming
convention (‘.’)
. if referenced parameter is array or matrix,
individual scalar elements will be expanded to variables using array naming convention
(‘[]’)
.
when a simulink model with model reference block is exported to fmu, you can also export base workspace variables, model arguments and instance parameters that are promoted from the sub model.
on the simulink toolstrip, under save, select export model to standalone fmu to view options for exporting an fmu with internal variables.
fmu solver
fixed-step solvers are supported for standalone fmu export. it is recommended to set a fixed fundamental sample time (solver > solver details > fixed-step size) before exporting the model. when simulating the standalone fmu in another environment, communication step-size must be an integral multiple of the fundamental sample time.
fmu dynamic library
a generated fmu contains a dynamic library build for the current platform. the default
fmi2typesplatform
value is used.
all required and optional fmi2
functions defined by fmi standard
can be invoked. however, the following functions have no operation and return
fmi2ok
immediately:
model-exchange functions
functions accessing or serializing
fmustate
functions setting or getting input or output derivatives
functions querying
fmi2dostep
status, or cancellingfmi2dostep
function computing directional derivatives of variables
save source code with fmu export
you can export a simulink model to fmu along with c source code. you can check save source
code in the export model to fmu co-simulation window or
use the command exporttofmu2cs('mdlname','savesourcecodetofmu','on')
to
export the model to fmu with c source code.
note
to export a simulink model to fmu with c source code, install simulink coder™
if the simulink model contains model references with custom data types or fixed-point
functions, exporting fmu with source code may cause an error due to duplicate header files
in the _sharedutils
folder. follow instructions on generate shared
utility code to set the code generation >
interface > shared code placement
parameter to 'shared location
' and regenerate the fmu.
you can export a simulink model with a fmu import blocks as nested standalone fmu. when exporting a nested fmu, simulink packs all dependent inner fmus into the resources/ folder of the nested fmu. when the nested fmu is instantiated in a simulation environment, all inner fmus will share the same callback functions provided by the environment, for example, logger and memory allocation functions.
specify additional files
while exporting a simulink to a standalone fmu, you can specify additional files to be included in the generated fmu, such as resource, dll etc. the target locations for these files can be:
– dependent dlls/binaries/ /
– data files, lookup tables, etc/resources/
– user provide their own help content/documentation/
for an example on specifying additional files while exporting a simulink model, see .
export protected model
you can export a simulink model that is protected. for an example on exporting protected models, see .
limitations
you cannot generate fmu from a simulink model, due to these limitations:
variable-step solvers are not supported.
non-zero simulation start time is not supported.
export a simulink model
use the export dialog box
export the vdp
example using the simulink toolstrip: simulation > save >
standalone fmu
open the model
vdp
in the simulink editor, navigate to simulation > save > standalone fmu.
in simulink editor, select save > export to > fmu co-simulation.
in the export dialog box, specify the path to export the fmu.
click create
by default, simulink creates the fmu and a harness model with its dependencies stored in a
mat
file. it then packs them into archived project (.mlproj
). you can change the behavior by setting contents option to standalone fmu.
use the programmatic interface
export the
vdp
example to an fmu using the defaultexporttofmu2cs
function. this command creates the fmu filemodelname.fmu
. by default, the command also creates a simulink modelmodelname_fmu.slx
, that contains an fmu co-simulation block with the original model. create this model if you want to check the integrity of the exported fmu.load_system('vdp') set_param('vdp', 'solvertype', 'fixed-step') exporttofmu2cs('vdp')
export the
vdp
example to an fmu using theexporttofmu2cs
function, but do not create a simulink model. this command creates the fmu filemodelname.fmu
.load_system('vdp') set_param('vdp', 'solvertype', 'fixed-step') exporttofmu2cs('vdp','createmodelaftergeneratingfmu','off')
export the
vdp
example to an fmu using theexporttofmu2cs
function. create a model for the fmu and use an image of the original model as the block icon. this command creates the fmu file,modelname.fmu
and a simulink model with an fmu co-simulation block whose block icon is the original model.exporttofmu2cs('vdp','addicon','snapshot')
examples for different workflows
the examples below illustrate how to use fmu export for all different scenarios:
see also
| | | | |