Pltf Simulation Scripting
Pltf Simulation Scripting
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.
See here for e-mail addresses for your local office: Sales, pricing and general
information
[Link]
about_us/contact/[Link]#lms
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
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
Index Index-1
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:
• perform complex and automated pre-processing: parameter checking and dependant parameter
calculations,
• integrate a Simcenter Amesim model within an external application, reading and writing files with
user-defined formats, connecting to databases, communicating over networks,
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.
Secondly, you have to check your PATH environment variable, it must contain at least:
• 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
• Call the Python command from a command-line interface of your Operating System.
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.1.3 VBA
• If you have closed Simcenter Amesim, it is necessary to run the AMELoad utility:
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.
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.
Python
>>> help('amesim')
MATLAB
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:
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:
Note:
For the full list of the functions with their descriptions, please refer to the Simulation Scripting
Reference HTML document.
The Simulation Scripting facility provides functions that make it possible to get or set the values of most
of the parameters in Simcenter Amesim.
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:
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:
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.
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]).
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:
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
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:
Note:
Some of these functions are not available for the Visual Basic Application scripting language.
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.
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,
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 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 allows you to retrieve or modify the values of the different columns in
an export parameter.
This section describes the basic functions for working with the API. A full list of API functions is given in
the HTML documentation.
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).
Below, we describe the different methods for adding a new parameter to an export configuration.
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")
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:
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])
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
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:
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.
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\
OptimizationRobustnessDOE\Optimization\[Link]")
# Add state variable parameter to the Input type
seat_param = xpt_config.get_param(‘seatD’)
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])
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
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]")
seat_param = xpt_config.get_param(‘seatD’)
seat_param.get_iotype()
# return 1
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’
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.
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
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.
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)
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))
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])
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 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.
• 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.
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
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]
This section describes the basic functions for working with the API. A full list of API functions is given in
the HTML documentation.
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).
Below, we describe the different methods for adding a new parameter to a study configuration.
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\
OptimizationRobustnessDOE\Optimization\[Link]")
# Add the pressure sensor gain by passing its data path
pressure_param = study_config.add_param("gain@pressuresensor")
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:
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_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])
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:
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.
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’)
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])
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
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
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
• 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’
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
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
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))
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]')
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”
The function above can be called with a second parameter as a string referring to the type of study as
below:
You can save all the studies in the model_studies object by typing the command: print
(ms.save_studies() )
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.
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')
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)
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()
You can set the property “Used” for that param to “True” by typing:
first_param.set_property('Used', True)
Running a study
[Link]()
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.
You can get the result object from a study object and store it in a “result” variable by typing:
result=study.get_result()
result.is_available()
result.get_properties()
You can get the value of property “Best_Value” for the result object by typing:
result.get_property('Best_Value')
• For design experiment studies, control inputs and response outputs cannot be changed. They are
defined from the Simcenter Amesim export setup only.
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:
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.
• 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.
import os
import pylab
import scipy
import numpy
import amesim
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');
1. In Simcenter Amesim, use Help > Get demo to load the Engine_DID_Turbocharged.ame demo
model.
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).
import ame_export_apy
export_config=ame_export_apy.XPT.get_config(r'$AME\demo\Libraries\SIG
\
[Link]')
except Exception as e:
print ("Exception caught\n")
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))
%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')
%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)
1. In Simcenter Amesim, use Help > Get demo to load the Robustness_Monte_Carlo.ame demo
model:
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).
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')
is_algo_prop_set=new_algo.set_property(Algorithm.algorithm_property.
No_Of_Runs, '12')
print (is_algo_prop_set)
is_prop_set=param.set_property(Parameter.parameter_property.Mean_Valu
e,
'0.25')
print (is_prop_set)
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)
In Simcenter Amesim, replace the 1-port rotary load with a 2-port rotary load and save it as scrdemo2:
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
Open the MECRL0A-1 variable list and assign the following linear analysis 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
app = [Link]()
if app is None:
app = [Link]([])
plot = [Link]()
# select the index of the jacfile to use (use 1 to display the second
linearization
time)
jacfileIndex = 0
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
[Link]()
5.1.2 MATLAB
[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,:));
• 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.
Go back to Sketch mode and add a GA00 component to the sketch as shown in the figure below:
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.
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.
In the Compound Output Parameters field, create a new compound parameter called maxangle, and
assign it the following expression: globMax(outangle)
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.
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.
Start the analysis by clicking on the Start Run button in the Design Exploration window.
When the analysis is complete, right-click on the test1 study and select Response Surface:
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.
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.
5.2.2 Python
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])
# 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)
[Link]('maximum of '+outangle_name)
[Link](('2nd order RSM','3rd order RSM','simulation'))
[Link]()
• MATLAB:
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
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