FMIConnector - MapleSim Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : MapleSim Toolboxes : MapleSim FMI Connector : FMIConnector Package : FMIConnector/GenerateCode

FMIConnector

  

GenerateCode

  

generate FMI C code

 

Calling Sequence

Parameters

Returns

Options

Description

Examples

Calling Sequence

GenerateCode(system, options)

Parameters

system

-

module ; MapleSim model (connection module created using MapleSim[LinkModel])

options

-

(optional) equation(s) of the form name = value

Returns

• 

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.

Options

FMI Version and Environment

• 

fmiVersion : string; one of "FMI1.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:

1. 

string : Path to the XML modelDescription file.

2. 

string : Path to the generated C file.

3. 

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.

4. 

string : Name of the temporary directory where the generated files are placed.

5. 

string : FMU architecture (see preceding option architecture in this section).

6. 

string : Path to the Microsoft Visual Studio compiler (empty string for UNIX-based platforms).

7. 

true or false : Specifies if the temporary directory should be removed (see the following option removetmpdir in this section).

8. 

true or false : Specifies if the sources directory should be removed (see following option removesrc in this section).

9. 

string : FMI version (see the fmiVersion option in FMI Version and Environment).

10. 

string : FMU type (see the fmiTypeoption in FMI Version and Environment).

  

These settings are used as arguments when calling FMIConnector[CreateArchive].

• 

MSVCtarget : string

  

Specifies the target argument for vcvarsall.bat (Visual C++ command that sets the path and environment variables for command-line builds according to the target architecture). This option is only used if compiling on a Windows platform. The default is "x86" for architecture = "32" and "x64" for architecture = "64" (that is, native 32-bit or 64-bit compilation is assumed). All other cross-compilation options, such as "x86_amd64" (x86 cross-compiler for x64 targets) or "amd64_x86" (x64 cross-compiler for x86 targets), must be explicitly specified by using this option. Please consult your MSVC documentation as required target options vary with Microsoft Visual Studio versions.

• 

outputdir : string

  

Specifies the output directory for the generated file(s). The default is the home directory (kernelopts('homedir')).

• 

pathVC : string

  

Specifies the path to the Visual C++ installation directory if generating on a Windows platform.  This option is ignored if the platform is not Windows. The default is the Visual C++ directory specified in your %PATH% environment variable.

• 

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.

• 

tunableparams : set

  

Specifies a set of parameter names that will be generated with tunable variability (parameter value is constant between external events for ModelExchange, and between communication points for Co-Simulation). The default is an empty set.

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 FMI type "CS".

For Co-Simulation Only

• 

solver : string; one of the following: "Euler", "ImplicitEuler", "RK2", "RK3", "RK4"

  

Specifies which fixed step solver should be generated as the embedded solver for Co-Simulation. The default value is "Euler".

• 

stepsize : positive

  

Specifies the Co-Simulation maximum step size. This value must be specified by the user.

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, "Propietary", "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".

Description

• 

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.

• 

For MapleSim 2016.2 and later versions, 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.

Examples

Linking to a MapleSim model located in the following .msim file:

filecatkernelopts'toolboxdir'=MapleSim,/data/examples/RLCcircuit.msim:

AMapleSim:-LinkModelfilename=file:

Return a 2.0 Model Exchange FMU archive named "RLC" in the home directory:

FMIConnector:-GenerateCodeA,'fname'=RLC:

Return a sequence of settings to be used with FMIConnector[CreateArchive]:

FMIConnector:-GenerateCodeA,'makeFMU'=false

/tmp/fmiTmpjxmpSBIs/modelDescription.xml,/tmp/fmiTmpjxmpSBIs/sources/_UNASSIGNED.c,/tmp/fmiTmpjxmpSBIs/sources/_UNASSIGNED.c,/tmp/fmiTmpjxmpSBIs,64,,true,false,FMI2.0,DLL

(1)

See Also

FMIConnector

FMIConnector[CreateArchive]

MapleSim

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam