Some useful scripts for code saturne
Posted: Mon Mar 12, 2018 4:01 pm
Hi,
I have done some scripts, while working on a code_saturne project, to makes it easier to have information, I put them in case it is useful for someone one day.
First come some bash aliases that should be put in the .bashrc
If launched in a folder containing a result in RESU, it gives the number of steps done by counting in the listing the number of time "INSTANT" is written and refresh every 15 seconds. it is useful for following the progression of a simulation.
From the RESU folder, cd into the last modified directory, usually the one with the last computation and where the user wants to go, the "l" stand for "last"
just useful, I usually then type F if the simulation is still running or G otherwise to see the end of the file
Shortcut for paraview and grace to plot the pressure
I have written a Ruby script (attachment explain.rb) that reads the xml setup filed used in a simulation and extracts useful information such as turbulence model or rotational velocity. XML file are hard to read, the goal of this script is to make parametrization more easily accessible than having to type "less setup.xml" and read the XML. Actually that would be nice if code saturne print a human-readable sum up of the simulation for human that want fast basic info on the simulation. And if the GUI in "Prepare batch calculation" part let the user write comments on the calculation in a text area. So that a user can write the intends in the changes he does from the previous calculations.
csexplain should be called in a result folder and write a nice sum up of the parameter of the simulation that I need to now (so mostly turbo-machinery related, I don't change the physical parameter and so they are not displayed). Ruby should be available in every mainstream distro, but if there is interest for a script like that, I can rewrite it in python, in English and with flag support like "csexplain -aT" to display all general information and turbomachinery "csexplain -p" to only display physics and so forth
Last but not least, a Python script that slowly accelerate a turbomachine by launching a frozen rotor simulation at a chosen velocity, wait for the simulation to converge and launch a new simulation a bit faster with de data from the previous one. This script launches from inside DATA and need to have a valid initial setup.
I am sorry that the comments are in French for the two last script, I'll translate them if there is any interest.
I have done some scripts, while working on a code_saturne project, to makes it easier to have information, I put them in case it is useful for someone one day.
First come some bash aliases that should be put in the .bashrc
Code: Select all
alias csw="watch -n 15 \"cat listing | grep \\\"INSTANT\\\" | wc -l\""
Code: Select all
alias cdl="cd \`ls -1r | head -n 1 \`"
Code: Select all
alias lli="less listing"
Code: Select all
alias pvr="paraview postprocessing/RESULTS.case"
Code: Select all
alias xmp="xmgrace -nxy monitoring/probes_Pressure.dat"
Code: Select all
alias csexplain="~/explain.rb"
csexplain should be called in a result folder and write a nice sum up of the parameter of the simulation that I need to now (so mostly turbo-machinery related, I don't change the physical parameter and so they are not displayed). Ruby should be available in every mainstream distro, but if there is interest for a script like that, I can rewrite it in python, in English and with flag support like "csexplain -aT" to display all general information and turbomachinery "csexplain -p" to only display physics and so forth
Last but not least, a Python script that slowly accelerate a turbomachine by launching a frozen rotor simulation at a chosen velocity, wait for the simulation to converge and launch a new simulation a bit faster with de data from the previous one. This script launches from inside DATA and need to have a valid initial setup.
I am sorry that the comments are in French for the two last script, I'll translate them if there is any interest.
Code: Select all
# Import module pour appeler du bash et un module pour lire/écrire du xml
import subprocess
from lxml import etree
# Condition initiale
# Que vous voudrez probablement changer
NB_PAS = 2325
CHECKPOINT= "20180309-1338"
ROTOR_VITESSE=75
Dossier= "Vitesse"
# Boucle tant que l'on n'a pas atteinds 350 rad/s
while ROTOR_VITESSE<=350:
#===== Cree fichier setup ======
# Lire fichier xml source
tree = etree.parse("setup.xml")
for elem in tree.xpath('//iterations'):
# Mettre à jour le nombre de pas
elem.text = str(NB_PAS)
for elem in tree.xpath('//velocity//value'):
# Mettre à jour la vitesse du Rotor
elem.text = str(ROTOR_VITESSE)
for elem in tree.xpath('//start_restart//restart'):
# Mettre à jour le fichier checkpoint
elem.attrib['path'] = "RESU/"+str(CHECKPOINT)+"/checkpoint"
#===== écrire nouveau fichier setup dans DATA/ ======
with open("setup"+str(ROTOR_VITESSE)+".xml", 'w') as setup:
setup.write(etree.tostring(tree, pretty_print=True, encoding='utf8'))
#===== Lancer le calcul ======
# Le dosier où est lancé le calcul est le futur checkpoint
CHECKPOINT=Dossier+str(ROTOR_VITESSE)
# Code lancé sur 4 MPI 2 OPENMP
p = subprocess.Popen("cd ../SCRIPTS && code_saturne run --param setup"+str(ROTOR_VITESSE)+".xml --threads-per-task 2 --nprocs 4 --id "+str(CHECKPOINT), stdout=subprocess.PIPE, shell=True)
#Attendre la fin du calcul avant de repartir
(output, err) = p.communicate()
p_status = p.wait()
print("Vitesse: "+ str(ROTOR_VITESSE))
#La prochaine itération sera 25rad/s plus vite et sur 1000 pas
NB_PAS+=1000
ROTOR_VITESSE+=25
#end