FMIConnector
GenerateCode
generate FMI C code
Calling Sequence
Parameters
Returns
Options
Description
Examples
GenerateCode(system, options)
system
-
module ; MapleSim model (connection module created using MapleSim[LinkModel])
options
(optional) equation(s) of the form name = value
list(string) : a list containing the path and name of the generated Functional Mock-Up Unit (FMU). If the target is a Windows DLL, the compiler call used to generate the DLL is also included in the list.
FMI Version and Environment
fmiVersion : string; one of "FMI3.0" or "FMI2.0"
Specifies which version of the FMI standard should be generated. The default value is "FMI2.0".
fmiType : string; one of "CS" or "ME"
Specifies the format of the FMU export, either "ME" for ModelExchange or "CS" for Co-Simulation. The default value is "ME".
Export and Compiler Settings
architecture : string; one of "32" or "64"
Specifies the architecture of the target binary. The default value is based on the Maple installation (that is, "32" builds a 32-bit binary, while "64" builds a 64-bit binary.
The Maple installation can be checked by running the kernelopts('wordsize') command from Maple.
fname : string
Specifies the name of the generated FMU and C file. The default value is "FMUModel".
fmiDistType : string; one of "DLL" or "SourceCode"
Specifies if the generated sources should be compiled into a dynamically linked library (DLL).
If set to "SourceCode", the FMU will contain source code only. This setting will generate sources with FMI_FUNCTION_PREFIX (or FMI2_FUNCTION_PREFIX) defined as the name of the FMU followed by an underscore character. This name will be prepended to all the FMI functions. If such prefix is not desired then the source code must be compiled with the "-DDISABLE_PREFIX" flag, which will disable this setting. The default value is "DLL".
makeFMU : true or false
Specifies whether the FMU archive should be returned. The default value is true.
Note: If set to true, an FMU is generated in the home directory (or outputdir), and a list containing the path and name of the generated FMU is returned. See the Returns section for more details.
If set to false, a sequence of string and boolean settings is returned in the following order:
string : Path to the XML modelDescription file.
string : Path to the generated C file.
string : Path to MsimModel.c (file containing Maple-specific functions) if the FMI version is "FMI1.0" (see the fmiVersion option in FMI Version and Environment). Otherwise, same as second string.
string : Name of the temporary directory where the generated files are placed.
string : FMU architecture (see preceding option architecture in this section).
string : Path to the Microsoft Visual Studio compiler (empty string for UNIX-based platforms).
true or false : Specifies if the temporary directory should be removed (see the following option removetmpdir in this section).
true or false : Specifies if the sources directory should be removed (see following option removesrc in this section).
string : FMI version (see the fmiVersion option in FMI Version and Environment).
string : FMU type (see the fmiType option in FMI Version and Environment).
These settings are used as arguments when calling FMIConnector[CreateArchive].
compiler : string
Specifies the compiler to use during construction of the FMU. The default is "CLANG" for Windows (installed with MapleSim) and "GCC" for Linux and Mac. Valid options for Windows include "CLANG" (default), "MSVC", and "TCC"(path must be provided). Valid options for Mac/Linux include "GCC" (default) and "TCC". If architecture is specified as anything other than "64", only "MSVC" can be used for Windows and only "GCC" for Mac/Linux.
path : string
Specifies the path for the compiler. For "CLANG" this only need be used for an alternate installation of the clang compiler. For "MSVC" this should specify the path to the compiler setup batch script (vcvars*.bat) for the version of Microsoft Visual C++ to be used. For "TCC" this should specify the path to the tcc binary (tcc.exe on Windows, tcc on Mac/Linux). For "GCC" path is ignored. If "MSVC" is chosen for the compiler, but no path has been provided, then the connector will try to find an MSVC installation in the PATH environment variable, or in standard install locations.
outputdir : string
Specifies the output directory for the generated file(s). The default is the home directory (kernelopts('homedir')).
removesrc : true or false
Specifies whether the generated source directory and its contents should be removed. The default value is false.
removetmpdir : true or false
Specifies whether the generated temporary directory should be removed. The temporary directory is generated in directory specified with the outputdir option and its name is a combination of the string fmiTmp and a randomly generated number. This directory temporarily stores the contents of an FMU before they are packaged into a file with a .fmu file extension. The default value is true.
Inputs, Outputs, and Parameters
inputs : list of functions
Specifies the names of the system's input variables. By default, the inputs will be determined directly from the MapleSim model. For the top-level model, inputs will be an empty list.
outputs : list of functions
Specifies the names of the system's output variables. By default, the outputs will be determined directly from the MapleSim model. For the top-level model, outputs will be a list of top-level probes.
params : list of equations name = value
Specifies the values of the system's parameters for parameters to be exported in the FMU. By default, the parameters will be determined directly from the MapleSim model. Only those parameters defined at the specified (sub)system level are exported.
longparnames : true or false
Specifies whether parameter names will be fully-qualified (long parameter names) in the FMU. The default value is false.
Constraint Handling
coniter : non-negative integer
Specifies the maximum number of constraint projection iterations. The default value is 20.
contol : positive
Specifies the constraint projection error tolerance. The default value is 1e-7.
evtproj : true or false
Specifies whether constraint projection should be applied during event iterations. The default value is true.
Event Handling
evtiter : positive integer
Specifies the maximum number of event iterations. The default value is 10.
evthyst : non-negative
Specifies the width of the event hysteresis band. The default value is 1e-10.
Run-time Error Reporting
rtetrack : true or false
Specifies whether run-time error reporting should be used. The default value is false.
Fixed-Step Integrator
optforfixed : true or false
Specifies if the generated code should be optimized for use with fixed-step integrators. The default value is true for FMI version "FMI1.0" or if "CS" type FMU is exported with a fixed-step solver.
For Co-Simulation Only
solver : string; one of the following: "Euler", "ImplicitEuler", "RK2", "RK3", "RK4", "CK45", "Rosenbrock"
Specifies which solver should be generated as the embedded solver for Co-Simulation. The variable-step solvers are "CK45" and "Rosenbrock", the rest are fixed-step. The default value is "Euler".
stepsize : positive
Specifies the Co-Simulation maximum step size. This value must be specified by the user.
allowintermediatesteps = false or a list of [num::non negative integer, tol::positive number]
If the solver option is set to either "Euler" or "ImplicitEuler" for a Co-Simulation FMI2.0 FMU, this option specifies that events should be triggered inside a fixed step, by taking at most num internal steps, which are taken according to the following methodology: If the stepsize is h, then if an event occurrence is estimated at r*h (0 < r < 1), step to (r+tol)*h. Note an optimal value of tol is dependent on the model behavior. If the behavior of the solution between steps is fairly linear, then the small value of tol (for example, 1e-7) can be used to get accurate event crossings. If the solution is far from linear, then a larger value of tol (for example, 1e-2) will be required to ensure that the event trigger processes before (r+tol)*h. If the value of this option is set to false, then all events that occur in a step will be triggered at the end of the step. The default is false.
tunableparams : set(posint)
Specifies the indices of the system's tunable parameters. A tunable parameter in an FMU (supported only in FMI 2.0 Co-Simulation) is a parameter whose value can be changed during simulation if supported by the simulation environment. The default value is an empty set.
Baumgarte Constraint Stabilization
baumgarte : list of numeric values
Specifies the Baumgarte parameters using a list of the form [Alpha, Beta], where Alpha sets the derivative gain and Beta sets the proportional gain for Baumgarte constraint stabilization. If baumgarte is set to an empty list, Baumgarte constraint stabilization is not applied. The default value is an empty list.
Optional Model Information
optmodelinfo: record or string "default"
Specifies a record containing optional model information to be included in the XML modelDescription file.
For FMI version "FMI1.0", the following fields apply:
author : Name and organization of the model author (for example, "Maplesoft http://www.maplesoft.com/").
descript : Brief description of the model (for example, "Model of battery").
modelver : Version of FMU (for example, "4.1.5").
For FMI version "FMI2.0", in addition to the above fields, the following fields apply:
copyright : Intellectual property copyright (for example "(C) MyCompany 2015").
license : Intellectual property licensing (for example, "Proprietary", "Public Domain", or "BSD License").
The default value is the string "default", which means that all optional information will be an empty strings in the XML modelDescription file.
Additional Settings
forceoverwrite : true or false
Specifies whether the FMU archive should be overwritten without prompting the user. The default value is false, meaning the user will be asked to confirm if the original files should be overwritten.
initial : set of equations
Specifies the initial conditions for all the system's states, algebraic variables, and inputs. The default value is "_UNASSIGNED", meaning the initial values will be determined directly from the MapleSim model.
nosubs : true or false
Specifies whether the parameters are entered as the original model names or the substituted names. The original model names are in the long form, for example, `Main.MyModel.Parameter1` and the short names are uniquely shortened versions of the long names, for example `Parameter1`. The default value is false.
optimize : true, false, or string; one of the following: false, "subexpronly", "fast", true
Specifies the level of code optimization. If set to false, no optimization is performed. If set to "subexpronly", only simple expressions are optimized. If set to "fast", subexpression and some additional fast optimizations are performed. If set to true, full code optimization is done. The default value is "subexpronly".
FMIjacobians : true or false
Specifies whether symbolic Jacobians should be generated for the initialization and integration model structure (supported only in FMI 2.0). These can be used to provide partial derivative matrices. If used, the FMU will have "providesDirectionalDerivatives' flag set to true. The default value is false.
expose : one of "minimal" or "extended"
Specifies which variables to expose in the FMU model description. If set to "minimal", only the inputs, outputs, parameters, and states/derivatives are exposed. If set to "extended", the same variables as "minimal" plus the index-1 variables (variables with initial = "calculated" and/or variability = "discrete") are exposed. The default value is "extended".
The GenerateCode command generates an FMU (Functional Mock-Up Unit) from a MapleSim system.
An FMU is a zip archive with an .fmu file extension. It contains the binaries, data, documentation, and sources folders, and the XML modelDescription file, according to the FMI specification.
The FMU is generated in the home directory or in the path specified by the outputdir option.
To return a sequence of settings to be used with MapleSim[CreateArchive], use the option makeFMU = false.
For more details, see Export and Compiler Settings in the Options section of this topic.
Linking to a MapleSim model located in the following .msim file:
file≔cat⁡kernelopts⁡toolboxdir=MapleSim,/data/examples/RLCcircuit.msim:
A≔MapleSim:-LinkModel⁡filename=file:
Return a 2.0 Model Exchange FMU archive named "RLC" in the home directory:
FMIConnector:-GenerateCode⁡A,fname=RLC:
Return a sequence of settings to be used with FMIConnector[CreateArchive]:
FMIConnector:-GenerateCode⁡A,makeFMU=false,forceoverwrite
/tmp/fmiTmpjxmpSBIs/modelDescription.xml,/tmp/fmiTmpjxmpSBIs/sources/_UNASSIGNED.c,/tmp/fmiTmpjxmpSBIs/sources/_UNASSIGNED.c,/tmp/fmiTmpjxmpSBIs,64,,true,false,FMI2.0,DLL
See Also
FMIConnector[CreateArchive]
MapleSim
Download Help Document