Commit c792a9d7 authored by Mark Olesen's avatar Mark Olesen
Browse files

TUT: script cleanup, provide cleanCase0 for commonly used operation

parent e16121af
......@@ -15,4 +15,4 @@ fi
wmake
# ----------------------------------------------------------------- end-of-file
#------------------------------------------------------------------------------
......@@ -30,9 +30,7 @@
# and all its subdirectories.
#
#------------------------------------------------------------------------------
# Source tutorial clean functions
. $WM_PROJECT_DIR/bin/tools/CleanFunctions
. $WM_PROJECT_DIR/bin/tools/CleanFunctions # Tutorial clean functions
thisScript=$0
if [ "/${thisScript#/}" != "$thisScript" ]
......
......@@ -30,19 +30,18 @@
# and all its subdirectories.
#
#------------------------------------------------------------------------------
. $WM_PROJECT_DIR/bin/tools/RunFunctions # Tutorial run functions
# Normally use standard "make"
make="make"
# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions
thisScript=$0
if [ "/${thisScript#/}" != "$thisScript" ]
then
thisScript="$PWD/$thisScript"
fi
unset passArgs runTests
skipFirst=false
# Parse options
......@@ -52,16 +51,15 @@ do
-t | -test)
passArgs="-test"
runTests=true
shift
;;
-s | -skipFirst)
skipFirst=true
shift
;;
*)
break
;;
esac
shift
done
# If an argument is supplied do not execute ./Allrun to avoid recursion
......
......@@ -31,7 +31,7 @@
cleanTimeDirectories()
{
echo "Cleaning $PWD case"
echo "Cleaning case $PWD"
zeros=""
while [ ${#zeros} -lt 8 ]
do
......@@ -105,15 +105,13 @@ cleanCase()
cleanSnappyFiles
rm -f 0/cellDist > /dev/null 2>&1
if [ -d constant ]
then
(cd constant && \
rm -rf \
cellDecomposition cellToRegion cellLevel* pointLevel* \
polyMesh tetDualMesh \
> /dev/null 2>&1 \
)
fi
(
cd constant 2>/dev/null && \
rm -rf \
cellDecomposition cellToRegion cellLevel* pointLevel* \
polyMesh tetDualMesh \
> /dev/null 2>&1 \
)
if [ -e system/blockMeshDict.m4 ]
then
......@@ -122,9 +120,17 @@ cleanCase()
}
# Frequently used - cleanCase and rm -rf 0/
cleanCase0()
{
cleanCase
rm -rf 0
}
removeCase()
{
echo "Removing ${1:-unknown} case"
echo "Removing case ${1:-unknown}"
[ "$#" -ge 1 ] && rm -rf "$1"
}
......@@ -143,7 +149,7 @@ cleanUcomponents()
cleanApplication()
{
echo "Cleaning $PWD application"
echo "Cleaning application $PWD"
wclean
}
......
......@@ -3,7 +3,7 @@
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
# \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
# \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM.
......@@ -43,6 +43,7 @@ isParallel()
return 1
}
#
# Look for '-test' in the argument list.
#
......@@ -52,6 +53,7 @@ isTest()
return 1
}
#
# Extract 'numberOfSubdomains' from system/decomposeParDict
# (or alternative location).
......@@ -100,120 +102,139 @@ getApplication()
fi
}
#
# Run given application in serial with logfile output.
# The preexistence of the log file prevents rerunning.
#
runApplication()
{
APP_RUN=
LOG_IGNORE=false
LOG_APPEND=false
LOG_SUFFIX=
# Parse options and executable
while [ $# -gt 0 ] && [ -z "$APP_RUN" ]; do
key="$1"
case "$key" in
-append|-a)
LOG_IGNORE=true
LOG_APPEND=true
local appRun logFile logMode
# Any additional parsed arguments (eg, decomposeParDict)
local appArgs
# Parse options until executable is encountered
while [ $# -gt 0 -a -z "$appRun" ]
do
case "$1" in
-a | -append)
logMode=append
;;
-overwrite|-o)
LOG_IGNORE=true
-o | -overwrite)
logMode=overwrite
;;
-suffix|-s)
LOG_SUFFIX=".$2"
-s | -suffix)
logFile=".$2"
shift
;;
-decomposeParDict)
appArgs="$appArgs $1 $2"
shift
;;
'')
;;
*)
APP_RUN="$key"
APP_NAME="${key##*/}"
LOG_SUFFIX="${APP_NAME}${LOG_SUFFIX}"
appRun="$1"
;;
esac
shift
done
if [ -f log.$LOG_SUFFIX ] && [ "$LOG_IGNORE" = "false" ]
local appName="${appRun##*/}"
logFile="log.$appName$logFile"
if [ -f "$logFile" -a -z "$logMode" ]
then
echo "$APP_NAME already run on $PWD:" \
"remove log file 'log.$LOG_SUFFIX' to re-run"
echo "$appName already run on $PWD:" \
"remove log file '$logFile' to re-run"
else
echo "Running $APP_RUN on $PWD"
if [ "$LOG_APPEND" = "true" ]; then
$APP_RUN "$@" >> log.$LOG_SUFFIX 2>&1
echo "Running $appRun on $PWD"
if [ "$logMode" = append ]
then
$appRun $appArgs "$@" >> $logFile 2>&1
else
$APP_RUN "$@" > log.$LOG_SUFFIX 2>&1
$appRun $appArgs "$@" > $logFile 2>&1
fi
fi
}
#
# Run given application in parallel with logfile output.
# The preexistence of the log file prevents rerunning.
#
runParallel()
{
APP_RUN=
LOG_IGNORE=false
LOG_APPEND=false
LOG_SUFFIX=
# Store any parsed additional arguments e.g. decomposeParDict
APP_PARARGS=
# Initialise number of procs to unset value
nProcs=-1
# Parse options and executable
while [ $# -gt 0 ] && [ -z "$APP_RUN" ]; do
key="$1"
case "$key" in
-append|-a)
LOG_IGNORE=true
LOG_APPEND=true
local appRun logFile logMode nProcs
# Any additional parsed arguments (eg, decomposeParDict)
local appArgs="-parallel"
# Parse options until executable is encountered
while [ $# -gt 0 -a -z "$appRun" ]
do
case "$1" in
-a | -append)
logMode=append
;;
-overwrite|-o)
LOG_IGNORE=true
-o | -overwrite)
logMode=overwrite
;;
-suffix|-s)
LOG_SUFFIX=".$2"
-s | -suffix)
logFile=".$2"
shift
;;
-np|-n)
-n | -np)
nProcs="$2"
shift
;;
-decomposeParDict)
appArgs="$appArgs $1 $2"
nProcs=$(getNumberOfProcessors "$2")
APP_PARARGS="$APP_PARARGS -decomposeParDict $2"
shift
;;
'')
;;
*)
APP_RUN="$key"
APP_NAME="${key##*/}"
LOG_SUFFIX="${APP_NAME}${LOG_SUFFIX}"
appRun="$1"
;;
esac
shift
done
[ "$nProcs" -eq -1 ] && nProcs=$(getNumberOfProcessors system/decomposeParDict)
[ -n "$nProcs" ] || nProcs=$(getNumberOfProcessors system/decomposeParDict)
if [ -f log.$LOG_SUFFIX ] && [ "$LOG_IGNORE" = "false" ]
local appName="${appRun##*/}"
logFile="log.$appName$logFile"
if [ -f "$logFile" -a -z "$logMode" ]
then
echo "$APP_NAME already run on $PWD:" \
"remove log file 'log.$LOG_SUFFIX' to re-run"
echo "$appName already run on $PWD:" \
"remove log file '$logFile' to re-run"
else
echo "Running $APP_RUN in parallel on $PWD using $nProcs processes"
if [ "$LOG_APPEND" = "true" ]; then
( mpirun -np $nProcs $APP_RUN $APP_PARARGS -parallel "$@" < /dev/null >> log.$LOG_SUFFIX 2>&1 )
echo "Running $appRun ($nProcs processes) on $PWD "
if [ "$logMode" = append ]
then
(
mpirun -np $nProcs $appRun $appArgs "$@" </dev/null >> $logFile 2>&1
)
else
( mpirun -np $nProcs $APP_RUN $APP_PARARGS -parallel "$@" < /dev/null > log.$LOG_SUFFIX 2>&1 )
(
mpirun -np $nProcs $appRun $appArgs "$@" </dev/null > $logFile 2>&1
)
fi
fi
}
compileApplication()
{
echo "Compiling $1 application"
wmake $1
}
#
# cloneCase srcDir dstDir
#
......@@ -249,6 +270,7 @@ cloneCase()
return 0
}
#
# cloneParallelCase srcDir dstDir [...times]
#
......@@ -312,6 +334,7 @@ cloneParallelCase()
return 0
}
# Overwrite 0/ with the contents of 0.orig/ if it exists.
# The -processor option to do the processor directories instead
#
......@@ -338,4 +361,5 @@ restore0Dir()
fi
}
#------------------------------------------------------------------------------
......@@ -8,4 +8,4 @@ wmake $targetType snappyHexMesh
wmake $targetType blockMesh
wmake $targetType extrudeModel
# ----------------------------------------------------------------- end-of-file
#------------------------------------------------------------------------------
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
# Source tutorial clean functions
. $WM_PROJECT_DIR/bin/tools/CleanFunctions
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/CleanFunctions # Tutorial clean functions
cleanCase
rm -f 0/enstrophy
......
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/RunFunctions # Tutorial run functions
runApplication blockMesh
runApplication boxTurb
......
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
# Source tutorial clean functions
. $WM_PROJECT_DIR/bin/tools/CleanFunctions
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/CleanFunctions # Tutorial clean functions
cleanCase
......
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/RunFunctions # Tutorial run functions
runApplication blockMesh
......
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/RunFunctions # Tutorial run functions
# Reset the controlDict
if [ -f system/controlDict.orig ]
......
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
# Source tutorial clean functions
. $WM_PROJECT_DIR/bin/tools/CleanFunctions
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/CleanFunctions # Tutorial clean functions
cleanCase
rm -rf Fieldview > /dev/null 2>&1
......
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/RunFunctions # Tutorial run functions
runAnsysToFoam()
{
......
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/CleanFunctions
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/CleanFunctions # Tutorial clean functions
cleanCase0
cleanCase
rm -f constant/polyMesh/boundary
rm -f constant/polyMesh/zoneID
rm -rf 0
#------------------------------------------------------------------------------
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/RunFunctions
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/RunFunctions # Tutorial run functions
./Allrun.pre
......
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/RunFunctions
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/RunFunctions # Tutorial run functions
runApplication blockMesh
......
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/CleanFunctions # Tutorial clean functions
# Source tutorial clean functions
. $WM_PROJECT_DIR/bin/tools/CleanFunctions
cleanCase
rm -rf 0
cleanCase0
#------------------------------------------------------------------------------
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/RunFunctions # Tutorial run functions
restore0Dir
runApplication blockMesh
......
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/CleanFunctions # Tutorial clean functions
# Source tutorial clean functions
. $WM_PROJECT_DIR/bin/tools/CleanFunctions
cleanCase
rm -rf 0
cleanCase0
#------------------------------------------------------------------------------
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/bin/tools/RunFunctions # Tutorial run functions
restore0Dir
runApplication blockMesh
......
Markdown is supported
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