0% found this document useful (0 votes)
2K views160 pages

Amesim & Simulink - Interface

Uploaded by

killerghosts666
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views160 pages

Amesim & Simulink - Interface

Uploaded by

killerghosts666
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 160

Simcenter Amesim

2021.2
Simulink Interface
User's guide
How to contact us
www.siemens.com/plm/simcenter-amesim Web site

https://support.sw.siemens.com Technical support

See here for e-mail addresses for your local office: Sales, pricing and general
information
https://www.plm.automation.siemens.com/en_us/
about_us/contact/product-contacts.shtml#lms

Simcenter Amesim™ software User’s guides


© 2021 Siemens Digital Industries Software
The software described in this documentation is furnished under a license agreement. The
software may be used or copied only under the terms of the license agreement. No part of
this manual may be photocopied or reproduced in any form without prior written consent
from Siemens Industry Software NV.

Simulink Interface, 1
© 2021 Siemens
Contents

Introduction
The two interfaces ───────────────────────────────────── 1-1
Selecting the interface you require ────────────────────────── 1-2
Supported Simulink Interface modes ───────────────────────── 1-2
Co-simulation in Simcenter Amesim: Simcenter Amesim as Master, Simulink as Slave
(SL2AMECosim) ───────────────────────────────────── 1-3
Co-simulation in Simulink: Simcenter Amesim as Slave, Simulink as Master
(AME2SLCosim) ───────────────────────────────────── 1-4
Model Exchange: Export of Simcenter Amesim model into Simulink (AME2SL) ─── 1-4
Using multiple Simulink Interfaces ────────────────────────────── 1-4
Combining with other interfaces ─────────────────────────────── 1-5
Requirements ──────────────────────────────────────── 1-7
Common requirements ───────────────────────────────────── 1-7
Simcenter Amesim to Simulink software requirements ────────────────── 1-9
Simulink to Simcenter Amesim software requirements ────────────────── 1-9

Using the Simcenter Amesim to Simulink Interface


Constructing the model in Simcenter Amesim ─────────────────── 2-3
Importing the model into Simulink ───────────────────────── 2-10
Co-simulation interface ───────────────────────────────── 2-29
Introduction ─────────────────────────────────────────── 2-29
Usage of the co-simulation interface ──────────────────────────── 2-30
Using more than one interface block ──────────────────────── 2-39
Using the Simcenter Amesim-Simulink Black-box interface ────────── 2-41
Preparing the Simcenter Amesim model ────────────────────────── 2-42
Generating the ASBB ───────────────────────────────────── 2-43
Importing Black-box models into Simulink using amecreatebbmask command ── 2-46
A more advanced example using all types of global parameter and a table ───── 2-48
Importing and using the Black-box manually ─────────────────────── 2-53
Graphical Interface Summary ───────────────────────────── 2-58
Simcenter Amesim Library ────────────────────────────────── 2-58
The Main Window ─────────────────────────────────────── 2-59
Run Parameters Window for the Standard Interface ─────────────────── 2-60
Run Parameters Window for the Co-Simulation Interface ──────────────── 2-60
Model Parameters Window for the Co-Simulation Interface ────────────── 2-61
Importing into Simulink Without Using the Simcenter Amesim Library ─── 2-62
Importing a Simcenter Amesim Model for the Standard Interface ─────────── 2-62
Importing Simcenter Amesim Model for Co-Simulation Interface ─────────── 2-65
Importing a Simcenter Amesim Model for a Standard Interface Using a Black-Box ─ 2-69

Using the Simulink to Simcenter Amesim Interface


Using the SL2AMECosim interface - Co-simulation Mode ──────────── 3-1

Simulink Interface, 2
© 2021 Siemens
Contents

Preparing the Simulink model ───────────────────────────────── 3-2


Generating the code - SL2AMECosim ──────────────────────────── 3-2
Importing the generated code into Simcenter Amesim-Co-simulation Mode
───────────────────────────────────────────── 3-5
SL2AMECosim advanced topics ───────────────────────────── 3-9
Hiding input and output blocks ─────────────────────────────── 3-10
Hiding parameters ─────────────────────────────────────── 3-14
Advanced hiding I/O and parameters ──────────────────────────── 3-18
Known limitations ─────────────────────────────────────── 3-20
Tutorials ────────────────────────────────────────── 3-21
One-level voltage source ─────────────────────────────────── 3-22
Force control in semi-active car damper ────────────────────────── 3-31
Conclusions ──────────────────────────────────────── 3-37

Concluding remarks and FAQs


Common problems and their solutions ──────────────────────── 4-1
Open-loop simulations for basic model checks ─────────────────────── 4-1
Compilation failure with error message related to the simstruct.h file ───────── 4-3
Compilation window blocked during the first use of the interface ─────────── 4-3
Not possible to run sequential simulations ───────────────────────── 4-4
About Simulink numerical solver methods ───────────────────── 4-5
Influence of interface modes on the Simulink solver ─────────────────── 4-5
Simulink solver type: fixed-step or variable-step ────────────────────── 4-7
Discrete or continuous Simulink solver ─────────────────────────── 4-8
Implicit or explicit Simulink solver (stiff or non-stiff systems) ────────────── 4-8
Choosing a fixed-step Simulink solver (for example, for Real-Time applications) ── 4-10
Impact of algebraic loops on the Simulink solver ───────────────────── 4-11
Correspondences between Simcenter Amesim and Simulink solver methods
───────────────────────────────────────────── 4-11
Simcenter Amesim and comparable Simulink solver methods for Model Exchange modes
─────────────────────────────────────────────── 4-12
Summary for choosing a Simulink solver ───────────────────────── 4-13
Example ───────────────────────────────────────────── 4-16

Black-box compatibility A-1

Glossary B-1

Index ─ Index-1

Simulink Interface, 3
© 2021 Siemens
4 Simulink Interface,
© 2021 Siemens
1. Introduction
This manual introduces the Simcenter Amesim™ software and Simulink® interfaces and their
interaction.

We describe both the standard interface (using the Simulink integrator) and the co-simulation interface
(where integrators from both Simulink and Simcenter Amesim are used). The main part of the manual
deals with the standard interface and Co-simulation interface looks at the differences between the
standard and the co-simulation interface. The Concluding remarks and FAQs section gives a summary of
the most important things to remember, as well as the answers to the most frequently asked questions
(FAQ).

Sometimes a section of text is only applicable to a Linux® environment. For such text the following
presentation is used:

Using Linux:
Description for Linux environments.

Sometimes a section of text is only applicable to a Windows® environment. For such text the following
presentation is used:

Using Windows:
Description for Windows environments.

Note:
Please be sure to consult the Concluding remarks and FAQs of this manual, which provides the
solutions to many of the problems you may encounter when using the Simulink interface.

1.1 The two interfaces


The Simcenter Amesim-Simulink and Simulink-Simcenter Amesim interfaces makes it possible to
perform simulations with a combination of Simcenter Amesim and Simulink models. Since there are
two software packages involved, the interfaces provide two main options: importing the Simcenter
Amesim model into Simulink, or importing the Simulink model into Simcenter Amesim.

With the Simcenter Amesim-Simulink interface the user has the choice of these two methods. In
addition to these two methods, it is also possible to export the Simcenter Amesim solver (with the
Simcenter Amesim model) to Simulink. This is sometimes called co-simulation since we use the solvers
from the two software packages, and they perform the simulation together.

Simulink Interface, 1-1


© 2021 Siemens
1. Introduction

In this manual we first describe the process of importing the Simcenter Amesim model into Simulink,
with or without the solver. After this we describe the process of importing the Simulink model with its
fixed-step solver (co-simulation) into Simcenter Amesim.

1.2 Selecting the interface you require


How do I select the interface I need?

There is no single answer to this question. The answer depends on many things. There are Simcenter
Amesim systems that are difficult or impossible to solve using the Simulink solver. If this is the case,
then the user needs to select co-simulation. This means that both the Simcenter Amesim and the
Simulink solvers will be used and that each one will be responsible for its part.

Sometimes the Simulink system is very complex and importing it into Simcenter Amesim is probably
not the best solution as it will enforce the use of a Simulink fixed-step solver, which sometimes is not
suitable.

In addition to the technical reasons, one must also consider what the model is to be used for. If the main
purpose is to test/develop the Simcenter Amesim model, it might be the best strategy to import the
Simulink model into Simcenter Amesim. If the main purpose is to test/develop a controller in Simulink
with a physical model written in Simcenter Amesim obviously it is a better idea to work in Simulink.

In many cases, one person develops the Simulink model, and another develops the Simcenter Amesim
model. The person responsible for integrating the models will obviously prefer to work in "his"
environment.

There are some obvious "rules": if the Simulink model is small and the Simcenter Amesim model is
large, you would put the Simulink model into Simcenter Amesim. If access is required to unique
features in Simcenter Amesim you would also put the Simulink model in Simcenter Amesim. If there
are special features in MATLAB® /Simulink that you need to use, you would put the Simcenter Amesim
model into Simulink.

1.3 Supported Simulink Interface modes


Supported interface modes are shown below:

Envisaged interface mode Supported

1.1 Co-simulation in Simcenter Amesim: Simcenter Amesim as Yes 1.2. (SL2AMECosim)


Master (Simulink as Slave)

2.1 Co-simulation in Simulink: Simcenter Amesim as Slave Yes 3. (AME2SLCosim)


(Simulink as Master)

1-2 Simulink Interface,


© 2021 Siemens
Co-simulation in Simcenter Amesim: Simcenter Amesim as Master, Simulink as Slave (SL2AMECosim)

Envisaged interface mode Supported

2.2 Model Exchange: Export of Simcenter Amesim model into Yes 3.4. (AME2SL)
Simulink

1. For SL2AMECosim, please note that once the Simulink model has been imported into
Simcenter Amesim, Simulink is not needed anymore for running the simulation (and no
Simulink license either).

2. In SL2AMECosim, the embedded Simulink solver is always of type fixed-step. Simulink model
referencing is supported.

3. For model exchange or co-simulation in Simulink (AME2SL or AME2SLCosim), Simcenter


Amesim models (with or without solver) are exported as S-functions.

4. This mode complies with the Black-Box option.

1.3.1 Co-simulation in Simcenter Amesim: Simcenter Amesim as Master,


Simulink as Slave (SL2AMECosim)

Simulink Interface, 1-3


© 2021 Siemens
1. Introduction

1.3.2 Co-simulation in Simulink: Simcenter Amesim as Slave, Simulink as


Master (AME2SLCosim)

1.3.3 Model Exchange: Export of Simcenter Amesim model into Simulink


(AME2SL)

1.3.4 Using multiple Simulink Interfaces

This section describes using multiple Simulink interfaces.

General remarks

• If Simcenter Amesim is the target environment, the interface blocks are completely independent
(viewed as standard submodels by Simcenter Amesim). So, the possibilities of mixing different block
types or settings on the same Simcenter Amesim sketch are theoretically not limited.

1-4 Simulink Interface,


© 2021 Siemens
Combining with other interfaces

• It is possible to use several Simulink models in a single Simcenter Amesim system (and vice-versa),
but it is not possible to use the same Simulink model several times in a single Simcenter Amesim
system (and vice-versa).

• There are as many blocks used in the target environment as independent systems.

Advanced capabilities

Capability Supported interface modes for blocks

Use N Simulink blocks in Simcenter Co-simulation (SL2AMECosim): Simcenter Amesim


Amesim as Master (Simulink as Slave)

Use N Simulink blocks with different solver Co-simulation (SL2AMECosim): Simcenter Amesim
types (variable/fixed-step) or solver settings as Master (Simulink as Slave)2
in Simcenter Amesim

Use N Simcenter Amesim blocks in Co-simulation (AME2SLCosim): Simcenter Amesim


Simulink as Slave (Simulink as Master)

Model Exchange (AME2SL): Export of Simcenter


Amesim model into Simulink

Both Co-simulation (AME2SLCosim): Simcenter


Amesim as Slave (Simulink as Master) and Model
Exchange (AME2SL): Export of Simcenter Amesim
model into Simulink

Use N Simcenter Amesim blocks with Co-simulation (AME2SLCosim): Simcenter Amesim


different solver types (variable/fixed-step) or as Slave (Simulink as Master)
solver settings in Simulink

1. In SL2AMECosim, the solver type is always fixed-step but the settings (e.g. step sizes) can be
different.

2. Some of these model exchange blocks can be of Black-Box type.

1.3.5 Combining with other interfaces

This section describes how to combine Simcenter Amesim/Simulink with other interfaces through an
example of three-way co-simulation with Motion:

Simulink Interface, 1-5


© 2021 Siemens
1. Introduction

Three-way co-simulation example (Simcenter Amesim-Motion, Simcenter Amesim-


Simulink)

This example shows a three-way co-simulation scheme, involving both a Simcenter Amesim-Motion
interface (co-simulation, Simcenter Amesim as master), and the Simulink interface (SL2AMECosim,
Simcenter Amesim as master). In this case, Motion is used to create a complex 3D mechanism,
Simcenter Amesim is used to model the complete physical system, and Simulink is used for the
controls. Please note that once the Simulink model (including the solver) has been imported into
Simcenter Amesim for co-simulation, Simulink is no longer needed and Simcenter Amesim or Motion
can be selected as the integration platform for result analysis.

1-6 Simulink Interface,


© 2021 Siemens
Requirements

1.4 Requirements

1.4.1 Common requirements

Please note the following requirements. You must have:

• MATLAB-Simulink.

• A Simulink interface for Simcenter Amesim.

• A common C compiler available in both MATLAB and Simcenter Amesim.


Under Windows, supported compilers for each Simulink version are indicated hereafter. In this table
“MSVC” denotes “Microsoft Visual C compiler” and ”MS” denotes “Microsoft”.
Support for the 32-bit architecture is no longer available (as of release R2015b of Simulink).
Refer to the following table for details on 64-bit architectures:

Simulink Interface, 1-7


© 2021 Siemens
1. Introduction

R2016a R2016b R2017a R2017b R2018a R2018b R2019a R2019b R2020a R2020b R2021a
MS
SDK
7.1
Ming
GW
5.3(1)
MSVC
2010
MSVC
2012
MSVC
2013
MSVC
2015
MSVC
2017
MSVC
2019
(1) MingGW is currently not supported by the Simulink to Simcenter Amesim interface (SL2Amecosim).

Under Linux, the supported compilers are:

• GNU GCC 4.4 or above (64-bit only)

• Intel C/C++ 12.0 or above (64-bit only)

The list of Simulink compilers is available at:

• https://fr.mathworks.com/support/requirements/simulink.html for the current version of


MATLAB , and at

• https://fr.mathworks.com/support/requirements/previous-releases.html for older versions.

Note:
Ensure that the active compiler in the compilation tab of the Simcenter Amesim preferences is
the same as the one you selected in MATLAB (using the "mex -setup" command). Please note
that for binary compatibility reasons, both Simcenter Amesim and MATLAB must use the same
version of the same C compiler.

• A MATLAB environment variable well defined (pointing to your installation root folder).
Using Windows

1-8 Simulink Interface,


© 2021 Siemens
Simcenter Amesim to Simulink software requirements

echo %MATLAB%
C:\Program Files\MATLAB\R2019a

Note:
To configure the MinGW64 compiler in MATLAB, please follow the procedure below:

• In MATLAB, install the Add-On for the support of MinGW64.

• Execute a mex -setup command and select the MinGW64 compiler.

• Make sure an environment variable called MW_MINGW64_LOC has been set on your PC; if
not, then create it and set it to the value obtained when executing a
getenv('MW_MINGW64_LOC') command under MATLAB.

• Restart your machine and select the GNU GCC (64-bit) compiler in Simcenter Amesim.

Using Linux

echo $MATLAB
/usr/local/MATLAB/R2019a

1.4.2 Simcenter Amesim to Simulink software requirements

Windows — The Simcenter Amesim to Simulink interface for Simcenter Amesim 2021.2 has been
extensively tested using MATLAB/Simulink R2016a and R2021a. All releases between these two
versions should work.

Linux — The Simcenter Amesim to Simulink interface for Simcenter Amesim 2021.2 has been
extensively tested using MATLAB/Simulink R2017a and R2021a. All releases between these two
versions should work.

1.4.3 Simulink to Simcenter Amesim software requirements

Windows — The Simulink to Simcenter Amesim interface for Simcenter Amesim 2021.2 has been
extensively tested using MATLAB/Simulink R2016a and R2021a. All releases between these two
versions should work.

Linux — The Simulink to Simcenter Amesim interface for Simcenter Amesim 2021.2 has been
extensively tested using MATLAB/Simulink R2017a and R2021a. All releases between these two
versions should work.

In addition to the common requirements, please note that:

• You must have Simulink coder (formerly known as the Real-Time Workshop).

Simulink Interface, 1-9


© 2021 Siemens
1. Introduction

• Only Visual C compiler is available on Windows for such an interface.

• Make sure that the Visual C compiler is accessible from the machine where Simcenter Amesim and
MATLAB/Simulink are installed.

1-10 Simulink Interface,


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink
Interface
The Simcenter Amesim to Simulink interface enables you to construct a model of a subsystem in
Simcenter Amesim and to convert it to a Simulink S-Function. The S-Function can then be imported
into Simulink and used within a Simulink system just like any other S-Function.

Note:
S-functions resulting from converted Simcenter Amesim models are fully compatible with
Simulink “Normal” and “Accelerator” simulation modes.

The interface is designed so that you can continue to use many of the Simcenter Amesim facilities
while the model is running in Simulink. In particular you can change the parameters of the Simcenter
Amesim model within Simcenter Amesim in the normal way, examine the results within Simcenter
Amesim by creating plots just as if they were produced in a regular Simcenter Amesim run.

Normally you will have Simcenter Amesim and Simulink running simultaneously so that you can use
the full facilities of both packages. The process is illustrated below:

Simulink Interface, 2-1


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

