CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums

bash script for noob and OpenFoam

Register Blogs Community New Posts Updated Threads Search

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 --------------------------------------------------------------------------------------------

#/!bin/bash
# Launching script for experiment

cd job1

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

blockMesh
decomposePar

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

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

Comments

  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:

    #!/bin/bash
    ./erase
    echo case erased
    mkdir -p logs
    RASmod=inout.kwSSTLowRe #CC: codeCase = {1->0.5mm, 2->1.0mm, 3->1.5mm, 4->2.0mm}
    MeshName=yPlus1.msh
    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:

    !/bin/bash
    source ~/.bashrc
    cd constant/polyMesh
    rm -f faces neighbour owner points *Zones
    cd ../../
    RemoveAllCases
    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*
    done
    }
    --------------------------------------------------------------------------------------
    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.
    permalink
    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 22:26.