exportToFMU
Syntax
Description
exportToFMU(
exports mdl
, 'FMIVersion', FMIVersion
, 'FMUType', FMUType
)mdl
to mdl.fmu
. The model solver type must be
fixed-step
solver for a co-simulation FMU.
exportToFMU(
exports a model to a Functional Mock-Up Unit (FMU) using one or more mdl
, 'FMIVersion', FMIVersion
, 'FMUType', FMUType
, Name,Value
)Name,
Value
pair arguments.
Note
This function requires the FMU Builder for Simulink® support package.
Examples
Export a Model to FMU Using exportToFMU
Export the model vdp
to an FMU.
Open the model.
openExample('simulink_general/VanDerPolOscillatorExample') open_system('vdp')
Set the solver type of the model to
fixed-step
.
set_param('vdp', 'SolverType', 'Fixed-step')
Export the model to vdp.fmu
exportToFMU('vdp','FMIVersion','2.0','FMUType','CS')
Input Arguments
mdl
— Name of model
string
Name of the model to be exported to an FMU, specified as a string.
FMIVersion
— Specify the FMI version
2 | 2.0 | 3 | 3.0
Specify the FMI version of the exported FMU.
Data Types: char
| string
FMUType
— Specify the FMU type
CS | ME
Specify the type of the exported FMU. Specify CS
for
co-simulation FMU and ME
for model exchange FMU.
Data Types: char
| string
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: 'CreateModelAfterGeneratingFMU','off'
CreateModelAfterGeneratingFMU
— Option to create model after export
'off'
(default) | 'on'
Option to create model after export, specified as 'on'
or
'off'
. This argument creates a model,
mdl_harness.slx
, that contains an FMU Co-Simulation block with
the original model. Create this model to check the integrity of the exported
FMU.
When set to 'off'
, no model is created.
AddIcon
— Block icon or exported FMU image
'snapshot'
(default) | 'off'
| 'filepath'
Block icon or exported FMU image, character vector specified as one of these values:
'off'
– No block icon image.'snapshot'
– Use image of model as block icon.'filepath'
– Filepath of the image.
Generate32BitDLL
— Option to generate 32-bit DLL
'off'
(default) | 'on'
Option to generate 32-bit DLL, specified as 'on'
or
'off'
. Set the option to 'on'
to support
exporting Co-simulations of FMUs with 32-bit binaries. Only valid on
win64
platform with MSVC toolchain installed.
ConstantPeriodicClock
— Option to export model to FMU with constant periodic clock
'off'
(default) | 'on'
Option to export model to FMU with constant periodic clock. This is valid for
cosimulation FMUs that have a fixed-step solver and are compatible with FMI 3.0
standards. The FMU will register unique discrete periodic sample rates and offsets
specified in the Simulink root inport and outport blocks as constant periodic clocks for the
generated FMU. The modelDescription.xml
file will contain
<Clock>
elements within ModelVariables
that
defines the clock variable for each of the exported clock. These clock variables are
registered with the corresponding input and output variables.
EnableFMUState
— Option to export model to FMU with FMUState
'on'
(default) | 'off'
Option to export model to FMU with FMUState
. This is valid for
cosimulation FMUs that have a fixed-step solver and are compatible with FMI 2.0 and
3.0 standards. The canGetAndSetFMUState
and
canSerializeFMUState
flags in
modelDescription.xml
are set to true when FMU state is enabled.
This enables enhanced simulation control like fast restart, model operating point, and
backward simulation stepping.
supportMultiInstance
— Option to generate multi-instantiable FMU
'off'
(default) | 'of'
Option to generate multi-instantiable FMU compatible with FMI 2.0 and 3.0 standards for a model with fixed-step solver.
The canBeInstantiatedOnlyOncePerProcess
flag in
modelDescription.xml
is set to false
when this
argument is specified as on
.
GenerateLinuxBinaryWithWSL
— Option to generate Linux® binary on Windows®
'on'
| 'off'
Choose if you want to generate Linux binary for the FMU on Windows using WSL 2.
Data Types: char
| string
SaveSourceCodeToFMU
— Option to save source code to FMU
'off'
(default) | 'on'
Option to save source code to FMU, specified as 'on'
or
'off'
. Set to 'on'
to package the source code
in the source directory and documentation file, which recompiles the binary files in
the documentation directory in the FMU. This option requires Simulink
Coder™.
This option has the following limitations:
This feature utilizes
packNGo
function and is subject to its limitations. For a list of its limitations, seepackNGo
(MATLAB Coder).This feature is not supported for models that contain an FMU block.
This feature may pack operating system dependent code.
This feature only supports C and C++ files. Source code dependencies to other file types are unsupported.
SaveDirectory
— Specify save location for FMU
string | character vector
Save location for FMU, specified as a string or character vector. By default, the location is the current working folder.
Example: exportToFMU(model, 'FMIVersion','2.0','FMUType','CS',
'SaveDirectory', '/tmp/flightcontrol/')
ExportedContent
— Option to create a wrapper archived project or harness model with dependencies
'off'
(default) | 'project'
Option to create to create a wrapper-archived project or harness model with
dependencies, specified as 'off'
or 'project'
.
Set to 'project'
to enable this option.
ExportedParameters
— Specify the names of parameters to be exported
'{}'
(default) | {''}
| {'param1','param2'}
Specify the names of parameters to be exported as a cell array of character
vectors. Argument entry {}
exports all the parameters while
{''}
exports no parameters. To export all the valid parameters,
use the output of Simulink.fmuexport.GetExportableVariableList
function.
Example: exportToFMU(model, 'FMIVersion','2.0','FMUType','CS',
'ExportedParameters', {''})
exports no parameters
ExportedParameterNames
— Specify the exported names of parameters
'{}'
(default) | {'paramName'}
Specify the exported names of the parameters specified using
ExportedParameters
as a cell array of character vectors. The
length of the character vector should be the same as character vector specified for
ExportedParameters
. If this value is not set, the exported
parameters names are the same as the default names specified in the model.
Example: exportToFMU(model, 'FMIVersion','2.0','FMUType','CS',
'ExportedParameters', {'gain1'},'ExportedParameterNames',{'Gain_1'})
exports the parameter gain1
as
Gain_1
ExportedInternals
— Specify the names of internal variables to be exported
'{}'
(default) | {''}
| {'var1','var2'}
Specify the names of internal variables to be exported as a cell array of
character vectors. Argument entry {}
exports all the internal
variables while {''}
exports none. To export all the valid internal
variables, use the output of Simulink.fmuexport.GetExportableVariableList
function.
Example: exportToFMU(model, 'FMIVersion','2.0','FMUType','CS',
'ExportedInternals', {''})
exports no internal variables
ExportedInternalNames
— Specify the exported names of internal variables
'{}'
(default) | {'varName'}
Specify the exported names of the internal variables specified using
ExportedInternals
as a cell array of character vectors. The
length of the character vector should be the same as character vector specified for
ExportedInternals
. If this value is not set, the exported
internal variable names are the same as the default names specified in the
model.
Example: exportToFMU(model, 'FMIVersion','2.0','FMUType','CS',
'ExportedInternals', {'var1'},'ExportedInternalNames',{'Var_1'})
exports
the internal variable var1
as
Var_1
ExportedInputNames
— Specify the exported names of root inports
{'InputName1' 'InputName2'}
Specify the exported names of the root inports specified as a cell array of character vectors. The length of the character vector should be the same as the number of root input ports. If this value is not set, the exported input names are the same as the default names specified in the model.
ExportedOutputNames
— Specify the exported names of root outports
{'OutputName1' 'OutputName2'}
Specify the exported names of the root outports specified as a cell array of character vectors. The length of the character vector should be the same as the number of root output ports. If this value is not set, the exported output names are the same as the default names specified in the model.
DataTypeConversion
— Enable automatic data type conversion
'off'
(default) | 'on'
Enable automatic data type conversion of unsupported FMI data types for inputs, outputs, and internal variables.
Note
This is valid only when FMIVersion
argument is set to
2
or 2.0
FMUName
— Name of the generated FMU
string
Name of the generated FMU file, specified as a string. By default, the name of the FMU file is the same as the model name.
Example: exportToFMU('myModel', 'FMIVersion', '2.0', 'FMUType', 'ME',
'FMUName', 'myFMU_FMI2_ME');
ProjectName
— Name of archived project
string
Name of the archived project with harness model, specified as a string. This
argument must be specified along with the 'ExportContent'
argument.
By default, the archived project is named modelName_fmu
Package
— Destination folder and the files to be packaged
cell array
Destination folder and files to be packaged, specified as a cell array.
Example: exportToFMU(model, 'Package', {'documentation/',
{'/local/bouncingBall/index.html','/local/bouncingBall/siteFiles'},...
'resources',{'local/bouncingBall/resources/input.txt'}})
Version History
Introduced in R2023b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)