When the process is complete, the Simcenter Amesim model parameters may be changed within
Simcenter Amesim, as can the Simulink parameters within Simulink. A series of runs can be
performed. Typically, a controller can be designed for the system.

Note:
Please be sure to consult Concluding remarks and FAQs in this manual, which provides the
solutions to many of the problems you may encounter when using the Simulink interface.

2-2 Simulink Interface,


© 2021 Siemens
Constructing the model in Simcenter Amesim

2.1 Constructing the model in Simcenter Amesim

Figure 2-1. The model in Simcenter Amesim

The process of constructing the Simcenter Amesim model is described with the help of a simple
example. You will understand the process better if you create and run the system yourself. The exercise
can be completed within about an hour.

Create the system shown in the figure above, calling it skyhook. It consists of two masses connected
with a spring which represent a quarter car suspension.

Note:
• Two transducers determine the positi ons of the wheel and the car body.

• Connected to the wheel is a spring to which the road profile is applied.

• The system is incomplete with six ports unconnected.

Simulink Interface, 2-3


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

Figure 2-2. The Simcenter Amesim model with the interface block

The force representing the damping in the suspension will be provided by Simulink and the output from
the velocity transducers will be sent to Simulink. To scope the displacement in Simulink, two outputs
from displacement transducers are sent to it. Finally, the road profile is provided by Simulink.

To complete the system it is necessary to add a special interface icon. The figure above shows this block
added to the system.

2-4 Simulink Interface,


© 2021 Siemens
Constructing the model in Simcenter Amesim

Figure 2-3. First step in creating the interface icon

To create the interface blocks, click on the Interface block pulldown menu shown in the previous figure.
This menu is designed to be used with the Simulink interface and other interfaces but in our case it will
be Simulink. Select the item labeled Create interface block. This is used to define the variables which
are provided and received by the companion software. From Simcenter Amesim these variables are
seen as inputs and outputs respectively. The dialog box shown in the following figure is produced.

Figure 2-4. Interface Icon Creation dialog box

There are currently no input or output variables. By selecting the arrow buttons in the top corners, the
number of input or output variables can be adjusted. You can have any number including 0 but a
reasonable upper limit is 10. If you want more than this, it is better to use more than one interface
block. In our example, we require two input variables and one output variable, so ensure that the fields
have the values 4 and 2 respectively.

Simulink Interface, 2-5


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

The next stage is to get Simcenter Amesim to create a specific icon for the interface. The number of
ports is now specified but it is also necessary to add a label to each port. To do this, we will add text to
give a name to the variables. In addition, we will give a general name for the whole interface block. The
following figure shows text added in this way. Select each field and type an appropriate text string. In
this example, we select the “model exchange” interface (AME2SL). This implies that the Simcenter
Amesim model will be exported without its solver. If you want to perform co-simulation, you should
select the AME2SLCosim interface type.

Figure 2-5. Specifying the interface block

Note the three buttons labeled Clear all text, OK and Cancel.

• Click on Cancel to abandon the process.

• Click on Clear all text to remove any text you have entered.

• Click on OK to obtain the icon produced by Simcenter Amesim.

An icon similar to that shown in the following figure will appear. Note the port position is denoted by >.

Figure 2-6. The completed interface block

The pointer will take on the appearance of the icon and can be treated like a normal Simcenter Amesim
component icon. Thus it can be mirrored, rotated, deleted or added to system sketch. All Simcenter
Amesim interface blocks have signal type ports.

2-6 Simulink Interface,


© 2021 Siemens
Constructing the model in Simcenter Amesim

Connect the block inputs and output to the other components of the model as shown in the The
Simcenter Amesim model with the interface block figure.

It is worth mentioning the following important points:

• You can have more than one interface block but if you do, they must all be of the same type (all
Simulink standard interface blocks in the current example) - See Using more than one interface
block.

• the Simcenter Amesim model must be explicit. In other words, there cannot be any implicit variables,
unless the co-simulation interface is used.

• Input and output variables to and from Simulink cannot be vectors.

• Each interface icon is limited to 99 ports to keep the size of the icon reasonable.

Note:
In most cases, models containing interface blocks cannot be run as they are. However, it can be
useful to perform some basic checks such as open-loop simulations to see if the configuration of
your model is correct; for example to check whether it can locate all its resources (typically tables)
and that it initializes correctly. See section Open-loop simulations for basic model checks for more
detail on this topic.

Now switch to Submodel mode. The interface block will automatically be associated with a special
submodel and you are not allowed to change these. For the other submodels select Premier submodel
so as to get the simplest submodels.

Figure 2-7. Compilation to create the S-Function

Simulink Interface, 2-7


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

Next, change to Parameter mode. Normally Simcenter Amesim would create an executable program
that you would start in Simulation mode. However, because the system contains Simulink interface
blocks, an S-Function is created. The normal System Compilation window should appear (as in the
previous figure) and you should enter Parameter mode. If any errors occur, it is likely that the MATLAB
environment variable is not properly set. In this case save the system, exit from Simcenter Amesim and
carry out the instructions for setting this variable as described in Common requirements.

You might also get an error message if the wrong compiler (GNU GCC (32-bit)) is selected. To check
which compiler is being used, go to Tools > preferences:

Figure 2-8. Simcenter Amesim preferences

On the Compilation tab, make sure Subplatform type is set to:

• win64, Microsoft Visual C++, if using 64 bits version of MATLAB.

• win32, Microsoft Visual C++, if using 32 bits version of MATLAB.

• GNU GCC (64-bit), if using 64 bits version of MATLAB 2018a or above.

In order to change parameters of the Simcenter Amesim model from Simulink, a set of global
parameters must be created. These parameters will be accessible in Simulink and will be able to be
modified independently of Simcenter Amesim.

2-8 Simulink Interface,


© 2021 Siemens
Constructing the model in Simcenter Amesim

Create the following set of global parameters:

Real global parameters

Name Title Unit Value Minimum Default Maximum

Bodymass Mass of a quarter car kg 400 0 400 1e+06

Wheelmass Mass of one wheel kg 40 0 40 1e+06

Suspspring Suspension spring N/m 15000 0 15000 1e+06

Totalmass Total mass kg Bodymass 0 440 2e+06


+Wheelmass

Submodel name
and type Belongs to category Main simulation parameters

Property definition

MECMAS21 1D Mechanical mass[kg] = Bodymass


translation mass

SPR000A-1 ideal linear Mechanical spring rate [N/m] = Suspspring


spring
spring force with both
displacements zero [N] =
9.81*Bodymass

MECMAS211D Mechanical mass [kg] = Wheelmass


translation mass

SPR000A-2 ideal linear Mechanical spring force with both


spring displacements zero [N] =
9.81*Totalmass
spring rate [N/m] = 200000

Simulink Interface, 2-9


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

Warning:
When you change from Parameter mode to Simulation mode, special data files containing the
parameters are written. When you run the S-Function within Simulink, these files will be read.
Therefore when you change any parameters, make sure you enter Simulation mode. If not, your
changes will not be seen by Simulink.

At this point, you are ready to run the Simcenter Amesim model within Simulink. There are four ways
to start Simulink:

• In the normal way, use the Tools > Start MATLAB menu from Simcenter Amesim. In this case the
MATLAB Current Directory and path are automatically set to the directory where the Simcenter
Amesim model is stored, ensuring that the MATLAB environment is the same as for Simcenter
Amesim.

• Right-click on the interface block and select Launch Interface. The following dialog box appears:

Select Simulink and click OK. As indicated previously, the MATLAB environment is automatically set.

• Start a simulation run (F7). The Select Action dialog box opens as above. As indicated previously, the
MATLAB environment is automatically set.

• The MATLAB path is automatically updated to point to the directory where the currently-used
Simcenter Amesim is installed.

2.2 Importing the model into Simulink


The Simcenter Amesim model has now been created. It must be imported into Simulink.

2-10 Simulink Interface,


© 2021 Siemens
Importing the model into Simulink

Note:
When using the Simcenter Amesim to Simulink interface, be careful to save the Simulink
subsystem with a name that differs from all the names of he Simcenter Amesim models that will
be imported. Otherwise variable name conflicts could occur within the MATLAB workspace.

Remember that when you close Simcenter Amesim, the files defining your system are compressed into
a single file. This means that Simulink will not have access to the S-Function. For this reason, it is
normal to have Simcenter Amesim and Simulink running simultaneously when using the interface.
This way, you can change the parameters in the Simcenter Amesim model and restart the simulation
very rapidly. You can also examine the results in Simcenter Amesim.

Another mode of working is to close Simcenter Amesim but then to type in a terminal (under Linux) or
DOS window (under Windows):

AMELoad skyhook

...to expand the single file into its constituent parts. Simulink will then have access to all the files it
needs.

Note:
For the rest of this exercise it will be assumed you employ the first mode of working.

A graphical interface is available to help you to import the Simcenter Amesim model into Simulink and
to configure it. It runs under Windows or Linux. In this exercise, it will be assumed this version will be
used.

This interface is available only if Simulink is started from Simcenter Amesim:

• using the Tools > Start MATLAB menu then start Simulink from MATLAB or

• using the Tools > Simulink menu

When MATLAB is started, the path list is automatically updated as shown in the following figure.

Simulink Interface, 2-11


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

Figure 2-9. The Simcenter Amesim environment installation

AMESimLib is added automatically, ensuring that the MATLAB version is compatible with the use of the
graphical interface.

The graphical interface is launched from a specialized Simulink block grouped in a Simulink library.

2-12 Simulink Interface,


© 2021 Siemens
Importing the model into Simulink

Figure 2-10. The Simcenter Amesim Interfaces library

When you start the Simulink Library Browser, the Simcenter Amesim library (figure above) contains
two blocks. The first one, called AME2SL, is used in case of standard interfaces between Simcenter
Amesim and Simulink. This one will be used in the current exercise.

From the library browser, drag and drop the AME2SL block to a Simulink subsystem. Now, the
Simcenter Amesim import block is ready to be configured using the graphical interface. The graphical
interface is launched by double-clicking on the block. The main window of the interface is now available
as shown in the following figure.

Simulink Interface, 2-13


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

Figure 2-11. Starting with AME2SL block

The main window shows that the Simcenter Amesim model "system" does not exist by displaying its
name in red. The first thing to do is to select the name of the Simcenter Amesim model to import. This
can be done in two ways:

• Write the name of model in the edit box (case sensitive), in this example skyhook and push on the
Load model button.

• Select the mex file from the file browser dialog by clicking on the 'open file' icon as shown in the
following figure.

2-14 Simulink Interface,


© 2021 Siemens
Importing the model into Simulink

Figure 2-12. Selecting the mex file

Note:
The extension of the mex file is automatically pre-defined by the interface according to the
platform and MATLAB architecture. The list of mex file extensions is available using the MATLAB
command mexext. In this example the extension is mexw64 because the platform is Windows
and using MATLAB 64 bits.

Note:
As of Simcenter Amesim 2020.2, it is no longer necessary to set the working directory of your
Simulink model to the same location as the Simcenter Amesim model. To save the location of
the Simcenter Amesim model to your MATLAB path for later reuse, it is possible to execute a
savepath command right after importing the Simcenter Amesim model. If this location is no
longer in the MATLAB path, it can be added automatically with a double-click on the AME2SL/
AME2SLCosim block.
Moreover, AME2SL and AME2SLCosim blocks are now compatible with Simulink "linked libraries".
This permits library publishers to propagate changes applied to Simcenter Amesim-originating
models to all end-user models containing those models (these models will inherit the changes
made to the libraries they are linked with). Note however that changing parameters in such
models directly (in other words, not in the linked library) is not allowed unless the link is
deactivated.

Once the Simcenter Amesim model has been read, the AME2SL block is automatically sized with the
appropriate number of inputs and outputs. Input and output labels and the name of the Simcenter
Amesim model are displayed on the block icon (figure below).

Simulink Interface, 2-15


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

Figure 2-13. Imported Simcenter Amesim model

Warning:
Important note:
If your Simcenter Amesim model has more than one input coming from Simulink, the input
signals to Simcenter Amesim have their order reversed when compared to what is sent from
Simulink. This is due to the fact that Simcenter Amesim numbers the ports in counter-clockwise
order while the Mux block in Simulink numbers them starting at the top. The output side of the
interface block is not affected by this, since in this case the variables are numbered from the top in
both softwares. This can be seen by comparing the model in Simcenter Amesim and Simulink as
shown in the figures below:

Figure 2-14. Order of inputs and outputs

2-16 Simulink Interface,


© 2021 Siemens
Importing the model into Simulink

The graphical interface can be closed at any time by clicking on the close button. To open it again, just
double click on the AME2SL block.

At this stage, the Simcenter Amesim model has been imported and the Simulink system can be
completed as shown in the following figure.

Figure 2-15. The system ready to run

Note:
The values of Gain and Gain 1 come from the Car suspension example in Section 2 of the
Simcenter Amesim Tutorial manual.

Why has the transfer function been inserted?

This is a consequence of the fact that the Simcenter Amesim interface S-Function is defined as having
direct feed through. This means that the outputs from the block may be directly dependent on the input.
For most realistic Simcenter Amesim systems this is not true, there are normally state variable(s)
between inputs and outputs. The way the S-Function is created makes it necessary to specify that all
systems have a direct feed through in every case.

The transfer function (a first order lag) that is inserted is required to break the algebraic loop that
Simulink sees due to this direct feed through. For the current system it can be regarded as the dynamics
of the actuator that applies the damping force.

Simulink Interface, 2-17


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

Once the Simulink system is completed, it is time to configure the run parameters. Open the main
window interface and click on the Run parameters icon . The run parameters window appears as
shown in the following figure.

Figure 2-16. The run parameters window for a standard interface

With a normal Simcenter Amesim run, a print interval is specified which enables you to control the size
of the results file. Simulink runs in a somewhat different way and consequently the Simcenter Amesim
result files can become unacceptably large. To prevent this from occurring a special Simcenter Amesim
print interval is specified. The data added to the Simcenter Amesim results file will be spaced with a
time interval not less than this value.

The Create result file check-box indicates whether a Simcenter Amesim result is to be created. The
interface makes it possible to specify the print interval. The print interval parameter can be defined by a
MATLAB expression. Furthermore, through this window you can load the print interval parameter
defined in the Simcenter Amesim run parameters popup by clicking on the Get Simcenter Amesim
parameters button.

Note:
The Run parameters of the Simcenter Amesim model are not used for the simulation, except for
the Activity index calculation. If you want the activity variables to be calculated during the
simulation, proceed as follows in Simcenter Amesim:

1. Open the Run Parameters dialog box.

2. Select the Standard options tab and tick the Activity check-box

2-18 Simulink Interface,


© 2021 Siemens
Importing the model into Simulink

3. Simcenter Amesim forces the model to recompile.

4. Select File > Write files for simulation

Note:
All parameter windows in the graphical interface work in this way:

Simulink Interface, 2-19


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

• Press the OK button to validate change and close window

• Press the Cancel button to cancel change and close window

• Press the Apply button to validate change, the window keeps opened

The Close button of the window is disabled. Closing the main window forces the closure of all
children parameter windows.

Now you can set the Simulink simulation parameters.

Figure 2-17. Setting the simulation parameters

In Simulink it seems that both solvers for stiff systems can be used for Simcenter Amesim models. In
this particular case, use the ode15s (stiff/NDF) method (in older versions, Gear and Adams/Gear were
the ones most suitable). Set the stop time to 5 seconds, this will be quite enough to produce some
interesting results (figure above).

Initiate the Simulink run and observe the output from the Scope block. This will give the input force
supplied to the car suspension as shown in the following figure.

2-20 Simulink Interface,


© 2021 Siemens
Importing the model into Simulink

Figure 2-18. Force in Simulink

Enabling Result file creation allows us to observe the same quantity plotted within Simcenter Amesim
(figure below). If you chose to generate a Simcenter Amesim result file, it is possible from within
Simcenter Amesim to access the full range of variables of the Simcenter Amesim model. These can be
plotted like a normal Simcenter Amesim simulation.

Simulink Interface, 2-21


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

Figure 2-19. Force in Simcenter Amesim

The following figure shows the body and wheel displacements. These can be plotted from the
Simcenter Amesim components:

2-22 Simulink Interface,


© 2021 Siemens
Importing the model into Simulink

Figure 2-20. Force in Simcenter Amesim

Now we demonstrate how to change model parameters through the graphical interface. Open the main
interface and click on the Model parameters icon . The model parameter window appears as shown
in the following figure.

Figure 2-21. The model parameters window

Simulink Interface, 2-23


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

This window summarizes all global parameters defined in the Simcenter Amesim model. The value of
each parameter can be modified by editing the Value field for each line. The value of Global Parameters
can be defined by a MATLAB expression.

Furthermore, this window allows you to:

• Reset all parameters to their default values by clicking on the Set to default value button.

• Quickly load the global parameter set defined in Simcenter Amesim by clicking on the Get
Simcenter Amesim parameters button.

Note:
If a global (real or integer) parameter is set as an expression in Simcenter Amesim the expression
will not be visible or usable from Simulink. Text parameters are treated as text and can thus
contain any type of text- including expressions.
Since the totalmass parameter is an expression of two other parameters, it is reasonable to
assume that it should not be possible to set it independently of the other parameters. This is the
reason why the interface will ignore this parameter.

To illustrate the correct updating of parameters we can for example set the body mass value to 100kg as
shown in the following figure.

Figure 2-22. Modifying model parameters

Click on the Apply button and run the simulation; we can now look at the displacement curves plotted
in Simulink (figure below) and notice the difference with the preceding simulation (figure: Force in
Simcenter Amesim).

2-24 Simulink Interface,


© 2021 Siemens
Importing the model into Simulink

Figure 2-23. Result changes

Note:
All values of run parameters and model parameters are saved in the Simulink model
independently of their values defined in Simcenter Amesim. This means that data modified are
persistent, and are not lost when the Simulink model is closed.

Click on the IO connection icon to launch the model connection window (see the following figure).

