mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: support -case option for foamCleanTutorials, foamRunTutorials
- makes it easier to run/clean individual cases
This commit is contained in:
@ -7,23 +7,10 @@
|
|||||||
# \\/ M anipulation |
|
# \\/ M anipulation |
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
# Copyright (C) 2011 OpenFOAM Foundation
|
# Copyright (C) 2011 OpenFOAM Foundation
|
||||||
# Copyright (C) 2019 OpenCFD Ltd.
|
# Copyright (C) 2019-2020 OpenCFD Ltd.
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
# License
|
# License
|
||||||
# This file is part of OpenFOAM.
|
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
|
||||||
#
|
|
||||||
# OpenFOAM is free software: you can redistribute it and/or modify it
|
|
||||||
# under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
# for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
#
|
||||||
# Script
|
# Script
|
||||||
# foamCleanTutorials
|
# foamCleanTutorials
|
||||||
@ -32,10 +19,6 @@
|
|||||||
# Run either Allwclean, Allclean or default cleanCase in current directory
|
# Run either Allwclean, Allclean or default cleanCase in current directory
|
||||||
# and all its subdirectories.
|
# and all its subdirectories.
|
||||||
#
|
#
|
||||||
# When an argument is provided, it is treated as a directory name.
|
|
||||||
# If an option (eg, -self) is provided, it suppresses calling
|
|
||||||
# Allwclean or Allclean (ie, to avoid recursion)
|
|
||||||
#
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
. $WM_PROJECT_DIR/bin/tools/CleanFunctions # Tutorial clean functions
|
. $WM_PROJECT_DIR/bin/tools/CleanFunctions # Tutorial clean functions
|
||||||
|
|
||||||
@ -45,29 +28,68 @@ then
|
|||||||
thisScript="$PWD/$thisScript"
|
thisScript="$PWD/$thisScript"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Simple option/argument parsing.
|
printHelp() {
|
||||||
# By default use Allclean, Allwclean when present
|
cat <<USAGE
|
||||||
#
|
|
||||||
# If an argument is supplied, treat as a change directory
|
|
||||||
#
|
|
||||||
# If an option (eg, -self) is provided,
|
|
||||||
# do not execute ./Allwclean or ./Allclean (to avoid recursion)
|
|
||||||
|
|
||||||
withAllclean=true
|
Usage: ${0##*/} [OPTION]
|
||||||
|
${0##*/} [OPTION] directory
|
||||||
|
options:
|
||||||
|
-0 use cleanCase0 instead of cleanCase
|
||||||
|
-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.
|
||||||
|
By default uses Allclean, Allwclean when present.
|
||||||
|
|
||||||
|
USAGE
|
||||||
|
exit 0 # clean exit
|
||||||
|
}
|
||||||
|
|
||||||
|
# Report error and exit
|
||||||
|
die()
|
||||||
|
{
|
||||||
|
exec 1>&2
|
||||||
|
echo
|
||||||
|
echo "Error encountered:"
|
||||||
|
while [ "$#" -ge 1 ]; do echo " $1"; shift; done
|
||||||
|
echo
|
||||||
|
echo "See '${0##*/} -help' for usage"
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Parse options
|
||||||
|
unset skipSelf clean0
|
||||||
if [ "$#" -gt 0 ]
|
if [ "$#" -gt 0 ]
|
||||||
then
|
then
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-h | -help*)
|
-h | -help*)
|
||||||
echo "${0##*/}: recursively clean an OpenFOAM case directory" 1>&2
|
printHelp
|
||||||
exit 0
|
|
||||||
;;
|
;;
|
||||||
-self | -*)
|
-0)
|
||||||
unset withAllclean
|
clean0=true
|
||||||
|
;;
|
||||||
|
-case)
|
||||||
|
[ "$#" -ge 2 ] || die "'$1' option requires an argument"
|
||||||
|
shift
|
||||||
|
cd "$1" 2>/dev/null || {
|
||||||
|
echo "${0##*}: No such directory $1" 1>&2
|
||||||
|
exit 2
|
||||||
|
}
|
||||||
|
;;
|
||||||
|
-self*)
|
||||||
|
skipSelf=true
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
cd "$1" 2>/dev/null || {
|
cd "$1" 2>/dev/null || {
|
||||||
echo "${0##*}: No such directory" 1>&2
|
echo "${0##*}: No such directory $1" 1>&2
|
||||||
exit 2
|
exit 2
|
||||||
}
|
}
|
||||||
;;
|
;;
|
||||||
@ -75,18 +97,34 @@ then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [ -n "$withAllclean" ] && [ -f Allwclean ]
|
unset exitCode
|
||||||
|
if [ -z "$skipSelf" ]
|
||||||
then
|
then
|
||||||
# Specialized script
|
# Use specialized script(s)
|
||||||
./Allwclean
|
if [ -f Allwclean ]
|
||||||
elif [ -n "$withAllclean" ] && [ -f Allclean ]
|
then
|
||||||
|
./Allwclean
|
||||||
|
exitCode="$?"
|
||||||
|
elif [ -f Allclean ]
|
||||||
|
then
|
||||||
|
./Allclean
|
||||||
|
exitCode="$?"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
if [ -n "$exitCode" ]
|
||||||
then
|
then
|
||||||
# Specialized script
|
exit "$exitCode"
|
||||||
./Allclean
|
|
||||||
elif [ -d system ]
|
elif [ -d system ]
|
||||||
then
|
then
|
||||||
# Normal case
|
# Normal case
|
||||||
cleanCase
|
if [ "$clean0" = true ]
|
||||||
|
then
|
||||||
|
cleanCase0
|
||||||
|
else
|
||||||
|
cleanCase
|
||||||
|
fi
|
||||||
elif [ -d Make ]
|
elif [ -d Make ]
|
||||||
then
|
then
|
||||||
# Normal application
|
# Normal application
|
||||||
@ -95,7 +133,7 @@ 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" )
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@ -7,18 +7,17 @@
|
|||||||
# \\/ M anipulation |
|
# \\/ M anipulation |
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
# Copyright (C) 2011-2016 OpenFOAM Foundation
|
# Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
# Copyright (C) 2018-2019 OpenCFD Ltd.
|
# Copyright (C) 2018-2020 OpenCFD Ltd.
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
# License
|
# License
|
||||||
# This file is part of OpenFOAM, licensed under GNU General Public License
|
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
|
||||||
# <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
#
|
||||||
# Script
|
# Script
|
||||||
# foamRunTutorials
|
# foamRunTutorials
|
||||||
#
|
#
|
||||||
# Description
|
# Description
|
||||||
# Run either Allrun or blockMesh/application in current directory
|
# Recursively run Allrun/Alltest or blockMesh+application,
|
||||||
# and all its subdirectories.
|
# 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
|
||||||
# placeholder can be used instead of the usual Allrun script.
|
# placeholder can be used instead of the usual Allrun script.
|
||||||
@ -36,20 +35,67 @@ then
|
|||||||
thisScript="$PWD/$thisScript"
|
thisScript="$PWD/$thisScript"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
unset passArgs runTests skipFirst
|
printHelp() {
|
||||||
|
cat <<USAGE
|
||||||
|
|
||||||
|
Usage: ${0##*/} [OPTION]
|
||||||
|
options:
|
||||||
|
-case <dir> specify starting directory, default is cwd
|
||||||
|
-self | -skipFirst avoid Allrun, Alltest script (prevent infinite recursion)
|
||||||
|
-test prefer Alltest script, pass -test argument to scripts
|
||||||
|
-help print the usage
|
||||||
|
|
||||||
|
Recursively run Allrun/Alltest or blockMesh+application,
|
||||||
|
starting with the current directory or the specified -case directory.
|
||||||
|
|
||||||
|
USAGE
|
||||||
|
exit 0 # clean exit
|
||||||
|
}
|
||||||
|
|
||||||
|
# Report error and exit
|
||||||
|
die()
|
||||||
|
{
|
||||||
|
exec 1>&2
|
||||||
|
echo
|
||||||
|
echo "Error encountered:"
|
||||||
|
while [ "$#" -ge 1 ]; do echo " $1"; shift; done
|
||||||
|
echo
|
||||||
|
echo "See '${0##*/} -help' for usage"
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
# Parse options
|
# Parse options
|
||||||
|
unset passArgs runTests skipSelf
|
||||||
|
|
||||||
while [ "$#" -gt 0 ]
|
while [ "$#" -gt 0 ]
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-t | -test)
|
-h | -help*)
|
||||||
|
printHelp
|
||||||
|
;;
|
||||||
|
-case)
|
||||||
|
[ "$#" -ge 2 ] || die "'$1' option requires an argument"
|
||||||
|
shift
|
||||||
|
cd "$1" 2>/dev/null || {
|
||||||
|
echo "${0##*}: No such directory $1" 1>&2
|
||||||
|
exit 2
|
||||||
|
}
|
||||||
|
;;
|
||||||
|
-test)
|
||||||
passArgs="-test"
|
passArgs="-test"
|
||||||
runTests=true
|
runTests=true
|
||||||
;;
|
;;
|
||||||
|
|
||||||
# Avoid infinite recursion when invoked from an Allrun or Alltest script
|
# Avoid infinite recursion when invoked from an Allrun/Alltest script
|
||||||
-s | -skipFirst)
|
-self* | -skipFirst)
|
||||||
skipFirst=true
|
skipSelf=true
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
break
|
break
|
||||||
@ -58,18 +104,30 @@ do
|
|||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -z "$skipFirst" ] && [ -n "$runTests" ] && test -f Alltest
|
|
||||||
|
unset exitCode
|
||||||
|
if [ -z "$skipSelf" ]
|
||||||
then
|
then
|
||||||
# Run specialized Alltest script
|
# Use specialized script(s)
|
||||||
./Alltest $passArgs $*
|
if [ "$runTests" = true ] && [ -f Alltest ]
|
||||||
elif [ -z "$skipFirst" ] && test -f Allrun
|
then
|
||||||
|
./Alltest $passArgs $*
|
||||||
|
exitCode="$?"
|
||||||
|
elif [ -f Allrun ]
|
||||||
|
then
|
||||||
|
./Allrun $passArgs $*
|
||||||
|
exitCode="$?"
|
||||||
|
elif [ -f Allrun-optional ]
|
||||||
|
then
|
||||||
|
echo "Skipped optional case $PWD"
|
||||||
|
exitCode=0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
if [ -n "$exitCode" ]
|
||||||
then
|
then
|
||||||
# Run specialized Allrun script
|
exit "$exitCode"
|
||||||
./Allrun $passArgs $*
|
|
||||||
elif [ -z "$skipFirst" ] && test -f Allrun-optional
|
|
||||||
then
|
|
||||||
# Has Allrun-optional script - skip this tutorial.
|
|
||||||
echo "Skipped optional case $PWD"
|
|
||||||
elif [ -d system ]
|
elif [ -d system ]
|
||||||
then
|
then
|
||||||
# Run normal case with blockMesh and the application
|
# Run normal case with blockMesh and the application
|
||||||
@ -79,7 +137,7 @@ else
|
|||||||
# Loop over sub-directories and compile any applications
|
# Loop over sub-directories and compile any applications
|
||||||
for caseName in *
|
for caseName in *
|
||||||
do
|
do
|
||||||
if [ -d "$caseName" ] && [ -d "$caseName/Make" ]
|
if [ -d "$caseName/Make" ]
|
||||||
then
|
then
|
||||||
( compileApplication "$caseName" )
|
( compileApplication "$caseName" )
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user