CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

FOAM Command Flow 1 .bash

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 17, 2013, 09:36
Lightbulb FOAM Command Flow 1 .bash
  #1
New Member
 
Y
Join Date: Feb 2013
Location: The Earth
Posts: 25
Rep Power: 13
peteryuan is on a distinguished road
Hey guys,

I have been learning bash scripting these days and for practice I wrote a small bash script to make openfoam usage a little easier (try to).
I call it fcf1, as the title of this thread.
I want to share this with you. Feel free to try it out and modify it. I am a beginner in bash scripting and I know there are a lot of advanced users here. So, if you are interested, please work further on this script and post the improved versions - so that we can learn from each other. I would also be happy if you tell me where I can improve.

cheers!
peter

Code:
#!/bin/bash
###############################################################
# this is a script to make FOAM easier to use
# I call it foam command flow no. 1 ==> fcf1
# written by x.yuan
# last change on 2013.11.17
###############################################################
function usage
{
    echo ""
    echo "usage: -h to show this..
    whatever.... 
    "
    echo "
    some message to write .... 
    "
}
function press_enter
{
    echo ""
    echo -n "Press Enter to continue"
    read
    # clear
}
###############################################################
interactive=
filename="default"
while [ "$1" != "" ]; do
    case $1 in
        -f | --file )        shift
                             filename=$1
                             echo "file name is : $filename"
                             ;;
        -i | --interactive)  interactive=1
                             echo "interactive on"
                             ;;
        -h | --help)         usage
                             exit 0
                             ;;
        * )                  usage  # otherwise show help
                             exit 1
    esac
    shift
done
###############################################################
# title:
###############################################################
echo ""
echo ==========================================================
echo "0: FOAM flow control 01"
echo ==========================================================
[ -d constant ] && echo "IN A CASE DIR, GOOD." || exit 1
echo ==========================================================
echo ready to go...
sleep 2
###############################################################
# case dir setup:
###############################################################
cs=n  # like control string
echo -n "1: pyFoamClearCase.py (y or n) > "
read cs
# if $cs == "y"; then  # does not work this way!
if [ $cs = "y" ]; then
    echo yes to clearcase..
    pyFoamClearCase.py ./; press_enter
fi
echo ==========================================================
###############################################################
# pre processing like mesh generation:
###############################################################
# echo -n "2: blockMesh apply (y or n) > "
# read cs
# if [ $cs = "y" ]
# then
#     echo yes to blockMesh
#     blockMesh | tee blockMesh.log
# fi
selection=
until [ "$selection" = "0" ]; do
    echo "2: PRE MENU"
    echo ""
    echo "1 - blockMesh | tee logfile"
    echo "2 - pyFoamDisplayBlockMesh.py <blockMeshDict>"
    echo "3 - checkMesh"
    echo "4 - paraFoam to view the mesh"
    echo ""
    echo "0 - exit loop"
    echo ""
    echo -n "Enter selection: "
    read selection
    echo ""
    case $selection in
        1 ) blockMesh | tee blockMesh.log ; press_enter ;;
        2 ) pyFoamDisplayBlockMesh.py constant/polyMesh/blockMeshDict; press_enter ;;
        3 ) checkMesh ; press_enter ;;
        4 ) paraFoam ; press_enter ;;
        # 0 ) exit ;;  # this exit whole programm!
        0 ) break ;;
        * ) echo "Please enter your selection!"; press_enter
    esac
done
echo ==========================================================
###############################################################
# solver running:
###############################################################
# try to get the string from file:
[ -d system ] && grep "application" system/controlDict || exit 2


solver=
echo -n "3: solver app to use > "
read solver
selection=
until [ "$selection" = "0" ]; do
    echo ""
    echo "3: SOLVER MENU"
    echo ""
    echo "1 - $solver | tee logfile"
    echo "2 - pyFoamPlotRunner.py $solver"
    echo "3 - pyFoamPlotWatcher.py logfile"
    echo "4 - paraFoam to view the results"
    echo ""
    echo "0 - exit loop"
    echo ""
    echo -n "Enter selection: "
    read selection
    echo ""
    case $selection in
        1 ) $solver | tee $solver.log ; press_enter ;;
        2 ) pyFoamPlotRunner.py $solver ; press_enter ;;
        # 3 ) pyFoamPlotWatcher.py PyFoamRunner.$solver.logfile ; press_enter ;;
        3 ) echo dont try that... ;;
        4 ) paraFoam ; press_enter ;;
        0 ) break ;;
        * ) echo "Please enter your selection!"; press_enter
    esac
done
echo ==========================================================
###############################################################
# post processing like data manipulation:
###############################################################
# foamCalc...
# sample...
# yPlusRAS...





###############################################################
echo fcf1 ends here, sir.
echo ==========================================================
echo ""
exit 0
###############################################################
by the way, here is the main source of my learning:

http://linuxcommand.org/writing_shell_scripts.php
filmsbykris.com
peteryuan is offline   Reply With Quote

Reply

Tags
bash, command, script


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Other] mesh airfoil NACA0012 anand_30 OpenFOAM Meshing & Mesh Conversion 13 March 7, 2022 18:22
[blockMesh] error message with modeling a cube with a hold at the center hsingtzu OpenFOAM Meshing & Mesh Conversion 2 March 14, 2012 10:56
[blockMesh] BlockMesh FOAM warning gaottino OpenFOAM Meshing & Mesh Conversion 7 July 19, 2010 15:11
[blockMesh] Axisymmetrical mesh Rasmus Gjesing (Gjesing) OpenFOAM Meshing & Mesh Conversion 10 April 2, 2007 15:00
[Gmsh] Import gmsh msh to Foam adorean OpenFOAM Meshing & Mesh Conversion 24 April 27, 2005 09:19


All times are GMT -4. The time now is 23:00.