ENH: improve handling of etc/controlDict for Alltest

- only backup/modify controlDict if it contains a DebugSwitches entry

- add -no-debug option to suppress modification entirely
This commit is contained in:
Mark Olesen 2019-01-15 09:36:15 +01:00
parent 2a1d0f36ec
commit 02ea8b1ce8

View File

@ -4,7 +4,7 @@
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
# \\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
# \\/ M anipulation | Copyright (C) 2017-2019 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, licensed under GNU General Public License
@ -20,7 +20,7 @@
# The entire OpenFOAM environment (WM_PROJECT_DIR, etc)
#
#------------------------------------------------------------------------------
cd ${0%/*} || exit 1 # Run from this directory
cd "${0%/*}" || exit 1 # Run from this directory
usage()
{
@ -33,6 +33,7 @@ usage: ${0##*/} [OPTION]
options:
-git Use git to retrieve the tutorials
-no-git Do not use git to retrieve the tutorials
-no-debug Do not adjust DebugSwitches (fvSchemes, solution)
-root dir Specify root directory to run tests from
-default Sets up a default scheme on all schemes
-help Print the usage
@ -61,8 +62,9 @@ die()
#------------------------------------------------------------------------------
ROOT="./"
unset DEFAULT_SCHEMES
useDefaultSchemes=false
useGit=auto
adjustDebugSwitches=true
# Parse options
while [ "$#" -gt 0 ]
@ -82,8 +84,11 @@ do
-no-git)
unset useGit
;;
-no-debug)
unset adjustDebugSwitches
;;
-d | -default)
DEFAULT_SCHEMES=true
useDefaultSchemes=true
;;
*)
die "Unknown option/argument: '$1'"
@ -93,7 +98,7 @@ do
done
# Set FOAM_TUTORIALS directory location, as required.
. $WM_PROJECT_DIR/bin/tools/RunFunctions
. "${WM_PROJECT_DIR:?}/bin/tools/RunFunctions"
#------------------------------------------------------------------------------
@ -131,17 +136,27 @@ EOF
#
# Location of the user or project controlDict
# Locate the user or project controlDict to adjust
#
if MAIN_CONTROL_DICT="$($WM_PROJECT_DIR/bin/foamEtcFile -mode=uo controlDict)"
unset ETC_CONTROL_DICT
if [ "$adjustDebugSwitches" = true ]
then
if [ -e "${MAIN_CONTROL_DICT}.orig" ]
if ETC_CONTROL_DICT="$($WM_PROJECT_DIR/bin/foamEtcFile -mode=uo controlDict)"
then
die "File ${MAIN_CONTROL_DICT}.orig already exists" \
"Did Alltest fail in some way and then run again?"
if [ -e "${ETC_CONTROL_DICT}.orig" ]
then
die "File ${ETC_CONTROL_DICT}.orig already exists" \
"Did Alltest fail in some way and then run again?"
fi
grep DebugSwitches "${ETC_CONTROL_DICT}" 1> /dev/null 2>&1 || {
echo "No DebugSwitches to adjust in ${ETC_CONTROL_DICT}" 1>&2
unset ETC_CONTROL_DICT
}
else
echo "No main (user or project) controlDict to adjust" 1>&2
unset ETC_CONTROL_DICT
fi
else
die "No main (user or project) controlDict found"
fi
@ -176,7 +191,7 @@ buildDir="$WM_PROJECT_DIR/build/$WM_OPTIONS/${TEST_RUN_DIR##*/}"
if [ -d "$buildDir" ]
then
echo "Removing old build directory: $buildDir" 1>&2
rm -rf $buildDir
rm -rf "$buildDir"
fi
unset gitbase
@ -208,7 +223,7 @@ fi
if [ -n "$gitbase" ]
then
echo "Copying the tutorials from current git branch" 1>&2
mkdir -p ${TEST_RUN_DIR}
mkdir -p "${TEST_RUN_DIR}"
( cd "$gitbase/tutorials" && git archive --format=tar HEAD . ) | \
( cd "$TEST_RUN_DIR" && tar -xf - )
else
@ -216,37 +231,41 @@ else
cp -a "$TUTORIALS_DIR" "$TEST_RUN_DIR"
fi
cd "${TEST_RUN_DIR}" || exit 1
echo 1>&2
# Clean up on termination and on Ctrl-C
trap 'mv ${MAIN_CONTROL_DICT}.orig ${MAIN_CONTROL_DICT} 2>/dev/null; exit 0' \
EXIT TERM INT
cp -f "${MAIN_CONTROL_DICT}" "${MAIN_CONTROL_DICT}.orig"
# Adjust etc controlDict, and clean up on termination and on Ctrl-C
if [ -f "${ETC_CONTROL_DICT}" ]
then
trap 'mv ${ETC_CONTROL_DICT}.orig ${ETC_CONTROL_DICT} 2>/dev/null; exit 0' \
EXIT TERM INT
echo "Modifying ${MAIN_CONTROL_DICT}" 1>&2
echo "Modifying DebugSwitches: ${ETC_CONTROL_DICT}" 1>&2
sed \
-e s/"\(fvSchemes[ \t]*\)\([0-9]\);"/"\1 1;"/g \
-e s/"\(solution[ \t]*\)\([0-9]\);"/"\1 1;"/g \
"${MAIN_CONTROL_DICT}.orig" > "${MAIN_CONTROL_DICT}"
cp -f "${ETC_CONTROL_DICT}" "${ETC_CONTROL_DICT}.orig"
sed \
-e 's/\(fvSchemes[ \t]*\)\([0-9]\);/\1 1;/g' \
-e 's/"\(solution[ \t]*\)\([0-9]\);/\1 1;/g' \
"${ETC_CONTROL_DICT}.orig" > "${ETC_CONTROL_DICT}"
fi
cd "${TEST_RUN_DIR}" || exit 1
echo "Modifying the controlDicts to run only one time step" 1>&2
echo "Modifying the case controlDicts to run only one time step" 1>&2
echo 1>&2
for CD in $(find . -name "controlDict*" -type f)
do
cp -f "${CD}" "${CD}.orig"
sed \
-e s/"\(startFrom[ \t]*\)\([a-zA-Z]*\);"/"\1 latestTime;"/g \
-e s/"\(stopAt[ \t]*\)\([a-zA-Z]*\);"/"\1 nextWrite;"/g \
-e s/"\(writeControl[ \t]*\)\([a-zA-Z]*\);"/"\1 timeStep;"/g \
-e s/"\(writeInterval[ \t]*\)\([0-9a-zA-Z.-]*\);"/"\1 1;"/g \
-e 's/\(startFrom[ \t]*\)\([a-zA-Z]*\);/\1 latestTime;/g' \
-e 's/\(stopAt[ \t]*\)\([a-zA-Z]*\);/\1 nextWrite;/g' \
-e 's/\(writeControl[ \t]*\)\([a-zA-Z]*\);/\1 timeStep;/g' \
-e 's/\(writeInterval[ \t]*\)\([0-9a-zA-Z.-]*\);/\1 1;/g' \
"${CD}.orig" > "${CD}"
done
if [ "$DEFAULT_SCHEMES" = true ]
if [ "$useDefaultSchemes" = true ]
then
echo "Modifying the fvSchemes to contain only default schemes" 1>&2
for FV_SC in $(find . -name fvSchemes -type f)
@ -260,10 +279,11 @@ then
done
fi
cp -f $FOAM_TUTORIALS/Allrun .
[ -f Allrun ] || cp -f "${FOAM_TUTORIALS:?}/Allrun" .
./Allrun -test
# The rest here doesn't seem to be used
sed -e :a -e '/\\$/N; s/\\\n//; ta' Allrun > temp
APPLICATIONS=\
$(grep "applications=" temp | sed 's/applications=\"\([A-Za-z \t]*\)\"/\1/g')