Skip to content
Snippets Groups Projects
Commit 7d2a9fad authored by Mark OLESEN's avatar Mark OLESEN
Browse files

ENH: add auto-detect 0/ to foamCleanTutorials

- in the 'auto' mode (now the default), it will use cleanCase and also
  remove the 0/ directory if a 0.orig/ directory also exists.

  This corresponds to a frequent idiom and can be used quite safely
  for most cases.

ENH: add -serial / -parallel preference for foamRunTutorials
parent 096b9dc5
No related merge requests found
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
# \\/ M anipulation | # \\/ M anipulation |
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Copyright (C) 2011 OpenFOAM Foundation # Copyright (C) 2011 OpenFOAM Foundation
# Copyright (C) 2019-2020 OpenCFD Ltd. # Copyright (C) 2019-2021 OpenCFD Ltd.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# License # License
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later. # This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
# foamCleanTutorials # foamCleanTutorials
# #
# Description # Description
# Run either Allwclean, Allclean or default cleanCase in current directory # Recursively clean an OpenFOAM case directory,
# and all its subdirectories. # using Allclean, Allwclean (when present) or regular cleanCase.
# #
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
. ${WM_PROJECT_DIR:?}/bin/tools/CleanFunctions # Tutorial clean functions . ${WM_PROJECT_DIR:?}/bin/tools/CleanFunctions # Tutorial clean functions
...@@ -34,17 +34,24 @@ printHelp() { ...@@ -34,17 +34,24 @@ printHelp() {
Usage: ${0##*/} [OPTION] Usage: ${0##*/} [OPTION]
${0##*/} [OPTION] directory ${0##*/} [OPTION] directory
options: options:
-0 use cleanCase0 instead of cleanCase -0 Perform cleanCase, remove 0/ unconditionally
-case <dir> specify starting directory, default is cwd -auto Perform cleanCase, remove 0/ if 0.orig/ exists [default]
-self avoid Allclean script (prevent infinite recursion) -no-auto Perform cleanCase only
-help print the usage -case=DIR Specify starting directory, default is cwd
-self Avoid Allclean script (prevent infinite recursion)
-help Print the usage
Recursively clean an OpenFOAM case directory. Recursively clean an OpenFOAM case directory, using Allclean or Allwclean
By default uses Allclean, Allwclean when present. when present.
The -skipFirst option is the same as -self.
In the default 'auto' mode, it will use cleanCase and will automatically
remove the 0/ directory if a corresponding 0.orig directory exists.
Equivalent options:
| -case=DIR | -case DIR |
USAGE USAGE
exit 0 # clean exit exit 0 # A clean exit
} }
# Report error and exit # Report error and exit
...@@ -63,15 +70,43 @@ die() ...@@ -63,15 +70,43 @@ die()
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Parse options # Parse options
unset skipSelf clean0 unset skipSelf
cleanType=auto
if [ "$#" -gt 0 ] if [ "$#" -gt 0 ]
then then
case "$1" in case "$1" in
-h | -help*) (- | --)
shift
break # Stop option parsing
;;
(-h | -help* | --help*)
printHelp printHelp
;; ;;
-auto)
cleanType="auto"
;;
-no-auto)
cleanType="noauto"
;;
-0) -0)
clean0=true cleanType="0"
;;
## long-option (internal dispatch form)
--clean=0 | --clean=auto | --clean=noauto)
cleanType="${1#*=}"
;;
--clean=*)
echo "$0: unknown setting: $1" 1>&2
;;
-case=*)
caseName="${1#*=}"
cd "$caseName" 2>/dev/null || {
echo "${0##*}: No such directory $caseName" 1>&2
exit 2
}
;; ;;
-case) -case)
[ "$#" -ge 2 ] || die "'$1' option requires an argument" [ "$#" -ge 2 ] || die "'$1' option requires an argument"
...@@ -84,10 +119,6 @@ then ...@@ -84,10 +119,6 @@ then
-self* | -skipFirst) -self* | -skipFirst)
skipSelf=true skipSelf=true
;; ;;
--)
shift
break
;;
*) *)
cd "$1" 2>/dev/null || { cd "$1" 2>/dev/null || {
echo "${0##*}: No such directory $1" 1>&2 echo "${0##*}: No such directory $1" 1>&2
...@@ -95,46 +126,48 @@ then ...@@ -95,46 +126,48 @@ then
} }
;; ;;
esac esac
shift
fi fi
unset exitCode # Use specialized script(s), but not on self
if [ -z "$skipSelf" ] if [ -z "$skipSelf" ]
then then
# Use specialized script(s) if [ -f ./Allwclean ]
if [ -f Allwclean ]
then then
./Allwclean ./Allwclean
exitCode="$?" exit "$?"
elif [ -f Allclean ] elif [ -f ./Allclean ]
then then
./Allclean ./Allclean
exitCode="$?" exit "$?"
fi fi
fi fi
if [ -d system ]
if [ -n "$exitCode" ]
then
exit "$exitCode"
elif [ -d system ]
then then
# Normal case # Tutorial case
if [ "$clean0" = true ] cleanCase
then case "$cleanType" in
cleanCase0 (auto)
else [ -d 0.orig ] && rm -rf 0 ;;
cleanCase (0)
fi rm -rf 0 ;;
esac
elif [ -d Make ] elif [ -d Make ]
then then
# Normal application # Application
cleanApplication cleanApplication
else else
# Recurse into subdirectories # Recurse into subdirectories
for caseName in * for caseName in *
do do
( cd "$caseName" 2>/dev/null && "$thisScript" ) (
cd "$caseName" 2>/dev/null \
&& "$thisScript" ${cleanType:+--clean=$cleanType}
)
done done
fi fi
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
# \\/ M anipulation | # \\/ M anipulation |
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Copyright (C) 2011-2016 OpenFOAM Foundation # Copyright (C) 2011-2016 OpenFOAM Foundation
# Copyright (C) 2018-2020 OpenCFD Ltd. # Copyright (C) 2018-2021 OpenCFD Ltd.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# License # License
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later. # This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
# foamRunTutorials # foamRunTutorials
# #
# Description # Description
# Recursively run Allrun/Alltest or blockMesh+application, # Recursively run Allrun/Alltest or blockMesh and application,
# starting with the current directory or the specified -case directory. # starting with the current directory or the specified -case directory.
# #
# For tutorials that are known to run poorly, an Allrun-optional # For tutorials that are known to run poorly, an Allrun-optional
...@@ -40,17 +40,22 @@ printHelp() { ...@@ -40,17 +40,22 @@ printHelp() {
Usage: ${0##*/} [OPTION] Usage: ${0##*/} [OPTION]
options: options:
-case <dir> specify starting directory, default is cwd -case=DIR Specify starting directory, default is cwd
-self avoid Allrun, Alltest script (prevent infinite recursion) -serial Prefer Allrun-serial if available
-test prefer Alltest script, pass -test argument to scripts -parallel Prefer Allrun-parallel if available
-help print the usage -test Prefer Alltest script, pass -test argument to scripts
-self Avoid initial Allrun, Alltest scripts
(prevent infinite recursion)
-help Print the usage
Recursively run Allrun/Alltest or blockMesh+application, Recursively run Allrun/Alltest (or blockMesh + application)
starting with the current directory or the specified -case directory. starting from the current directory or the specified -case directory.
The -skipFirst option is the same as -self.
Equivalent options:
| -case=DIR | -case DIR |
USAGE USAGE
exit 0 # clean exit exit 0 # A clean exit
} }
# Report error and exit # Report error and exit
...@@ -69,14 +74,44 @@ die() ...@@ -69,14 +74,44 @@ die()
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Parse options # Parse options
unset passArgs runTests skipSelf unset passArgs runTests runType skipSelf
while [ "$#" -gt 0 ] while [ "$#" -gt 0 ]
do do
case "$1" in case "$1" in
-h | -help*) (- | --)
shift
break # Stop option parsing
;;
(-h* | -help* | --help*)
printHelp printHelp
;; ;;
## Prefer serial or parallel
-serial | -parallel)
runType="${1#*-}"
;;
-test)
passArgs="-test"
runTests=true
;;
## long-option (internal dispatch form)
--run=serial | --run=parallel)
runType="${1#*=}"
;;
--run=*)
echo "$0: unknown setting: $1" 1>&2
;;
-case=*)
caseName="${1#*=}"
cd "$caseName" 2>/dev/null || {
echo "${0##*}: No such directory $caseName" 1>&2
exit 2
}
;;
-case) -case)
[ "$#" -ge 2 ] || die "'$1' option requires an argument" [ "$#" -ge 2 ] || die "'$1' option requires an argument"
shift shift
...@@ -85,19 +120,11 @@ do ...@@ -85,19 +120,11 @@ do
exit 2 exit 2
} }
;; ;;
-test)
passArgs="-test"
runTests=true
;;
# Avoid infinite recursion when invoked from an Allrun/Alltest script # Avoid infinite recursion when invoked from an Allrun/Alltest script
-self* | -skipFirst) -self* | -skipFirst)
skipSelf=true skipSelf=true
;; ;;
--)
shift
break
;;
*) *)
break break
;; ;;
...@@ -106,34 +133,43 @@ do ...@@ -106,34 +133,43 @@ do
done done
unset exitCode # Use specialized script(s), but not on self
if [ -z "$skipSelf" ] if [ -z "$skipSelf" ]
then then
# Use specialized script(s) # Use specialized script(s)
if [ "$runTests" = true ] && [ -f Alltest ] if [ "$runTests" = true ] && [ -f Alltest ]
then then
./Alltest $passArgs $* ./Alltest $passArgs $*
exitCode="$?" exit "$?"
elif [ -f Allrun ]
then
./Allrun $passArgs $*
exitCode="$?"
elif [ -f Allrun-optional ] elif [ -f Allrun-optional ]
then then
echo "Skipped optional case $PWD" echo "Skipped optional case $PWD"
exitCode=0 exit 0
fi
# Prefer -serial or -parallel when available?
if [ -n "$runType" ]
then
if [ -f ./"Allrun-${runType}" ]
then
./"Allrun-${runType}" $passArgs $*
exit "$?"
fi
fi
if [ -f ./Allrun ]
then
./Allrun $passArgs $*
exit "$?"
fi fi
fi fi
if [ -n "$exitCode" ] if [ -d system ]
then
exit "$exitCode"
elif [ -d system ]
then then
# Run normal case with blockMesh and the application # Run normal case with blockMesh and the application
runApplication blockMesh runApplication blockMesh
runApplication $(getApplication) runApplication $(getApplication)
else else
# Loop over sub-directories and compile any applications # Loop over sub-directories and compile any applications
for caseName in * for caseName in *
...@@ -143,12 +179,14 @@ else ...@@ -143,12 +179,14 @@ else
( compileApplication "$caseName" ) ( compileApplication "$caseName" )
fi fi
done done
FOAM_TARGETS=$(for d in *; do [ -d "$d" ] && echo "$d"; done | xargs)
subdirs=$(for d in *; do [ -d "$d" ] && echo "$d"; done | xargs)
# Run all cases which have not already been run # Run all cases which have not already been run
$make -k -f $WM_PROJECT_DIR/bin/tools/MakefileDirs \ "$make" -k -f "${WM_PROJECT_DIR:?}"/bin/tools/MakefileDirs \
FOAM_TARGETS="$FOAM_TARGETS" \ FOAM_TARGETS="$subdirs" \
FOAM_APP="$thisScript" FOAM_ARGS="$passArgs $*" FOAM_APP="$thisScript" \
FOAM_ARGS="$passArgs ${runType:+--run=$runType} $*"
fi fi
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
...@@ -76,7 +76,14 @@ optRunLimit=1 ...@@ -76,7 +76,14 @@ optRunLimit=1
while [ "$#" -gt 0 ] while [ "$#" -gt 0 ]
do do
case "$1" in case "$1" in
-h* | -help*) printHelp ;; (- | --)
shift
break # Stop option parsing
;;
(-h* | -help* | --help*)
printHelp
;;
-force) -force)
optForce=true optForce=true
...@@ -102,10 +109,6 @@ do ...@@ -102,10 +109,6 @@ do
outputDir="${1#*=}" outputDir="${1#*=}"
;; ;;
--)
break
;;
-*) -*)
die "unknown option $1" die "unknown option $1"
;; ;;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment