Simcenter Amesim How to change parameter in AMESim using Python Script?

2021-07-14T04:32:34.000-0400
Simcenter Amesim Automation Connect Simcenter System Simulation Client for Git Simcenter Amesim Teamcenter Share

Summary

The purpose of this tutorial is to show you, how can you change the parameters easily by using python API. If the number of parameters is very high, and if you wanted to change it without opening AMESim, then that would be also possible by using cmd window.


Details

This tutorial will show you, how can you change the parameters easily by using python API. Please note that the AMESim model should not be opened in GUI while running the python script.

Let us create a simple model as shown in the below picture.


In this model, we will change the below parameters by using a script.
  1. The pressure at port 1 in the pressure source.
  2. Area of orifice
  3. Volume of chamber
  4. The initial temperature inside the volume chamber model
  5. Global parameter U, (Thermal exchange coefficient in Volume chamber model)
 
Please download the below file for a better understanding
  • Changeparameter.ame            ----> It is AMESim model created in version 2019.2
  • ChangePar.py                            -----> Python script to change the parameter.
 
Please note that, when you will run the python script, then, it will follow the below step in the sequence
  1. Open Changeparameter.ame in the background
  2. Change above 5 parameters
  3. Save the model
  4. Close the model.
 
The below part of the python script is indicating the parameter change section. In this section, you can create a variable followed by linking that variable to the parameter path in AMESim. Please note that, here, the parameter value will behave as a string.


In this section, the first 4 parameters are stored in different variables and then, subsequently, each variable is linked to its respective parameter path by "AMESetPatameterValue"
 
Note the value of these parameters before running the script. Please note that the py and .ame files should be placed in the same directory. Follow the below steps
  • Close the model.
  • Change the parameters in the py file.
  • Save the .py file.
  • Go to Tools >>> Python command interpreter

 
  • Execute below command
    • AMEInitAPI()
    • os.chdir("Path of the folder, where ame and py file is available")      #----in this update the path of a directory, where, you saved ame file and py file.
    • exec(open("ChangePar.py").read())
  • Wait till execution is complete.
  • Now, open the AMESim model once again.
  • Now, you should see the value change of targeted parameters
 You must take a precaution with the unit. Eg Pa is the default unit considered by the script
To check the unit, Please execute the below command

You can note the unit of pressure is Pa, hence, whenever, you want to see the same value in AMESim, you should set the same unit in AMESim as well.


Still have a question, click here to raise the support case

KB Article ID# KB000045215_EN_US

Contents

SummaryDetails

Associated Components

Amesim Automation Connect