Simulink Interface, 2-25


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

Figure 2-24. The model connection window

To help in model adjustment, you can disconnect each input and output of the Simcenter Amesim
model in the Simulink subsystem and set a constant value instead of real signal.

Furthermore, this window allows you to:

• Disconnect/connect all inputs of the Simcenter Amesim model by clicking on the Disconnect all or
Connect all button in the Input panel.

• Disconnect/connect all outputs of the Simcenter Amesim model by clicking on the Disconnect all or
Connect all button in the Output panel.

2-26 Simulink Interface,


© 2021 Siemens
Importing the model into Simulink

Figure 2-25. The model connection window

For example, disconnecting the road input and setting the signal value to 0.5 as shown in the figure
above, produces the following simulation result (see the following figure).

Simulink Interface, 2-27


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

Figure 2-26. Road entry disconnected

The simulation runs using the specified input value instead of the signal delivered by the pulse
generator. Disconnected inputs and outputs are indicated by a diamond symbol on the block as shown
in the following figure for the Road input

2-28 Simulink Interface,


© 2021 Siemens
Co-simulation interface

Figure 2-27. Disconnected input for Road

2.3 Co-simulation interface


There are two ways to create an interface with Simulink: the standard interface and the co-simulation
interface. Here we will explain what the differences are between the two, and describe how to use the
co-simulation interface.

The main difference between the two interfaces is that the co-simulation interface uses two (or more)
solvers, while the standard interface uses only one. This means that Simcenter Amesim and Simulink
use their own solvers for the co-simulation interface whereas they both use the Simulink solver for the
standard interface. Another difference is that with the standard interface the Simcenter Amesim part is
seen as a time continuous block in Simulink and in the co-simulation it is a time discrete block. Since
the co-simulation block is seen as a discrete block it makes this interface very suitable for discrete
controllers implemented in Simulink controlling a Simcenter Amesim model.

2.3.1 Introduction

The figure below shows in more detail how the interfaces work. In the standard interface the Simcenter
Amesim part of the system gets state variables and input variables from Simulink and calculates state
derivatives and output variables. The process of exchanging this information is controlled entirely by the
Simulink solver. In this case one could say that we import the equations into Simulink.

In the co-simulation case, the only variables exchanged are the input and output variables. In this case,
the rate of exchange is set according to a user-defined parameter. As the name indicates, the model is
not entirely in the hands of a single piece of software (Simulink) but it is a co-operation between two
(or more) software packages. It is important to realize that by exchanging only input and output
variables at a certain sample rate there is a loss of information.

Simulink Interface, 2-29


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

Figure 2-28. The two Simcenter Amesim-Simulink interfaces, exchange of information

This can be compared with the difference between a continuous and a sampled controller. Normally, the
smaller the sample rate used, the closer to the continuous result we get. Another problem is the loss of
information about possible cross couplings between the systems since we do not communicate
information about states and state derivatives.

Warning:
All these factors mean that co-simulation can be difficult to set up if the two separate systems are
continuous. In this case you should try to find an interface between the systems where the
coupling is as weak as possible.
The obvious situation where co-simulation may be used is of course when the interface between
the systems is sampled, for example when using a sampled controller.

2.3.2 Usage of the co-simulation interface

We will reuse the Simcenter Amesim system created earlier (figure: The model in Simcenter
Amesim). Save the system as skyhookcosim. Now we add the interface block. The process is similar to
the process for creating the standard Simulink interface, except that we select SimuCosim in the field
labeled Type of interface instead of Simulink. See the following figure.

2-30 Simulink Interface,


© 2021 Siemens
Usage of the co-simulation interface

Figure 2-29. Creating the icon for co-simulation

Go into Parameter mode and then Simulation mode. Next we create the Simulink system as shown in
the Simulink model - Co-simulation figure.

To create the Co-Simulation interface in Simulink, the only difference is to select the block
AME2SLCoSim in the library browser, instead of the AME2SL block.

Again drag and drop the block in the subsystem and double click it to open the main interface window,
as shown in the following figure

Simulink Interface, 2-31


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

Figure 2-30. Starting with an AME2SLCoSim block

Select the Simcenter Amesim model to import: skyhookcosim, and connect the block. The co-
simulation subsystem is ready to use.

2-32 Simulink Interface,


© 2021 Siemens
Usage of the co-simulation interface

Figure 2-31. Simulink model - Co-simulation

At this time, the co-simulation parameters must be set. Open the Run parameters window by clicking
on the dedicated icon ( ) from the main window. The run parameter window for co-simulation appears
as shown in the following figure.

Simulink Interface, 2-33


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

Figure 2-32. The run parameters window for the co-simulation interface

This window presents most of the Simcenter Amesim run parameters that can be adjusted from the
Simulink interface. Once the run parameters are modified from the Simulink interface, they are saved
independently of any run parameters defined in Simcenter Amesim.

Furthermore, this window allows you to load the run parameters defined in the Simcenter Amesim run
parameters popup by clicking on the Get Simcenter Amesim parameters button.

The run parameters are listed below:

Parameter Description

Integrator type Select the type of integrator, variable (standard) or fixed step solver.

General parameters

Sample time Time between exchange of values between Simcenter Amesim and Simulink.

2-34 Simulink Interface,


© 2021 Siemens
Usage of the co-simulation interface

Parameter Description

This parameter must absolutely set according to the model dynamics. It can be
defined by a MATLAB expression.

Print interval Define the print interval in the result file, the same as in the Simcenter Amesim
run parameters popup. It can be defined by a MATLAB expression.

Statistics The same as in the Simcenter Amesim run parameters popup.

Monitor time The same as in the Simcenter Amesim run parameters popup.

Standard options

Tolerance The same as in the Simcenter Amesim run parameters popup. It can be defined
by a MATLAB expression.

Maximum time The same as in the Simcenter Amesim run parameters popup. It can be defined
step by a MATLAB expression.

Solver type Adjust the optimization solver level, the same as in the Simcenter Amesim run
parameters popup.

Discontinuities The same as in the Simcenter Amesim run parameters popup.


printout

Fixed step options

Integration The same as in the Simcenter Amesim run parameters popup.


method

Order Order of the integration method:


1 for Euler
2 to 4 for Adams or Runge-Kutta

Step Time step of integration method. The same as in the Simcenter Amesim run
parameters popup.

Warning:
It is possible to set the sample time to the value -1. This means that the sample time is inherited
from the Simulink workflow. It will probably cause a backward integration that is not supported
by Simcenter Amesim, and produce an error during the simulation.

Simulink Interface, 2-35


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

To prevent this problem, we may use an inherited sample time only when a fixed-step solver is
configured in Simulink, or using the Simcenter Amesim model in a triggered subsystem.

Set the sample time to 10-2 s and the print interval to 10-3 s.

The sample time chosen in this example is set fairly high on purpose, to make the effects of the
sampling more obvious. The chosen sample time is for this case the maximal sampling time possible to
use. The damping force calculated by the Simulink model is shown in the Force as calculated by
Simulink using a sample time of 0.01 s figure using a sample time of 0.01s, compare this with the
force in the Force in Simulink figure. The stability of the system has gone down due to the sampled
controller.

Figure 2-33. Force as calculated by Simulink using a sample time of 0.01 s

2-36 Simulink Interface,


© 2021 Siemens
Usage of the co-simulation interface

Looking more closely at the input to the Simcenter Amesim system (figure below) we can easily
observe the time-discrete nature of the force. The sampled controller results for the body and wheel
displacements are more oscillatory (figure: Body and wheel displacement with a sample time of
0.001 s) than with the continuous controller (figure: Force in Simcenter Amesim). By selecting a
smaller sample time we can get a result that is more similar to the one we had with the standard
interface (continuous controller). In figures Body and wheel displacement with a sample time of
0.01 s and Body and wheel displacement with a sample time of 0.001 s the sample time is set to
0.001s and the Simcenter Amesim communication interval is set to 0.0002 s.

Figure 2-34. Detailed view of force input to Simcenter Amesim model using sample time of 0.01 s

Simulink Interface, 2-37


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

Figure 2-35. Body and wheel displacement with a sample time of 0.01 s

Figure 2-36. Actual input to the Simcenter Amesim model using a sample interval of 0.01 s

2-38 Simulink Interface,


© 2021 Siemens
Using more than one interface block

Figure 2-37. Body and wheel displacement with a sample time of 0.001 s

2.4 Using more than one interface block

Figure 2-38. Using several interface blocks

Make sure you give each port a unique name.

When the S-Function is created, Simcenter Amesim will concatenate all the inputs and concatenate all
the outputs. To see how this is done, select Interfaces > Interface status status. A dialog box (figure
below) shows how the ports are arranged.

Simulink Interface, 2-39


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

Figure 2-39. Concatenated inputs and outputs

To illustrate the use of multiple interface blocks we will use the example from Constructing the model in
Simcenter Amesim, the difference being that whereas previously the road profile and wheel
displacement were supplied by Simcenter Amesim, now they are supplied by Simulink:

2-40 Simulink Interface,


© 2021 Siemens
Using the Simcenter Amesim-Simulink Black-box interface

Note:
If you place multiple interface blocks on your sketch, remember that editing them afterwards has
an impact on the model in Simulink. The order in which you place them on the sketch dictates the
order of the ports in Simulink. If, for example, in the model above the three blocks were placed in
order from top to bottom, the inputs and outputs in Simulink reflect this fact. Should you decide
to then edit the topmost interface block, this would change the ordering of inputs and outputs in
Simulink, and the edited block would in effect become the last block in the model, leading to
problems in the Simulink model.
To avoid this type of problem, you can simply create one block for the inputs, and one for the
outputs. This way you can easily control the order of the variables.

2.5 Using the Simcenter Amesim-Simulink Black-box interface


The following sections present the three main steps in using the Simcenter Amesim-Simulink Black-box
(ASBB) interface:

• Preparing the Simcenter Amesim model

• Generating the code

• Using the ASBB in Simulink

Simulink Interface, 2-41


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

Note:
There are limitations on which libraries can be used in the Simcenter Amesim model. A list of
libraries compatible with Black Box Export is given in the section Black-box compatibility.

We will take the example from the standard Simcenter Amesim-Simulink interface presented in the
The Simcenter Amesim model with the interface block figure, and to illustrate use of more than one
interface block, we will replace the interface block with three blocks, as shown in the Simcenter
Amesim example model with standard Simulink interface blocks figure. It is not mandatory to use
more than one interface block to create an ASBB.

Note:
The ASBB is limited to the Simulink interface using the Simulink solver - it is not applicable when
using the Simcenter Amesim-Simulink co-simulation.

Note:
By design, it is not possible to generate code (e.g. with the Simulink Coder) from a Simulink
model containing a Simcenter Amesim Black Box. In particular, it is not possible to export this
model to a real-time target. The Black Box option is only intended for running the model within
the Simulink environment with all dependencies to Simcenter Amesim removed.

2.5.1 Preparing the Simcenter Amesim model

Add interface blocks for input/output variables

As we start with the Simcenter Amesim system used in the first part of this manual we already have a
Simcenter Amesim system that is suitable. The ASBB export will only give access to variables on the
ports (and the state variables).

2-42 Simulink Interface,


© 2021 Siemens
Generating the ASBB

Figure 2-40. Simcenter Amesim example model with standard Simulink interface blocks

The Simulink system is the same as that shown in the The system ready to run figure. Save the
Simcenter Amesim model as skyhook.ame.

As we proceed in chapter 1.5, we use the AME2SL block to import the Simcenter Amesim model into
the Simulink sketch. Once again, we need to select the imported Simcenter Amesim model and adjust
the global parameter values. We recommended that you test your model with the final global parameter
setup before creating the ASBB.

2.5.2 Generating the ASBB

Main data files

The function behind the Simcenter Amesim-Simulink Black-box is the function developed for export of
Simcenter Amesim models to real-time platforms. Real-time platforms do not normally include disk
access. So for real-time platforms the main data (model_.data, model_.gp, and model_.gp2) are stored
in character arrays compiled into the C code. The same procedure is used also for the Simcenter
Amesim-Simulink Black-box. Since the goal with the ASBB is to encapsulate a model with potentially
sensitive data, we have added encryption of the character arrays. In this way it is difficult (in practice
probably impossible) to access the data used in the model.

Simulink Interface, 2-43


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

Data files for submodels

Tables used by submodels will also be put into the ASBB. Data files for submodels that can be
incorporated into the ASBB model include all table types that the Simcenter Amesim table editor can
deal with. If the tables have been created with another tool it is recommended that the first line of the
file should contain an indication of the file type like:

# Table format: 1D

For files provided with Simcenter Amesim this will always be the case.

The allowed file types are:

• 0D : a flat file with one value per line. Often used for solid properties.

• 1D : Used for y = f(x)

• T1D: Used for y = f(x1, x2)

• 2D: Used for y = f(x1, x2) when the y, x1, x2 values are equally spaced.

• 3D: y=f(x1,x2, x3)

• T3D: y=f(x1, x2, x3, x4)

Please note that the data in data files is not encrypted when put into the ASBB DLL. They are stored in a
binary format which gives a certain protection (the same as any compiled code). Please note that if the
files are of an unknown type they will not be inserted into the DLL. This means that it is indeed possible
to use data files other than the supported ones if it is acceptable to provide the data files separately.

Customized super-components

If there are customized super-components in the system all their private data (contents of the gp2 file)
will also be encrypted into the DLL.

Generate the Simcenter Amesim-Simulink Black-box

Since the generation of the Simcenter Amesim-Simulink Black-box includes the data files in the
compiled S-function it is necessary to perform the code generation from Simulation mode. If you have a
license for the Black-box generation you will have a menu item Generate Simcenter Amesim-Simulink
black-box in your Interfaces menu. When this item is selected the code generation starts immediately.

2-44 Simulink Interface,


© 2021 Siemens
Generating the ASBB

Figure 2-41. Black-box generation menu in Simulation mode

Figure 2-42. First step in creating a Black-box - press continue to proceed

Simulink Interface, 2-45


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

Figure 2-43. Compilation and linking of the Simcenter Amesim-Simulink Black-box

Note the title "Creating Simcenter Amesim/Simulink Black-box S-function" at the end of the text in this
popup. This is actually the only difference between a standard compilation and a ASBB compilation. We
recompile both the standard S-function and the newly created ASBB S-function. We do this to be 100%
sure that the standard S-function and the ASBB S-function contain the same code. You will now have
two S-functions in your working directory: the standard S-function skyhook_.mexw64 and the black-box
skyhook.mexw64.

2.5.3 Importing Black-box models into Simulink using amecreatebbmask


command

We will now create the black-box S-function in Simulink. From the subsystem containing the standard
interface AM2SL block, open the main interface window. After setting run and model parameters using
the interface as shown in Importing the model into Simulink, press the Create black-box icon .

A new subsystem is created including the Simcenter Amesim black-box S-Function as shown in the
following figure.

2-46 Simulink Interface,


© 2021 Siemens
Importing Black-box models into Simulink using amecreatebbmask command

Figure 2-44. Creating an ASBB S-Function from the AME2SL interface

This S-Function can be used in any Simulink sketch. Double-clicking on it allows you to access the global
parameters of the embedded Simcenter Amesim model (Fig 1.ac). For example, the AME2SL block of
the Simulink subsystem can be removed and replaced by this newly created S-Function.

Figure 2-45. Mask of the ASBB S-Function

Simulink Interface, 2-47


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

2.5.4 A more advanced example using all types of global parameter and a
table

In the Quarter car example shown previously, no tables are involved, so we will now use a different
Simcenter Amesim system to demonstrate the use of data files - we will also demonstrate what
happens when using integer and text parameters.

Figure 2-46. Simcenter Amesim system using all types of global parameter and table file

1. Define the following global parameters:

Type Name Title Unit Value Minimum Default Maximum

Real freq Frequency Hz 10 0 10 1e+06


to filter

Integer fluidindex Index of 0 0 0 1


hydraulic
fluid

Text expr Expressio x^2 x^2


n for
function
block

2. Set the following submodel parameters:

2-48 Simulink Interface,


© 2021 Siemens
A more advanced example using all types of global parameter and a table

Submodel Parameter name Value

FX00-1 expression in terms of the input x expr

LAG2-1 natural frequency freq

FXA001-1 name of ASCII file fxa0data.dat

3. Use the Simcenter AmesimTable Editor to create the file fxa0data.dat setting the following data
table:

For data files that are not recognized by Simcenter Amesim you will need to specify the type manually.
If there are files used by the model that are not supported by Simcenter Amesim, you should select
Other, not supported as the data file type. If unsupported files are used in the simulation, it is
necessary to provide these files with the S-Function. You should in this case make sure that the path to
the file is relative (for example: data\file_to_use.dat) instead of absolute (for example: c:\path\to\my
\data\files\file_to_use.dat). The reason is simple: it is unlikely that the end-user of the ASBB will have the
same directory structure as you have.

For the other data file used in the Simcenter Amesim system (fxa0data.dat - used by FXA01),
Simcenter Amesim recognizes the file type without any help. This will be the case for all files that have
been created using the Table Editor tool in Simcenter Amesim. For files generated by other means, you
will need to select the file type manually (or add a first line containing the table type).

Simulink Interface, 2-49


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

Figure 2-47. Summary of the data files used in the model and their type

The popup (figure above) displays a summary of the data files used in the model and their type. In this
list, you will often see expressions used in submodels that accept either expressions or filenames. Since
the file generation process has no safe way of determining whether a text parameter is a filename or an
expression, it displays these expressions as NOT_FOUND. Most of the time this kind of warning comes
from a text parameter which does not refer to a filename - such as the unnamed fluid in FP04 in the
current example.

The window that opens when you close the Generating files for Simcenter Amesim-Simulink Black-
Box popup is the classic System Compilation window (figure below). As we can see from this window,
it is clear that:

• Simcenter Amesim first does a "normal" (re-)compilation of the Simulink S-function. After this,

