|
[Sponsors] |
June 4, 2021, 11:18 |
OpenFoam Bash Script
|
#1 |
New Member
Subodh
Join Date: Sep 2013
Location: Canada
Posts: 25
Rep Power: 13 |
Hi i am new to learning BASH and wondering if someone here can explain me what this bash code is doing.
#!/bin/sh 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 } 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 # Run from this directory cd "${0%/*}" || exit 1 # Source tutorial run functions . "$WM_PROJECT_DIR/bin/tools/RunFunctions" if [ $meshType -eq 0 ] || [ $meshType -eq 1 ]; then { ./Allmesh.1 } elif [$meshType -eq 2 ]; then { ./Allmesh.2 } fi runApplication setFields runApplication decomposePar runParallel $(getApplication) runApplication reconstructPar #------------------------------------------------------------------------------ Thanks in advance!! |
|
June 6, 2021, 09:42 |
|
#2 |
Senior Member
Join Date: Apr 2020
Location: UK
Posts: 736
Rep Power: 14 |
Okay, well here goes:
Code:
#!/bin/sh Code:
usage () ... } Code:
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 Code:
cd "${0%/*}" || exit 1 Code:
. "$WM_PROJECT_DIR/bin/tools/RunFunctions" Code:
if [ $meshType -eq 0 ] || [ $meshType -eq 1 ]; then { ./Allmesh.1 } elif [$meshType -eq 2 ]; then { ./Allmesh.2 } fi Code:
runApplication setFields runApplication decomposePar Code:
runParallel $(getApplication) runApplication reconstructPar Happy? |
|
June 7, 2021, 11:07 |
|
#3 | |
New Member
Subodh
Join Date: Sep 2013
Location: Canada
Posts: 25
Rep Power: 13 |
Quote:
Appreciate your reply. Can you expand a bit more on what these lines of code are doing usage () { exec 1>&2 while [ "$#" -ge 1 ]; do echo "$1"; shift; done cat <<USAGE Usage: ${0##*/} [OPTIONS] Also, if you can suggest some resources to learn about Bourne shell scripts, especially from the point of view of Open foam application. Thanks again! |
||
June 7, 2021, 11:42 |
|
#4 |
Senior Member
Join Date: Apr 2020
Location: UK
Posts: 736
Rep Power: 14 |
Ok - let me paste the whole of the function in and run through it.
Start at the top - the following line denotes that this is a function definition Code:
usage () { Code:
exec 1>&2 Code:
while [ "$#" -ge 1 ]; do echo "$1"; shift; done Code:
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 Code:
exit 1 } |
|
June 23, 2021, 14:58 |
|
#5 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40 |
Quote:
For good measure, the old references are still really good: https://tldp.org/LDP/Bash-Beginners-...tml/index.html https://tldp.org/LDP/abs/html/ |
||
July 8, 2021, 11:06 |
|
#6 |
Member
Petros Ampatzidis
Join Date: Oct 2018
Location: Bath, UK
Posts: 64
Rep Power: 8 |
Thanks both for the very useful information provided.
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Salome] Script for converting a mesh from Salome-Platform to OpenFOAM | nsf | OpenFOAM Meshing & Mesh Conversion | 86 | February 8, 2023 11:30 |
Running OpenFOAM case through shell script (bash) | ilaj | OpenFOAM Programming & Development | 2 | January 28, 2020 14:14 |
[Other] Assistance needed to download openfoam and bash ubuntu for windows 10 | nagaman | OpenFOAM Installation | 1 | April 25, 2019 08:37 |
OpenFOAM Training Jan-Apr 2017, Virtual, London, Houston, Berlin | cfd.direct | OpenFOAM Announcements from Other Sources | 0 | September 21, 2016 12:50 |
OpenFOAM v3.0.1 Training, London, Houston, Berlin, Jan-Mar 2016 | cfd.direct | OpenFOAM Announcements from Other Sources | 0 | January 5, 2016 04:18 |