MapleSim FMI Connector Getting Started Guide
MapleSim FMI Connector Getting Started Guide
MapleSim FMI Connector Getting Started Guide
Maplesoft, Maple, and MapleSim are all trademarks of Waterloo Maple Inc.
iii
Introduction
The MapleSim™ FMI Connector and FMI Connector package provides all of the tools you need to prepare and export
your dynamic systems models into an FMU (Functional Mock-up Unit) archive file. You can create a model in
MapleSim, simplify it in Maple™ by using an extensive range of analytical tools, and then generate FMU executables
that you can incorporate into your MODELISAR toolchain.
Requirements
For installation instructions and system requirements, see the Install.html file on the product disc, or visit the Maplesoft
System Requirements website at http://www.maplesoft.com/products/system_requirements.aspx.
Windows users need to install a third-party 'zip' utility which must be included in the PATH environment variable in
order to successfully generate an FMU.
On 64-bit Windows, some features require Microsoft Visual Studio 2013, 2015, or 2017.
Distribution of an FMU
Under the terms and conditions of the Maplesoft End User License Agreement, you have the right to use an FMU
created with the MapleSim FMI Connector within your organization. If you wish to distribute this FMU outside
your organization, you must first obtain a FMU Commercial Distribution License from Maplesoft. For more
information, see FMU Distribution.
Note: This is the directory that contains the .dll file (Windows) or the .so file (Linux or Macintosh) that is used in
your model.
2. Add the library directory found in step 1 to the appropriate environment variable for your operating system.
• For Windows, add the library directory to your PATH environment variable.
• For Linux and Macintosh, add the library directory to your LD_LIBRARY_PATH environment variable.
Consult the help for your operating system for instructions on how to edit these environment variables.
3. Restart your computer.
iv
1 Getting Started
1.1 FMI Code Generation Steps
This chapter describes how to use the FMI app and in the Example: RLC Circuit Model (page 7) section of this
chapter, a step by step procedural example shows you how to create an FMU archive file. The FMU Generation app
consists of the following steps to generate C code:
1. Subsystem selection
2. Inputs/Outputs and parameter management
3. FMI code generation options
4. Generate FMI C code
5. View generated FMI C code
The FMI Connector package is a collection of procedures for manually generating and compiling FMI code from
MapleSim models. For information about the FMI Connector package, in Maple, refer to the FMIConnector help page.
With this app, you can define inputs and outputs for the system, set the level of code optimization, generate the source
code, and choose the format of the resulting FMU component and library code. You can assign model equations to a
variable, group inputs and outputs, and define additional input and output ports for variables.
Note: FMU component generation now handles all systems modeled in MapleSim, including hybrid systems with
defined signal input (RealInput) and signal output (RealOutput) ports.
Example models are available in MapleSim. To access these, from the Help menu, select Examples > FMI Connector
Examples.
1
2 • Getting Started
To connect a subsystem to modeling components outside of its boundary, you add subsystem ports to your model. A
subsystem port is an extension of a component port in your subsystem. The resulting signals can then be directed as
inputs and outputs for the FMU archive files. By creating a subsystem you improve the visual layout of a system in
the model workspace and also prepare the model for export. The example in Chapter 2 shows you how to group all of
the components into a subsystem.
You can select which subsystems from your model you want to export to an FMU archive file. After selecting a sub-
system, click Load Selected Subsystem. All defined input and output ports are loaded.
After the subsystem is loaded you can group individual input and output variable elements into a vector array, and add
additional input and output ports for customized parameter values. Input ports can include variable derivatives, and
output ports can include subsystem state variables. You can specify prefixes for both input and output port variables.
The prefix for the input (output) port variables will be applied to all the variables in the input ports (outputs) table.
3 • Getting Started
Note: If the parameters are not marked for export they will be numerically substituted. Parameters marked as tunable
will also be marked for export by default. However, tunable parameters will be ignored if FMI Version and Environment
(see Step 3: Export Options) are anything other than FMI 2.0 and Co-Simulation. To use fully qualified parameter
names for the generated FMU, check the corresponding check box; otherwise, short parameter names will be used by
default.
Select View advanced FMU settings to see Contraint Handling, Event Handling, and Code Generation options.
To match the MapleSim model's current simulation settings, click the Match Simulation Settings button. (Note that
you can revert to the default settings for Model Exchange and Co-Simulation using the refresh button at the top
of the app window.)
Jacobian: In the case of the Implicit Euler solver, specify either numeric or symbolic formulation for the system Jac-
obian.
The Constraint Handling Options specifies whether the constraints are satisfied in a DAE system by using constraint
projection in the generated FMU archive file. Use this option to improve the accuracy of a DAE system that has con-
straints. If the constraint is not satisfied, the system result may deviate from the actual solution and could lead to an
increase in error at an exponential rate.
The Baumgarte constraint stabilization method stabilizes the position constraint equations, by combining the position,
velocity, and acceleration constraints into a single expression. By integrating the linear equation in terms of the accel-
eration, the Baumgarte parameters, alpha and beta, act to stabilize the constraints at the position level.
Set the Projection iterations to specify the maximum number of times that a projection is permitted to iterate to obtain
a more accurate solution.
Set the Projection tolerance to specify the desirable error tolerance to achieve after the projection.
5 • Getting Started
The Event Handling Options specifies whether the events are satisfied in a DAE system by using event projection in
the generated FMU archive file. Use this option to improve the accuracy of a DAE system with events. If the constraint
is not satisfied, the system result may deviate from the actual solution and could lead to an increase in error at an expo-
nential rate.
Set the Event iterations to specify the maximum number of times that a projection is permitted to iterate to obtain a
more accurate solution.
Set the Initial hysteresis to specify the desirable error tolerance to achieve after the projection.
Select Event projection to perform event projection using the event projection routine in the External Model Interface
as described on The MathWorks web site to control the drift in the result of the DAE system.
Note: Currently, if the model has events, they are handled using the event handling functions in the generated Msim-
Model.c file, and not the FMI provided Event Handling routines.
The Code Generation Options control details of the generated code and run-time errors.
Add directional derivatives: Select the check box to generate directional derivatives code.
Optimize for fixed-step solver: Specifies if the generated code should be optimized for use with fixed-step solvers.
Author: Name and organization of the model author (for example, J. Smith, Maplesoft http://www.maplesoft.com).
Description: Brief description of the model (for example, Model of a lithium-ion battery).
License: Intellectual property licensing (for example, Proprietary, Public Domain, or BSD License).
Step 5: Export
Generating the C code creates temporary files for viewing purposes.
Specify the locations for the Target Directory and Visual C++ Directory.
Note: The Visual C++ Directory is not required for Linux and Mac® platforms. For Windows platforms, a typical
location for the Visual C++ Directory is: C:\Program Files (x86)\Microsoft Visual Studio\version\WDExpress\VC
(64-bit) or C:\Program Files\Microsoft Visual Studio version\VC (32-bit). If necessary, navigate to the correct
Visual C++ Directory for your platform using the Browse button.
Provide a name for the generated FMU archive in FMU Archive Name.
Select Remove Source Files from the FMU Archive: to remove source files after code generation.
Select Remove temporary `fmiTMPXXXXXX`directory to remove temporary files after code generation.
Note: If your model contains an external library, you must add the directory that contains the external library to your
search path. See Adding External Libraries to Your Search Path (page iv) for instructions on how to do this.
After you execute your FMU, the extended visualization data file is created in the same directory that your FMU is in.
See MapleSim > Using MapleSim > Simulating a Model > Importing FMU or Simulink(R) S-function Results
in the MapleSim help system for information on how to import these results into MapleSim.
To view an example:
1. From the Help menu, select the Examples > FMI Connector Examples menu, and then click the entry for the
model that you want to view.
Note: Some models include additional documents, such as templates that display model equations or define custom
components.
2. In the Attached Files tab, expand Documents. You can open any of these documents by right-clicking (Control-click-
ing for Mac) its entry in the list and clicking View. After you add a template to a model, it will be available from
this list.
To create a subsystem:
1. Draw a box around all of the components in the model by dragging your mouse over them.
8
9 • Example: Exporting a Model as an FMU File
You will convert the displacements of the slider and the joint between the crank and connecting rod to output signals.
The input will be a torque driver that is applied to the revolute joint that represents the crank shaft.
3. In the Library Components tab ( ) on the left side of the MapleSim window, expand the Multibody palette
and then expand the Sensors submenu.
4. Drag the Absolute Translation component to the Model Workspace and place it below the Prismatic Joint
component.
5. Right-click (Control-click for Mac®) the Absolute Translation component and select Rotate Counterclockwise.
6. From the Signal Blocks > Routing > Demultiplexers menu, drag a Real Demultiplexer component to the Model
Workspace and place it to the right of the Absolute Translation component.
7. To connect the Absolute Translation component to the model, click the frame_b connector. The frame is highlighted
in green when you hover your pointer over it.
8. Draw a vertical line and click the connection line directly above the component. The sensor is connected to the rest
of the diagram.
10 • Example: Exporting a Model as an FMU File
9. In the same way, connect the r output port ( ) of the Absolute Translation component to the input
port of the demultiplexer. This is the displacement signal from the sensor in x, y, and z coordinates. Since the slider
only moves along the x axis, the first coordinate must be an output signal.
10. Hover your pointer over the first demultiplexer port and click your mouse button once.
11. Drag your pointer to the subsystem boundary and then click the boundary once. A real output port is added to your
subsystem.
12. Add another Absolute Translation component above the Connecting Rod subsystem.
13. Right-click (Control-click for Mac) the Absolute Translation component and select Flip Vertical. Right-click
the Absolute Translation component again and select Rotate Clockwise.
14. Add a Real Demultiplexer component to the right of the sensor and connect the components as shown below. Since
the crank is moving in the x, y plane, you only need to output the first two signals. You are now ready to add a real
input port to your subsystem to control the torque on the crank shaft.
15. Click on the white flange of the leftmost Revolute Joint and drag the pointer to the left boundary. This will act as
the acausal input connection to the subsystem.
11 • Example: Exporting a Model as an FMU File
16. Click Main ( ) in the Model Workspace toolbar to browse to the top level of the model.
17. From the 1-D Mechanical > Rotational > Torque Drivers menu, add a Torque component to the Model Workspace
and place it next to the subsystem.
18. From the Signal blocks>Common menu, add a Constant signal component to the Model Workspace and next to
the Torque component and connect it to the Torque component.
19. Click Attach Probe ( ) above the Model Workspace toolbar and then click the top output port of the SliderCrank
subsystem.
20. In the Model Workspace, click the probe once to position it.
21. In the same way, add probes to the other SliderCrank output ports as shown below.
12 • Example: Exporting a Model as an FMU File
To edit parameters
1. Double-click the SliderCrank component on the Model Workspace to see the detailed view of the SliderCrank
subsystem, and then click Parameters ( ) in the Model Workspace toolbar. The parameter editor appears.
2. In the first Name field, type CrankL and press Enter.
3. Change the Type to Length from the drop-down menu.
4. Specify a default value of 1m and enter Crank length as the description.
5. In the second row of the table, define a parameter called ConRodL and press Enter.
6. Change the Type to Length from the drop-down menu.
7. Specify a default value of 2m and enter Connecting Rod Length as the description.
8. Click Diagram View ( ) to switch to the diagram view, and then click Main ( ).
9. Select the SliderCrank subsystem. The parameters are defined in the Properties tab ( ).
10. Double-click the SliderCrank subsystem, and then select the Crank subsystem.
13 • Example: Exporting a Model as an FMU File
11. In the Properties tab ( ), change the length value (L) to CrankL. The Crank subsystem now inherits the numeric
value of CrankL that you defined.
12. Select the ConnectingRod subsystem and change its length value to ConRodL.
13. Click Main ( ) in the Model Workspace toolbar to navigate to the top level of the model. You will include these
parameter values in the model that you export. You are now ready to convert your model to an FMI block.
2.3 Exporting Your Model Using the FMU File Generation App
After preparing the model, you can use the FMU Generation app to set export options and convert the model to an
FMU file.
5. In the Export section, specify the location for the Target Directory, Visual C++ Directory and provide a name
for the generated FMU Archive.
6. Click Generate FMU Archive to generate the .FMU zip file.
Index
A
Apps, 1
FMU File Generation, 13
E
Examples
RLC circuit model, 7
slider-crank model, 8
Export Options, 3
Exporting, iv
Extended Visualization Data, 6
External Libraries, iv
F
FMI
exporting, 8
FMI Connector Examples, 1
G
Generate
External Libraries, 6
FMU Archive, 6, 14
L
License
Distribution of FMU, iv
M
Models using external libraries, iv
P
Port and Parameter Management, 2
S
Subsystem parameters, 12
Subsystem Selection, 2
15