How to run python recursively

From KratosWiki
Jump to: navigation, search

Often the same kratos example has to be run many times in order to get, for instance, a parametric analysis. In this cases script files could be useful to automatize the procedure of their launch. This script file consists in a text file with ".sh" extension containing ordered shell commands. Let's consider,for example, the case of the calculation of the aeroelastic derivatives (AD) of a bridge deck cross section: these parameters has to be evaluated as functions of another adimensional parameter called reduced velocity (UR) in order to get a curve in the UR-AD plane. To do that a certain number of similar kratos FSI or ALE analyses are required. Let's call "/main_folder/pippo/" the principal folder and "UR_X" all the subfolders in which the meshes and the python files, called "AE_X.py", are contained. An example of script file to run three analyses for UR equal to 5, 10 and 15 colud be:

       #!/bin/sh
       cd /main_folder/pippo/UR_5/
       nohup python AE_5.py >out.out 2>err.log
       echo"UR 5 analysis done"
       cd /main_folder/pippo/UR_10/
       nohup python AE_10.py >out.out 2>err.log
       echo"UR 10 analysis done"
       cd /main_folder/pippo/UR_15/
       nohup python AE_15.py >out.out 2>err.log
       echo"UR 15 analysis done"


Let's have a look line by line:


       #!/bin/sh

This line is needed to specify the interpreter, in this case the shell interpreter (sh) contained in the "/bin/" folder.


       cd /main_folder/pippo/UR_5/

This line represents the simple shell command to load "/main_folder/pippo/UR_5/" folder.


       nohup python AE_5.py >out.out 2>err.log

This line executes the kratos analysis through "AE_5.py" as usual.


       echo"UR 5 analysis done"

This line prints "UR 5 analysis done" on the display at the end of the analysis


The script file, called for example "AE.sh", should be executed throw the command:

       nohup ./AE.sh &


This allows to close the prompt after the end of the whole analysis.

Personal tools
Categories