• Simcenter Amesim does another compilation of the system, the second time with special options
that will include the data files in the generated MEX file. The result of this second mex command of
the system (named hydraulic.ame in this case) is a MEX file hydraulic.mexw64 (in recent versions of
MATLAB).

2-50 Simulink Interface,


© 2021 Siemens
A more advanced example using all types of global parameter and a table

Figure 2-48. System Compilation message window

In MATLAB we will create a submodel including an import AME2SL block. Once the Simcenter
Amesim system hydraulic has been selected, the global parameters can be seen via the model
parameter window as shown in the following figure.

Simulink Interface, 2-51


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

Figure 2-49. Simulink submodel

Figure 2-50. View of all types of global parameter

From the main window of the AME2SL block, the black-box can be created by clicking on the Create
black-box icon. Like any other parameters, integer and text parameters can be modified.

2-52 Simulink Interface,


© 2021 Siemens
Importing and using the Black-box manually

Figure 2-51. View ASBB produced

2.5.5 Importing and using the Black-box manually

System without global parameters

The generated S-function is a normal S-function, more or less, as they have always been generated from
Simcenter Amesim. The new feature introduced is the access to global parameters. If you don't need
(or want) to give the end-user easy access to global parameters in the Simcenter Amesim system, the
S-function can be used in the same way as the S-functions normally created by Simcenter Amesim.
After putting the S-function block on the Simulink sketch you only need to change the name in the S-
function parameters popup and it is ready for use. The two parameters normally given to a Simcenter
Amesim S-function concern the creation of a result file, but since an ASBB never creates a result file
these parameters are not really useful.

If you plan to only use the amecreatebbmask command you can stop reading here.

Simulink Interface, 2-53


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

Figure 2-52. Black-box s-function without global parameters

Systems with global real parameters

The next step is to add the access to the global real parameters in the Simcenter Amesim model.

To do this you will need to add the two dummy parameters again, this time as an array. The actual
values are not important but they must be present.

Then follows two matrices: the first with the names of the global real parameters and the second with
their values.

Note that Simulink requires that every row in text matrices has the same length. So blanks have to be
added to fill up every row to the same length (as shown in the following figure). You can achieve this by
using the strvcat function. So writing [strvcat('gain', 'damping', 'freq')] as the second matrix will ensure
that all rows have the same length without having to count spaces.

Figure 2-53. Black-box s-function with global parameters

2-54 Simulink Interface,


© 2021 Siemens
Importing and using the Black-box manually

Note that the third matrix (with the values) must be a matrix of numbers. It could also be a matrix of
MATLAB workspace variables as in [matlab_gain ; matlab_damping; matlab_frequency] (as in the figure
below). This will of course make it possible to perform batch runs in MATLAB with different values on
the MATLAB variables.

Figure 2-54. Using workspace parameters

What was described here is basically what the amecreatemask command does. It reads the global
parameter file (using amegetgpar) and creates a mask using this information. The S-function arguments
are created to fit with the created mask. The following figure shows the S-function parameters created
by amecreatebbmask. Note that both the name and the value matrices consist of variables. These
variables are "mask" variables that are set in the initialization commands for the mask (figure:
Initialization commands for the mask).

Figure 2-55. S-function parameters created by amecreatebbmask.m

Simulink Interface, 2-55


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

Figure 2-56. Initialization commands for the mask

2.5.5.1 Accessing integer parameters

In order to give access to integer parameters you simply add two more matrices with the names and
values of the integer parameters, see the figure below.

Figure 2-57. S-function with global integer parameters

2.5.5.2 Accessing text parameters

Accessing the text parameters requires two additional matrices. Note that all rows in text matrices must
have the same length. This is most conveniently dealt with by using the strvcat command (as seen in
figure S-function with global text parameters).

2-56 Simulink Interface,


© 2021 Siemens
Accessing text parameters

Note that this image has been split into two in order to display it on the page.

Figure 2-58. S-function with global text parameters (part one)

Figure 2-59. S-function with global text parameters (part two)

Note that accessing the text parameters requires that the preceding matrices must be defined even if
they are empty (as in the following figure)

Figure 2-60. S-function with global text parameters

Simulink Interface, 2-57


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

2.6 Graphical Interface Summary


This section gives an overview of the graphich user interface. Here we describe the Simcenter Amesim
library, the main window and its icons and buttons, the run parameters window for the Standard
interface, the run parameters window for the co-simulation interface, and the model parameters
window for the co-simulation interface.

Note:
The interface is only available if you are using MATLAB version r2008a or higher.
MATLAB must be started from Simcenter Amesim.

2.6.1 Simcenter Amesim Library

This library is available in the Simulink library browser when you start Simulink:

Figure 2-61. The Simcenter Amesim Interfaces library

The library contains two blocks:

• The AME2SL block designed for the standard interface (import of Simcenter Amesim models into
Simulink).

• The AME2SLCoSim block designed for the co-simulation interface between Simcenter Amesim and
Simulink.

2-58 Simulink Interface,


© 2021 Siemens
The Main Window

Figure 2-62. Simcenter Amesim blocks

Note:
Deleting the Simcenter Amesim block or closing the Simulink subsystem containing the block
closes all windows of the graphical interface.

2.6.2 The Main Window

You can access the main window by double-clicking on the Simcenter Amesim blocks. Its main utility is
to:

• select the Simcenter Amesim model with which to interface,

• start tool windows.

This window contains a toolbar containing five icons:

Icon Function Description

Open file Select the Simcenter Amesim model with which to interface.
The file selected is the mex file produced by Simcenter
Amesim.

Run parameters Open the Run parameters window.

Model parameters Open the Model parameters window.

Enable/Disable inputs Inputs and outputs management.


and outputs

Create black-box mask Create a Black-Box. This is only available for the standard
interface.

The window aslo contains the following:

Simulink Interface, 2-59


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

• The Update model button, which you can use to load the Simcenter Amesim model. It can be used
at anytime, and is very useful when the Simcenter Amesim model has been modified and needs to
be updated in Simulink.

• An edit box to set the name of the Simcenter Amesim model with which to interface. This is an
alternative method to using the File open icon for selecting the Simcenter Amesim model.

2.6.3 Run Parameters Window for the Standard Interface

This window is available by clicking on the Run parameter window icon in the main window. This
window shows the tunable run parameters for the standard interface:

• The Create result file option, with which you can enable/disable creation of the result file.

• The Print interval, an editable field to set the print interval for the result file.

Figure 2-63. Run parameters

Additionally, the Get Simcenter Amesim parameters button can be used to load the print interval
defined in Simcenter Amesim

2.6.4 Run Parameters Window for the Co-Simulation Interface

This window is available by clicking on the Run parameter window icon in the main window. This
window shows the tunable run parameters for the co-simulation interface:

• Integrator type (standard or fixed step).

• General co-simulation parameters such as Sample time

• Standard integrator parameters

• Fixed-step integrator parameters

2-60 Simulink Interface,


© 2021 Siemens
Model Parameters Window for the Co-Simulation Interface

Figure 2-64. Run parameters

Additionally, the Get Simcenter Amesim parameters button can be used to load the run parameter set
defined in Simcenter Amesim.

2.6.5 Model Parameters Window for the Co-Simulation Interface

This window is available by clicking on the Model parameter window icon in the main window. This
window shows the tunable global parameters defined in the Simcenter Amesim model:

Simulink Interface, 2-61


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

Figure 2-65. Model parameters

This window contains:

• An array box to edit the value of global parameters. The tunable parameters available are:

• All real parameters that are non-dependent on an expression

• All integer parameter that are non-dependent on an expression

• All text parameters

• The Get Simcenter Amesim parameters button, which you can use to load the global parameter set
defined in Simcenter Amesim. This is useful when the global parameter set has been modified in
Simcenter Amesim and must be updated in Simulink.

• The Set default values button, which you can use to set all parameters to their default values.

2.7 Importing into Simulink Without Using the Simcenter Amesim


Library
Exporting Simcenter Amesim models to Simulink is possible without using the Simcenter Amesim
library. It is mandatory if you are using MATLAB version r2008a or older.

All steps in Simcenter Amesim to set the interface block and generate the model interface are the same
as presented in preceding section, the only differences in the process are on the Simulink side.

2.7.1 Importing a Simcenter Amesim Model for the Standard Interface

Once again, we strongly recommend that you start MATLAB from Simcenter Amesim to automatically
inherit the environment. Simcenter Amesim models must remain open in Simcenter Amesim during
the process.

Assuming that the Simcenter Amesim model is named skyhook, the best way to create the S-Function
used to import the Simcenter Amesim model is to use a dedicated MATLAB script amecreatemask such
as:

2-62 Simulink Interface,


© 2021 Siemens
Importing a Simcenter Amesim Model for the Standard Interface

The first parameter is the name of a Simulink submodel which does not yet exist. The second parameter
is the Simcenter Amesim model name.

The result of the script is the creation of a Simulink submodel named SimulinkImport which includes
the S-Function to import the Simcenter Amesim model.

The name of the input and output are not set yet. To do this, it is necessary to run the submodel in
Simulink once. After this dummy simulation of the submodel, the name of IO is set on the S-Function.

The run and global parameters are available by double clicking on the S-Function.

Simulink Interface, 2-63


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

S-Function Parameter Description

Using the model hydraulic presented in Importing Black-box models into Simulink using
amecreatebbmask command, the S-Function produced after the call to amecreatemask is shown below;
we also present the S-Function parameters created by the script for this particular example. The mask
parameters are presented in the S-Function Mask Parameters after call to amecreatemask figure.

Figure 2-66. S-Function Parameter Description

Figure 2-67. S-Function Mask Parameters after call to amecreatemask

2-64 Simulink Interface,


© 2021 Siemens
Importing Simcenter Amesim Model for Co-Simulation Interface

2.7.2 Importing Simcenter Amesim Model for Co-Simulation Interface

Once again, it is strongly recommended to start MATLAB from Simcenter Amesim to automatically
inherit the environment. Simcenter Amesim models must remain open in Simcenter Amesim during
the process.

Assuming that the Simcenter Amesim model is named skyhookcosim, the best way to create the S-
Function used to import the Simcenter Amesim model is to use a dedicated MATLAB script
amecreatecosimsfunmask such as:

Simulink Interface, 2-65


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

The first parameter is the name of a Simulink submodel that does not exist yet. The second parameter is
the Simcenter Amesim model name.

The result of the script is the creation of a Simulink submodel named SimulinkCosim which includes
the S-Function importing the Simcenter Amesim model.

The name of the input and output are not set yet. To do, it is necessary to run the submodel in Simulink
one time. After this dummy simulation of the submodel, name of IO are set on the S-Function.

The run and global parameters are available by double clicking on the S-Function.

2-66 Simulink Interface,


© 2021 Siemens
Importing Simcenter Amesim Model for Co-Simulation Interface

Figure 2-68. Run and global parameters

S-Function Parameter Description

Using the model hydraulic presented in Importing Black-box models into Simulink using
amecreatebbmask command with a co-simulation interface, the S-Function produced after the call to

Simulink Interface, 2-67


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

amecreatecosimsfunmask is shown in the Function parameters after the call to


amecreatecosimsfunmask figure. Here we also present the S-Function parameters created by the script
for this particular example.

Figure 2-69. S-Function parameters after call to amecreatecosimsfunmask

Figure 2-70. Function parameters after the call to amecreatecosimsfunmask

2-68 Simulink Interface,


© 2021 Siemens
Importing a Simcenter Amesim Model for a Standard Interface Using a Black-Box

2.7.3 Importing a Simcenter Amesim Model for a Standard Interface Using a


Black-Box

Once again, it is strongly recommended to start MATLAB from Simcenter Amesim to automatically
inherit the environment. Simcenter Amesim models must remain open in Simcenter Amesim during
the process.

Assuming that the Simcenter Amesim model is named skyhook, the best way to create the S-Function
used to import the Simcenter Amesim model is to use a dedicated MATLAB script amecreatebbmask
such as:

The first parameter is the name of a Simulink submodel that does not exist yet. The second parameter is
the Simcenter Amesim model name.

The result of the script is the creation of a Simulink submodel named SimulinkBB which includes the S-
Function that imports the Simcenter Amesim model.

Simulink Interface, 2-69


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

The name of the input and output are not set yet. To do so, it is necessary to run the submodel in
Simulink once. After this dummy simulation of the submodel, name of the IO is set on the S-Function.

The global parameters are available by double clicking on the S-Function.

S-Function Parameter Description

Using the model hydraulic presented in Importing Black-box models into Simulink using
amecreatebbmask command with a co-simulation interface, the S-Function produced after the call to
amecreatebbmask is shown in the following figure. We also present the S-Function parameters created
by the script for this particular example. The mask parameters are presented in the S-Function Mask
Parameters after call to amecreatebbmask figure.

2-70 Simulink Interface,


© 2021 Siemens
Importing a Simcenter Amesim Model for a Standard Interface Using a Black-Box

Figure 2-71. S-Function Parameters after call to amecreatebbmask

Figure 2-72. S-Function Mask Parameters after call to amecreatebbmask

Simulink Interface, 2-71


© 2021 Siemens
2. Using the Simcenter Amesim to Simulink Interface

2-72 Simulink Interface,


© 2021 Siemens
3. Using the Simulink to Simcenter Amesim
Interface
The Simulink to Simcenter Amesim interface enables you to construct a model of a subsystem in
Simulink and to import it to a Simcenter Amesim submodel.

In SL2AMECosim, "SL2AME" stands for "Simulink to Simcenter Amesim" interface. This interface enables
you to export a Simulink model to Simcenter Amesim.

The Simulink to Simcenter Amesim interface creates C code from a Simulink model using the
Simulink Coder. The C code is generated in such a way that it can be used in Simcenter Amesim as a
normal submodel.

Due to the existing limitations of the Simulink Coder, the generated submodel code will use the fixed-
step Simulink solver.

This method (co-simulation) is robust and not very sensitive to changes in the Simulink Coder. See
Requirements for more details regarding SL2AMECosim. During the code export, some parameters of
the Simulink model can be hidden. This means that it is possible to generate "black box" type submodels
for Simcenter Amesim.

Note:
The Simulink to Simcenter Amesim interface is not compatible with the Continuation Run
feature. Indeed, due to a Simulink Coder limitation, it is not possible to start simulations of
imported Simulink models (SL2AMECosim blocks) at initial values other than 0.

3.1 Using the SL2AMECosim interface - Co-simulation Mode


The following sections present the three main steps in using the SL2AMECosim interface:

Simulink Interface, 3-1


© 2021 Siemens
3. Using the Simulink to Simcenter Amesim Interface

• Preparing the Simulink model

• Generating the code

• Creating a Simcenter Amesim submodel from the exported code

3.1.1 Preparing the Simulink model

In most cases, the only preparation work should be to add input and output blocks to the Simulink
model. These I/O blocks should correspond to the interface you want to provide in Simcenter Amesim.
Note that in versions of MATLAB older than 2011a the names of the input/output ports are not exported
to the Simcenter Amesim model.

One important rule (that may be eliminated in later versions) is that the input/output variables must be
scalar and of type double.

Warning:
Only fixed step solvers can be used (the "auto mode" is not allowed: the solver itself and its step
size need to be defined before running the SL2AMECosim script).

Note:
SL2AMECosim is similar to the GRT-Malloc target. Some Simulation parameters and generated
code options have an effect on the generated code and its compatibility with Simcenter Amesim.
The optimization and configuration hints and remarks applicable for GRT targets, which are
described in The Real Time Workshop User's Guide (The Mathworks), are also applicable for
SL2AMECosim.

3.1.2 Generating the code - SL2AMECosim

Automatic export

For people who are not familiar with Simcenter Amesim categories and icon organization, there is a
fully automatic export option.

3-2 Simulink Interface,


© 2021 Siemens
Generating the code - SL2AMECosim

>> sl2amecosim('relay','C:\AMETest\libsl2ame','auto')

With the 'auto' option, Simcenter Amesim takes care of the creation of an icon automatically. This is
the ‘short’ way of running the command which takes care of the following:

• Submodel C, SPE and Help files (and compiling the submodel).

Note:
The C code does not contain the actual Simulink model.
It is possible to edit the generated submodel with Submodel Editor in order to make minor
cosmetic updates.

• Library (LIB) file containing the actual Simulink model.

• AME.make file instructing Simcenter Amesim to link with the generated library.

• The new category icon if not available (SL2AME by default).

• The new component icon with the proper number and type of ports (if not available) with a name
indicating the number of inputs/outputs.

• The submodels.index and AMEIcons files (if not available)

All these files will be stored in themysl2amelib directory where the command is run. As you can edit the
submodel using Submodel Editor, it is easy to change icons etc.

Advanced export

To allow greater control over the export process, there are some additional arguments that can be used.
You can also link the exported model to an existing component icon instead of creating a new one. In
order to achieve this, you must specify the icon name instead of the ‘auto’ argument.

The full syntax is:

>> sl2amecosim(‘system’,’C:\library’,’icon’,’codegenoptions’, debug)

This command exports a C code for system.mdl and links it to the icon of the Simcenter Amesim
component library located in C:\library. The generated code is compiled in debug mode if debug equals
one.

The systemname, library and iconname are mandatory. Very little is verified in terms of compatibility
between the Simulink model and the provided icon name. It is up to the user to verify that the number
and type of I/O ports of the Simcenter Amesim component icon and the Simulink model are
compatible.

Simulink Interface, 3-3


© 2021 Siemens
3. Using the Simulink to Simcenter Amesim Interface

The codegenoptions is a text string containing one or both of hide_params or hide_vars. This can be
used for completely hiding the internal parameters and variables in the Simulink system. This makes it
possible to send sensitive/confidential models to clients or providers.

The debug flag is also optional. RTW’s verbose flag is forced to on in debug mode, and the generated
code is compiled in debug mode. Note that if the RTW verbose flag is set to on, it will never be forced to
off by SL2AMECosim

A normal standard output (with RTW Verbose set to off) is similar to the following example:

