CFD Online Logo CFD Online URL
Home > Forums

bash script for noob and OpenFoam

Register Blogs Members List Search Today's Posts Mark Forums Read

Rate this Entry

bash script for noob and OpenFoam

Posted May 13, 2013 at 23:13 by gregjunqua

Hi there I am a noob in linux and i like efficient tutorial, easy to understand easy to use.
Here is my first bash script for launch CFD job one after one while you are not there and perhaps sleeping.

P.S. there is a lot of copy with *.org, it's just i like to have the origin file. And this is quiet basic i hope one day i would give you an improved one.

----- Copy there --------------------------------------------------------------------------------------------

# Launching script for experiment

cd job1

cp 0/ 0/alpha1
cp 0/ 0/gamma
cp 0/ 0/pd
cp 0/ 0/p_rgh
cp 0/ 0/U
cp 0/ 0/nut
cp 0/ 0/k
cp 0/ 0/omega


mpirun -np 2 waveFoam -parallel
rm -r processor*

cd ..
cd job2
Posted in Uncategorized
Views 2225 Comments 1 Edit Tags Email Blog Entry
« Prev     Main     Next »
Total Comments 1


  1. Old Comment
    I also think it's a good idea create a script to manage the case.

    My idea is generate a shell-script running inside of each case, and then manage the results from a main script running outside of all the cases.

    In the case I show you can change the structure of the script by a function and then pass the name of the variables 'RASmod' and 'MeshName' from the main script to this one.

    If you are running in parallel and once you know that your case setup is correct, I think you can define in controlDict your sample functions to extract the profiles or whatever you're interesting. And then you don't need the reconstructPar function, wich is time consuming specially in unsteady.

    What I mean is, at the end you have a main script placed on the top of your cases and different cases with the corresponding script to manage everything in the case. At the end of the simulation, some folders with different samples will be created, then you can manage it from you main script to call another script, let say written in octave to plot the profiles, save the images, etc.

    This is what I'm doing.

    An example of my first script working as a script and not as a function, and of course called from the terminal.

    run script:

    echo case erased
    mkdir -p logs
    RASmod=inout.kwSSTLowRe #CC: codeCase = {1->0.5mm, 2->1.0mm, 3->1.5mm, 4->2.0mm}
    fluentMeshToFoam constant/polyMesh/mesh/$MeshName > logs/fluentMeshToFoam.log
    echo mesh generated
    decomposePar > logs/decomposePar.log
    echo decomposition done
    echo running the solver
    time mpirun -np 4 simpleFoam -parallel > logs/simpleFoam.log
    echo end of the simulation
    reconstructPar > logs/reconstructPar.log
    echo reconstruction done
    yPlusRAS > logs/yPlusRAS.log
    echo yPlusRAS computed
    wallShearStress > logs/wallShearStress.log
    echo wallShearStress computed
    sample -latestTime > logs/sample.log
    echo sample done
    cd logs
    gnuplot residuals
    cd ..
    echo residuals ploted
    mv sets/streamLines/ ./
    file=$(ls sets/)
    mv sets/$file/* sets/
    rm -r sets/$file
    rm -r -f /home/$RASmod
    cp -r sets /home/$RASmod
    echo sample moved
    echo work DONE

    erase script:

    source ~/.bashrc
    cd constant/polyMesh
    rm -f faces neighbour owner points *Zones
    cd ../../
    rm -r -f sets streamLines logs/*.log probes processor* 0/y 0/yPlus 0/R 0/wallShearStress

    a function that I created to erase all the time step in case except 0

    function RemoveAllCases
    rm -r -f 0.* #also could remove the case 0.old!!!

    for (( i=1; i<=9; i++)); do
    rm -r -f $i*
    Of course I did everything before to know OpenFOAM has its own function to manage the script, so I suggest you to use it! it's more elegant and less time consuming.
    Posted May 26, 2013 at 09:20 by s.espintolosa s.espintolosa is offline
    Updated May 26, 2013 at 16:48 by s.espintolosa (privacy of the roots directories in some part of the code)

All times are GMT -4. The time now is 16:56.