Welcome to the forums. Please post in English or French.

You are not logged in.

#1 2019-10-22 14:05:23

Registered: 2019-10-21
Posts: 9

Automation with Python

Hello everyone

I am currently working on automating simulations using a python script.
My goal is to simulate a 2D plate with a hole in it. Each simulation provides results of stress and strain with the hole in a specific location. The python script should be able to:
1. take a template file (for example I'm using the dump study) and edit some coordinates
2. export this new file in a new folder (for example TEST1)
3. Run a simulation on that fie with a already created command file and export the results in the TEST1 folder
4. repeat this process for a desire amount of time.

As I'm not very good with python scripting and I couldn't find much on automating the simulation process I wrote the basic template of the python script that would translate the coordinates of the input file. I have attached here the template file. Any help would be greatly appreciated!!!

here is the code that I started to write:


x=20;    #fix value of x
NewValue = x+i;    #new value of x to replace fix value

for i in {1..60}
    $sed         ’s/x/NewValue/g‘    prova.py > prova1.py

    #command to run simulation
    #export in folder


prova.py, Size: 21.07 KiB, Downloads: 7


#2 2019-10-23 08:13:36

Registered: 2012-06-27
Posts: 51

Re: Automation with Python


I attached an old demo case, with fully python solution (no shell scripts). The code is simplistic, so I think it can be followed by beginners in python.
You will find 4 files:

studySupV.py: this is the supervisor, it handles the parameter preparation, running of salome for meshing and aster for calculation. This is what you need to run to start the process, simply: python studySupV.py

salomeScript.py: a prepared salome dump file, which will update the mesh and writes out the new .med file
ScriptStudy.comm : aster command file, it is simple at this moment, and does not change during the iterations
exportSal.export: export file to run as_run, the supervisor script changes the input and output med file names.

The script simply updates the mesh (doubles the number of elements on the 3 edges of a simple bolck ) but does not change the geometry and the study, so it is a kind of mesh convergence study.
The key is the paramDict, which is a python dictionary, and holds the parameters. It is writen out (by pickle python module) by studySupV and read in by salomeScript.py to change the mesh. In this setup the input meshes will be over written, but it keeps all the results.

It is tested with SalomeMeca 2017 and python 2.* so you need to update it if required, and adapt it to your environment (path of salome).


Last edited by dezsit (2019-10-23 08:18:53)

scriptedMesh.zip, Size: 3.91 KiB, Downloads: 34


#3 2019-10-23 17:22:17

Registered: 2019-10-21
Posts: 9

Re: Automation with Python

Thank you very much my friend!!! You really helped me a lot with that.