>> sl2amecosim('relay','here', 'auto', '')

====> STARTING SL2AMECOSIM CODE GENERATION FOR MODEL RELAY...


====> Step #1: Checking system and model...
====> Step #2: Generating code & building OBJ file
### Starting build procedure for model: relay
### Successful completion of build procedure for model: relay
====> Step #3:
====> Step #4: Restoring initial model configuration
====> Step #5: Create Simcenter Amesim submodel - and compile it
Solvername = 'FixedStepDiscrete'
Stepsize=0.001
1 inputs
1 outputs
4 numrealparams
2 numintparams
0 numbiosignals
1 tot num inputs
1 tot num outputs
0 : relay/In1
0 : relay/Out1

Submodels Windows compilation batch file.

-----------------------------------------------------------------------
This batch file is to automate the compile procedure for submodels
or other userwritten C files using the Microsoft Visual C++ compiler.

-----------------------------------------------------------------------

- Will compile the following file(s):


RELAY.c
cl -nologo -MT -W3 -EHsc -wd4996 -fp:precise -DWIN32 -DNDEBUG
-D "_WINDOWS" -D "_MBCS"
-c RELAY.c -Fowin32\

3-4 Simulink Interface,


© 2021 Siemens
Importing the generated code into Simcenter Amesim-Co-simulation Mode

RELAY.c
Submodel build completed!

INFO: found Icons/sl2ame.ico in here/AMEIcons


====> Step #6: Adding model to here/Icons/sl2ame.ico
WARNING : SubModel already referenced for this Icon. Updating
files...
The option for reusing signal storage is active.
This will reduce the number of variables in the AMESim submodel.
The option for block reduction is active.
This will reduce the number of variables in the AMESim submodel.
The option for Parameter Pooling is active.
This will reduce the number of parameters in the AMESim submodel.
====> SL2AMECOSIM CODE GENERATION FOR MODEL RELAY FINISHED
SUCCESSFULLY.

In Step 2 there will be a lot of messages about compilation etc. if the RTW options are set to verbose for
the model.

Step 5 generates and compiles the actual Simcenter Amesim submodel. The messages here can be
useful for understanding how the generated submodel is set up. Information is displayed about the
solver used and the stepsize. Note that in this case a version of MATLAB is used that can extract the
information about input/output variable names. The term biosignals is short for block input/output
signals which are the variables internal to the Simulink system.

In Step 6 some messages about the current options are displayed. Most of them must be considered as
normal. They transmit useful information to allow verification that the options used (such as the
absence of inputs, outputs, states, parameters or block I/O etc.) are what were intended. In most cases,
they do not require any corrective action.

As the code generation process makes temporary modifications to the Simulink model the model will
typically be closed and reopened in the process. This is done to ensure that any modifications are really
temporary. This also means that the Simulink model must be saved before the SL2AMECosim process is
started.

3.2 Importing the generated code into Simcenter Amesim-Co-


simulation Mode
Once the created submodel has been added to the Simcenter Amesim category, you can use the
exported model in Simcenter Amesim as a normal Simcenter Amesim submodel.

Remember to add the path to the new category (for instance C:\AMETest\libsl2ame) to your Simcenter
Amesim path list (accessible from the Sketch menu).

Simulink Interface, 3-5


© 2021 Siemens
3. Using the Simulink to Simcenter Amesim Interface

The automatically-created category is present in the Library Tree:

Figure 3-1. The category in the Library Tree

Figure 3-2. Using the exported model

The exported submodel has the same number of input ports as there are input blocks on the Simulink
root diagram. The same rule is valid for the output ports.

The current version of SL2AMECosim only supports scalar input/output blocks. The main reason for this
is that there are very few submodels in Simcenter Amesim with vector ports.

3-6 Simulink Interface,


© 2021 Siemens
Importing the generated code into Simcenter Amesim-Co-simulation Mode

The parameters of the exported submodel are the parameters available in the Simulink blocks plus one
additional integer parameter.

This integer parameter is called undersample - the Simulink system will use the fixed step solver step
that was specified in Simulink (you can check the generated help file to see the step size used). By
default the Simcenter Amesim model will exchange with the Simulink model every Simulink time step
- and generate a Simcenter Amesim discontinuity. Using this parameter it is possible to let the Simulink
solver take several steps between each communication with Simcenter Amesim, thus reducing the
number of generated discontinuities.

Figure 3-3. The Change Parameters window

After a simulation, you have access to the following variables for plotting:

• inputs

• outputs

• I/O blocks

Simulink Interface, 3-7


© 2021 Siemens
3. Using the Simulink to Simcenter Amesim Interface

Note:
The input/output variables will get their names from the Simulink sketch if MATLAB 2011a or
later is used. In older versions of MATLAB a generic name will be used.

Figure 3-4. The variables

The generated submodel has a special help file (*.html) that is directly accessible via the Help buttons in
the Parameter List and Variable List dialog boxes.

3-8 Simulink Interface,


© 2021 Siemens
SL2AMECosim advanced topics

Figure 3-5. Help

