Amesim & Simulink - Interface
Amesim & Simulink - Interface
2021.2
Simulink Interface
User's guide
How to contact us
www.siemens.com/plm/simcenter-amesim Web site
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
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
Simulink Interface, 2
© 2021 Siemens
Contents
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.
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.
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.
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.
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.
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.
• 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
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
1. In SL2AMECosim, the solver type is always fixed-step but the settings (e.g. step sizes) can be
different.
This section describes how to combine Simcenter Amesim/Simulink with other interfaces through an
example of three-way co-simulation with Motion:
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.4 Requirements
• MATLAB-Simulink.
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).
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
echo %MATLAB%
C:\Program Files\MATLAB\R2019a
Note:
To configure the MinGW64 compiler in MATLAB, please follow the procedure below:
• 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
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.
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.
• You must have Simulink coder (formerly known as the Real-Time Workshop).
• Make sure that the Visual C compiler is accessible from the machine where Simcenter Amesim and
MATLAB/Simulink are installed.
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:
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.
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.
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.
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.
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.
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.
Note the three buttons labeled Clear all text, OK and Cancel.
• Click on Clear all text to remove any text you have entered.
An icon similar to that shown in the following figure will appear. Note the port position is denoted by >.
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.
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.
• 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.
• 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.
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:
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.
Submodel name
and type Belongs to category Main simulation parameters
Property definition
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.
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.
• using the Tools > Start MATLAB menu then start Simulink from MATLAB or
When MATLAB is started, the path list is automatically updated as shown in the following figure.
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.
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.
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.
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).
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:
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.
Note:
The values of Gain and Gain 1 come from the Car suspension example in Section 2 of the
Simcenter Amesim Tutorial manual.
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.
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.
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:
2. Select the Standard options tab and tick the Activity check-box
Note:
All parameter windows in the graphical interface work in this way:
• 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.
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.
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.
The following figure shows the body and wheel displacements. These can be plotted from the
Simcenter Amesim components:
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.
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.
• 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.
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).
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).
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.
• 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.
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).
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
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.
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.
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.
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
Select the Simcenter Amesim model to import: skyhookcosim, and connect the block. The co-
simulation subsystem is ready to use.
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.
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.
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.
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.
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.
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.
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.
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
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
Figure 2-37. Body and wheel displacement with a sample time of 0.001 s
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.
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:
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.
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.
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).
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.
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.
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.
• 0D : a flat file with one value per line. Often used for solid properties.
• 2D: Used for y = f(x1, x2) when the y, x1, x2 values are equally spaced.
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.
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.
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.
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.
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.
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
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).
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).
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.
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.
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.
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.
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.
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).
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.
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).
Note that this image has been split into two in order to display it on the page.
Note that accessing the text parameters requires that the preceding matrices must be defined even if
they are empty (as in the following figure)
Note:
The interface is only available if you are using MATLAB version r2008a or higher.
MATLAB must be started from Simcenter Amesim.
This library is available in the Simulink library browser when you start Simulink:
• 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.
Note:
Deleting the Simcenter Amesim block or closing the Simulink subsystem containing the block
closes all windows of the graphical interface.
You can access the main window by double-clicking on the Simcenter Amesim blocks. Its main utility is
to:
Open file Select the Simcenter Amesim model with which to interface.
The file selected is the mex file produced by Simcenter
Amesim.
Create black-box mask Create a Black-Box. This is only available for the standard
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.
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.
Additionally, the Get Simcenter Amesim parameters button can be used to load the print interval
defined in Simcenter Amesim
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:
Additionally, the Get Simcenter Amesim parameters button can be used to load the run parameter set
defined in Simcenter Amesim.
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:
• An array box to edit the value of global parameters. The tunable parameters available are:
• 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.
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.
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:
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.
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.
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:
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.
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
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.
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.
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.
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.
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.
Automatic export
For people who are not familiar with Simcenter Amesim categories and icon organization, there is a
fully automatic export option.
>> 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:
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.
• AME.make file instructing Simcenter Amesim to link with the generated library.
• The new component icon with the proper number and type of ports (if not available) with a name
indicating the number of inputs/outputs.
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.
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.
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:
-----------------------------------------------------------------------
This batch file is to automate the compile procedure for submodels
or other userwritten C files using the Microsoft Visual C++ compiler.
-----------------------------------------------------------------------
RELAY.c
Submodel build completed!
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.
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).
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.
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.
After a simulation, you have access to the following variables for plotting:
• inputs
• outputs
• I/O blocks
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.
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.
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).
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.
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.
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.
This will create a submodel (in a directory called "here") without internal variables - see figure below.
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.
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).
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.
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.
[tag_param=<TagParamName>] [maxdimension=<dimMax>]
Value Description
Value Description
Value Description
Note:
Only one TAG value for signal filtering and one TAG for parameter filtering can be used at the
same time.
Command Filtering
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.
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.
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.
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.
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.
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.
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.
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.
• If control != 0, R is set to Rt
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 voltages V1 and V2 are state variables. They are computed from their derivative with respect to time
as:
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:
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.
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).
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:
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.
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.
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.
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
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.
The MATLAB script force_control_law_initialization.m can be run in order to load the global parameters
in the workspace automatically.
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:
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.
5. Add the workspace variables you want to access in Simcenter Amesim to the global parameters
table.
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).
The parameters of the exported submodel are presented in the following chart:
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’.
• 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 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.
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.
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.1.2 Compilation failure with error message related to the simstruct.h file
Versions
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:
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
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
Solution
3. Type the index corresponding to the Microsoft Visual C++ compiler in this field (3 in this example)
and hit the Enter key.
This used to be a common problem but the solution has been partially automated and fortunately now
is much rarer.
Versions
Situation
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.
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.
The following table indicates for each mode of the Simulink interface whether it has an influence on the
Simulink solver or not.
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.
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
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.
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.
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-
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.
The following table indicates when to use a continuous or a discrete Simulink solver.
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.
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.
Table 4-4. Analysis tools for the dynamic behavior of your model
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:
Note:
Most of the classic Simcenter Amesim systems are stiff and require an implicit method to
integrate.
Implicit continuous variable-step solvers are especially suited for stiff systems. In Simulink, you can
choose from: ode15s, ode23s, ode23t or ode23tb.
• If your model is only moderately stiff or to prevent numerical damping, try using ode23t.
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.
Explicit continuous variable-step solvers are especially designed for non-stiff systems. In Simulink, you
can choose among ode45, ode23 or ode113.
• 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.
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.
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.
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
also be accessed through the State Contribution pane of the Performance Analyzer ("external
constraints" mentioned in the Type column).
• 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.
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.
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),
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.
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
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.
Table 4-8. Combinations for dynamic behavior in Simcenter Amesim and Simulink models
Simulink Model
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".
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 to SL2AMECosim Fixed step C1F, …, C9F and D1F, …, D9F or more
Simcenter precisely:
Amesim
Finally, the table below allows you to select an appropriate Simulink solver for your configuration.
C8Vascs, C8Vsacs
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.
3D Mechanical ✓
Air Conditioning ✓
Aircraft Electrics ✓
Automotive Electrics
Cooling System
Discrete Partitioning
Electrical Basics ✓
Electric Storage ✓
Electrochemistry Components
Electromechanical ✓
Filling
Fuel Cell
Gas Mixture ✓
Gas Turbine
Generic Co-Simulation
Hydraulic ✓
Hydraulic Resistance ✓
IFP-Drive ✓
IFP-Engine ✓
IFP-Exhaust ✓
Liquid Propulsion ✓
Mechanical ✓
Moist Air ✓
Planar Mechanical ✓
Pneumatic ✓
Powertrain ✓
Signal, Control ✓
Simulation ✓
Thermal ✓
Thermal Hydraulic ✓
Two-Phase Flow ✓
Vehicle Dynamics ✓
Note:
This list may evolve during the lifecycle of the product.
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.
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.
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.
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.
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.
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
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.
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:
• 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.
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
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-
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.
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.
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
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.
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
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