CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   Open Foam Version 8 Planing Hull Tutorial. (https://www.cfd-online.com/Forums/openfoam-solving/236553-open-foam-version-8-planing-hull-tutorial.html)

Subodh21 June 4, 2021 09:31

Open Foam Version 8 Planing Hull Tutorial.
 
Hi,

OpenFoam Version 8 (year 2020) has a tutorial file for planing hull in multiphase RAS folder.
I am wondering if anyone had a chance to run it.

I am able to run it but when I try to investigate the codes, I am lost
and finding it difficult to understand what is actually happening.

So I am trying my luck here to see if any expert here had a chance to explore the planing hull tutorial and can give me some guidelines to what is happening
within the codes.

Thanks in advance!

Tobi June 7, 2021 08:21

What is your actual question and to which code do you refer? Do you mean the Allrun script?

Subodh21 June 7, 2021 08:30

Quote:

Originally Posted by Tobi (Post 805472)
What is your actual question and to which code do you refer? Do you mean the Allrun script?

Hi Tobias,
Thanks for the reply.
Yes the Allrun script, I am familiar with C++ programming
but a beginner in bash, so looking for some explanation on the
flow of Allrun script.

Thanks!

Tobi June 7, 2021 10:17

Hey, so I won´t say that but shame on you :P
If you are familiar with c++ the bash script should be just simple.

Code:

#!/bin/sh
Shows that it is a shell script and tells the OS to invoke the specific shell - here sh.
Code:

usage () {
    exec 1>&2
    while [ "$#" -ge 1 ]; do echo "$1"; shift; done
    cat <<USAGE
Usage: ${0##*/} [OPTIONS]
Options:
  -i | -interface      no refinment in vertical direction of the mesh
  -l | -local          mesh with local refinment
  -h | -help          help
Ship hull simulation to demonstrate two different meshing strategies that can be
used with PLIC type schemes.
USAGE
    exit 1
}

This is a function definition. It will show the options you can use with the script such as:
Code:

~: ./Allrun -i
~: ./Allrun -l
~: ./Allrun -h

The other parts in the above code can be checked out using google or any search engine.
Code:

meshType=0

# OPTIONS
while [ "$#" -gt 0 ]
do
    case "$1" in
    -i | -interface)
        meshType=1
        break
        ;;
    -l | -local)
        meshType=2
        break
        ;;
    -h | -help)
        usage
        ;;
    -test)
        shift
        ;;
    -*)
        usage "Invalid option '$1'"
        ;;
    *)
        usage "Invalid option '$1'"
        break
        ;;
    esac
done

Here we define a variable named meshType and loop through a while loop if you added a parameter to the script, e.g., Allrun -i or Allrun -l. If you call Allrun -h you will call the usage function. If you call any other non-sense such as Allrun -foobar or Allrun noneSense you call the usage function while sending the parameter $1. The $1 includes the parameter you added to the Allrun script call. This parameter is used in the function usage later on (if needed). If you just call ./Allrun (without parameter) the meshType has the value zero.

Code:

# Run from this directory
cd "${0%/*}" || exit 1

# Source tutorial run functions
. "$WM_PROJECT_DIR/bin/tools/RunFunctions"

Should be obvious with the two comments
Code:

if [ $meshType -eq 0 ] || [ $meshType -eq 1 ]; then
{
    ./Allmesh.1
}
elif [$meshType -eq 2 ]; then
{
    ./Allmesh.2
}
fi

Depending which input you specified, you execute either the first or second script for meshing. The rest is just calling OpenFOAM applications:

Code:

runApplication setFields

runApplication decomposePar

runParallel $(getApplication)

runApplication reconstructPar

$(getApplication) is defined in the RunFunctions script we load in prior. However, you question is not related to OpenFOAM at all and is just a bash scripting question - was not expecting people who say
Quote:

I am familiar with C++ programming
ask such questions :) - okay. bash is sometimes a bit wired to read but, hey, you seem to be a programmer so its common that things look strange ;)


Hope this was enough information and I was just kidding with the shame on you sentence :)


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