The quantity of parameters or variables available depends on the code generation options (see
SL2AMECosim advanced topics and refer to the Real Time Workshop User's Guide).

3.3 SL2AMECosim advanced topics


By default, the exported model gives access to all inputs, outputs, parameters and variables between
Simulink blocks (block I/O). Note that for large Simulink models with more than 1000 block I/O
variables these are automatically hidden. The same limit (1000) is valid for parameters. In SL2AMECosim
an option is provided to hide all parameters and/or all variables. To reduce the number of variables, you
can use the reuse block I/O and similar options in the RTW configuration. To reduce the number of
parameters, use the tunable parameters option in RTW.

Simulink Interface, 3-9


© 2021 Siemens
3. Using the Simulink to Simcenter Amesim Interface

3.3.1 Hiding input and output blocks

Block I/O variables are the input and output from blocks in the Simulink model. An option exists in
SL2AMECosim to completely hide these "internal" variables. If the option hide_vars is passed to the
SL2AMECosim command all block I/O will be hidden. This can be useful if there are confidential
information in the model - or simply if the internal workings of the model is not interesting/useful for
the end user. In the example below the signal from the "Transfer Fcn1" is a "block I/O" variable.

As the resulting Simcenter Amesim system has several input output variables, we will need to consider
how Simcenter Amesim numbers its ports. Simcenter Amesim starts its numbering at the bottom left
corner of the icon and counts counterclockwise. SL2AMECosim will always place the output on the left
side of the icon. So in this case the created submodel will have the ports as indicated in the figure
below. The first output is thus on the bottom of the right side. You can open the External Variables
popup to see the ports. If you hover the mouse cursor over a port you can see the variable name.

3-10 Simulink Interface,


© 2021 Siemens
Hiding input and output blocks

The extended names of the block I/O signals are available in the help for the generated submodel. In the
help you can also clearly see the names of the variables on the ports. Note again the port numbering.

Simulink Interface, 3-11


© 2021 Siemens
3. Using the Simulink to Simcenter Amesim Interface

3-12 Simulink Interface,


© 2021 Siemens
Hiding input and output blocks

You can hide some of the I/O blocks via signal storage optimization using the options Signal storage
reuse and enable local block outputs.

This reduces the number of I/O blocks in the model at code generation stage. To completely hide the
internal variables use the hide_vars option.

>> sl2amecosim('relayAndMore','here', 'auto', 'hide_vars')

This will create a submodel (in a directory called "here") without internal variables - see figure below.

Simulink Interface, 3-13


© 2021 Siemens
3. Using the Simulink to Simcenter Amesim Interface

3.3.2 Hiding parameters

By default, all parameters of the Simulink model that RTW consider "tunable" are accessible in the
exported Simcenter Amesim submodel. Note that some parameters are "structural" and not accessible.

Here we use the extended example from the previous section (relayandmore.mdl). Note that the
number of delays are not accessible (structural) and that the coefficients for the transfer function have
been rewritten to refer to a statespace formulation.

3-14 Simulink Interface,


© 2021 Siemens
Hiding parameters

In order to make the model simpler to use, you can hide some of the parameters by using the Tunable
parameters option in RTW (using workspace variables).

Simulink Interface, 3-15


© 2021 Siemens
3. Using the Simulink to Simcenter Amesim Interface

Figure 3-6. Hiding parameters through the tunable (workspace) variables

By selecting Inline parameters and clicking on the Configure button you can select the workspace
variables which are to be accessible in Simcenter Amesim and add these variables to the Tunable
parameters list.

3-16 Simulink Interface,


© 2021 Siemens
Hiding parameters

Figure 3-7. Adding workspace variables to the Global parameters list

All the other parameters will be hidden in the exported model.

Simulink Interface, 3-17


© 2021 Siemens
3. Using the Simulink to Simcenter Amesim Interface

3.3.3 Advanced hiding I/O and parameters

Advanced options of SL2AMECosim are only available when using MATLAB version R2014b and higher.

Advanced options are available to hide or show block signals and block parameters. Block I/O and
parameters can be filtered against a specific Simulink TAG block and/or dimension.

The advanced option line is decomposed as shown below:

[<optFilterVar>] [<optFilterParam>] [tag_bio=<TagVarName>]

[tag_param=<TagParamName>] [maxdimension=<dimMax>]

Table 3-1. Option optFilterVar value

Value Description

show_vars Show all block I/O variables without any


restrictions (default value).

hide_vars Hide all block I/O variables without any


restrictions.

hide_tagged_vars Show all block I/O variables but block tagged


ones.
The tag_bio option is required.

show_tagged_vars Hide all block I/O variables but block tagged


ones.
The tag_bio option is required

Table 3-2. Option optFilterParam value

Value Description

show_params Show all block parameters without any


restrictions (default value).

hide_params Hide all block parameters without any


restrictions.

hide_tagged_params Show all block parameters but block tagged


ones.

3-18 Simulink Interface,


© 2021 Siemens
Advanced hiding I/O and parameters

Value Description

The param option is required.

show_tagged_params Hide all block parameters but block tagged ones.


The param option is required.

Note:
Only one TAG value for signal filtering and one TAG for parameter filtering can be used at the
same time.

Table 3-3. SL2AMECosim command examples

Command Filtering

sl2amecosim('relayAndMore','here', 'auto') No filtering, everything will be exposed.

sl2amecosim('relayAndMore','here', 'auto' No filtering, everything will be exposed.


‘show_vars show_params’)

sl2amecosim('relayAndMore','here', 'auto' All block I/O variables will be hidden.


‘hide_vars’)
All parameters will be exposed.

sl2amecosim('relayAndMore','here', 'auto' All block I/O variables will be hidden.


‘hide_vars hide_params’)
All parameters will be hidden.

sl2amecosim('relayAndMore','here', 'auto' All block I/O variables will be shown except those
‘hide_tagged_vars show_tagged_params of blocks tagged T1.
tag_bio=T1 tag_param=T2’)
All parameters will be hidden except those of
blocks tagged T2.

sl2amecosim('relayAndMore','here', 'auto' All block I/O variables will be hidden.


‘hide_vars maxdimension=2’)
All parameters with dimension>2 will be hidden.

Note:
A tag set on a subsystem block is applied automatically on all included blocks in this subsystem.
Therefore filtering a subsystem block is equivalent to filtering its constituents.

Simulink Interface, 3-19


© 2021 Siemens
3. Using the Simulink to Simcenter Amesim Interface

3.3.4 Known limitations

This section should help you working around the few SL2AMECosim limitations.

Data typing

Due to the reuse of the generated code in Simcenter Amesim, all interfaced data must be of type
double. See Preparing the Simulink model. Note also that the interfaced data must be scalar (this limit
might be removed in future versions).

This applies to inputs and outputs to the model - you must ensure that the data type is double on the
input and output blocks. Parameters and internal variables can be of integer types, illustrated by the
example below where the gain in the gain block is of integer type. The generated code will translate
integer type (for example uint8, int8, int16 etc.) parameters into Simulink to integer parameters in
Simcenter Amesim. Floating type parameters (single and double) will be mapped to Simcenter
Amesim real parameters.

Note that no special type limit check is made on integer parameters. As a consequence it is possible to
set an int8 parameter to values exceeding the range [-127:127], the results are not defined.

As Simcenter Amesim variables can only be of type double, all variables in the Simulink model will be
converted to double. This can (in some extreme cases) cause round-off issues.

3-20 Simulink Interface,


© 2021 Siemens
Tutorials

External mode

External mode is an RTW feature that enables the user to control the code execution with a GUI, like the
Simulink model graphical interface.

This has been disabled for SL2AMECosim.

Data logging

In a Simulink model, you can specify that you want to save data, such as inputs, outputs and states to
the workspace (or disk). This feature has been disabled for SL2AMECosim. Simcenter Amesim
proposes a similar one, and gives access to those variables.

3.4 Tutorials
This section provides tutorials to help you get familiar with the Simcenter Amesim-Simulink interface.

Simulink Interface, 3-21


© 2021 Siemens
3. Using the Simulink to Simcenter Amesim Interface

Note:
Please be sure to consult the Concluding remarks and FAQs section of this manual which provides
the solutions to many of the problems you may encounter when using the Simulink interface.

3.4.1 One-level voltage source

Model presentation

The following diagram represents the one-level voltage source we intend to model with a Simulink
block diagram and to export to Simcenter Amesim.

Figure 3-8. One-level voltage source

This model requires 3 input and 2 output ports. The currents [A] are input at ports 1 and 2. A
dimensionless control signal [null] is input at port 3. V1 [V] and V2 [V] are computed by the model and
output signals at ports 1 and 2.

The transistor model is represented using a variable resistor:

• If control = 0, R is set to 1e8 Ohm

• If control != 0, R is set to Rt

3-22 Simulink Interface,


© 2021 Siemens
One-level voltage source

Two very small 'virtual' capacitors C1 and C2 have been added to the circuit for numerical reasons. This
makes it possible to compute the derivative of the voltages at port 1 and 2.

The equations used are presented hereafter:

The voltages V1 and V2 are state variables. They are computed from their derivative with respect to time
as:

The corresponding Simulink model is presented in the following block diagram:

Simulink Interface, 3-23


© 2021 Siemens
3. Using the Simulink to Simcenter Amesim Interface

The Simcenter Amesim model is named voltage_source_and_DC.ame. The model parameters have
been defined using global parameters from the MATLAB workspace:

Where:

• > [V] ' voltage source Vs

• Rs [Ohm] ' source resistor

• Rd [Ohm] ' extinction resistor

• Rt [Ohm] ' transistor resistor

• Vz [V] ' Zener diode extinction voltage

• C1 [F] ' first virtual capacitor

• C2 [F] ' second virtual capacitor

The model also requires two initial conditions for the voltage state variables (V10 and V20).

On the Simulink block diagram, the input blocks are green and the output blocks are blue.

3-24 Simulink Interface,


© 2021 Siemens
One-level voltage source

The blocks using global parameters from the workspace are red. In order to load these global parameters
into the MATLAB workspace an M-script is created (voltage_source_initialization.m).

This m-file should be run before SL2AMECosim.

Code export from Simulink to Simcenter Amesim

The following steps enable you to export the Simulink block diagram of the one-level voltage source to
Simcenter Amesim.

1. Get the voltage_source_and_DC.ame model, available in through Help > Get demo in the Platform
> MiLSiLRealTime > MiLSiL > SimulinkAmesim folder. This model is available from the
VoltageSource.pck pack file:

Simulink Interface, 3-25


© 2021 Siemens
3. Using the Simulink to Simcenter Amesim Interface

This gives access to the voltage_source.mdl model and the voltage_source_initialization.m files.

2. Within MATLAB, run the voltage_source_initialization.m script in order to load the global
parameters in the MATLAB workspace.

3. Open the voltage_source.slx model, click on the Simulation menu and choose Configuration
parameters.

4. Select Optimization, tick the Inline parameters box and click on the Configure button.

3-26 Simulink Interface,


© 2021 Siemens
One-level voltage source

Figure 3-9. Configure button

5. Add the workspace variables to the global parameters table.

6. Save the Simulink model.

7. In the MATLAB command window, type:

sl2amecosim('voltage_source','c:\AMETest\libsl2ame','auto');

where C:\AMETest\libsl2ame is the directory where you intend to save the SL2AMECosim
category.

8. The model export is now completed and a new submodel VOLTAGE_SOURCE should be available in
the libsl2ame category. Add this new category to the Simcenter Amesim path list.

Simulink Interface, 3-27


© 2021 Siemens
3. Using the Simulink to Simcenter Amesim Interface

9. Now you can use and test the voltage source model by connecting it to a DC motor built with the
signal and mechanical libraries (voltage_source_and_DC.ame)

The parameters and the variables of the exported submodel are presented hereafter.

3-28 Simulink Interface,


© 2021 Siemens
One-level voltage source

The validation of the exported model can be done through direct comparison with an equivalent model
built in Simulink or Simcenter Amesim. The following comparison has been made using the

Simulink Interface, 3-29


© 2021 Siemens
3. Using the Simulink to Simcenter Amesim Interface

voltage_source_and_DC_vs_EMD.ame model, available in the Simcenter Amesim Infrastructure >


Interfaces > SimulinkAmesim folder.

3-30 Simulink Interface,


© 2021 Siemens
Force control in semi-active car damper

3.4.2 Force control in semi-active car damper

Figure 3-10. Symbolic representation of a semi-active suspension

Model presentation

The Simulink model force_control_law.slx represents the control law used to compute the valve
opening section which gives the desired force in the semi-active damper.

This model requires 2 input ports (green) and 1 output port (blue). The Simulink blocks using global
parameters are represented in red. The model also uses one lookup table.

Simulink Interface, 3-31


© 2021 Siemens
3. Using the Simulink to Simcenter Amesim Interface

The MATLAB script force_control_law_initialization.m can be run in order to load the global parameters
in the workspace automatically.

Code export from Simulink to Simcenter Amesim

The following steps allow you to export the Simulink block diagram to Simcenter Amesim.

1. Get the demo force_control_flowvalve.ame from the Platform > MiLSiLHiLRealTime >
SimulinkAmesim folder. This model is available in the ForceControl.pck pack file:

3-32 Simulink Interface,


© 2021 Siemens
Force control in semi-active car damper

This gives access to the force_control_law.slx model and the force_control_law_initialization.m


script.

2. Within MATLAB, run the force_control_law_initialization.m script in order to load the global
parameters in the MATLAB workspace.

3. Open the force_control_law.slx model, click on the Simulation menu and choose Configuration
parameters.

4. Select Optimization, tick the Inline parameters box and click on the Configure button.

Simulink Interface, 3-33


© 2021 Siemens
3. Using the Simulink to Simcenter Amesim Interface

Figure 3-11. Configure button

5. Add the workspace variables you want to access in Simcenter Amesim to the global parameters
table.

Figure 3-12. Global parameters table

6. Save the Simulink model.

3-34 Simulink Interface,


© 2021 Siemens
Force control in semi-active car damper

7. In the MATLAB command window, type:

sl2amecosim('force_control_law','C:\AMETest\libsl2ame','auto');

Where C:\AMETest\libsl2ame is the directory where you intend to save the SL2AME category.

The model export is now completed and a new submodel FLOW_CONTROL_LAW should be
available in the libsl2ame category.

8. Now you can use and test the exported model (force_control_law.ame).

Simulink Interface, 3-35


© 2021 Siemens
3. Using the Simulink to Simcenter Amesim Interface

The parameters of the exported submodel are presented in the following chart:

3-36 Simulink Interface,


© 2021 Siemens
Conclusions

Validation of the exported model can be done through direct comparison with the standard demo
example ClosedLoopControl.ame which can be loaded from the Simcenter Amesim Help menu: Help >
Get Demo > Solutions > Automotive > Chassis.

3.5 Conclusions
SL2AMECosim has been designed to be as easy as possible to use. Of course, it is highly recommended
to test the exported model thoroughly in Simcenter Amesim and to compare the results from Simulink
and Simcenter Amesim. Remember that solver and discontinuity handling are different in Simcenter
Amesim and Simulink.

In order to make the model easier to use, we recommend replacing the component icons generated by
SL2AMECosim with more explicit icons created with Simcenter Amesim's Icon editor. Another
suggestion is to create a supercomponent to wrap around the generated submodel. This would, for
example, allow you to add ‘physical ports’.

Simulink Interface, 3-37


© 2021 Siemens
3. Using the Simulink to Simcenter Amesim Interface

3-38 Simulink Interface,


© 2021 Siemens
4. Concluding remarks and FAQs
This manual has presented a simple example to introduce the use of the Simulink interface. Before you
start developing your own models, we now summarize the most important points.

• The input of the interface block in Simcenter Amesim has its ports in reverse order compared with
Simulink.

• Remember to change from Parameter to Simulation mode in Simcenter Amesim before running the
simulation in Simulink or to use File > Write aux. files.

• For systems using the AME2SLCosim (Co-Simulation) interface, it is important to remember the
following:

• The Simcenter Amesim block is seen as a discrete block from Simulink.

• The parameters to the S-Functions are as shown in the table in Usage of the co-simulation
interface, and they are not the same as the parameters for the standard interface.

• For systems using the AME2SL (Model Exchange) interface the following points are important:

• The Simcenter Amesim model must be explicit i.e. there cannot be any implicit variables. The
reason for this is that the Simulink integrators can handle only ordinary differential equations.

• Users of previous versions of the Simcenter Amesim-Simulink interface should notice that the
output dealing with discontinuities (Hit Crossing) has been removed.

4.1 Common problems and their solutions


This section presents some common problems and their solutions.

4.1.1 Open-loop simulations for basic model checks

As an alternative to using signal sinks and sources as replacements for interface blocks to verify that
your model runs correctly (or can at least be initialized) with its current configuration and resources
(typically tables), you can temporarily change the interface type to Open-loop simulation in the
Interface status display dialog box.

Simulink Interface, 4-1


© 2021 Siemens
4. Concluding remarks and FAQs

Figure 4-1. Interface status display

Note:
You can open this dialog box in Sketch mode through the Interfaces menu.

This function allows you to perform minimal checks on the model by deactivating the connection with
the companion tool without having to remove and replace the interface blocks.

Note:
Zeros are sent to the model inputs (the interface block's outputs) when you perform an open-loop
simulation. However, null inputs may not be suitable for some models. To resolve this issue, you
may need to override these zeroes with more meaningful values. You can do this simply by
disconnecting the interface block's outputs from your model and reconnecting them to signal
sinks. Then you must reconnect any broken connections to suitable sources and/or time traces
read from one or more table files. You can also use signal switches if you do not want to modify
the sketch when activating or deactivating your chosen interface.

Once you have verified that your model behaves correctly during open-loop simulations, you can switch
back to your chosen interface type to reactivate it.

4-2 Simulink Interface,


© 2021 Siemens
Compilation failure with error message related to the simstruct.h file

4.1.2 Compilation failure with error message related to the simstruct.h file

Versions

All MATLAB versions under Windows.

Situation

• When compiling a Simcenter Amesim system containing interface blocks, the compilation fails and
the following error message is displayed in the System Compilation window:

'... simstruc.h: No such file or directory...' , or

'... Cannot open include file: 'simstruc.h'...'.

Solution

• The file simstruc.h is supplied with the Simulink application and it is stored in a sub-directory of the
MATLAB installation directory. This implies that Simulink must be installed with MATLAB and this is
the first point to check.

• If you get the first message, you must set the MATLAB environment variable so that it points to the
MATLAB installation directory. For more details, please refer to Common requirements.

• If you have the second message, this is because you have installed MATLAB in a directory which has a
blank character in its path (such as Program Files...). In this case, you must uninstall MATLAB and re
install it in a directory whose path contains no blank character.

4.1.3 Compilation window blocked during the first use of the interface

Versions

All MATLAB versions under Windows.

Situation

• The Simcenter Amesim /Simulink interface is used for the first time.

• When compiling the Simcenter Amesim system with Simulink blocks, the compilation window in
Simcenter Amesim seems to be blocked and the following information is displayed:
Select a compiler:
[1] Digital Visual Fortran version 6.0 in C:\Program Files\Microsoft Visual Studio
[2] Lcc C version 2.4 in C:\MATLAB6P5\sys\lcc
[3] Microsoft Visual C/C++ version 6.0 in C:\Program Files\Microsoft Visual Studio
[0] None

Simulink Interface, 4-3


© 2021 Siemens
4. Concluding remarks and FAQs

Solution

Simcenter Amesim is waiting for the user to select a compiler:

1. Right click at the bottom of the compilation window.

A menu labeled Interactive compilation appears.

2. Select this menu.

A blank field appears at the bottom of the compilation window.

3. Type the index corresponding to the Microsoft Visual C++ compiler in this field (3 in this example)
and hit the Enter key.

The compilation starts.

4.1.4 Not possible to run sequential simulations

This used to be a common problem but the solution has been partially automated and fortunately now
is much rarer.

Versions

MATLAB r11, r12 and r13 under Linux and Windows.

Situation

• A Simulink model containing the S-Function corresponding to a Simcenter Amesim model


(.DLL, .mexsol, ...) is opened.

• The first simulation in Simulink works fine.

• When running a new simulation, the following error message ( mdlInitializeConditions) is


systematically displayed:

4-4 Simulink Interface,


© 2021 Siemens
About Simulink numerical solver methods

Solutions

Under most circumstances it is necessary to force Simulink to reload the Simcenter Amesim model for
each new simulation. To avoid any problems, we recommend that you always do this.

One way to achieve this is to clear the Simcenter Amesim mex function from (MATLAB) memory
before starting a new simulation. This can be done in two ways, manually or automatically:

• The manual way is to type "clear mex" or "clear xxxx_" where xxxx is the Simcenter Amesim system
name. This needs to be done before each new simulation starts (or after each simulation).

• In Simulink version 2 and higher it is possible to specify a command to be executed after each
simulation. Taking the Simulink system in the The system ready to run figure as an example we can
type: set_param('skyhook/S-Function','StopFcn','clear skyhook_') at the MATLAB
command prompt. This makes Simulink unload the Simcenter Amesim mex function after each
simulation, and thus forcing it to be reloaded when a new simulation is run.

If the Java interface (MATLAB 6 or higher) is used, a menu item File > Model properties exists in the
Simulink menu bar that does the same thing as the set_param command. In the Simulation stop
function zone add the expression "clear xxxx_" where xxxx is the Simcenter Amesim system name.
Click on the Apply button. Save the Simulink model so that modifications are definitely taken into
account.

4.2 About Simulink numerical solver methods


This section describes the different Simulink numerical solver methods, and their different applications.

Most of the information provided hereafter is intended to provide guidance on solver aspects for using
Simcenter Amesim's Simulink Interface in a simplified way. It is also worth mentioning that this section
mainly addresses the case where Simulink is used for the controls whereas Simcenter Amesim is used
for the plant model. Remember that sometimes the Simulink model can also be a plant model of a
physical system while Simcenter Amesim is used for the controls, which might lead to slightly different
recommendations regarding Simulink solver choices.

Note:
Please refer to the Simulink documentation for more details on the various solver types and
methods supported by Simulink. See also the Performance Analyzer manual for more info on
numerical aspects and computational performance.

4.2.1 Influence of interface modes on the Simulink solver

The following table indicates for each mode of the Simulink interface whether it has an influence on the
Simulink solver or not.

Simulink Interface, 4-5


© 2021 Siemens
4. Concluding remarks and FAQs

Table 4-1. Influence of interface modes on the Simulink solver

Influence
on the
Simulink
Interface mode solver Comments

SL2AMECosim Limited Using this mode will enforce the use of a fixed-step solver for
the Simulink part (see below).
Sometimes, the co-simulation can influence the method to be
selected for the Simulink solver, due to the stability aspects
typically encountered with sampled systems.

AME2SLCosim Limited Sometimes, the co-simulation can influence the method to be


selected for the Simulink solver, due to the stability aspects
typically encountered with sampled systems. If algebraic loops
are formed by the complete coupled system, this also has an
effect on the Simulink solver (see Impact of algebraic loops on
the Simulink solver).

AME2SL Yes (solver Only the Simulink solver will be used to solve the equations of
type and/or both the Simcenter Amesim model and the Simulink model.
settings) So, the dynamics and/or the states introduced by the Simcenter
Amesim model need to be taken into account for selecting the
Simulink solver. Try using the ode15s solver in Simulink,
especially for stiff systems (see Implicit or explicit Simulink
solver (stiff or non-stiff systems) and Simcenter Amesim and
comparable Simulink solver methods for Model Exchange modes
for more details). If algebraic loops are formed by the complete
coupled system, this also has an effect on the Simulink solver
(see Impact of algebraic loops on the Simulink solver).

Note:
The goal of co-simulation is to isolate all the solvers involved such that each of them uses the most
appropriate settings for its system. This is why SL2AMECosim or AME2SLCosim usually have no
influence on individual solver options. However, since the subsystems are coupled, each of them is
seen as discrete by the others and the chosen communication time step can imply a modification
of solver settings if instabilities arise.

• For SL2AMECosim and AME2SLCosim, if co-simulation instabilities are encountered and if adjusting
the co-simulation communication interval is not sufficient, Runge-Kutta methods might be selected
instead of Euler methods for the Simulink solver.

• For SL2AMECosim and AME2SLCosim, it is worth mentioning that connecting the Simcenter
Amesim model to the Simulink model doesn't add any continuous state to the Simulink model. This

4-6 Simulink Interface,


© 2021 Siemens
Simulink solver type: fixed-step or variable-step

is why these two interface modes have no consequence on the choice of a discrete or a continuous
solver for Simulink and only limited influence on other solver aspects.

4.2.2 Simulink solver type: fixed-step or variable-step

Usually, a variable-step solver can significantly shorten the simulation time. Indeed for a given level of
accuracy, it can adjust the step size dynamically and thus reduce the total number of steps.

A fixed-step solver uses a single step size throughout the simulation, which explains why a very small
step can sometimes be required for a given desired level of accuracy. Especially for systems in which
dynamics appear and disappear locally (e.g. if a hydraulic valve opens), this can be very constraining
and inefficient in terms of CPU time.

In Simulink, solver type selection (fixed-step or variable-step) depends on the dynamics of the model -
as in other tools -, but it also depends on the way the model will be deployed. See the following table.

Table 4-2. Simulink solver type for each interface mode

Simulink solver type

Interface mode Fixed-step solver Variable-step solver

SL2AMECosim Not supported (*)

AME2SLCosim

AME2SL

(*) Using the variable-step solver is currently not permitted by Simulink. This is always the case each
time code is generated from a Simulink model.

If the goal is to import into Simulink a Simcenter Amesim model without the Simcenter Amesim
solver embedded into (AME2SL), then the choice between a variable-step and a fixed-step solver for the
Simulink master only depends on the dynamics of the resulting Simcenter Amesim-Simulink model.

Note:
Most Simulink controllers do not require variable step integration due to the presence of low
dynamics or sampled signals in the model.

Note:
The fact that the Simulink solver is always fixed-step if the Simulink control model is used in
Simcenter Amesim is not a limitation for users who want to export the resulting model to a real-

Simulink Interface, 4-7


© 2021 Siemens
4. Concluding remarks and FAQs

time target for which a "direct" export workflow exists (i.e. with no need for the Simulink Coder
between Simcenter Amesim and the target).
A fixed-step solver is indeed necessary for real-time.

4.2.3 Discrete or continuous Simulink solver

The following table indicates when to use a continuous or a discrete Simulink solver.

Table 4-3. Continuous or discrete Simulink solver

Presence of continuous states Discrete or continuous Simulink solver

Some continuous states in the Simulink model Continuous1

Some continuous states in the Simcenter Amesim Continuous1


model while using AME2SL (Model Exchange)

No continuous states in the Simulink model, and No Discrete2


continuous states in the Simcenter Amesim model
while using AME2SL (Model Exchange)

1. This selection is mandatory to prevent errors in Simulink.


2. This selection is automatic in Simulink (both the fixed-step and the variable-step discrete solvers
will be used).

Note:
Continuous states are referred to as explicit state variables in Simcenter Amesim. Checking for
the presence of continuous states within the Simcenter Amesim model is possible via the
Simcenter Amesim compilation window or the State Contribution pane of the Performance
Analyzer.

Note:
In Simulink, trying to use a fixed-step discrete solver for updating or simulating the model raises
an error message in presence of continuous states. This can be a way to check for the presence of
continuous states on the Simulink side.

4.2.4 Implicit or explicit Simulink solver (stiff or non-stiff systems)

A stiff system is a system having extremely different time scales. Implicit solvers provide greater stability
but are computationally more expensive than explicit solvers. This is why a compromise needs to be
found. For in-depth information on the dynamic behavior of your model in Simcenter Amesim, use the
analysis tools listed in the table below.

4-8 Simulink Interface,


© 2021 Siemens
Stiff systems

Table 4-4. Analysis tools for the dynamic behavior of your model

Tools to identify the dynamics of the Simcenter Amesim subsystem

Eigenvalues
Use this tool to identify the frequencies and time constants of your system. Use
several linearization times if you suspect specific local dynamics of appearing in and
disappearing from your model (e.g. opening and closing of a hydraulic valve during
the simulation.

Performance Analyzer
Also performs frequency analysis but additionally provides useful statistics on where
CPU time is spent. High total number of BDF states could mean that your system is
stiff.

The following table indicates when to use an implicit or an explicit Simulink solver:

Table 4-5. Implicit or explicit Simulink solver

System Simulink Solver

Stiff system Implicit (stable)

Non-stiff system Explicit (fast)

Note:
Most of the classic Simcenter Amesim systems are stiff and require an implicit method to
integrate.

4.2.4.1 Stiff systems

Implicit continuous variable-step solvers are especially suited for stiff systems. In Simulink, you can
choose from: ode15s, ode23s, ode23t or ode23tb.

• Start by using ode15s.

• At crude error tolerances, try using ode23s or ode23tb.

• If your model is only moderately stiff or to prevent numerical damping, try using ode23t.

Simulink Interface, 4-9


© 2021 Siemens
4. Concluding remarks and FAQs

Note:
Try to avoid using methods that are not designed for stiff systems on intervals where solutions
change slowly. Indeed, such methods use time steps small enough to capture the fastest possible
change whereas for stiff problems, the solution of interest changes on a much longer time scale.

4.2.4.2 Non-stiff systems

Explicit continuous variable-step solvers are especially designed for non-stiff systems. In Simulink, you
can choose among ode45, ode23 or ode113.

• Usually the best compromise is ode45.

• At crude error tolerances and/or in presence of mild stiffness ode23 can be preferable.

• With stringent error tolerances or for computationally intensive problems, ode113 can be chosen.

Note:
If ode45 fails or is highly inefficient, it can mean that the problem is stiff and thus in need of an
implicit solver.

4.2.5 Choosing a fixed-step Simulink solver (for example, for Real-Time


applications)

Most of the time, a fixed-step continuous solver needs to be selected except if there are no continuous
states in the Simulink system. Otherwise, fixed-step discrete solvers can be envisaged. Typically, the
selection of a fixed-step Simulink solver is necessary for real-time simulations.

To check the solver's accuracy for a small enough step size, you are advised to select ode1 first (n=1),
then to proceed via a binary search technique (n+2 then n+1… See the following figure) to choose the
best compromise between accuracy and computational effort until ode5. Result accuracy can for
instance be verified by comparing with the results obtained with a variable-step solver and/or with those
of a reference model that has not been simplified for real-time purpose.

4-10 Simulink Interface,


© 2021 Siemens
Impact of algebraic loops on the Simulink solver

Figure 4-2. Simulink fixed-step continuous solver selection

4.2.6 Impact of algebraic loops on the Simulink solver

When using AME2SLCosim or AME2SL, connecting the Simcenter Amesim block to the Simulink model
may result in (at least) one algebraic loop generated in the complete coupled model. If this situation
cannot be avoided by changing the Simcenter Amesim/Simulink subsystem decomposition, then the
Simulink Algebraic Loop Solver methods will have to be selected. Please refer to the Simulink
documentation for more information on how to cope with algebraic loops in Simulink.

4.3 Correspondences between Simcenter Amesim and Simulink


solver methods
This section describes correspondences between Simcenter Amesim and Simulink solver methods.

Note:
Most of the principles mentioned for the Simulink solver are still valid for the Simcenter Amesim
solver. However, for the Simcenter Amesim variable-step solver, most of the choices are made
automatically and dynamically among 17 various integration methods. This is a major difference
with Simulink since users usually do not have to worry about solver aspects in Simcenter
Amesim.

• Unlike Simulink, it is possible to benefit from Simcenter Amesim's variable-step solver in a co-
simulation with Simulink (both with AME2SLCosim and SL2AMECosim).

• As for Simulink, AME2SLCosim and SL2AMECosim only have a limited influence on the settings of the
Simcenter Amesim solver, except when instabilities are encountered due to the coupling with the
Simulink system. In cases where implicit variables (algebraic loops) are generated in the Simcenter
Amesim model due to the connection with the Simulink block, adapted integration algorithms are
selected accordingly (DASSL) and automatically. The following figure illustrates what we can see in
the Simcenter Amesim compilation window if such an algebraic loop is created. This information can

Simulink Interface, 4-11


© 2021 Siemens
4. Concluding remarks and FAQs

also be accessed through the State Contribution pane of the Performance Analyzer ("external
constraints" mentioned in the Type column).

Figure 4-3. Algebraic loop on the Simcenter Amesim side

• In the Simcenter Amesim model, generated or declared implicit variables must be avoided in order to
be able to select a fixed-step solver (in other words: the Simcenter Amesim model should only
contain explicit state variables).

• As for Simulink, if co-simulation instabilities are encountered with Simcenter Amesim fixed-step
solver, Runge-Kutta methods might be selected instead of Euler or Adams-Bashforth methods.

4.3.1 Simcenter Amesim and comparable Simulink solver methods for


Model Exchange modes

For the AME2SL (Model Exchange) mode of the Simulink Interface, since a unique solver is used, it can
be interesting to take into account the correspondences between Simcenter Amesim and Simulink
solver methods to maximize the chances that the results will be similar to those obtained by the native
solvers. However, since the assembled model results from the combination of a Simcenter Amesim
model with a Simulink model, its behavior differs from the individual Simulink and Simcenter Amesim
"component" models. Nevertheless, the table below gives an idea of more or less equivalent solvers, in
term types (fixed-step or variable-step), orders of accuracy and stability.

Table 4-6. Simcenter Amesim and Simulink comparable solver methods

Simcenter Amesim solver methods Simulink solver methods

Simcenter Amesim (explicit) fixed-step solver with ode1 (Euler's method)


Euler method

Simcenter Amesim (explicit) fixed-step solver with ode2 (Heun's method of order 2),
Runge-Kutta method of order 2, 3 and 4
ode3 (Bogacki-Shampine Formula of order 3),
ode4 (Runge-Kutta method of order 4)

Simcenter Amesim (explicit) fixed-step solver ode2 (Heun's method of order 2),
ode3 (Bogacki-Shampine Formula of order 3),

4-12 Simulink Interface,


© 2021 Siemens
Summary for choosing a Simulink solver

Simcenter Amesim solver methods Simulink solver methods

with Adams Bashforth method of order 2, 3 and 4 ode4 (Runge-Kutta method of order 4)

Simcenter Amesim variable-step solver ("standard Non-stiff system: ode45, ode23, ode113
integrator")
Moderately stiff system: ode23t
Stiff system: ode15s, ode23s, ode23tb

Note:
As integration methods are selected automatically and dynamically by the Simcenter Amesim
variable-step solver, some discrepancies might be observed between a Simcenter Amesim system
integrated by Simcenter Amesim or by Simulink.

In cases where algebraic loops are formed by the complete coupled model, these loops are detected by
Simcenter Amesim (SL2AMECosim) or by Simulink (AME2SL or AME2SLCosim). Simcenter Amesim
switches from LSODA to DASSL integration methods whereas Simulink also disposes of specific iterative
methods for resolving algebraic loops. However the names of the Simulink solvers are the same. In co-
simulation modes (AME2SLCosim or SL2AMECosim), these generated algebraic loops have no influence
on the solver embedded in the block that has been imported.

4.3.2 Summary for choosing a Simulink solver

The goal of this section is to help you defining your configuration for selecting a Simulink solver based
on all the previous recommendations.

First, you need to know about the presence of continuous states (explicit state variables in Simcenter
Amesim) in your models, see the following table. You will then be able to know whether you are in a C
or a D situation. Please refer to Discrete or continuous Simulink solver for more details.

Table 4-7. Combinations for continuous states in Simcenter Amesim and Simulink models

Simulink Model

Simcenter Amesim model With continuous states Without continuous states

With continuous states C C

Without continuous states C D

The following table is intended to specify the characteristics of your Simcenter Amesim and Simulink
models. Please refer to Implicit or explicit Simulink solver (stiff or non-stiff systems) for more details.

Simulink Interface, 4-13


© 2021 Siemens
4. Concluding remarks and FAQs

Possible configurations at this point are: C1 to C9 and D1 to D9.

Table 4-8. Combinations for dynamic behavior in Simcenter Amesim and Simulink models

Simulink Model

Simcenter Amesim model Non-stiff Moderately stiff Stiff

Non-stiff C1, D1 C2, D2 C3, D3

Moderately stiff C4, D4 C5, D5 C6, D6

Stiff C7, D7 C8, D8 C9, D9

We will now introduce short notations for interface modes, as described in the table below. Sometimes
indeed, specifying the interface mode will be needed. In the notations of this table, "as" means
"Simcenter Amesim to Simulink", "sa" means "Simulink to Simcenter Amesim", "me" stands for "Model
Exchange" whereas "cs" stands for "co-simulation".

Table 4-9. Short interface mode notations for configurations

Simulink Interface mode Notation

Simulink to Simcenter Amesim SL2AMECosim sacs

Simcenter Amesim to Simulink AME2SLCosim ascs

AME2SL asme

With the following table, you will be able to see what types of Simulink solvers are available for a given
interface mode. Usually and if available, a variable-step solver - "V" - is recommended, except if a fixed-
step solver - "F" - is needed (for instance for real-time applications). See Simulink solver type: fixed-step
or variable-step for more details.

At this point, possible configurations are C1F to C9F, C1V to C9V, D1F to D9F, and D1V to D9V.

Table 4-10. Simulink Solver types available for each interface mode

Simulink Combinations of Simcenter Amesim and


Simulink Interface mode solver type Simulink model characteristics

Simulink to SL2AMECosim Fixed step C1F, …, C9F and D1F, …, D9F or more
Simcenter precisely:
Amesim

4-14 Simulink Interface,


© 2021 Siemens
Summary for choosing a Simulink solver

Simulink Combinations of Simcenter Amesim and


Simulink Interface mode solver type Simulink model characteristics

C1Fsacs, …, C9Fsacs & D1Fsacs,…, D9Fsacs

Simcenter AME2SLCosim Fixed-step C1F, …, C9F and D1F, …, D9F or more


Amesim to precisely:
Simulink
C1Fascs, …, C9Fascs & D1Fascs,…, D9Fascs

Variable-step C1V, …, C9V and D1V, …, D9V or more


precisely:
C1Vascs, …, C9Vascs & D1Vascs,…, D9Vascs

AME2SL Fixed-step C1F, …, C9F and D1F, …, D9F or more


precisely:
C1Fasme, …, C9Fasme & D1Fasme,…,
D9Fasme

Variable-step C1V, …, C9V and D1V, …, D9V or more


precisely:
C1Vasme, …, C9Vasme & D1Vasme,…,
D9Vasme

Finally, the table below allows you to select an appropriate Simulink solver for your configuration.

Table 4-11. Advised Simulink solver for each configuration

Configuration Advised Simulink solver

D1F, … , D9F Simulink fixed-step discrete solver

C1F, … , C9F ode1, ode2, ode3, ode4, ode51, ode14x2

D1V, … , D9V Simulink variable-step discrete solver

C1V, ode45, ode23, ode113


C4Vascs, C4Vsacs,
C7Vascs, C7Vsacs

C2V, C5V, ode23t


C4Vasme,

Simulink Interface, 4-15


© 2021 Siemens
4. Concluding remarks and FAQs

Configuration Advised Simulink solver

C8Vascs, C8Vsacs

C3V, C6V, C9V ode15s, ode23s, ode23tb

1. See Choosing a fixed-step Simulink solver (for example, for Real-Time applications) for the process
of choosing a continuous fixed-step solver.
2. The ode14x solver might be used in specific cases where a fixed-step continuous implicit solver is
desired (e.g. if none of the previous solvers work).

4.3.3 Example

Let us assume you want to connect your Simcenter Amesim physical model and your Simulink control
model.

1. The Simulink controller has no continuous states but the Simcenter Amesim model has explicit
state variables. According to table 4-7, you are in a C configuration.

2. You could verify with the Performance Analyzer that your Simcenter Amesim model is stiff (see
Implicit or explicit Simulink solver (stiff or non-stiff systems)) and your Simulink model is non-stiff.
Thus your configuration is C7 (see table 4-8).

3. You want to analyze your results in Simulink: you need to select either the AME2SL or the
AME2SLCosim interface mode.

4. Your Simcenter Amesim model is somewhat complex and you want to benefit from the
specificities and the features of the native Simcenter Amesim solver. You thus need to go for a co-
simulation mode: AME2SLCosim has to be selected in this case.

5. You are not interested in performing real-time simulations and there are no specific reasons for
choosing a fixed-step solver. This is why, for more performance and since it is available according
to table 4-10, you will select a variable-step Simulink solver. Your configuration now is C7V or
more precisely C7Vascs.

6. According to table 4-11, you should try ode45, then ode23, then ode113.

These solvers are for Simulink non-stiff systems (see Implicit or explicit Simulink solver (stiff or non-stiff
systems) for details). They can be used even if the Simcenter Amesim model is stiff. Indeed, the
Simcenter Amesim (variable-step) solver is still used for the Simcenter Amesim model and due to the
co-simulation, it only has a limited influence on the Simulink solver, as explained in the Influence of
interface modes on the Simulink solver section.

4-16 Simulink Interface,


© 2021 Siemens
A. Black-box compatibility
Libraries Black- box

3D Mechanical ✓

Aeronautics and Space ✓

Air Conditioning ✓

Aircraft Electrics ✓

Aircraft Fuel System ✓

Automotive Electrics

Cams and Followers ✓

CFD 1D gas dynamics

Cooling System

Discrete Partitioning

Electric Motors and Drives ✓

Electrical Basics ✓

Electrical Static Conversion ✓

Simulink Interface, A-1


© 2021 Siemens
A. Black-box compatibility

Libraries Black- box

Electric Storage ✓

Electrochemistry Components

Electromechanical ✓

Engine Signal Generator ✓

Filling

Fuel Cell

Gas Mixture ✓

Gas Turbine

Generic Co-Simulation

Heat Exchangers Assembly Tool

Hydraulic ✓

Hydraulic Component Design ✓

Hydraulic Resistance ✓

IFP-Drive ✓

A-2 Simulink Interface,


© 2021 Siemens
Libraries Black- box

IFP-Engine ✓

IFP-Exhaust ✓

Liquid Propulsion ✓

Mechanical ✓

Moist Air ✓

Planar Mechanical ✓

Pneumatic ✓

Pneumatic Component Design ✓

Powertrain ✓

Signal, Control ✓

Simulation ✓

Thermal ✓

Thermal Hydraulic ✓

Thermal Hydraulic Component Design ✓

Simulink Interface, A-3


© 2021 Siemens
A. Black-box compatibility

Libraries Black- box

Thermal Hydraulic Resistance ✓

Two-Phase Flow ✓

Vehicle Dynamics ✓

Vehicle Dynamics iCAR ✓

Note:
This list may evolve during the lifecycle of the product.

A-4 Simulink Interface,


© 2021 Siemens
B. Glossary
A
Accelerator Simulation Mode
Simulink executes an Accelerator mode submodel by creating a MEX-file (or simulation target) for the
submodel, then running the MEX-file. The Accelerator mode generates and links code into a C-MEX S-
function. Simulink uses this acceleration target code to perform the simulation, and the code remains
available for use in later simulations. In Accelerator mode, the model methods are separate from the
Simulink software and are part of the Acceleration target code. A C-MEX S-function API communicates
with the Simulink software, and a MEX API communicates with MATLAB. The target code executes in
the same process as MATLAB and Simulink.

Algebraic Loop
An algebraic loop in a Simulink model occurs when a signal loop exists with only direct feedthrough
blocks within the loop. Direct feedthrough means that the block output depends on the value of an
input port; the value of the input directly controls the value of the output. Non-direct-feedthrough
blocks maintain a State variable. Two examples are the Integrator or Unit Delay block. When some
Simulink blocks have input ports with direct feedthrough, the software cannot compute the output of
these blocks without knowing the values of the signals entering the blocks at these input ports at the
current time step. In Simulink models, algebraic loops are algebraic constraints. Models with algebraic
loops define a system of differential algebraic equations. Simulink does not solve DAEs directly. Simulink
solves the algebraic equations (the algebraic loop) numerically for xa at each step of the ODE solver.

B
Black-box
A black-box model is a model whose inputs, outputs, and functional performance are known, but whose
internal implementation is unknown or irrelevant. Contrast with: glass box model, white box model. An
"Simcenter Amesim-Simulink Black-Box (ASBB)" is a Simulink license-free S-function.

Block Diagram
A classic block diagram model of a dynamic system graphically consists of blocks and lines (signals). The
history of these block diagram models is derived from engineering areas such as Feedback Control
Theory and Signal Processing. The relationship between signals and state variables are defined by a set
of equations represented by blocks. Each block consists of a set of equations (block methods). These
equations define a relationship between the input signals, output signals and the state variables.
Inherent in the definition of an equation is the notion of parameters, which are the coefficients found
within the equation.

Block Libraries
A block library is a collection of blocks that serve as prototypes for instances of blocks in a Simulink®
model.

Simulink Interface, B-1


© 2021 Siemens
B. Glossary

Block Parameters
Key properties of many standard blocks are parameterized with block parameters. For example, the
Constant value of the Simulink Constant block is a parameter. Each parameterized block has a block
dialog that lets you set the values of the parameters.

C
Closed Loop
Closed Loop refers to a controlled system using feedback or feedforward. It's also related to a closed-
loop transfer function in control theory, which is a mathematical expression (algorithm) describing the
net result of the effects of a closed (feedback) loop on the input signal to the circuits enclosed by the
loop.

Conditional Subsystem
A conditional subsystem, also known as a conditionally executed subsystem, is a subsystem whose
execution depends on the value of an input signal. The signal that controls whether a subsystem
executes is called the control signal. The signal enters a subsystem block at the control input.

Configurable Subsystem
Configurable Subsystem blocks simplify creation of models that represent families of designs. It
represents any block selected from user-specified library of blocks. The Configurable Subsystem block
represents one of a set of blocks contained in a specified library of blocks. The block's context menu lets
you choose which block the configurable subsystem represents. To create a configurable subsystem in a
model, users must first create a library containing a master configurable subsystem and the blocks that
it represents. They can then create configurable instances of the master subsystem by dragging copies
of the master subsystem from the library and dropping them into models.

Controller
A controller is a control system that manages the behavior of another device or system. It's a device,
possibly in the form of a chip, analogue electronics, or computer, which monitors and physically alters
the operating conditions of a given dynamical system. In SiL simulation, it refers to the (embedded)
control software that executes with simulated hardware (plant).

Control Logic
Control Logic is a key part of a software program that controls the operations of the program. The
control logic responds to commands from the user, and it also acts on its own to perform automated
tasks that have been structured into the program. Control logic can be modeled using a state diagram,
which is a form of hierarchical state machine. These state diagrams can also be combined with flow
charts to provide a set of computational semantics for describing complex control logic.

Control Strategy Design


Control Strategy Design involves developing a control algorithm that effectively manipulates the
actuators to meet the needs of the system requirements. The challenge is to achieve the desired system
behavior with a limited set of measured variables in the presence of disturbances, measurement noise
and part variations.

B-2 Simulink Interface,


© 2021 Siemens
Control System
A Control System is a device, or a collection of devices that manage the behavior of other devices. Some
devices are not controllable. A control system is an interconnection of components connected or related
in such a manner as to command, direct, or regulate itself or another system.

Co-simulation
Coupling (i.e., dynamic mutually exchange and utilization of intermediate results) of several simulation
programs including their numerical solvers in order to simulate a system consisting of several
subsystems. AME2SLCosim and SL2AMECosim interface modes are based on co-simulation between
Simcenter Amesim and Simulink.

D
Demux
Demux extracts and outputs elements of vector signal. The Demux block extracts the components of an
input signal and outputs the components as separate signals. The output signals are ordered from top to
bottom output port.

Dialog Parameters
Users can pass parameters to an S-function at the start of and during the simulation, using the S-
function parameters field of the Block Parameters dialog box. Such parameters are called dialog box
parameters to distinguish them from run-time parameters created by the S-function to facilitate code
generation. Dialog parameters can be either tunable or non-tunable.

Dialog Variables
The Dialog variables list displays the names of the variables associated with the subsystem's mask
parameters.

DLL (Dynamic-Link Library)


DLL is Microsoft's implementation of the shared library concept in the Microsoft Windows and OS/2
operating systems. As with executables, a DLL file can contain code, data, and resources, in any
combination. A function contained in a DLL cannot run on its own, it can only run from inside an
executable file in which it was previously declared before being called (DLL function call).

E
ECU (Electronic Control Unit)
Embedded system that controls one or more electrical subsystems in a vehicle, for instance. In a car,
examples for ECU are: Engine Control Unit (ECU), Transmission Control Unit (TCU), Telephone Control
Unit (TCU), Human-Machine Interface (HMI).

Enabled Subsystem
It represents a subsystem whose execution is enabled by external input Enabled subsystems are
subsystems that execute at each simulation step for which the control signal has a positive value.

Simulink Interface, B-3


© 2021 Siemens
B. Glossary

Exported Code
Code (most of the time, C Source Code) that can be used for Hardware-in-the-Loop Simulation, Rapid
Control Prototyping, Model Integration into other simulation programs (typically Simulink via a S-
function) or even accelerated simulation runs.

F
Feedback
Feedback is considered when the output of the system is passed through some sort of processing unit H,
and that result is fed into the plant as an input.

Feedforward
Feedforward is considered when a priori knowledge is used to forecast at least part of the control
response.

Fixed-Step Solver
Fixed-step solvers are solvers that use the same step size during the simulation. They provide no error
control and do not locate zero crossings but comply with Real-Time constraints.

From
The From block accepts a signal from a corresponding Goto block, then passes it as output. The data
type of the output is the same as that of the input from the Goto block. From and Goto blocks allow you
to pass a signal from one block to another without actually connecting them. To associate a Goto block
with a From block, enter the Goto block's tag in the Goto Tag parameter.

G
Goto
The Goto block passes its input to its corresponding From blocks. The input can be a real- or complex-
valued signal or vector of any data type. From and Goto blocks allow you to pass a signal from one block
to another without actually connecting them.

I
I/O
Input/Output.

Icon Display
Specify the information to be displayed on the icon of this input port. Settings are Signal name: to
display the name of the signal connected to this port (or signals if the input is a bus), Port number: to
display port number of this port, Port number and signal name: to display both the port number and the
names of the signals connected to this port. Default setting is Port number.

B-4 Simulink Interface,


© 2021 Siemens
Inport
Create input port for subsystem or external input. Inport blocks are the links from outside a system into
the system.

L
Libraries Pane
The Libraries pane allows users to select block libraries for browsing. The pane displays a tree-structured
directory (tree view) of libraries installed on your system, each of whose nodes you can select with your
mouse or keyboard.

Library Browser
The Library Browser is used to browse and search Simulink block libraries for blocks to use in your
models. You can also select from a list of your most frequently used blocks.

Linked Blocks
When users copy a block from a library into a model, Simulink creates a linked block in the model, and
connects it to the library block using a library link. The library block is the prototype block, and the linked
block in the model is an instance of the library block.

Lookup Table
A lookup table block uses an array of data to map input values to output values, approximating a
mathematical function. Given input values, Simulink performs a "lookup" operation to retrieve the
corresponding output values from the table. If the lookup table does not define the input values, the
block estimates the output values based on nearby table values.

M
Makefile
Files that contain a collection of commands that allow groups of programs, object files, libraries, etc. to
interact. Makefiles are executed by the make utility.

Mask
Masks are custom interfaces users can apply to Simulink blocks. A mask hides the user interface of the
block, and instead displays a custom dialog to control specific parameters of the masked block. Users
can use the Simulink Mask Editor to define a custom interface for a Subsystem block, Model block, S-
Function block, or built-in blocks.

Master
A master is a device that controls one or more other devices. In networking, for example, a master/slave
configuration is a communications model in which one device or process (known as the master) controls
one or more other devices or processes (known as slaves).

Master/Slave
A method of communication, where one device or process has unidirectional control over one or more
other devices. Once a master/slave relationship between devices or processes is established, the

Simulink Interface, B-5


© 2021 Siemens
B. Glossary

direction of control is always from the master to the slaves. In some systems a master is elected from a
group of eligible devices, with the other devices acting in the role of slaves.

MathWorks
MathWorks is the leading developer of mathematical computing software. It was founded in 1984.
MATLAB®, the language of technical computing, is a programming environment for algorithm
development, data analysis, visualization, and numeric computation. Simulink® is a graphical
environment for simulation and Model-Based Design of multidomain dynamic and embedded systems.

MathWorks Help / Simulink


Simulink software provides comprehensive online help describing features, blocks, and functions with
detailed procedures for common tasks. It's accessible on: http://www.mathworks.com/help/simulink/
index.html. Users can access additional Simulink resources on the MathWorks® Web site, including
Simulink related books, webinars, and technical support. To access the Simulink product page, go to:
http://www.mathworks.com/products/simulink.

MDL Model File


Models and libraries format when saved. Simulink saves the model by generating a specially formatted
file called the model file that contains the block diagram and block properties.

MEX File
MEX stands for "MATLAB executable". Users can call their own C, C++, or Fortran subroutines from the
MATLAB® command line as if they were built-in functions. These programs, called binary MEX-files, are
dynamically-linked subroutines that the MATLAB interpreter loads and executes. The term mex has
different meanings:

• Source MEX-file: C, C++, or Fortran source code file.

• Binary MEX-file: dynamically-linked subroutine executed in the MATLAB environment.

• MEX function library: MATLAB C/C++ and Fortran API Reference library to perform operations in the
MATLAB environment.

• Mex build script: MATLAB function to create a binary file from a source file.

MIMO
Multi-Input, Multi-Output (MIMO) models. Users can define for example MIMO Transfer Function Model,
MIMO State-Space Model, or MIMO Frequency Response Data Model.

Model Configuration
A model configuration is a named set of values for the parameters of a model. It is referred to as a
configuration set. Every new model is created with a default configuration set, called Configuration,
that initially specifies default values for the model parameters.

B-6 Simulink Interface,


© 2021 Siemens
Model Export
The process of exporting a model into a format that can be understood by another tool.

Mux
Mux combines several input signals into vector. The Mux block combines its inputs into a single vector
output. An input can be a scalar or vector signal. All inputs must be of the same data type and numeric
type. The elements of the vector output signal take their order from the top to bottom, or left to right,
input port signals.

N
Normal Simulation Mode
Simulink executes a Normal mode submodel interpretively. Normal mode executes slower than
Accelerator mode does. In Normal mode, the MATLAB technical computing environment is the
foundation on which the Simulink software is built. Simulink controls the solver and model methods
used during simulation. Model methods include such things as computation of model outputs. Normal
mode runs in one process.

O
Open-loop Controller
An open-loop controller, also called a non-feedback controller, is a type of controller that computes its
input into a system using only the current state and its model of the system.

Outport
Outport creates output port for subsystem or external output Outport blocks are the links from a system
to a destination outside the system.

P
Plant Model
A plant in control theory is the combination of process and actuator. Plant modeling can be data-driven
or first principles based. Data-driven plant modeling uses techniques such as System identification. With
system identification, the plant model is identified by acquiring and processing raw data from a real-
world system and choosing a mathematical algorithm with which to identify a mathematical model.
Various kinds of analysis and simulations can be performed using the identified model before it is used
to design a model-based controller. First principles based modeling is based on creating a block diagram
model that implements known differential-algebraic equations governing plant dynamics. A type of first
principles based modeling is physical modeling, where a model is created by connecting blocks that
represent the physical elements that the actual plant consists of. The plant model is the engine model,
vehicle model, airplane model, etc. that is expected by the ECU. Its complexity level depends on the
desired application. For developing ECU control capability against the plant model, higher fidelity may
be required than for "only" testing the diagnostic capability of the ECU. For instance, to develop a new

Simulink Interface, B-7


© 2021 Siemens
B. Glossary

multi-injection fueling strategy for a diesel engine, the plant model should be capable of accumulating
and reacting to all of the fuel pulses.

Port Label
Port Label draws port label on masked subsystem icon.

R
Rapid Accelerator Simulation Mode
The Rapid Accelerator mode creates a Rapid Accelerator standalone executable from your model. This
executable includes the solver and model methods, but it resides outside of MATLAB and Simulink. It
uses External mode to communicate with Simulink.

RTW
Real Time Workshop, see Simulink Coder.

Run-time Parameters
Users can create internal representations of external S-function dialog box parameters called run-time
parameters. Run-time parameters facilitate the following kinds of S-function operations:

• Computed parameters: often the output of a block is a function of the values of several dialog
parameters.

• Data type conversions: often a block needs to change the data type of a dialog parameter to facilitate
internal processing.

• Code generation: during code generation, the Simulink Coder product writes all run-time parameters
automatically to the model.rtw file.

S
Sample Time
The sample time of a block is a parameter that indicates when, during simulation, the block produces
outputs and if appropriate, updates its internal state. The internal state includes but is not limited to
continuous and discrete states that are logged.

Scope
The Scope block displays inputs signals with respect to simulation time.

S-function
S-function (system-function) blocks allow you to write MATLAB, C, C++, or Fortran code to define
custom functionality. It's a customized Simulink block written in C or M-code. S-functions can be inlined
in the Real-Time Workshop. C, C++, and Fortran S-functions are compiled as MEX files using the mex
utility. As with other MEX files, S-functions are dynamically linked subroutines that the MATLAB
interpreter can automatically load and execute. S-functions use a special calling syntax called the S-

B-8 Simulink Interface,


© 2021 Siemens
function API that enables users to interact with the Simulink engine. This interaction is very similar to
the interaction that takes place between the engine and built-in Simulink blocks. S-functions follow a
general form and can accommodate continuous, discrete and hybrid systems.

Simulink
Simulink® is an environment for multi-domain simulation and Model-Based Design for dynamic and
embedded systems. It provides an interactive graphical environment and a customizable set of block
libraries that let you design, simulate, implement, and test a variety of time-varying systems, including
communications, controls, signal processing, video processing, and image processing. Simulink provides
a graphical editor, customizable block libraries, and solvers for modeling and simulating dynamic
systems. Simulink is integrated with MATLAB®, providing immediate access to an extensive range of
tools that let you develop algorithms, analyze and visualize simulations, create batch processing scripts,
customize the modeling environment, and define signal, parameter, and test data.

Simulink Coder
Simulink Coder™ (formerly Real-Time Workshop® prior to MATLAB R2011b) generates and executes C
and C++ code from Simulink® diagrams, Stateflow® charts, and MATLAB® functions. The generated
source code can be used for real-time and non-real-time applications, including simulation acceleration,
rapid prototyping, and hardware-in-the-loop testing. You can tune and monitor the generated code
using Simulink or run and interact with the code outside MATLAB and Simulink.

SISO
Continuous-time Single-Input, Single-Output (SISO) models. Users can define for example Transfer
Function Model Using Numerator and Denominator Coefficients, Transfer Function Model Using Zeros/
Poles/Gain, State-Space Model, or Frequency-Response Model.

Slave
See Master/Slave.

SLX Model File


The default file format for Simulink models in R2012b is SLX. Users save new models and libraries in the
SLX format by default, with file extension .slx. SLX is a compressed package that conforms to the Open
Packaging Conventions (OPC) interoperability standard. SLX stores model information using Unicode®
UTF-8 in XML and other international formats. Saving Simulink models in the SLX format typically
reduces file size compared to MDL. The file size reduction between MDL and SLX varies depending on
the model. It also solves some problems in previous releases with loading and saving MDL files
containing Korean and Chinese characters.

Solver
A solver is a component of the Simulink software. The Simulink product provides an extensive library of
solvers, each of which determines the time of the next simulation step and applies a numerical method
to solve the set of ordinary differential equations that represent the model. Every solver in the Simulink
library can perform on models that contain algebraic loops. Solver refers to the integration algorithms
used to solve the Ordinary Differential Equations (ODE). For a non-real-time simulation this could be a
variable step solver such as ODE45, ODE15t, etc. However, these solvers are not suitable for real-time
simulations since they require 'going back' in time. Simulink generates code that uses real-time solvers
such as ODE1(Euler's method), ODE2, ODE4, etc.

Simulink Interface, B-9


© 2021 Siemens
B. Glossary

Stability
If the controller parameters are chosen incorrectly, the controlled process input can be unstable, i.e., its
output diverges, with or without oscillation, and is limited only by saturation or mechanical breakage.
Instability is caused by excess gain, particularly in the presence of significant lag. Generally, stabilization
of response is required and the process must not oscillate for any combination of process conditions and
setpoints, though sometimes marginal stability (bounded oscillation) is acceptable or desired.

Stateflow
Stateflow® is an environment for modeling and simulating combinatorial and sequential decision logic
based on state machines and flow charts. Stateflow lets you combine graphical and tabular
representations, including state transition diagrams, flow charts, state transition tables, and truth
tables, to model how your system reacts to events, time-based conditions, and external input signals.
With Stateflow you can design logic for supervisory control, task scheduling, and fault management
applications. Stateflow includes state machines animation and static and run-time checks for testing
design consistency and completeness before implementation.

Subsystem
A subsystem is a set of blocks that users replace with a single block called a Subsystem block. As the
model increases in size and complexity, users can simplify it by grouping blocks into subsystems. Using
subsystems has these advantages: it helps reduce the number of blocks displayed in your model
window, it keeps functionally related blocks together, it establishes a hierarchical block diagram, where
a Subsystem block is on one layer and the blocks that make up the subsystem are on another. A Simulink
block diagram can consist of layers. Each layer is defined by a subsystem. A subsystem is part of the
overall block diagram and ideally has no impact on the meaning of the block diagram. Subsystems are
provided primarily to help with the organizational aspects of a block diagram. Subsystems do not define
a separate block diagram.

T
Tolerance
The Relative tolerance measures the error relative to the size of each state. The relative tolerance
represents a percentage of the state value. The default, 1e-3, means that the computed state is accurate
to within 0.1%. The Absolute tolerance is a threshold error value. This tolerance represents the
acceptable error as the value of the measured state approaches zero.

Trigger
Add trigger port to model or subsystem. Adding a Trigger block to a model allows an external signal to
trigger its execution. Users can add a trigger port to a root-level model or to a subsystem.

Triggered Subsystems
Triggered subsystems are subsystems that execute each time a trigger event occurs. A triggered
subsystem has a single control input, called the trigger input, that determines whether the subsystem
executes. Users create a triggered subsystem by placing a trigger port block within a subsystem. The
resulting subsystem executes when a rising or falling edge with respect to zero is seen on the signal
driving the subsystem trigger port. A Stateflow chart can also have a trigger port which is defined by

B-10 Simulink Interface,


© 2021 Siemens
using the Stateflow editor. Simulink does not distinguish between a triggered subsystem and a triggered
chart.

Tunable Parameters
Many block parameters are tunable. A tunable parameter is a parameter whose value can be changed
without recompiling the model. A tunable parameter is a parameter that a user can change while the
simulation is running.

V
Variable Step Solver
Variable-step solvers can modify their step sizes during the simulation. They provide error control and
zero crossing detection and may not comply with Real-Time constraints.

Variants
Variants represent the different choices within a graphical model and enable you to specify multiple
configurations in a single unified block diagram and also switch programmatically between them prior
to model simulation.

Variant Subsystem
Variant subsystems represent a subsystem with multiple subsystems. Variant subsystems provide
multiple implementations for a subsystem where only one implementation is active during simulation.
Users can programmatically swap out the active implementation with another implementation without
modifying the model. The Variant Subsystem block includes multiple child subsystems, where only one
subsystem is active during simulation. Each child subsystem is associated with a variant control, which is
created in the base workspace.

Z
Zero Crossing
Zero crossings in Simulink will automatically detect exactly when the switch block changes its output,
and the solver will step to the exact time that the event happens.

Zero-Crossing Detection
A variable-step solver dynamically adjusts the time step size, causing it to increase when a variable is
changing slowly and to decrease when the variable changes rapidly. This behavior causes the solver to
take many small steps in the vicinity of a discontinuity because the variable is rapidly changing in this
region. This improves accuracy but can lead to excessive simulation times. The Simulink software uses a
technique known as zero-crossing detection to accurately locate a discontinuity without resorting to
excessively small time steps. Usually this technique improves simulation run time, but it can cause some
simulations to halt before the intended completion time.

Simulink Interface, B-11


© 2021 Siemens
B. Glossary

B-12 Simulink Interface,


© 2021 Siemens
Index
A
AME2SL 2-13
AMESim model 2-7

C
Co-simulation interface 2-29
create result file 2-18
create result file check-box 2-18

G
generating files for Simcenter Amesim-Simulink
Black-Box 2-50

I
Interface icons 2-4
adding to sketch 2-6
specifying number of inputs 2-5
specifying number of outputs 2-5
using more than one 2-39

M
mdlInitializeConditions 4-4

O
Open-loop simulation 4-1

S
select a compiler 4-3
Simcenter Amesim-Simulink interface, Information
exchange 2-29
simstruct.h file 4-3
Simulink
versions supported 1-9
Simulink interface 1-1
System Compilation
produces S-Function 2-8

Simulink Interface, Index-1


© 2021 Siemens
Siemens Digital Industries Software
Headquarters Europe
Granite Park One Stephenson House
5800 Granite Parkway Sir William Siemens Square
Suite 600 Frimley, Camberley
Plano, TX 75024 Surrey, GU16 8QD
USA +44 (0) 1276 413200
+1 972 987 3000

Asia-Pacific
Americas Suites 4301-4302, 43/F
Granite Park One AIA Kowloon Tower, Landmark East
5800 Granite Parkway 100 How Ming Street
Suite 600 Kwun Tong, Kowloon
Plano, TX 75024 Hong Kong
USA +852 2230 3308
+1 314 264 8499

About Siemens Digital Industries Software


Siemens Digital Industries Software is a leading global provider of product life cycle management
(PLM) software and services with 7 million licensed seats and 71,000 customers worldwide.
Headquartered in Plano, Texas, Siemens Digital Industries Software works collaboratively with
companies to deliver open solutions that help them turn more ideas into successful products. For
more information on Siemens Digital Industries Software products and services, visit
www.siemens.com/plm.
This software and related documentation are proprietary and confidential to Siemens.
© 2021 Siemens. A list of relevant Siemens trademarks is available. Other trademarks belong to
their respective owners.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy