0% found this document useful (0 votes)
0 views71 pages

Pltf Simulation Scripting

The Simcenter Amesim Simulation Scripting User's Guide provides instructions for using scripting languages like Python, MATLAB, and VBA to automate interactions with Simcenter Amesim models. It includes details on setting up the environment, listing classes and functions, and performing various simulations and analyses. The document emphasizes the proprietary nature of the content and outlines the limitations and requirements for using the scripting capabilities effectively.

Uploaded by

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

Pltf Simulation Scripting

The Simcenter Amesim Simulation Scripting User's Guide provides instructions for using scripting languages like Python, MATLAB, and VBA to automate interactions with Simcenter Amesim models. It includes details on setting up the environment, listing classes and functions, and performing various simulations and analyses. The document emphasizes the proprietary nature of the content and outlines the limitations and requirements for using the scripting capabilities effectively.

Uploaded by

ibrahim.hamid77
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Simcenter Amesim

Simulation Scripting
User's guide
Simcenter Amesim 2310
Unpublished work. © 2023 Siemens

This Documentation contains trade secrets or otherwise confidential information owned by Siemens Industry Software Inc. or
its affiliates (collectively, “Siemens”), or its licensors. Access to and use of this Documentation is strictly limited as set forth in
Customer’s applicable agreement(s) with Siemens. This Documentation may not be copied, distributed, or otherwise disclosed
by Customer without the express written permission of Siemens, and may not be used in any way not expressly authorized by
Siemens.

This Documentation is for information and instruction purposes. Siemens reserves the right to make changes in specifications
and other information contained in this Documentation without prior notice, and the reader should, in all cases, consult
Siemens to determine whether any changes have been made.
No representation or other affirmation of fact contained in this Documentation shall be deemed to be a warranty or give rise to
any liability of Siemens whatsoever.
If you have a signed license agreement with Siemens for the product with which this Documentation will be used, your use of
this Documentation is subject to the scope of license and the software protection and security provisions of that agreement.
If you do not have such a signed license agreement, your use is subject to the Siemens Universal Customer Agreement, which
may be viewed at [Link] as supplemented by the product specific terms
which may be viewed at [Link]
SIEMENS MAKES NO WARRANTY OF ANY KIND WITH REGARD TO THIS DOCUMENTATION INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF
INTELLECTUAL PROPERTY. SIEMENS SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL OR
PUNITIVE DAMAGES, LOST DATA OR PROFITS, EVEN IF SUCH DAMAGES WERE FORESEEABLE, ARISING OUT OF OR RELATED
TO THIS DOCUMENTATION OR THE INFORMATION CONTAINED IN IT, EVEN IF SIEMENS HAS BEEN ADVISED OF THE POSSIBILITY
OF SUCH DAMAGES.

TRADEMARKS: The trademarks, logos, and service marks (collectively, "Marks") used herein are the property of Siemens or other
parties. No one is permitted to use these Marks without the prior written consent of Siemens or the owner of the Marks,
as applicable. The use herein of third party Marks is not an attempt to indicate Siemens as a source of a product, but is
intended to indicate a product from, or associated with, a particular third party. A list of Siemens’ Marks may be viewed at:
[Link]/global/en/legal/[Link]. The registered trademark Linux® is used pursuant to a
sublicense from LMI, the exclusive licensee of Linus Torvalds, owner of the mark on a world-wide basis.

About Siemens Digital Industries Software


Siemens Digital Industries Software is a global leader in the growing field of product lifecycle management (PLM),
manufacturing operations management (MOM), and electronic design automation (EDA) software, hardware, and services.
Siemens works with more than 100,000 customers, leading the digitalization of their planning and manufacturing processes. At
Siemens Digital Industries Software, we blur the boundaries between industry domains by integrating the virtual and physical,
hardware and software, design and manufacturing worlds. With the rapid pace of innovation, digitalization is no longer
tomorrow’s idea. We take what the future promises tomorrow and make it real for our customers today. Where today meets
tomorrow. Our culture encourages creativity, welcomes fresh thinking and focuses on growth, so our people, our business, and
our customers can achieve their full potential.

Support Center: [Link]

Send Feedback on Documentation: [Link]/doc_feedback_form


2 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310
© 2023 Siemens
How to contact us
[Link]/plm/simcenter-amesim Web site

[Link] Technical support

See here for e-mail addresses for your local office: Sales, pricing and general
information
[Link]
about_us/contact/[Link]#lms

Simcenter Amesim™ software User’s guides

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 3


© 2023 Siemens
Contents

Introduction
Setting the environment ─────────────────────── 1-1
Python ───────────────────────────────── 1-2
MATLAB ──────────────────────────────── 1-2
VBA ────────────────────────────────── 1-3
Setting the working area ─────────────────────── 1-3
Listing all classes and functions ──────────────────── 1-4
Displaying class and function descriptions ─────────────── 1-4

The Simulation Scripting environment in detail


Basic functions ─────────────────────────── 2-1
Export setup ───────────────────────────── 2-4
Using the Export Setup API ──────────────────────── 2-5
Saving and Exporting Configurations ─────────────────── 2-11
Optimization, Design of Experiments ───────────────── 2-13
Using the Study API ─────────────────────────── 2-16
Using the Design Exploration API ───────────────────── 2-22
Getting result objects and result properties ───────────────── 2-26

Limitations 3-1

Simple examples
Temporal Analysis ────────────────────────── 4-1
Python script ────────────────────────────── 4-2
MATLAB script ────────────────────────────── 4-3
Export Setup ──────────────────────────── 4-4
Design Exploration study ─────────────────────── 4-8

Advanced examples
Linear analysis ──────────────────────────── 5-1
Python ───────────────────────────────── 5-2
MATLAB ──────────────────────────────── 5-6
Response surface modeling ────────────────────── 5-8
Creating a simple RSM ────────────────────────── 5-9
Python ──────────────────────────────── 5-14

System requirements 6-1

Index Index-1

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 4


© 2023 Siemens
1. Introduction
Simcenter Amesim provides a complete set of scripts to write short programs in higher abstraction level
languages like Python, MATLAB or Visual Basic Application that automate interaction with models.

This manual gives an exhaustive list of these scripts with a short description for each. These scripts are
available for all the applications, except when indicated.

A complete Python distribution including the Scientific Python toolbox is supplied with Simcenter
Amesim. If you want to use this facility for the other applications, these must be installed on your
machine. Please refer to the next section to check compatibility.

These scripts are particularly designed for automating tasks in the Parameter and Simulation modes,
such as setting or getting parameter values, running temporal simulations or linear analysis, and post-
processing result variables. These tasks may be combined to build small or larger applications that, for
example:

• automate batch runs,

• perform complex and automated pre-processing: parameter checking and dependant parameter
calculations,

• do parameter studies: simple sweep, Monte Carlo analysis, sensitivity analysis…

• perform complex post-processing: creating 2D or 3D plots, animations, performing signal analysis


such as FFT, spectral estimation…

• build customized GUIs for pre- or post-processing,

• integrate a Simcenter Amesim model within an external application, reading and writing files with
user-defined formats, connecting to databases, communicating over networks,

• execute an optimization loop on a Simcenter Amesim model, etc.

Scripts are usually easy and fast to develop, as the scripting languages provide powerful abstractions
such as lists, hash tables, matrices, and numerous toolboxes for file handling, numerical analysis and
graphical post-processing of large data sets. In addition, all scripting languages except Visual Basic
Application are platform-independent.

1.1 Setting the environment


First, check your AME environment variable. It must contain the absolute path to the root Simcenter
Amesim directory.

Secondly, you have to check your PATH environment variable, it must contain at least:

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 1-1


© 2023 Siemens
1. Introduction

• under Windows: check that your %PATH% environment variable contains at least %AME% and
%AME%\win32. When using x64 versions of MATLAB, %AME%\win64 must also be present in your
%PATH%.

• under Linux: check that your $PATH environment variable contains at least $AME and your
$LD_LIBRARY_PATH contains at least $AME/lnx (or $AME/lnx_64 for x64 versions of MATLAB).

1.1.1 Python

Start the Python shell script with one of these methods:

• Call the Python command from a command-line interface of your Operating System.

• In Simcenter Amesim, select Tools > Python command interpreter.

The following welcome message is displayed:

Figure 1-1. Python command shell

Note:
A complete Python distribution including the Scientific Python toolbox is supplied with
Simcenter Amesim. If you want to use this facility for the other applications, these must be
installed on your machine.

1.1.2 MATLAB

In your local or system configuration file startup.m, add the following line:

addpath(fullfile(getenv('AME'),'scripting','matlab','amesim'));

1-2 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
VBA

1.1.3 VBA

Start Microsoft Excel, and open %AME%\scripting\VBA\[Link].

1.2 Setting the working area


• Make sure you are in the directory where your Simcenter Amesim models are stored.

• If you have closed Simcenter Amesim, it is necessary to run the AMELoad utility:

• from a terminal window if you are using Unix , or

• from a DOS window if you are using Windows.

This utility unpacks the Simcenter Amesim .ame file it receives in the argument provided it is called
from the directory where this file is stored. For using any command mentioned in this chapter, it is
necessary that a Simcenter Amesim model, for which a simulation has been run, is available and
unpacked.

• If you want to save the changes you have made with scripts you can use the AMESave and AMEClean
utilities.

As with AMELoad , these utilities must be called from:

• a terminal window if you are using Unix, or

• a DOS window if you are using Windows.

AMESave saves the Simcenter Amesim files of the model (whose name is given in the argument) to
its .ame file. Although the .ame file is updated, its constituent files are not deleted. Use the AMEClean
facility in order to delete these files.

AMEClean deletes the constituent files of the model whose name is given in the argument. [Link] file
is not deleted, it is the only remaining file associated with the model.

AMEPurge deletes by default only the result files of the model whose name is given in the argument.
The executable file is not deleted.

Note:
These utilities must be applied to a model that is unpacked and they must be called from the
directory where the model is stored.

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 1-3


© 2023 Siemens
1. Introduction

1.3 Listing all classes and functions


If you want to see a complete description, please refer to the associated help of the module.

Python

>>> help('amesim')

MATLAB

>> help amesim

1.4 Displaying class and function descriptions


If you want to get a complete description, please refer to the associated help command for each script. If
you want to know more on the ameputp script, for example, proceed as follows:

Python — >>> help('[Link]')

MATLAB — >> help ameputp

VBA — Open the ameputp subroutine located in the Visual Basic Editor. This is located in the
f_ameputp module.

For any modules that contain classes, please refer to the help command for each specific class of the
module. If you want to know more on the class Study of the Design Exploration module, proceed as
follows:

Python — >>> help('Study')

Then you can get help for the functions of a class. For example, for information on the
get_available_algorithms() function in the class Study, proceed as follows:

Python — >>> help('Study.get_available_algorithms')

1-4 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
2. The Simulation Scripting environment in
detail
In this section you will find a short description of features that are available from the Simulation
scripting functions.

Note:
For the full list of the functions with their descriptions, please refer to the Simulation Scripting
Reference HTML document.

2.1 Basic functions


Model parameters

The Simulation Scripting facility provides functions that make it possible to get or set the values of most
of the parameters in Simcenter Amesim.

These functions allow you to handle:

• The parameters of a generic object (submodels or supercomponents)

• The parameters of a customized object (submodels or supercomponents)

• The global parameters of a Simcenter Amesim model

Note:
The Simulation Scripting facility uses functions of reading and writing specific files of Simcenter
Amesim. These files are only used for simulation and have no impact on the Graphical User
Interface. In other words, any changes made to parameter values are not seen when the model is
opened in Simcenter Amesim.

Another way to access parameters is using unique identifiers. Each parameter is uniquely represented by
a data path in the form: identifier@component_name[.component_name[...]]

This unique identifier appears in the Name column of the Contextual parameters view window, and
can be copied directly from that location. For a parameter, right-click on the parameter concerned and
select Copy parameter path:

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 2-1


© 2023 Siemens
2. The Simulation Scripting environment in detail

Figure 2-1. Copy Parameter Path

Note:
An additional set of functions in the language C is available to handle global parameter files in
Simcenter Amesim.

Simulation

The Simulation Scripting module provides a function that makes it possible to execute a simulation of a
Simcenter Amesim model. This function is named amerunsingle. The arguments of the function allow
you to set the run parameters of the simulation. In these runs parameters, you can set:

• the start time

• the final time

• the print interval

• the solver (variable step or fixed step)

Temporal analysis

The Simulation Scripting facility provides functions that make it possible to retrieve the results of a
completed simulation of a Simcenter Amesim model.

2-2 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
Basic functions

Warning:
The Simulation Scripting facility uses functions of reading and writing specific files of Simcenter
Amesim. These files are only used for simulation and have no impact on the Graphical User
Interface. This means that the results files might not be synchronized with the parameter values of
the GUI if they are changed through the Simulation Scripting facility.

To access the variable results when a simulation is complete, you need to call ameloadvarst providing a
list of variable name (SUBMODELNAME_INSTANCE variable_title [unit]).

Another way to access variables is using ameloadvarstui that uses unique


identifiers. Each variable is uniquely represented by a data path in the form:
identifier@component_name[.component_name[...]]

This unique identifier appears in the Name column of the Contextual variables view window, and can
be copied directly from that location. To obtain a variables unique identifier, right-click on the variable
concerned and select Copy variable path:

Figure 2-2. Copy variable path

Two functions allow you also to handle the model initialization by setting the initial values of the state
variables of a Simcenter Amesim model to the final values of a previous run.

Variables can be plotted directly from the scripting environment. One function makes it possible to
open a variable browser window with two menus: Variables and Plot. The first menu can be used
to browse the variables by physical quantities. When a physical quantity is chosen in this menu, all

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 2-3


© 2023 Siemens
2. The Simulation Scripting environment in detail

relevant variables are displayed in the variable list. Selecting a variable and choosing a command in
the Plot menu creates a figure window with the selected variable plotted in full size or in a subplot:

Batch analysis

The Simulation Scripting facility provides functions to handle batch simulations of a Simcenter Amesim
model. The main arguments of the functions are the batch numbers of interest. These functions allow to
set your batch parameters, run the batchs and retrieve the results of the simulation runs.

Data exchange

The Simulation Scripting facility provides functions that make it possible to exchange data by exporting
Simcenter Amesim data to files or importing files within Simcenter Amesim. These data can be:

• Basic look-up tables

• Response surface model

• Space state matrix for linear modeling

• Transfer function for linear modeling

Note:
Some of these functions are not available for the Visual Basic Application scripting language.

2.2 Export setup


Simcenter Amesim provides a complete set of Object oriented API functions in Python to automate
Export Setup handling. This is called the Export Setup API. Using these sets of APIs you can handle
Export Setup without using the Simcenter Amesim application, all you need is the Simcenter Amesim
model in its expanded state. A typical case for using this API is in conjunction with the Design
Exploration API, which requires export parameters to be set before accessing the design exploration
studies in a model.

To set up an export configuration with the API, the user needs to know and understand some key
concepts.

Each concept is represented by an object in the ame_export_apy module. The details of each object are
as given in the following sections.

The XPT Manager (XPTManager)

This is the topmost object in charge of handling all studies for all Simcenter Amesim models. It results
from the fact that it is possible to have export setup parameters for multiple models simultaneously,

2-4 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
Using the Export Setup API

since this is the case with the Design Exploration API. The XPT manager is responsible for the
simultaneous handling of configuration of multiple model files.

The Export Config Handler (XPTConfig)

The Export Config Handler allows you to manipulate the export setup configuration for one model file.
It is possible to retrieve, add or delete export setup parameters using this handler.

The Export Parameter Handler (XPTParam)

The Export Parameter Handler allows you to retrieve or modify the values of the different columns in
an export parameter.

2.2.1 Using the Export Setup API

This section describes the basic functions for working with the API. A full list of API functions is given in
the HTML documentation.

Loading an Export parameters configuration

Follow the steps below to load a model's export configuration. You can access the export
configuration object of a model by typing the command below, where the parameter passed in is
the path of the model file:

xpt_config = XPT.get_config(r'$AME\demo\Platform\
OptimizationRobustnessDOE\Optimization\[Link]')

Warning:
You must ensure that the model is in its expanded state if you load the Export Setup API from a
Python console launched from outside Simcenter Amesim (you can right-click on the model and
select Explode).

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 2-5


© 2023 Siemens
2. The Simulation Scripting environment in detail

Adding new Export parameters

Below, we describe the different methods for adding a new parameter to an export configuration.

• Pass only the data_path

You can pass only the data path of any parameter or variable where the data path involved refers to a
parameter or variable in Simcenter Amesim as the only argument. For example:

import ame_export_apy
xpt_config = ame_export_apy.XPT.get_config(r"$AME\demo\Platform\
OptimizationRobustnessDOE\Optimization\[Link]")
# Add the pressure sensor gain by passing its data path
pressure_param = xpt_config.add_param("gain@pressuresensor")

• Pass only the IOType

This is used if you want to add a local Input Parameter or local Compound Parameter. This is
equivalent to adding the parameter using the Add button in the Export Parameters Setup dialog
box:

2-6 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
Using the Export Setup API

Figure 2-3. Export Parameters Setup dialog box

You need to pass the IOType enum for the required type as the argument. The possible values of
IOType are:

• Input

• Output

• Compound

For example:

import ame_export_apy
xpt_config = ame_export_apy.XPT.get_config(r"$AME\demo\Platform\
OptimizationRobustnessDOE\Optimization\[Link]")
# Add a local input parameter
local_input = xpt_config.add_param([Link])

• Pass data_path and IOType

The only case where both the data_path and IOType presence are relevant is when the IOType is
used to specify either the Input Parameters or Simple Output Parameters in cases of state variables.
For example:

import ame_export_apy
xpt_config = ame_export_apy.XPT.get_config(r"$AME\demo\Platform\
OptimizationRobustnessDOE\Optimization\[Link]")
# Add state variable parameter to the Input type
integrator_output = xpt_config.add_param(‘output@elect02’,
[Link])

If you are dealing with vectors, as the data path corresponds to the parameter of a vector type having
a particular dimension, the returned parameter corresponds to the particular dimension, but when it

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 2-7


© 2023 Siemens
2. The Simulation Scripting environment in detail

is added to XPTConfig, all the available parameters (of all the dimensions) are added. This is the same
behavior as seen in Simcenter Amesim where we add all or none.

For example, consider a case where the export API wants to add the parameters as selected below:

Figure 2-4. Parameter with vectors

Here, the command would be as follows:

import ame_export_apy
xpt_config = ame_export_apy.XPT.get_config(r"c:\hydraulic\
1d\simple_model.ame")
# Add the first parameter in the selected list above by passing
its data
pressure_param = xpt_config.add_param("pn_1@hydraulic_1")
#the pressure_param above refers to the first among the XPT
parameters
#added to the xpt configuration shown below.

Retrieving an existing Export parameter

You can retrieve a parameter by passing the export name as an argument to the following method:
import ame_export_apy:

import ame_export_apy
xpt_config = ame_export_apy.XPT.get_config(r"$AME\demo\Platform\

2-8 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
Using the Export Setup API

OptimizationRobustnessDOE\Optimization\[Link]")
# Add state variable parameter to the Input type
seat_param = xpt_config.get_param(‘seatD’)

Retrieving the list of Export parameters

or can retrieve a list of Export parameters by using the get_params_list API:

import ame_export_apy
xpt_config = ame_export_apy.XPT.get_config(r"$AME\demo\Platform\
OptimizationRobustnessDOE\Optimization\[Link]")
# Add state variable parameter to the Input type
all_params_list = xpt_config.get_params_list()

The export configuration has three different types of parameter named: input, output and compound
output parameters. Using the argument of type IOType, you can retrieve the list of XPTParam of a
particular type. If you do not pass any argument, then it will retrieve all the parameters of input, output
and compound types.

import ame_export_apy
xpt_config = ame_export_apy.XPT.get_config(r"$AME\demo\Platform\
OptimizationRobustnessDOE\Optimization\[Link]")
# Add state variable parameter to the Input type
input_params_list = xpt_config.get_params_list([Link])

Removing an Export parameter

You can remove a parameter using the remove_param API as shown below. You can either pass the
reference to the export param or the export name of the parameter to remove it.

import ame_export_apy
xpt_config = ame_export_apy.XPT.get_config(r"$AME\demo\Platform\
OptimizationRobustnessDOE\Optimization\[Link]")
# Add state variable parameter to the Input type
pressure_param = xpt_config.add_param("gain@pressuresensor")
seat_param = xpt_config.add_param("seatD")

xpt_config.remove_param(‘seat_param’)
# return True or False

Retrieving the IO type of an Export parameter

You can use the get_iotype API to determine the iotype of Export parameter:

import ame_export_apy
xpt_config = ame_export_apy.XPT.get_config(r"$AME\demo\Platform\
OptimizationRobustnessDOE\Optimization\[Link]")

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 2-9


© 2023 Siemens
2. The Simulation Scripting environment in detail

seat_param = xpt_config.get_param(‘seatD’)
seat_param.get_iotype()
# return 1

Retrieving the value of any column of an existing parameter

You can use the get_property API in order to retrieve the value of any column of the Export
parameter. You need to pass the Property enum corresponding to the column as the first argument:
Property, which is one of the following:

• Submodel

• Title

• Export_Name

• Units

• Default_Value

• Type

• Possible_Values

• Lower_Bound

• Upper_Bound

• Status

• Expression

import ame_export_apy
xpt_config = ame_export_apy.XPT.get_config(r"$AME\demo\Platform\
OptimizationRobustnessDOE\Optimization\[Link]")
seat_param = xpt_config.get_param(‘seatD’)
seat_param.get_property([Link])
# return ‘GLOBAL (seatD)’
seat_param.get_property(Property.Export_Name)
# return ‘seatD’

Modifying the value of any column of an existing parameter

You can use the set_property API in order to set the value of any column of the Export parameter.
You need to pass the Property enum corresponding to the column as the first argument and the new
value as the second argument.

2-10 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
Saving and Exporting Configurations

import ame_export_apy
xpt_config = ame_export_apy.XPT.get_config(r"$AME\demo\Platform\
OptimizationRobustnessDOE\Optimization\[Link]")
seat_param = xpt_config.get_param(‘seatD’)
seat_param.get_property(Property.Export_Name)
# return ‘seatD’
seat_param.set_property(Property.Export_Name, ‘new_seatD’)
# return True

2.2.2 Saving and Exporting Configurations

The Export setup API is an independent module, which uses files in a model (which are generated
by Simcenter Amesim) to manipulate an export setup configuration. Sharing of information between
the Export API and Simcenter Amesim is only performed through files. A license is not required to
use the Export Setup APIs. Unlike the Simcenter Amesim circuit API, it does not use extra Simcenter
Amesim licenses to run.

Saving the Export configuration

In order to save modifications made to an export configuration, you can use the API named save:

import ame_export_apy
xpt_config = ame_export_apy.XPT.get_config(r"$AME\demo\Platform\
OptimizationRobustnessDOE\Optimization\[Link]")
seat_param = xpt_config.get_param(‘seatD’)
seat_param.set_property(Property.Export_Name, ‘new_seatD’)
xpt_config.save()
# return True or False

Warning:
You can still access the Study API even if the script imports ame_export_apy.py using the two
following methods:

1. Create the [Link] file at the same location as the script. If this file contains the
text use_study_param_file, then the Study API is called instead of the Export API even
on importing ame_export_apy.py.

2. To access the Study API [study_param file] , you can initialize XPT =
use_study_param_file(true) at the beginning of the script.
Example:

import sys
from ame_export_apy import *
try:
XPT = use_study_param_file(true)

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 2-11


© 2023 Siemens
2. The Simulation Scripting environment in detail

xpt_config= XPT.get_config(r'D:\SourceCode_newcheckouts\
Projects\BatchDOE\TestReport\
New TestReport Data\ExportSettings_Scripts\
Engine_DID_Turbocharged.ame')
#here are the input parameters
print ("Study Input Parameters :: starts")
for cur_param in xpt_config.get_params_list([Link]):
print ("Param name:",
cur_param.get_property(Property.Export_Name))

Opening the Export configuration in Simcenter Amesim

You can open the Export Configuration in Simcenter Amesim.

Figure 2-5. Export Parameters Setup dialog box

In order to export to an external tool you can also specify the XptFormat enum. It can have one of the
following values:

• Default

• OPTIMUS

• iSIGHT

import ame_export_apy
xpt_config = ame_export_apy.XPT.get_config(r"$AME\demo\Platform\
OptimizationRobustnessDOE\

Optimization\[Link]")xpt_config.save([Link])

2-12 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
Optimization, Design of Experiments

2.3 Optimization, Design of Experiments


To set up a design exploration with the API, the user needs to know and understand some key concepts.
Each concept is represented by an object in the ame_DE_apy module. The details of each object are as
given in the following sections.

The DE Manager

This is the topmost object in charge of handling all the studies for all the Simcenter Amesim models.
This object is realized through the DEManager class.

The Model Studies Handler

The Studies handler is in charge of loading studies attached to a Simcenter Amesim model. It acts as a
manipulator for the studies list related to the Simcenter Amesim model. It makes it possible to get the
list of studies attached to the Simcenter Amesim model, to retrieve a given study, to create studies and
to save the list of studies to the Simcenter Amesim DE model file. This object is realized through the
ModelStudies class.

The Study

A study is the main entry point for a DE analysis. It gathers parameters (defined in the Simcenter
Amesim export setup dialog), algorithms (analysis methods) and results of the DE analysis.

There are 3 possible types of study:

• DOE (Design Of Experiments),

• OPT (OPTimization),

• MC (Monte Carlo),

When you create a study, the study type (DOE, OPT or MC) is required so that the instantiated study has
the expected type and can filter the algorithms accordingly. This object is realized through the Study
class.

The Parameters

Parameters are defined from the Simcenter Amesim export setup dialog. They can either be input
parameters or output parameters. This object is realized through the Parameter class.

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 2-13


© 2023 Siemens
2. The Simulation Scripting environment in detail

Figure 2-6. Example of input parameters defined from Simcenter Amesim

Figure 2-7. Example of output parameters defined from Simcenter Amesim

The Algorithm

Algorithm is the method used to compute a study. There are 10 possible algorithms. This object is
realized through the Algorithm class. Algorithms are applicable according to the study type, as shown
in the table below:

VALID FOR
STUDY
ALGORITHM TYPE NAMED

ParameterStudy_UniDirectional DOE

ParameterStudy_FullCombinations DOE

ParameterStudy_UserSets DOE

2-14 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
Optimization, Design of Experiments

VALID FOR
STUDY
ALGORITHM TYPE NAMED

FullFactorial DOE

CentralComposite DOE

NLPQL OPT

GeneticAlgorithm OPT

Optmized_LH MC

Latin_Hypercube MC

Random MC

Note:
Further details about each type of study and algorithm are given in the Design Exploration
manual.

The Result

The concept of result makes it possible to retrieve all the results of a DE analysis which has been
run. The result object encapsulates everything about the DE run, such as the number of simulations,
parameter values according to the run, best parameter values and so on. Of course the content of the
result depends on the parent study and specifically the parent study type. This object is realized through
the Result class.

Error management

An API throws exceptions when it is wrongly used or incorrect parameters are passed to it. The full list of
exceptions that can be thrown by each API is detailed in the reference documentation.

Note:
For more information on the concept of exceptions in Python please refer to the official Python
documentation about exceptions which is available at [Link]
[Link]

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 2-15


© 2023 Siemens
2. The Simulation Scripting environment in detail

2.3.1 Using the Study API

This section describes the basic functions for working with the API. A full list of API functions is given in
the HTML documentation.

Loading a Study parameters configuration

Follow the steps below to load a model's study configuration. You can access the study
configuration object of a model by typing the command below, where the parameter passed in is
the path of the model file:

study_config =
STUDY.get_config(r'$AME\demo\Platform\OptimizationRobustnessDOE\
Optimization\[Link]')

Warning:
You must ensure that the model is in its expanded state if you load the Study API from a Python
console launched from outside Simcenter Amesim (you can right-click on the model and select
Explode).

Adding new Study parameters

Below, we describe the different methods for adding a new parameter to a study configuration.

• Pass only the data_path

You can pass only the data path of any parameter or variable where the data path involved refers to a
parameter or variable in Simcenter Amesim as the only argument. For example:

import ame_study_apy
study_config = ame_study_apy.STUDY.get_config(r"$AME\demo\Platform\

2-16 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
Using the Study API

OptimizationRobustnessDOE\Optimization\[Link]")
# Add the pressure sensor gain by passing its data path
pressure_param = study_config.add_param("gain@pressuresensor")

• Pass only the IOType

This is used if you want to add a local Input parameter or local Compound parameter. This is
equivalent to adding the parameter using the Add button in the Study Manager dialog box:

Figure 2-8. Study Manager dialog box

You need to pass the IOType enum for the required type as the argument. The possible values of
IOType are:

• Input

• Output

• Compound

For example:

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 2-17


© 2023 Siemens
2. The Simulation Scripting environment in detail

import ame_study_apy
study_config = ame_study_apy.STUDY.get_config(r"$AME\demo\Platform\
OptimizationRobustnessDOE\Optimization\[Link]")
# Add a local input parameter
local_input = study_config.add_param([Link])

• Pass data_path and IOType

The only case where both the data_path and IOType presence are relevant is when the IOType is
used to specify either the Input parameters or Simple output parameters in cases of state variables.
For example:

import ame_study_apy
study_config = ame_study_apy.STUDY.get_config(r"$AME\demo\Platform\
OptimizationRobustnessDOE\Optimization\[Link]")
# Add state variable parameter to the Input type
integrator_output = study_config.add_param(‘output@elect02’,
[Link])

If you are dealing with vectors, as the data path corresponds to the parameter of a vector type having
a particular dimension, the returned parameter corresponds to the particular dimension, but when it
is added to STUDYConfig, all the available parameters (of all the dimensions) are added. This is the
same behavior as seen in Simcenter Amesim where we add all or none.

For example, consider a case where the study API wants to add the parameters as selected below:

Figure 2-9. Parameter with vectors

2-18 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
Using the Study API

Here, the command would be as follows:

import ame_study_apy
study_config = ame_study_apy.STUDY.get_config(r"c:\hydraulic\
1d\simple_model.ame")
# Add the first parameter in the selected list above by passing
its data
pressure_param = study_config.add_param("pn_1@hydraulic_1")
#the pressure_param above refers to the first among the STUDY
parameters
#added to the study configuration shown below.

Retrieving an existing Study parameter

You can retrieve a parameter by passing the study name as an argument to the following method:
import ame_study_apy:

import ame_study_apy
study_config = ame_study_apy.STUDY.get_config(r"$AME\demo\Platform\
OptimizationRobustnessDOE\Optimization\[Link]")
# Add state variable parameter to the Input type
seat_param = study_config.get_param(‘seatD’)

Retrieving the list of Study parameters

Or you can retrieve a list of Study parameters by using the get_params_list API:

import ame_study_apy
study_config = ame_study_apy.STUDY.get_config(r"$AME\demo\Platform\
OptimizationRobustnessDOE\Optimization\[Link]")
# Add state variable parameter to the Input type
all_params_list = study_config.get_params_list()

The study configuration has three different types of parameter named: input, output and compound
output parameters. Using the argument of type IOType, you can retrieve the list of STUDYParam of a
particular type. If you do not pass any argument, then it will retrieve all the parameters of input, output
and compound types.

import ame_study_apy
study_config = ame_study_apy.STUDY.get_config(r"$AME\demo\Platform\
OptimizationRobustnessDOE\Optimization\[Link]")
# Add state variable parameter to the Input type
input_params_list = study_config.get_params_list([Link])

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 2-19


© 2023 Siemens
2. The Simulation Scripting environment in detail

Removing a Study parameter

You can remove a parameter using the remove_param API as shown below. You can either pass the
reference to the study param or the study name of the parameter to remove it.

import ame_study_apy
study_config = ame_study_apy.STUDY.get_config(r"$AME\demo\Platform\
OptimizationRobustnessDOE\Optimization\[Link]")
# Add state variable parameter to the Input type
pressure_param = study_config.add_param("gain@pressuresensor")
seat_param = study_config.add_param("seatD")

study_config.remove_param(‘seat_param’)
# return True or False

Retrieving the iotype of a Study parameter

You can use the get_iotype API to determine the iotype of Study parameter:

import ame_study_apy
study_config = ame_study_apy.STUDY.get_config(r"$AME\demo\Platform\
OptimizationRobustnessDOE\Optimization\[Link]")
seat_param = study_config.get_param(‘seatD’)
seat_param.get_iotype()
# return 1

Retrieving the value of any column of an existing parameter

You can use the get_property API in order to retrieve the value of any column of the Study parameter.
You need to pass the Property enum corresponding to the column as the first argument: Property,
which is one of the following:

• Submodel

• Title

• Study_Name

• Units

• Default_Value

• Type

• Possible_Values

2-20 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
Using the Study API

• Lower_Bound

• Upper_Bound

• Status

• Expression

import ame_study_apy
study_config = ame_study_apy.STUDY.get_config(r"$AME\demo\Platform\
OptimizationRobustnessDOE\Optimization\[Link]")
seat_param = study_config.get_param(‘seatD’)
seat_param.get_property([Link])
# return ‘GLOBAL (seatD)’
seat_param.get_property(Property.Study_Name)
# return ‘seatD’

Modifying the value of any column of an existing parameter

You can use the set_property API in order to set the value of any column of the Study parameter. You
need to pass the Property enum corresponding to the column as the first argument and the new value
as the second argument.

import ame_study_apy
study_config = ame_study_apy.STUDY.get_config(r"$AME\demo\Platform\
OptimizationRobustnessDOE\Optimization\[Link]")
seat_param = study_config.get_param(‘seatD’)
seat_param.get_property(Property.Study_Name)
# return ‘seatD’
seat_param.set_property(Property.Study_Name, ‘new_seatD’)
# return True

Saving the study configuration

In order to save modifications made to a study configuration, you can use the API named save:

import ame_study_apy
study_config = ame_study_apy.STUDY.get_config(r"$AME\demo\Platform\
OptimizationRobustnessDOE\Optimization\[Link]")
seat_param = study_config.get_param(‘seatD’)
seat_param.set_property(Property.Study_Name, ‘new_seatD’)
study_config.save()
# return True or False

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 2-21


© 2023 Siemens
2. The Simulation Scripting environment in detail

Warning:
You can still access the Study API even if the script imports ame_export_apy.py using the two
following methods:

1. Create the [Link] file at the same location as the script. If this file contains the
text use_study_param_file, then the Study API is called instead of the Export API even
on importing ame_export_apy.py.

2. To access the Study API [study_param file] , you can initialize XPT =
use_study_param_file(true) at the beginning of the script.
Example:

import sys
from ame_export_apy import *
try:
XPT = use_study_param_file(true)
xpt_config= XPT.get_config(r'D:\SourceCode_newcheckouts\
Projects\BatchDOE\TestReport\
New TestReport Data\ExportSettings_Scripts\
Engine_DID_Turbocharged.ame')
#here are the input parameters
print ("Study Input Parameters :: starts")
for cur_param in xpt_config.get_params_list([Link]):
print ("Param name:",
cur_param.get_property(Property.Export_Name))

2.3.2 Using the Design Exploration API

Accessing studies in a model

Follow the steps below to access an existing study in a model. You can access the model_studies object
of a model by typing the command below, where the parameter passed in is the path of the model file:

ms=DE.get_model_studies (r'$AME\demo\Platform\OptimizationRobustnessDOE\
Optimization\[Link]')

You can access the study required from the model_studies object by typing the command below, where
the first parameter is “study name” and second is the “type of study”.

ms=DE.get_model_studies (r'$AME\demo\Platform\OptimizationRobustnessDOE\
Optimization\[Link]')

2-22 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
Using the Design Exploration API

Figure 2-10. Accessing a design exploration study in a model

Creating a new study in a model

Follow the steps below to create a new study in a model.

Access the model_studies object for the model with a given path.

ms=DE.get_model_studies (r'$AME\demo\Platform\OptimizationRobustnessDOE\
Optimization\[Link]')

You can create a study by typing the command below, where the first parameter is the “name of study”
and second parameter is the “type of study”

study=ms. create_study ( “new_study” , Study.study_type.OPT)

The function above can be called with a second parameter as a string referring to the type of study as
below:

study=ms. create_study ( “new_study” , “OPT”)

You can save all the studies in the model_studies object by typing the command: print
(ms.save_studies() )

Figure 2-11. Creating a new study

The new study name “new_study” and of type “OPT” has been created and saved in the model. You
can see the created study in the model by opening the model in Simcenter Amesim and accessing the
Design exploration window for that model.

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 2-23


© 2023 Siemens
2. The Simulation Scripting environment in detail

Setting the alogrithm to study and the properties of the alogrithm

You can set the algorithm to the previously created study. You can get the list of possible algorithms for
a study by typing:

study.get_available_algorithms()

You can set an algorithm to a study by typing the command below where the parameter passed in is
algorithm name:

algo=study.set_algorithm('GeneticAlgorithm')

You can get the available properties for an algorithm by typing:

algo.get_properties()

You can set the property of an algorithm by typing the command below, where the parameters passed in
are property_name and the value for that property consecutively:

algo.set_property('Population_Size', 50)

Figure 2-12. Setting the algorithm to study

Setting the properties of parameters in a study

You can get a parameter in a study and set its properties. You can get the list of parameters in the study
and store it in the variable param_list by typing:

param_list=study.get_parameters()

You can get the first param in the list to the variable first_param by typing:

first_param=param_list[0]

You can get the list of properties applicable to that parameter by typing:

first_param.get_properties()

2-24 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
Using the Design Exploration API

You can set the property “Used” for that param to “True” by typing:

first_param.set_property('Used', True)

Figure 2-13. Setting the properties of a parameter

Running a study

You can run a study by typing:

[Link]()

Figure 2-14. Running a study

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 2-25


© 2023 Siemens
2. The Simulation Scripting environment in detail

Figure 2-15. Successful completion of a study run

The study has been run and its results have been printed in the console. If any errors or warnings arise
during study execution, they will be displayed in the console.

2.3.3 Getting result objects and result properties

You can get the result object from a study object and store it in a “result” variable by typing:

result=study.get_result()

You can check whether a result is available by typing:

result.is_available()

You can get the available properties of a result object by typing:

result.get_properties()

You can get the value of property “Best_Value” for the result object by typing:

result.get_property('Best_Value')

2-26 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
Getting result objects and result properties

Figure 2-16. Getting results of a study and result properties

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 2-27


© 2023 Siemens
2. The Simulation Scripting environment in detail

2-28 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
3. Limitations
Please be aware of the following limitations when using the Simulation scripting:

• Undo/Redo is not supported for operations performed through scripting.

• To access a model and perform simulation, the model must be expanded.

• To run a simulation the model must be compiled

• Parameters changes are not saved in the model.

• For design experiment studies, control inputs and response outputs cannot be changed. They are
defined from the Simcenter Amesim export setup only.

• Design of Experiment and Optimization are available only as a Python module.

• VBA Simulation scripting is not compatible with Microsoft Excel 64 bits.

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 3-1


© 2023 Siemens
3. Limitations

3-2 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
4. Simple examples
Here we provide three simple examples to illustrate the use of the Simcenter Amesim Simulation
scripting.

4.1 Temporal Analysis


Start Simcenter Amesim, and build the following model, using Premier submodel:

Figure 4-1. Variable spring rate model

Note:
Simcenter Amesim Run users can get this system through Help > Get demo, from the Tutorials
[Link] file is called [Link].

Save this model as [Link] in your working directory and set the following parameters:

• Set the value of the parameter in FX00-1 to abs(x).

• Set the value of the shaft speed in MECRL0A-1 to 100 rev/min.

Note:
In this example, we will use the directory C:\AMETest as the working directory. If you use a
different working directory, you will of course have to change the commands used in this tutorial
accordingly.

In Simulation mode, select the File > Write files for simulation menu item to update the parameters.

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 4-1


© 2023 Siemens
4. Simple examples

Some general remarks:

• Each time a parameter is changed manually in Simcenter Amesim, you must use the Write files for
simulation command to refresh the parameters in the model files before using scripting functions.

• When working with scripts, the current model must always be open in Simcenter Amesim or
Simcenter Amesim Run in order to have all the necessary data files containing parameters and
variables available to the functions. Another way to proceed is to use the AMELoad utility to open an
existing model.

We will use some scripting functions to set the variable spring rate in the FXA01-1 component, run the
simulation and analyze results.

4.1.1 Python script

import os
import pylab
import scipy
import numpy
import amesim

# Create a 1D map for SIGFXA01-1


[Link](r'c:\AMETest')
theta = [0, 10, 10.1, 180]
K = [100, 100, 1000, 1000]
K = list([Link]/180.0*[Link](K))
amesim.fx2ame(theta,K,'[Link]')
[Link]('scrdemo','SIGFXA01 instance 1 name of ASCII file',
'[Link]')

# Running a the simulation and getting results


sim_opt = [Link]('scrdemo')
sim_opt.startTime = 0.0
sim_opt.finalTime = 1.0
sim_opt.printInterval = 0.01
[Link]('scrdemo', sim_opt)

# Post-processing the results


Results, Varnames = [Link]('scrdemo', {'MECRL0A_1 shaft
angle at
port 2 [degree]'})
print('Angle at time {:f} s is {:f} deg'.format(Results[0][-1],
Results[1][-1]))
[Link](Results[0], Results[1],'r')
[Link]()

4-2 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
MATLAB script

Figure 4-2. Angle at time 1 s is 0.11305 deg

4.1.2 MATLAB script

% Create a 1D map for FXA01-1


cd 'c:\AMETest'
theta = [0 10 10.1 180]
K = pi/180*[100 100 1000 1000]
fx2ame(theta, K, '[Link]')
ameputp('scrdemo', 'SIGFXA01 instance 1 name of ASCII
file','[Link]')

% Running a simulation and getting results


sim_opt = amegetsimopt('scrdemo')
sim_opt.startTime = 0.0
sim_opt.finalTime = 1.0
sim_opt.printInterval = 0.01
amerunsingle('scrdemo', sim_opt)

% Post-processing the results


[Results, Varnames] = ameloadvarst('scrdemo', {'MECRL0A_1 shaft angle at

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 4-3


© 2023 Siemens
4. Simple examples

port 2
[degree]'});
fprintf('Angle at time %f s is %f deg\n', Results(1, end), Results(2,
end))
plot(Results(1,:), Results(2,:), 'r');

Figure 4-3. Angle at 1.0 s is 0.113050deg

4.2 Export Setup


Proceed as follows to execute this simple example:

1. In Simcenter Amesim, use Help > Get demo to load the Engine_DID_Turbocharged.ame demo
model.

4-4 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
Export Setup

2. Start a Python console using Tools > Python command interpreter:

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 4-5


© 2023 Siemens
4. Simple examples

Warning:
You must ensure that the model is in its expanded state if you load the Export Setup API
from a Python console launched from outside Simcenter Amesim (you can right-click on the
model and select Explode).

3. Follow the sequence of steps as provided in the script.

import ame_export_apy

print("\n..........load the configuration .........")


try:

export_config=ame_export_apy.XPT.get_config(r'$AME\demo\Libraries\SIG
\
[Link]')
except Exception as e:
print ("Exception caught\n")

print("\n..........add mass of mass-friction port as input


parameter
.........")
mass = export_config.add_param('mass@mass_friction2port')
print("\n..........Export name of added param: %s"
%mass.get_property(ame_export_apy.Property.Export_Name))
print("\n..........modify the export parameter Name to Exportmass
.........")
mass.set_property(ame_export_apy.Property.Export_Name,
'Exportmass')
print("\n..........add stiction force of mass-friction port as
input

4-6 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
Export Setup

parameter
.........")
stiction_force =
export_config.add_param('stict@mass_friction2port')
print("\n..........Export name of added param: %s"

%stiction_force.get_property(ame_export_apy.Property.Export_Name))

print("\n..........modify the export parameter Name to


Exportstict
.........")
stiction_force.set_property(ame_export_apy.Property.Export_Name,
'Exportstict')

print("\n..........add pressure at port 1 .........")


pressureAtPort1 = export_config.add_param('p1@h2port_2')
print("..........Export name of added param: %s"

%pressureAtPort1.get_property(ame_export_apy.Property.Export_Name))
print("\n..........modify the export parameter Name to
pressureAtPort1
.........")

pressureAtPort1.set_property(ame_export_apy.Property.Export_Name,
'pressureAtPort1')

print("\n..........adding a compound parameter .........")


cmpd_param =
export_config.add_param(ame_export_apy.[Link])
print("..........Export name of added param: %s"

%cmpd_param.get_property(ame_export_apy.Property.Export_Name))
print("\n..........modify the export parameter Name to
CompundParam
.........")
cmpd_param.set_property(ame_export_apy.Property.Export_Name,
'CompoundParam')

cmpd_param.set_property(ame_export_apy.[Link],
'Exportmass+pressureAtPort1')
print("..........Modified Expresison value is : %s"

%cmpd_param.get_property(ame_export_apy.[Link]))
print("\n..........save the configuration file .........")
ret_value = export_config.save(ame_export_apy.[Link])
print("\n..........Save Status : %s" %ret_value)

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 4-7


© 2023 Siemens
4. Simple examples

4.3 Design Exploration study


Proceed as follows to execute this simple example:

1. In Simcenter Amesim, use Help > Get demo to load the Robustness_Monte_Carlo.ame demo
model:

2. Start a Python console using Tools > Python command interpreter....

4-8 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
Design Exploration study

Warning:
You should ensure that model is in its expanded state if you load the Design Exploration API
from a python console launched from outside Simcenter Amesim (you can right-click on the
model and select Explode).

3. Follow the sequence of steps as provided in the script.

Below, we present a sample script for running a design exploration study and getting results.

import ame_DE_apy
from ame_DE_apy import *
ms=DE.get_model_studies(r'E:\UserData\Amesim\Test\
Robustness_Monte_Carlo.ame')

print ('\n-------getting study NLPQL-------')


study=ms.get_study('Robustness1', Study.study_type.MC)
print (study)

print ('\n-------get available algorithm-------')


algo_list=study.get_available_algorithms()
print (algo_list)

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 4-9


© 2023 Siemens
4. Simple examples

print ('\n-------Set new algorithm-------')


new_algo=study.set_algorithm(Algorithm.algorithm_type.Random)
print (new_algo)

print ('\n-------get properties of the algorithm-------')


property_list=new_algo.get_properties()
print (property_list)

print ('\n-------set the property for the algorithm-------')

is_algo_prop_set=new_algo.set_property(Algorithm.algorithm_property.
No_Of_Runs, '12')
print (is_algo_prop_set)

print ('\n-------get parameter diamA-------')


param=study.get_parameters()[0]
print (param)

print ('\n-------check if the parameter is output-------')


print (param.is_output())

print ('\n-------change the property of the parameter :


Mean_Value = 0.25-------')

is_prop_set=param.set_property(Parameter.parameter_property.Mean_Valu
e,
'0.25')
print (is_prop_set)

print ('\n-------change the property of the parameter :


Distribution = Gaussian-------')

is_prop_set=param.set_property(Parameter.parameter_property.Distribut
ion,
'Gaussian')
print (is_prop_set)

ms.save_studies()
print ('\n-------Run the study-------')
[Link]()
print ('\n-------Get the result of the study-------')
result=study.get_result()
print (result)

print ('\n-------check if the result is available-------')


is_avble=result.is_available()
print (is_avble)

4-10 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
Design Exploration study

print ('\n-------Get number of runs-------')


total=result.get_nb_runs()
print (total)

print ('\n-------Check all the Stat_Mean_Value-------')


print
(result.get_property(Result.result_property.Stat_Mean_Value))

print ('\n-------Check Stat_Kurtosis value for the parameter


\'diamA\
'-------')
print
(result.get_property_parameter(Result.result_property.Stat_Kurtosis,
'diamA'))
ms.save_studies()

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 4-11


© 2023 Siemens
4. Simple examples

4-12 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
5. Advanced examples
In this section we introduce advanced examples for the scripting facility.

5.1 Linear analysis


The test model is non-linear as the spring has a variable stiffness. This model can be linearized at two
different operating points. Using the ameloadj and amebode scripts, the eigenvalues and frequency
response functions can be computed at each operating point.

In Simcenter Amesim, replace the 1-port rotary load with a 2-port rotary load and save it as scrdemo2:

Figure 5-1. Parameter values

Note:
Simcenter Amesim Run users can get this system through Help > Get demo, from the Tutorials
directory. The file is called [Link].

1. In Parameter mode, select the FX00 component and set its expression in terms of the input x to
abs (x). Set the value of the shaft speed in MECRL0A-1 to 100 rev/min.

2. In Simulation mode, select Linear analysis mode and add the following linearization times:

• 0 seconds

• 0.04 seconds

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 5-1


© 2023 Siemens
5. Advanced examples

Figure 5-2. Linearization times

Open the MECRL0A-1 variable list and assign the following linear analysis status:

• torque at port 1: control

• shaft angle at port 2: state observer

Figure 5-3. LA status

Select the File > Write files for simulation menu item to update the parameters.

5.1.1 Python

import amepyplot
import scipy
import [Link]
import numpy
from PySide6 import QtWidgets
import amesim

5-2 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
Python

app = [Link]()
if app is None:
app = [Link]([])

plot = [Link]()

# Retrieve linearization times (if needed)


times=[Link]('scrdemo2')

# Run the simulation


[Link]('scrdemo2')

# select the index of the jacfile to use (use 1 to display the second
linearization
time)
jacfileIndex = 0

[A, B, C, D, x, u, y, t, S] = [Link]('scrdemo2', jacfileIndex)

wrange = 2*[Link]*[Link](-1,2,400)

# uindex is the index of the control variable (Note that the indexes
start at 0)
uindex = 0
# yindex is the index of the observer variable (Note that the indexes
start at 0)
yindex = 0

# Compute bode using scipy


sys_a = [Link](A)
sys_b = [Link]((len(B[0]), 1))
for k in range(len(B[0])):
sys_b[k, 0] = B[0][k][uindex]
sys_c = [Link](C[yindex])
sys_d = D[0][yindex][uindex]

system = [Link](sys_a, sys_b, sys_c, sys_d)


wout, y = [Link](system, [w for w in wrange if w]) #
eliminate
w = 0 values
mag = abs(y)
phase = [Link](numpy.arctan2([Link], [Link])) * 180.0 / [Link]

freq_range = wout / (2 * [Link])


mag_dB = 20 * [Link].log10(mag)

# Create 2 graphs on the plot window


[Link](2)

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 5-3


© 2023 Siemens
5. Advanced examples

# Creation of the Bode graph (Magnitude)


x_item = [Link](freq_range, 'Frequency', 'Hz')
y_item = [Link](mag_dB, 'Gain', 'dB')
ampl_curve = amepyplot.Curve2D(x_item, y_item, title='Amplitude of
frequency
response')
ampl_graph = [Link](0, 0)
ampl_graph.addCurve(ampl_curve)
ampl_graph.xAxis().setLogScale(True)

# Creation of the Bode graph (Phase)


y_item = [Link](phase, 'Phase', 'deg')
phase_curve = amepyplot.Curve2D(x_item, y_item, title='Phase of
frequency response')
phase_graph = [Link](1, 0)
phase_graph.addCurve(phase_curve)
phase_graph.xAxis().setLogScale(True)

[Link]('Bode plot at t = {} s'.format(times[jacfileIndex]))


[Link](500, 400)
[Link]()

[Link]()

5-4 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
Python

Figure 5-4. Bode plot at t=0s

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 5-5


© 2023 Siemens
5. Advanced examples

Figure 5-5. Bode plot at t=0.04s

5.1.2 MATLAB

% Retrieve linearization times (if needed)


amela('scrdemo2')

% Run the simulation


amerunsingle('scrdemo2');

% select the index of the jacfile to use


jacfileIndex = 0

[A,B,C,D,x,u,y,t,xv]=ameloadj('scrdemo2',jacfileIndex);

w=2*pi*logspace(-1,2,400);

% uindex is the index of the control variable (Note that the indexes
start at 1)
uindex = 1;
uname = deblank(u(uindex,:));

% yindex is the index of the observer variable (Note that the indexes
start at 1)
yindex = 1;
yname = deblank(y(yindex,:));

5-6 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
MATLAB

% Compute bode using bode


[mag,phase] = bode(A,B(:,:,1),C,D(:,:,1),uindex,w);

% Creation of the Bode graph (Magnitude)


subplot(2,1,1);
loglog(w/(2*pi),mag);
xlabel('Frequency [rad/s]')
ylabel('Gain')
title([yname ' / ' uname]);
set(get(gca,'Title'),'FontSize',8)
grid on;

% Creation of the Bode graph (Phase)


subplot(2,1,2);
semilogx(w/(2*pi),phase);
xlabel('Frequency [rad/s]')
ylabel('Phase [deg]')
grid on;

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 5-7


© 2023 Siemens
5. Advanced examples

Figure 5-6. Bode plot at t=0s

5.2 Response surface modeling


Two functions are provided to read and use the Response Surface Model files generated by the Design
Exploration tool:

• the amersmreadrsm function reads an RSM file, selects one particular response and returns it as a
matrix or vector, depending on the order of the RSM,

• the amersmcreatevec function helps to evaluate the RSM at a specified point, by creating the vector
of all the values of the variables raised to the power up to the required order.

A first or second order RSM is represented by the matrix of the corresponding quadratic form, whereas a
third or higher order RSM is represented by a vector of polynomial coefficients. See the manual chapter
on the Design Exploration tool for more details.

We will create a simple RSM of one input variable and one output variable to illustrate the use of these
functions.

5-8 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
Creating a simple RSM

5.2.1 Creating a simple RSM

Go back to Sketch mode and add a GA00 component to the sketch as shown in the figure below:

Figure 5-7. Updated model

Note:
Simcenter Amesim Run users can get this system through Help > Get demo, from the Tutorials
directory. The file is called [Link].

This block acts as a scaling coefficient for the input variable of the duty cycle submodel FXA01-1. We will
study the influence of a gain variation on the maximum angular response of the system.

In Parameter mode, select the FX00 component and set its expression in terms of the input x to abs
(x).

Open the Study Manager and drag the value of gain parameter of GA00-1 from the Contextual
parameters view window and drop it onto the Input Parametersfield. Set the export name of this
parameter to thetascale.

Figure 5-8. Input

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 5-9


© 2023 Siemens
5. Advanced examples

Drag the shaft angle variable of MECRL0A-1 from the Contextual variables view window and drop it
onto the Simple Output Parameters tab of the Export Parameters Setup window. Set the export name
of this parameter to outangle.

Figure 5-9. Simple output

In the Compound Output Parameters field, create a new compound parameter called maxangle, and
assign it the following expression: globMax(outangle)

Figure 5-10. Compound output

Switch to the Studies tab. Select New > Monte Carlo to create a new study and give it a name (for
example test1).

Check thetascale is used in the Controls tab, setting a mean value of 1 and a standard deviation of
0.25. Set the sampling method to Optimized LH and the Number of runs to 50.

5-10 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
Creating a simple RSM

Figure 5-11. Controls

Check maxangle is used in the Responses tab and click on OK.

Figure 5-12. Responses

Open the Run Parameters dialog box and set the start time to 0.0 s, the final time to 1.0, the print
interval to 0.01 s and click on OK.

Figure 5-13. Run parameters

Start the analysis by clicking on the Start Run button in the Design Exploration window.

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 5-11


© 2023 Siemens
5. Advanced examples

When the analysis is complete, right-click on the test1 study and select Response Surface:

Figure 5-14. Run done

In the Response Surfaces window, select Second Order.

5-12 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
Creating a simple RSM

Figure 5-15. Second order

Click on the Save To File button to save the second order response surface as [Link]. Select
More… in the Response Surface Order list, and enter 3 as the Response Surface Order.

Figure 5-16. Third order

Save the third order response surface in a file named [Link].

The two RSM files are now available for post-processing with the scripts. These will be used to evaluate
the RSM over a range of values of the input variable, and compare the output of the RSM with the
corresponding simulation results.

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 5-13


© 2023 Siemens
5. Advanced examples

5.2.2 Python

Create the following [Link] script:

from amesim import *


import scipy, pylab
import numpy

sname = 'scrdemo3'
thetascale_range1 = [Link](0.5,1.5,0.01)
outangle_name = amegetvarnamefromui(sname, 'theta@rotaryload2ports')[0]
thetascale_name = amegetparamnamefromui(sname, 'k@gain')[0]
maxangle_rsmdata = []
# For each available RSM file
for filename in ('[Link]', '[Link]'):
# Read the first RSM in the .rsm file
M = [Link](amersmreadrsm(filename, 1))
# Evaluate the RSM at each point in thetascale_range1
maxangle_rsmdata.append([])
for thetascale in thetascale_range1:
dim = max([Link])
if dim <= 2:
# if the RSM order is less than or equal to 2
V = [Link](amersmcreatevec([thetascale],1))
resp = V*(M*V.T)
else:
# if the RSM order is greater than 2
V = [Link](amersmcreatevec([thetascale],dim-1))
resp = M*V.T
maxangle_rsmdata[-1].append(resp[0,0])

# Perform simulation for some values in the study range


thetascale_range2 = [Link](0.5,1.5,0.1)
maxangle_data = []
for thetascale in thetascale_range2:
# Set the input parameter to the desired value
ameputp(sname,thetascale_name,thetascale)
# Perform simulation
amerunsingle(sname)
#Get result variable max value during simulation
[time_data, outangle_data], names = ameloadvarst(sname,
[outangle_name])
maxangle_data.append(max(outangle_data))

# Graphically compare results with 2nd order and 3rd order RSM
[Link](thetascale_range1, maxangle_rsmdata[0],'b', thetascale_range1,
maxangle_rsmdata[1], 'g',thetascale_range2, maxangle_data, 'rD')
[Link](True)
[Link](thetascale_name)

5-14 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
Python

[Link]('maximum of '+outangle_name)
[Link](('2nd order RSM','3rd order RSM','simulation'))
[Link]()

When you execute the script the graphic output is as follows:

Figure 5-17. Script result

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 5-15


© 2023 Siemens
5. Advanced examples

5-16 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
6. System requirements
On Microsoft Windows 11 and Linux (Red Hat EL8), the Simulation Scripting officialy supports:

• Python 3.8.8 (32-bit and 64-bit)

• MATLAB:

• Windows: MATLAB R2019a to R2023a

• Linux: MATLAB R2020b to R2023a

Note:
Releases R2019b and R2020a of MATLAB are not supported under Linux because each of these
releases embeds its own standard library for C++ based on a compiler version that is older than
the reference version of Red Hat Enterprise Linux 8, which causes incompatibilities between
Application Binary Interfaces (ABI) versions.

• VBA Excel 2013 and Excel 2016 (32-bit) (Windows platform only)

A complete Python 3.8.8 (64-bit only) distribution is supplied within the Simcenter Amesim installation
on all platforms, with, among others, the following packages:

• Numpy 1.19.5

• Scipy 1.6

• Matplotlib 3.6.3

• PySide6 6.5.1

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 6-1


© 2023 Siemens
6. System requirements

6-2 Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310


© 2023 Siemens
Index
A
accessing studies in a model 2-22
advanced examples 5-1
AMEClean 1-3
AMEload utility 1-3
AMESave 1-3

E
error management 2-15

G
getting result objects and result properties 2-26

L
limitations 3-1

M
main concepts 2-13
MATLAB 1-1

P
Python 1-1

R
running a study 2-25

S
setting the algorithm to study and the properties of
the algorithm 2-24
setting the properties of parameters in a study 2-24
Simple example 4-8

T
the Algorithm 2-14
the DE Manager 2-13
the Model Studies Handler 2-13
the Parameters 2-13
the Result 2-15
the Study 2-13

V
VBA 1-1
Visual Basic Application 1-1

Simcenter Amesim Simulation Scripting, Simcenter Amesim 2310 Index-1


© 2023 Siemens

You might also like