Scripts in bin: improved script quality, option listing and
exit status on -help
This commit is contained in:
@ -3,7 +3,7 @@
|
|||||||
# ========= |
|
# ========= |
|
||||||
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
# \\ / O peration |
|
# \\ / O peration |
|
||||||
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
# \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
# \\/ M anipulation |
|
# \\/ M anipulation |
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# License
|
# License
|
||||||
@ -41,7 +41,7 @@
|
|||||||
# by colons or whitespace
|
# by colons or whitespace
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
usage() {
|
usage() {
|
||||||
cat <<USAGE 1>&2
|
cat <<USAGE
|
||||||
Usage: ${0##*/} [OPTION] path [wildcard1] .. [wildcardN]
|
Usage: ${0##*/} [OPTION] path [wildcard1] .. [wildcardN]
|
||||||
options:
|
options:
|
||||||
-strip remove inaccessible directories
|
-strip remove inaccessible directories
|
||||||
@ -58,6 +58,10 @@ options:
|
|||||||
2 initial value of 'path' is empty
|
2 initial value of 'path' is empty
|
||||||
|
|
||||||
USAGE
|
USAGE
|
||||||
|
}
|
||||||
|
|
||||||
|
error () {
|
||||||
|
usage 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,12 +72,15 @@ while [ "$#" -gt 0 ]
|
|||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-h | -help)
|
-h | -help)
|
||||||
usage
|
usage && exit 0
|
||||||
;;
|
;;
|
||||||
-strip)
|
-strip)
|
||||||
strip=true
|
strip=true
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-*)
|
||||||
|
error
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
@ -81,7 +88,7 @@ do
|
|||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
[ "$#" -ge 1 ] || usage
|
[ "$#" -ge 1 ] || error
|
||||||
|
|
||||||
dirList="$1"
|
dirList="$1"
|
||||||
shift
|
shift
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
# ========= |
|
# ========= |
|
||||||
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
# \\ / O peration |
|
# \\ / O peration |
|
||||||
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
# \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
# \\/ M anipulation |
|
# \\/ M anipulation |
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# License
|
# License
|
||||||
@ -31,8 +31,6 @@
|
|||||||
#
|
#
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
usage() {
|
usage() {
|
||||||
exec 1>&2
|
|
||||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
|
||||||
cat <<USAGE
|
cat <<USAGE
|
||||||
|
|
||||||
Usage: ${0##*/} [OPTION]
|
Usage: ${0##*/} [OPTION]
|
||||||
@ -45,6 +43,12 @@ Remove the contents of the constant/polyMesh directory as per the
|
|||||||
Foam::polyMesh::removeFiles() method.
|
Foam::polyMesh::removeFiles() method.
|
||||||
|
|
||||||
USAGE
|
USAGE
|
||||||
|
}
|
||||||
|
|
||||||
|
error () {
|
||||||
|
exec 1>&2
|
||||||
|
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||||
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,21 +59,21 @@ while [ "$#" -gt 0 ]
|
|||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-h | -help)
|
-h | -help)
|
||||||
usage
|
usage && exit 0
|
||||||
;;
|
;;
|
||||||
-case)
|
-case)
|
||||||
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
|
||||||
cd "$2" 2>/dev/null || usage "directory does not exist: '$2'"
|
cd "$2" 2>/dev/null || error "directory does not exist: '$2'"
|
||||||
caseDir=$2
|
caseDir=$2
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-region)
|
-region)
|
||||||
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
|
||||||
regionName=$2
|
regionName=$2
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
usage "unknown option/argument: '$*'"
|
error "unknown option/argument: '$*'"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
@ -133,7 +137,7 @@ for i in \
|
|||||||
surfaceIndex \
|
surfaceIndex \
|
||||||
;
|
;
|
||||||
do
|
do
|
||||||
rm -rf $meshDir/$i $meshDir/$i.gz
|
rm -rf ${meshDir:?}/$i ${meshDir:?}/$i.gz
|
||||||
done
|
done
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
# ========= |
|
# ========= |
|
||||||
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
# \\ / O peration |
|
# \\ / O peration |
|
||||||
# \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
# \\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation
|
||||||
# \\/ M anipulation |
|
# \\/ M anipulation |
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# License
|
# License
|
||||||
@ -33,38 +33,42 @@
|
|||||||
#
|
#
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
usage() {
|
usage() {
|
||||||
exec 1>&2
|
|
||||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
|
||||||
cat<<USAGE
|
cat<<USAGE
|
||||||
|
|
||||||
Usage: ${0##*/} [OPTION] <sourceCase> <targetCase>
|
Usage: ${0##*/} [OPTION] <source case> <target name>
|
||||||
options:
|
options:
|
||||||
-l | -latestTime clone the latest time directory
|
-latestTime clone the latest time directory
|
||||||
-h | -help print the usage
|
-help print the usage
|
||||||
|
|
||||||
Create a new <targetCase> case directory that includes time, system and constant
|
Create a new <targetCase> case directory that includes time, system and constant
|
||||||
directories of <sourceCase> directory.
|
directories of <sourceCase> directory.
|
||||||
The time directory is the first time directory by default.
|
The time directory is the first time directory by default.
|
||||||
|
|
||||||
USAGE
|
USAGE
|
||||||
|
}
|
||||||
|
|
||||||
|
error () {
|
||||||
|
exec 1>&2
|
||||||
|
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||||
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
TIME_OPTION="head -1"
|
time_option="head -1"
|
||||||
|
|
||||||
# parse options
|
# parse options
|
||||||
while [ "$#" -gt 0 ]
|
while [ "$#" -gt 0 ]
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-h | -help)
|
-h | -help)
|
||||||
usage
|
usage && exit 0
|
||||||
;;
|
;;
|
||||||
-l | -latestTime)
|
-l | -latestTime)
|
||||||
TIME_OPTION="tail -1"
|
time_option="tail -1"
|
||||||
shift 1
|
shift 1
|
||||||
;;
|
;;
|
||||||
-*)
|
-*)
|
||||||
usage "unknown option: '$*'"
|
error "unknown option: '$*'"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
break
|
break
|
||||||
@ -72,19 +76,18 @@ do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
[ $# -eq 2 ] || usage "Incorrect arguments specified"
|
[ $# -eq 2 ] || error "Incorrect arguments specified"
|
||||||
if [ "$(foamListTimes -case $1 2>&1 >/dev/null | grep 'FOAM FATAL ERROR')" ]
|
foamListTimes -case "$1" >/dev/null 2>&1 || \
|
||||||
then
|
error "'$1' is not a valid case directory"
|
||||||
usage "$1 is not does not a valid case directory"
|
|
||||||
fi
|
! [ -e "$2" ] || error "'$2' file/directory already exists, delete and re-run"
|
||||||
! [ -e $2 ] || usage "$2 file/directory already exists, delete and re-run"
|
|
||||||
|
|
||||||
echo "Making $2 case directory"
|
echo "Making $2 case directory"
|
||||||
mkdir $2
|
mkdir "$2"
|
||||||
|
|
||||||
TIME_DIR="$(foamListTimes -withZero -case $1 | $TIME_OPTION)"
|
time_dir="$(foamListTimes -withZero -case "$1" | $time_option)"
|
||||||
|
|
||||||
echo "Copying case directories from $1 to $2"
|
echo "Copying case directories from $1 to $2"
|
||||||
cp -r $1/system $1/constant $1/${TIME_DIR} $2
|
cp -r "$1"/system "$1"/constant "$1"/"${time_dir}" "$2"
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
# ========= |
|
# ========= |
|
||||||
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
# \\ / O peration |
|
# \\ / O peration |
|
||||||
# \\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation
|
# \\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation
|
||||||
# \\/ M anipulation |
|
# \\/ M anipulation |
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# License
|
# License
|
||||||
@ -32,19 +32,17 @@
|
|||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
usage () {
|
usage () {
|
||||||
exec 1>&2
|
|
||||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
|
||||||
cat <<USAGE
|
cat <<USAGE
|
||||||
|
|
||||||
Usage: ${0##*/} [OPTIONS] ...
|
Usage: ${0##*/} [OPTIONS] ...
|
||||||
options:
|
options:
|
||||||
-d | -dir <dir> directory containing png images (default local dir)
|
-dir | -d <dir> directory containing png images (default local dir)
|
||||||
-f | -fps <fps> frames per second (default = 10)
|
-fps | -f <fps> frames per second (default = 10)
|
||||||
-h | -help help
|
-help | -h help
|
||||||
-i | -image <name> name of image sequence (default = image)
|
-image | -i <name> name of image sequence (default = image)
|
||||||
-o | -out <name> name of output video file (default = video)
|
-out | -o <name> name of output video file (default = video)
|
||||||
-s | -start <frame> specify the start frame number for avconv
|
-start | -s <frame> specify the start frame number for avconv
|
||||||
-w | -webm WebM output video file format
|
-webm | -w WebM output video file format
|
||||||
|
|
||||||
Creates a video file from a sequence of PNG images
|
Creates a video file from a sequence of PNG images
|
||||||
- A sequence named "image" will expect files image.0000.png, image.0001.png, etc
|
- A sequence named "image" will expect files image.0000.png, image.0001.png, etc
|
||||||
@ -55,56 +53,55 @@ Creates a video file from a sequence of PNG images
|
|||||||
Requires avconv or mencoder for MPEG-4 output, avconv for WebM output
|
Requires avconv or mencoder for MPEG-4 output, avconv for WebM output
|
||||||
|
|
||||||
USAGE
|
USAGE
|
||||||
|
}
|
||||||
|
|
||||||
|
error () {
|
||||||
|
exec 1>&2
|
||||||
|
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||||
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Default settings
|
# Default settings
|
||||||
DIR='.'
|
dir=.
|
||||||
IMAGE='image'
|
image=image
|
||||||
VIDEO='video'
|
video=video
|
||||||
FPS=10
|
fps=10
|
||||||
FMT='mp4'
|
fmt=mp4
|
||||||
START_NUMBER=''
|
|
||||||
|
|
||||||
while [ "$#" -gt 0 ]
|
while [ "$#" -gt 0 ]
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-h | -help)
|
-h | -help)
|
||||||
usage
|
usage && exit 0
|
||||||
;;
|
;;
|
||||||
-d | -directory)
|
-d | -dir)
|
||||||
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
|
||||||
DIR=$2
|
dir=$2
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-f | -fps)
|
-f | -fps)
|
||||||
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
|
||||||
FPS=$2
|
fps=$2
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-i | -image)
|
-i | -image)
|
||||||
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
|
||||||
IMAGE=$2
|
image=$2
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-o | -out)
|
-o | -out)
|
||||||
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
|
||||||
VIDEO=$2
|
video=$2
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
-s | -start)
|
|
||||||
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
|
||||||
START_NUMBER="-start_number $2"
|
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-w | -webm)
|
-w | -webm)
|
||||||
FMT=webm
|
fmt=webm
|
||||||
echo "Selected $FMT format, requires avconv..."
|
echo "Selected $fmt format, requires avconv..."
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-*)
|
-*)
|
||||||
usage "invalid option '$1'"
|
error "invalid option '$1'"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
break
|
break
|
||||||
@ -116,37 +113,36 @@ done
|
|||||||
# MAIN
|
# MAIN
|
||||||
#
|
#
|
||||||
|
|
||||||
[ -f "$(ls -1 $DIR/$IMAGE.*.png | head -1)" ] || usage "Cannot find first file in image sequence"
|
[ -f "$(find "$dir" -name "$image.*.png" | sort | head -1)" ] || \
|
||||||
|
error "Cannot find first file in image sequence"
|
||||||
|
|
||||||
if [ "$FMT" = "webm" ] ; then
|
if [ "$fmt" = "webm" ] ; then
|
||||||
if command -v avconv >/dev/null 2>&1 ; then
|
if command -v avconv >/dev/null 2>&1 ; then
|
||||||
echo "Creating image with avconv..."
|
echo "Creating image with avconv..."
|
||||||
avconv \
|
avconv \
|
||||||
-framerate $FPS \
|
-framerate "$fps" \
|
||||||
$START_NUMBER \
|
-i "${dir}/${image}.%04d.png" \
|
||||||
-i ${DIR}/${IMAGE}.%04d.png \
|
|
||||||
-c:v libvpx -crf 15 -b:v 1M \
|
-c:v libvpx -crf 15 -b:v 1M \
|
||||||
$VIDEO.$FMT
|
"$video.$fmt"
|
||||||
else
|
else
|
||||||
usage "Please install avconv"
|
error "Please install avconv"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if command -v avconv >/dev/null 2>&1 ; then
|
if ! command -v avconv >/dev/null 2>&1 ; then
|
||||||
echo "Creating image with avconv..."
|
echo "Creating image with avconv..."
|
||||||
avconv \
|
avconv \
|
||||||
-framerate $FPS \
|
-framerate "$fps" \
|
||||||
$START_NUMBER \
|
-i "${dir}/${image}.%04d.png" \
|
||||||
-i ${DIR}/${IMAGE}.%04d.png \
|
|
||||||
-c:v libx264 -pix_fmt yuv420p \
|
-c:v libx264 -pix_fmt yuv420p \
|
||||||
$VIDEO.$FMT
|
"$video.$fmt"
|
||||||
elif command -v mencoder >/dev/null 2>&1 ; then
|
elif command -v mencoder >/dev/null 2>&1 ; then
|
||||||
echo "Creating image with mencoder..."
|
echo "Creating image with mencoder..."
|
||||||
mencoder \
|
mencoder \
|
||||||
"mf://$DIR/$IMAGE.*.png" \
|
"mf://$dir/$image.*.png" \
|
||||||
-mf fps=$FPS \
|
-mf fps="$fps" \
|
||||||
-o $VIDEO.$FMT \
|
-o "$video.$fmt" \
|
||||||
-ovc x264
|
-ovc x264
|
||||||
else
|
else
|
||||||
usage "Please install avconv or mencoder"
|
error "Please install avconv or mencoder"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
22
bin/foamExec
22
bin/foamExec
@ -3,7 +3,7 @@
|
|||||||
# ========= |
|
# ========= |
|
||||||
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
# \\ / O peration |
|
# \\ / O peration |
|
||||||
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
# \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
# \\/ M anipulation |
|
# \\/ M anipulation |
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# License
|
# License
|
||||||
@ -48,8 +48,6 @@
|
|||||||
#
|
#
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
usage() {
|
usage() {
|
||||||
exec 1>&2
|
|
||||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
|
||||||
cat<<USAGE
|
cat<<USAGE
|
||||||
|
|
||||||
Usage: ${0##*/} [OPTION] <application> ...
|
Usage: ${0##*/} [OPTION] <application> ...
|
||||||
@ -64,6 +62,12 @@ options:
|
|||||||
* run a particular OpenFOAM version of <application>
|
* run a particular OpenFOAM version of <application>
|
||||||
|
|
||||||
USAGE
|
USAGE
|
||||||
|
}
|
||||||
|
|
||||||
|
error () {
|
||||||
|
exec 1>&2
|
||||||
|
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||||
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,21 +92,21 @@ while [ "$#" -gt 0 ]
|
|||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-h | -help)
|
-h | -help)
|
||||||
usage
|
usage && exit 0
|
||||||
;;
|
;;
|
||||||
-m | -mode)
|
-m | -mode)
|
||||||
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
|
||||||
etcOpts="$etcOpts $1 $2" # pass-thru to foamEtcFile
|
etcOpts="$etcOpts $1 $2" # pass-thru to foamEtcFile
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-p | -prefix)
|
-p | -prefix)
|
||||||
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
|
||||||
etcOpts="$etcOpts $1 $2" # pass-thru to foamEtcFile
|
etcOpts="$etcOpts $1 $2" # pass-thru to foamEtcFile
|
||||||
prefixDir="$2"
|
prefixDir="$2"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-v | -version)
|
-v | -version)
|
||||||
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
|
||||||
etcOpts="$etcOpts $1 $2" # pass-thru to foamEtcFile
|
etcOpts="$etcOpts $1 $2" # pass-thru to foamEtcFile
|
||||||
version="$2"
|
version="$2"
|
||||||
shift
|
shift
|
||||||
@ -112,7 +116,7 @@ do
|
|||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
-*)
|
-*)
|
||||||
usage "invalid option '$1'"
|
error "invalid option '$1'"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
break
|
break
|
||||||
@ -139,7 +143,7 @@ sourceRc()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[ "$#" -ge 1 ] || usage "no application specified"
|
[ "$#" -ge 1 ] || error "no application specified"
|
||||||
|
|
||||||
sourceRc
|
sourceRc
|
||||||
exec "$@"
|
exec "$@"
|
||||||
|
|||||||
69
bin/foamJob
69
bin/foamJob
@ -3,7 +3,7 @@
|
|||||||
# ========= |
|
# ========= |
|
||||||
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
# \\ / O peration |
|
# \\ / O peration |
|
||||||
# \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
# \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
# \\/ M anipulation |
|
# \\/ M anipulation |
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# License
|
# License
|
||||||
@ -31,8 +31,6 @@
|
|||||||
#
|
#
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
usage() {
|
usage() {
|
||||||
exec 1>&2
|
|
||||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
|
||||||
cat<<USAGE
|
cat<<USAGE
|
||||||
|
|
||||||
Usage: ${0##*/} [OPTION] <application> ...
|
Usage: ${0##*/} [OPTION] <application> ...
|
||||||
@ -49,6 +47,12 @@ options:
|
|||||||
Redirects the output to 'log' in the case directory
|
Redirects the output to 'log' in the case directory
|
||||||
|
|
||||||
USAGE
|
USAGE
|
||||||
|
}
|
||||||
|
|
||||||
|
error () {
|
||||||
|
exec 1>&2
|
||||||
|
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||||
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,14 +62,14 @@ echoArgs() {
|
|||||||
|
|
||||||
for stringItem in "$@"; do
|
for stringItem in "$@"; do
|
||||||
|
|
||||||
echo -n "${addSpace}"
|
printf "%s" "${addSpace}"
|
||||||
|
|
||||||
if [ "${stringItem##* }" = "$stringItem" ]
|
if [ "${stringItem##* }" = "$stringItem" ]
|
||||||
then
|
then
|
||||||
echo -n "$stringItem"
|
printf "%s" "$stringItem"
|
||||||
addSpace=" "
|
addSpace=" "
|
||||||
else
|
else
|
||||||
echo -n "'$stringItem'"
|
printf "%s" "'$stringItem'"
|
||||||
addSpace=" "
|
addSpace=" "
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -76,38 +80,11 @@ echoArgs() {
|
|||||||
|
|
||||||
unset version
|
unset version
|
||||||
|
|
||||||
# Replacement for possibly buggy 'which'
|
|
||||||
findExec() {
|
findExec() {
|
||||||
case "$1" in
|
which "$1" 2>/dev/null
|
||||||
*/*)
|
command -v "$1" >/dev/null 2>&1
|
||||||
if [ -x "$1" ]
|
|
||||||
then
|
|
||||||
echo "$1"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
oldIFS=$IFS
|
|
||||||
IFS=':'
|
|
||||||
for d in $PATH
|
|
||||||
do
|
|
||||||
# echo "testing: $d/$1" 1>&2
|
|
||||||
if [ -x "$d/$1" -a ! -d "$d/$1" ]
|
|
||||||
then
|
|
||||||
# echo "Found exec: $d/$1" 1>&2
|
|
||||||
IFS=$oldIFS
|
|
||||||
echo "$d/$1"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
IFS=$oldIFS
|
|
||||||
echo ""
|
|
||||||
return 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Main script
|
# Main script
|
||||||
#~~~~~~~~~~~~
|
#~~~~~~~~~~~~
|
||||||
unset parallelOpt screenOpt waitOpt
|
unset parallelOpt screenOpt waitOpt
|
||||||
@ -118,11 +95,11 @@ while [ "$#" -gt 0 ]
|
|||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-h | -help)
|
-h | -help)
|
||||||
usage
|
usage && exit 0
|
||||||
;;
|
;;
|
||||||
-case)
|
-case)
|
||||||
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
|
||||||
cd "$2" 2>/dev/null || usage "directory does not exist: '$2'"
|
cd "$2" 2>/dev/null || error "directory does not exist: '$2'"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-p | -parallel)
|
-p | -parallel)
|
||||||
@ -142,7 +119,7 @@ do
|
|||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-v | -version)
|
-v | -version)
|
||||||
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
|
||||||
version="$2"
|
version="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
@ -151,7 +128,7 @@ do
|
|||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
-*)
|
-*)
|
||||||
usage "invalid option '$1'"
|
error "invalid option '$1'"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
break
|
break
|
||||||
@ -159,7 +136,7 @@ do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
[ "$#" -ge 1 ] || usage "No application specified"
|
[ "$#" -ge 1 ] || error "No application specified"
|
||||||
|
|
||||||
|
|
||||||
# Use foamExec for a specified version
|
# Use foamExec for a specified version
|
||||||
@ -169,11 +146,11 @@ then
|
|||||||
# When possible, determine if application even exists
|
# When possible, determine if application even exists
|
||||||
if [ -z "$version" ]
|
if [ -z "$version" ]
|
||||||
then
|
then
|
||||||
findExec $1 >/dev/null || usage "Application '$1' not found"
|
findExec "$1" >/dev/null || error "Application '$1' not found"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Use foamExec for dispatching
|
# Use foamExec for dispatching
|
||||||
APPLICATION=`findExec foamExec` || usage "'foamExec' not found"
|
APPLICATION=$(findExec foamExec) || error "'foamExec' not found"
|
||||||
|
|
||||||
[ -n "$version" ] && APPLICATION="$APPLICATION -version $version"
|
[ -n "$version" ] && APPLICATION="$APPLICATION -version $version"
|
||||||
|
|
||||||
@ -184,7 +161,7 @@ then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
APPLICATION=`findExec $1` || usage "Application '$1' not found"
|
APPLICATION=$(findExec "$1") || error "Application '$1' not found"
|
||||||
echo "Application : $1"
|
echo "Application : $1"
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
@ -200,7 +177,7 @@ then
|
|||||||
#
|
#
|
||||||
if [ -r "processor0" ]
|
if [ -r "processor0" ]
|
||||||
then
|
then
|
||||||
NPROCS="`/bin/ls -1d processor* | wc -l`"
|
NPROCS="$(/bin/ls -1d processor* | wc -l)"
|
||||||
else
|
else
|
||||||
echo "Case is not currently decomposed"
|
echo "Case is not currently decomposed"
|
||||||
if [ -r system/decomposeParDict ]
|
if [ -r system/decomposeParDict ]
|
||||||
@ -218,7 +195,7 @@ then
|
|||||||
#
|
#
|
||||||
# Find mpirun
|
# Find mpirun
|
||||||
#
|
#
|
||||||
mpirun=`findExec mpirun` || usage "'mpirun' not found"
|
mpirun=$(findExec mpirun) || error "'mpirun' not found"
|
||||||
mpiopts="-np $NPROCS"
|
mpiopts="-np $NPROCS"
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|||||||
18
bin/foamLog
18
bin/foamLog
@ -3,7 +3,7 @@
|
|||||||
# ========= |
|
# ========= |
|
||||||
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
# \\ / O peration |
|
# \\ / O peration |
|
||||||
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
# \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
# \\/ M anipulation |
|
# \\/ M anipulation |
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# License
|
# License
|
||||||
@ -35,11 +35,10 @@ siteDir=${WM_PROJECT_SITE:-${WM_PROJECT_INST_DIR:-<unknown>}/site}
|
|||||||
userDir=$HOME/.OpenFOAM
|
userDir=$HOME/.OpenFOAM
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
exec 1>&2
|
|
||||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
|
||||||
cat <<USAGE
|
cat <<USAGE
|
||||||
|
|
||||||
Usage: $Script [OPTIONS] <log>
|
Usage: $Script [OPTIONS] <log file>
|
||||||
|
options:
|
||||||
-list lists but does not extract
|
-list lists but does not extract
|
||||||
-n create single column files with the extracted data only
|
-n create single column files with the extracted data only
|
||||||
-quiet quiet operation
|
-quiet quiet operation
|
||||||
@ -49,13 +48,13 @@ Usage: $Script [OPTIONS] <log>
|
|||||||
$Script - extracts xy files from OpenFOAM logs.
|
$Script - extracts xy files from OpenFOAM logs.
|
||||||
|
|
||||||
USAGE
|
USAGE
|
||||||
exit 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
printHelp() {
|
printHelp() {
|
||||||
cat <<HELP
|
usage
|
||||||
|
cat <<HELP
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
The default is to extract for all the 'Solved for' variables the initial
|
The default is to extract for all the 'Solved for' variables the initial
|
||||||
residual, the final residual and the number of iterations. Additionally, a
|
residual, the final residual and the number of iterations. Additionally, a
|
||||||
@ -96,8 +95,13 @@ Option -q suppresses the default information and only prints the extracted
|
|||||||
variables.
|
variables.
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
HELP
|
HELP
|
||||||
|
}
|
||||||
|
|
||||||
usage
|
error () {
|
||||||
|
exec 1>&2
|
||||||
|
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
135
bin/foamMonitor
135
bin/foamMonitor
@ -3,7 +3,7 @@
|
|||||||
# ========= |
|
# ========= |
|
||||||
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
# \\ / O peration |
|
# \\ / O peration |
|
||||||
# \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
# \\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation
|
||||||
# \\/ M anipulation |
|
# \\/ M anipulation |
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# License
|
# License
|
||||||
@ -32,17 +32,15 @@
|
|||||||
#
|
#
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
usage() {
|
usage() {
|
||||||
exec 1>&2
|
|
||||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
|
||||||
cat<<USAGE
|
cat<<USAGE
|
||||||
|
|
||||||
Usage: ${0##*/} [OPTION] <file>
|
Usage: ${0##*/} [OPTION] <file>
|
||||||
options:
|
options:
|
||||||
-h | -help print the usage
|
-help | -h print the usage
|
||||||
-i | -idle <time> stops if <file> unchanging for <time> sec (default = 60)
|
-idle | -i <time> stops if <file> unchanging for <time> sec (default 60s)
|
||||||
-l | -logscale plots data (y-axis) on log scale, e.g. for residuals
|
-logscale | -l plots data (y-axis) on log scale, e.g. for residuals
|
||||||
-r | -refresh <time> refreshes display every <time> sec (default = 10)
|
-refresh | -r <time> refreshes display every <time> sec (default 10s)
|
||||||
-y | -yrange <range> sets data (y-axis) <range>, format "[0:1]"
|
-yrange | -y <range> sets data (y-axis) <range>, format "[0:1]"
|
||||||
|
|
||||||
Monitor data with Gnuplot from time-value(s) graphs written by OpenFOAM
|
Monitor data with Gnuplot from time-value(s) graphs written by OpenFOAM
|
||||||
e.g. by functionObjects
|
e.g. by functionObjects
|
||||||
@ -52,16 +50,22 @@ Example:
|
|||||||
foamMonitor -l postProcessing/residuals/0/residuals.dat
|
foamMonitor -l postProcessing/residuals/0/residuals.dat
|
||||||
|
|
||||||
USAGE
|
USAGE
|
||||||
|
}
|
||||||
|
|
||||||
|
error() {
|
||||||
|
exec 1>&2
|
||||||
|
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||||
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
plotFileHeader() {
|
plotFileHeader() {
|
||||||
cat<<EOF
|
cat<<EOF
|
||||||
set term x11 1 font "helvetica,17" linewidth 1.5 persist noraise
|
set term x11 1 font "helvetica,17" linewidth 1.5 persist noraise
|
||||||
$LOGSCALE
|
$logscale
|
||||||
$YRANGE
|
$yrange
|
||||||
set title "Data Monitoring"
|
set title "Data Monitoring"
|
||||||
set xlabel "$XLABEL"
|
set xlabel "$xlabel"
|
||||||
plot \\
|
plot \\
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
@ -69,48 +73,50 @@ EOF
|
|||||||
plotFileFooter() {
|
plotFileFooter() {
|
||||||
cat<<EOF
|
cat<<EOF
|
||||||
|
|
||||||
pause $REFRESH
|
pause $refresh
|
||||||
reread
|
reread
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
howMany() ( set -f; set -- $1; echo $# )
|
howMany() ( set -f; set -- $1; echo $# )
|
||||||
|
isInteger() {
|
||||||
|
[ ! -z "${1##*[!0-9]*}" ] && echo "$1" && return 0
|
||||||
|
}
|
||||||
|
|
||||||
IDLE=60
|
idle=60
|
||||||
REFRESH=10
|
refresh=10
|
||||||
LOGSCALE=""
|
logscale=""
|
||||||
YRANGE=""
|
yrange=""
|
||||||
GNUPLOT=$(which gnuplot)
|
command -v gnuplot >/dev/null 2>&1 || error "Gnuplot not installed"
|
||||||
! [ "x$GNUPLOT" = "x" ] || usage "Gnuplot not installed"
|
|
||||||
|
|
||||||
# parse options
|
# parse options
|
||||||
while [ "$#" -gt 0 ]
|
while [ "$#" -gt 0 ]
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-h | -help)
|
-h | -help)
|
||||||
usage
|
usage && exit 0
|
||||||
;;
|
;;
|
||||||
-i | -idle)
|
-i | -idle)
|
||||||
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
|
||||||
[ ! -z "${2##*[!0-9]*}" ] && IDLE=$2 || usage "Argument of '$1' is not an integer: '$2'"
|
idle=$(isInteger "$2") || error "Argument of '$1' is not an integer: '$2'"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-l | -logscale)
|
-l | -logscale)
|
||||||
LOGSCALE="set logscale y"
|
logscale="set logscale y"
|
||||||
shift 1
|
shift 1
|
||||||
;;
|
;;
|
||||||
-r | -refresh)
|
-r | -refresh)
|
||||||
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
|
||||||
[ ! -z "${2##*[!0-9]*}" ] && REFRESH=$2 || usage "Argument of '$1' is not an integer: '$2'"
|
refresh=$(isInteger "$2") || error "Argument of '$1' is not an integer: '$2'"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-y | -yrange)
|
-y | -yrange)
|
||||||
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
|
||||||
YRANGE="set yrange $2"
|
yrange="set yrange $2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-*)
|
-*)
|
||||||
usage "unknown option: '$*'"
|
error "unknown option: '$*'"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
break
|
break
|
||||||
@ -118,64 +124,65 @@ do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
[ $# -eq 1 ] || usage "Incorrect arguments specified"
|
[ $# -eq 1 ] || error "Incorrect arguments specified"
|
||||||
[ -f $1 ] || usage "File $1 does not exit"
|
[ -f "$1" ] || error "File $1 does not exit"
|
||||||
FILE=$1
|
file=$1
|
||||||
|
|
||||||
# Get KEYS from header
|
# Get keys from header
|
||||||
KEYS=$(grep -E '^#' $FILE | tail -1)
|
keys=$(grep -E '^#' "$file" | tail -1)
|
||||||
|
|
||||||
[ "x$KEYS" = "x" ] && KEYS="# Step"
|
[ "x$keys" = "x" ] && keys="# Step"
|
||||||
NKEYS=$(howMany "$KEYS")
|
n_keys=$(howMany "$keys")
|
||||||
NCOLS=$(tail -1 $FILE | awk '{ print NF}')
|
n_cols=$(tail -1 "$file" | awk '{ print NF }')
|
||||||
|
|
||||||
# With full column labels, NKEYS = NCOLS + 1, since it includes "#"
|
# With full column labels, n_keys = n_cols + 1, since it includes "#"
|
||||||
|
|
||||||
# If NKEYS > NCOLS + 1, REMOVE EXCESS KEYS
|
# If n_keys > n_cols + 1, REMOVE EXCESS keys
|
||||||
NCOLSPONE=$(expr $NCOLS + 1)
|
n_cols_pone=$(( n_cols + 1 ))
|
||||||
[ "$NKEYS" -gt "$NCOLSPONE" ] && KEYS=$(echo $KEYS | cut -d" " -f1-$NCOLSPONE)
|
[ "$n_keys" -gt "$n_cols_pone" ] && \
|
||||||
NKEYS=$(howMany "$KEYS")
|
keys=$(echo "$keys" | cut -d" " -f1-$n_cols_pone)
|
||||||
|
n_keys=$(howMany "$keys")
|
||||||
|
|
||||||
i=0
|
i=0
|
||||||
while [ "$NKEYS" -le "$NCOLS" ]
|
while [ "$n_keys" -le "$n_cols" ]
|
||||||
do
|
do
|
||||||
i=$(expr $i + 1)
|
i=$(( i + 1 ))
|
||||||
KEYS="$KEYS data$i"
|
keys="$keys data$i"
|
||||||
NKEYS=$(howMany "$KEYS")
|
n_keys=$(howMany "$keys")
|
||||||
done
|
done
|
||||||
|
|
||||||
# Remove # and Time keys
|
# Remove # and Time keys
|
||||||
XLABEL=$(echo $KEYS | cut -d " " -f2)
|
xlabel=$(echo "$keys" | cut -d " " -f2)
|
||||||
KEYS=$(echo $KEYS | cut -d " " -f3-)
|
keys=$(echo "$keys" | cut -d " " -f3-)
|
||||||
|
|
||||||
GPFILE=$(mktemp)
|
gp_file=$(mktemp)
|
||||||
plotFileHeader > $GPFILE
|
plotFileHeader > "$gp_file"
|
||||||
i=1
|
i=1
|
||||||
for field in $KEYS
|
for field in $keys
|
||||||
do
|
do
|
||||||
i=$(expr $i + 1)
|
i=$(( i + 1 ))
|
||||||
PLOTLINE="\"$FILE\" using 1:${i} with lines title \"$field\""
|
plot_line="\"$file\" using 1:${i} with lines title \"$field\""
|
||||||
if [ $i -lt $NCOLS ]
|
if [ $i -lt "$n_cols" ]
|
||||||
then
|
then
|
||||||
PLOTLINE="$PLOTLINE, \\"
|
plot_line="$plot_line, \\"
|
||||||
fi
|
fi
|
||||||
echo $PLOTLINE >> $GPFILE
|
echo $plot_line >> "$gp_file"
|
||||||
done
|
done
|
||||||
plotFileFooter >> $GPFILE
|
plotFileFooter >> "$gp_file"
|
||||||
|
|
||||||
touch $FILE
|
touch "$file"
|
||||||
$GNUPLOT $GPFILE &
|
gnuplot "$gp_file" &
|
||||||
PID=$!
|
pid=$!
|
||||||
|
|
||||||
while true
|
while true
|
||||||
do
|
do
|
||||||
MODTIME=$(stat --format=%Y $FILE)
|
mod_time=$(stat --format=%Y "$file")
|
||||||
IDLEAGO=$(expr $(date +%s) - $IDLE)
|
idle_ago=$(( $(date +%s) - idle ))
|
||||||
test "$MODTIME" -gt "$IDLEAGO" || break
|
test "$mod_time" -gt "$idle_ago" || break
|
||||||
sleep $REFRESH
|
sleep "$refresh"
|
||||||
done
|
done
|
||||||
|
|
||||||
kill -9 $PID
|
kill -9 $pid
|
||||||
rm $GPFILE
|
rm "$gp_file"
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|||||||
143
bin/foamNewBC
143
bin/foamNewBC
@ -30,12 +30,13 @@
|
|||||||
#
|
#
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
Script=${0##*/}
|
Script=${0##*/}
|
||||||
DIR="$FOAM_ETC/codeTemplates/BC"
|
dir="$FOAM_ETC/codeTemplates/BC"
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
|
||||||
cat<<USAGE
|
cat<<USAGE
|
||||||
Usage: $Script [-h | -help] <base> <type> <boundaryConditionName>
|
Usage: $Script [OPTIONS] <base> <type> <boundaryConditionName>
|
||||||
|
options:
|
||||||
|
-help | -h help
|
||||||
|
|
||||||
* Create directory of source and compilation files for a new boundary condition
|
* Create directory of source and compilation files for a new boundary condition
|
||||||
<boundaryConditionName> (dir)
|
<boundaryConditionName> (dir)
|
||||||
@ -62,8 +63,14 @@ USAGE
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error() {
|
||||||
|
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
cap() {
|
cap() {
|
||||||
echo $1 | sed -e 's/^./\U&/'
|
echo "$1" | sed -e 's/^./\U&/'
|
||||||
}
|
}
|
||||||
|
|
||||||
# Implicitly covers a lone -help
|
# Implicitly covers a lone -help
|
||||||
@ -71,105 +78,107 @@ cap() {
|
|||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
(-h | -help)
|
(-h | -help)
|
||||||
usage
|
usage && exit 0
|
||||||
;;
|
;;
|
||||||
(-f | -fixedValue | fixedValue)
|
(-f | -fixedValue | fixedValue)
|
||||||
BASE=fixedValue
|
base=fixedValue
|
||||||
;;
|
;;
|
||||||
(-m | -mixed | mixed )
|
(-m | -mixed | mixed )
|
||||||
BASE=mixed
|
base=mixed
|
||||||
;;
|
;;
|
||||||
(*)
|
(*)
|
||||||
usage "Unknown <base> condition '$1'"
|
error "Unknown <base> condition '$1'"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
(-a | -all | all | template)
|
(-a | -all | all | template)
|
||||||
TYPE=Type
|
type=Type
|
||||||
UNIT='VALUE-or-(VALUE 0 0)'
|
unit='VALUE-or-(VALUE 0 0)'
|
||||||
;;
|
;;
|
||||||
(-s | -scalar | scalar)
|
(-s | -scalar | scalar)
|
||||||
TYPE=scalar
|
type=scalar
|
||||||
UNIT=VALUE
|
unit=VALUE
|
||||||
;;
|
;;
|
||||||
(-v | -vector | vector)
|
(-v | -vector | vector)
|
||||||
TYPE=vector
|
type=vector
|
||||||
UNIT='(VALUE 0 0)'
|
unit='(VALUE 0 0)'
|
||||||
;;
|
;;
|
||||||
(-t | -tensor | tensor)
|
(-t | -tensor | tensor)
|
||||||
TYPE=tensor
|
type=tensor
|
||||||
UNIT='(VALUE 0 0 0 0 0 0 0 0)'
|
unit='(VALUE 0 0 0 0 0 0 0 0)'
|
||||||
;;
|
;;
|
||||||
(-symmTensor | symmTensor)
|
(-symmTensor | symmTensor)
|
||||||
TYPE=symmTensor
|
type=symmTensor
|
||||||
UNIT='(VALUE 0 0 0 0 0)'
|
unit='(VALUE 0 0 0 0 0)'
|
||||||
;;
|
;;
|
||||||
(-sphericalTensor | sphericalTensor)
|
(-sphericalTensor | sphericalTensor)
|
||||||
TYPE=sphericalTensor
|
type=sphericalTensor
|
||||||
UNIT=VALUE
|
unit=VALUE
|
||||||
;;
|
;;
|
||||||
(*)
|
(*)
|
||||||
usage "Unknown <type> option '$1'"
|
error "Unknown <type> option '$1'"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
[ "$#" -eq 1 ] || usage "Wrong number of arguments"
|
[ "$#" -eq 1 ] || error "Wrong number of arguments"
|
||||||
NAME=$1
|
name=$1
|
||||||
|
|
||||||
# Prevents over-writing of existing directory
|
# Prevents over-writing of existing directory
|
||||||
[ -d $NAME ] && usage "$NAME directory already exists, aborting..."
|
[ -d "$name" ] && error "$name directory already exists, aborting..."
|
||||||
echo "Creating $NAME directory" && mkdir $NAME
|
echo "Creating $name directory" && mkdir "$name"
|
||||||
|
|
||||||
# Establish meta template files to copy
|
# Establish meta template files to copy
|
||||||
FILES=$(cd ${DIR} && ls *.*)
|
files=$(find "${dir}" -name "*.*" -type f -exec basename {} \;)
|
||||||
[ "$TYPE" = "Type" ] || FILES=$(cd ${DIR} && ls BC.[CH])
|
[ "$type" = "Type" ] || \
|
||||||
|
files=$(find "${dir}" -name "BC.[CH]" -type f -exec basename {} \;)
|
||||||
|
|
||||||
# Substitutions for meta-template files
|
# Substitutions for meta-template files
|
||||||
FIELD="Field<${TYPE}>"
|
field="Field<${type}>"
|
||||||
[ "$TYPE" = "Type" ] || FIELD=${TYPE}Field
|
[ "$type" = "Type" ] || field=${type}Field
|
||||||
|
|
||||||
FVPATCHF=fvPatch$(cap $FIELD)
|
fvpatchf=fvPatch$(cap $field)
|
||||||
CLASS=$NAME$(cap $FVPATCHF)
|
class=$name$(cap "$fvpatchf")
|
||||||
PARENT=$BASE$(cap $FVPATCHF)
|
parent=$base$(cap "$fvpatchf")
|
||||||
CONSTRUCT=$(echo $CLASS | sed 's/<Type>//g')
|
construct=$(echo "$class" | sed 's/<Type>//g')
|
||||||
YEAR=$(date +%Y)
|
year=$(date +%Y)
|
||||||
|
|
||||||
# Create some example values for the Description
|
# Create some example values for the Description
|
||||||
n=0
|
n=0
|
||||||
for N in $(echo "ZERO ONE TWO THREE FOUR")
|
for N in zero one two three four
|
||||||
do
|
do
|
||||||
eval $(expr $N='$(echo $UNIT | sed "s#VALUE#$n#g")')
|
eval $N="$(echo \"$unit\" | sed "s#VALUE#$n#g")"
|
||||||
n=$(( $n + 1 ))
|
n=$(( n + 1 ))
|
||||||
done
|
done
|
||||||
|
|
||||||
# Make substitutions to meta-template files
|
# Make substitutions to meta-template files
|
||||||
for F in $FILES
|
for f in $files
|
||||||
do
|
do
|
||||||
EXT=$(echo $F | sed "s#BC##")
|
ext=$(echo "$f" | sed "s#BC##")
|
||||||
NEWFILE=${CONSTRUCT}${EXT}
|
new_file=${construct}${ext}
|
||||||
echo " Adding file ${NEWFILE}..."
|
echo " Adding file ${new_file}..."
|
||||||
|
|
||||||
# Adds readScalar function when TYPE = scalar
|
# Adds readScalar function when type = scalar
|
||||||
sed -e "s#TYPE#${TYPE}#g" \
|
# shellcheck disable=SC2154
|
||||||
-e "s#NAME#${NAME}#g" \
|
sed -e "s#TYPE#${type}#g" \
|
||||||
-e "s#BASE#${BASE}#g" \
|
-e "s#NAME#${name}#g" \
|
||||||
-e "s#CONSTRUCT#${CONSTRUCT}#g" \
|
-e "s#BASE#${base}#g" \
|
||||||
-e "s#YEAR#${YEAR}#g" \
|
-e "s#CONSTRUCT#${construct}#g" \
|
||||||
-e "s#CLASS#${CLASS}#g" \
|
-e "s#YEAR#${year}#g" \
|
||||||
-e "s#FIELD#${FIELD}#g" \
|
-e "s#CLASS#${class}#g" \
|
||||||
-e "s#FVPATCHF#${FVPATCHF}#g" \
|
-e "s#FIELD#${field}#g" \
|
||||||
-e "s#PARENT#${PARENT}#g" \
|
-e "s#FVPATCHF#${fvpatchf}#g" \
|
||||||
-e "s#ZERO#${ZERO}#g" \
|
-e "s#PARENT#${parent}#g" \
|
||||||
-e "s#ONE#${ONE}#g" \
|
-e "s#ZERO#${zero}#g" \
|
||||||
-e "s#TWO#${TWO}#g" \
|
-e "s#ONE#${one}#g" \
|
||||||
-e "s#THREE#${THREE}#g" \
|
-e "s#TWO#${two}#g" \
|
||||||
-e "s#FOUR#${FOUR}#g" \
|
-e "s#THREE#${three}#g" \
|
||||||
|
-e "s#FOUR#${four}#g" \
|
||||||
-e 's/>>/>>/g' \
|
-e 's/>>/>>/g' \
|
||||||
${DIR}/${F} > ${NAME}/${NEWFILE}
|
"${dir}/${f}" > "${name}/${new_file}"
|
||||||
|
|
||||||
case $BASE in
|
case $base in
|
||||||
fixedValue)
|
fixedValue)
|
||||||
# refValue(), refGrad(), valueFraction() removed
|
# refValue(), refGrad(), valueFraction() removed
|
||||||
# phip removed
|
# phip removed
|
||||||
@ -178,7 +187,7 @@ do
|
|||||||
-e '/refGrad/d' \
|
-e '/refGrad/d' \
|
||||||
-e '/valueFraction/d' \
|
-e '/valueFraction/d' \
|
||||||
-e '/const scalarField\& phip/,/);/d' \
|
-e '/const scalarField\& phip/,/);/d' \
|
||||||
${NAME}/${NEWFILE}
|
"${name}/${new_file}"
|
||||||
;;
|
;;
|
||||||
mixed)
|
mixed)
|
||||||
# evaluate() removed
|
# evaluate() removed
|
||||||
@ -186,15 +195,15 @@ do
|
|||||||
sed -i \
|
sed -i \
|
||||||
-e '/evaluate/d' \
|
-e '/evaluate/d' \
|
||||||
-e 's/operator==/refValue() =/g' \
|
-e 's/operator==/refValue() =/g' \
|
||||||
${NAME}/${NEWFILE}
|
"${name}/${new_file}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case $TYPE in
|
case $type in
|
||||||
Type)
|
Type)
|
||||||
# Build Macro removed (in ..Fields.C)
|
# Build Macro removed (in ..Fields.C)
|
||||||
sed -i -e '/Build Macro/,/^}/d' \
|
sed -i -e '/Build Macro/,/^}/d' \
|
||||||
${NAME}/${NEWFILE}
|
"${name}/${new_file}"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
# template<class Type> removed
|
# template<class Type> removed
|
||||||
@ -206,13 +215,15 @@ do
|
|||||||
-e 's/this->//g' \
|
-e 's/this->//g' \
|
||||||
-e 's/\.template[\t ]*\([a-Z]\)/\.\1/g' \
|
-e 's/\.template[\t ]*\([a-Z]\)/\.\1/g' \
|
||||||
-e '/#ifdef NoRepository/,/\/\/ */d' \
|
-e '/#ifdef NoRepository/,/\/\/ */d' \
|
||||||
${NAME}/${NEWFILE}
|
"${name}/${new_file}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Creating Make subdirectory" && cp -r ${DIR}/Make ${NAME}
|
echo "Creating Make subdirectory" && cp -r "${dir}/Make" "${name}"
|
||||||
COMPILED=$(cd ${NAME} && ls -r1 *C | head -1) # ...Fields.C for template class
|
|
||||||
sed -i -e "s#NAME#${NAME}#g" -e "s#COMPILED.*#${COMPILED}#g" ${NAME}/Make/files
|
# Get ...Fields.C for template class, otherwise ...Field.C
|
||||||
|
compiled=$(find "${name}" -name "*.C" -exec basename {} \; | sort | tail -1)
|
||||||
|
sed -i -e "s#NAME#${name}#g" -e "s#COMPILED.*#${compiled}#g" "${name}/Make/files"
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|||||||
35
bin/paraFoam
35
bin/paraFoam
@ -3,7 +3,7 @@
|
|||||||
# ========= |
|
# ========= |
|
||||||
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
# \\ / O peration |
|
# \\ / O peration |
|
||||||
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
# \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
# \\/ M anipulation |
|
# \\/ M anipulation |
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# License
|
# License
|
||||||
@ -33,8 +33,6 @@
|
|||||||
# undefined behaviour
|
# undefined behaviour
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
usage() {
|
usage() {
|
||||||
exec 1>&2
|
|
||||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
|
||||||
cat<<USAGE
|
cat<<USAGE
|
||||||
|
|
||||||
Usage: ${0##*/} [OPTION] [PARAVIEW_OPTION]
|
Usage: ${0##*/} [OPTION] [PARAVIEW_OPTION]
|
||||||
@ -47,12 +45,17 @@ options:
|
|||||||
-touchAll create .blockMesh, .OpenFOAM files (and for all regions)
|
-touchAll create .blockMesh, .OpenFOAM files (and for all regions)
|
||||||
-help print the usage
|
-help print the usage
|
||||||
|
|
||||||
|
|
||||||
paraview options start with a double dashes
|
paraview options start with a double dashes
|
||||||
|
|
||||||
* start paraview $ParaView_VERSION with the OpenFOAM libraries
|
* start paraview $ParaView_VERSION with the OpenFOAM libraries
|
||||||
|
|
||||||
USAGE
|
USAGE
|
||||||
|
}
|
||||||
|
|
||||||
|
error() {
|
||||||
|
exec 1>&2
|
||||||
|
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||||
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +80,7 @@ while [ "$#" -gt 0 ]
|
|||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-h | -help)
|
-h | -help)
|
||||||
usage
|
usage && exit 0
|
||||||
;;
|
;;
|
||||||
-block | -blockMesh)
|
-block | -blockMesh)
|
||||||
extension=blockMesh
|
extension=blockMesh
|
||||||
@ -89,12 +92,12 @@ do
|
|||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-case)
|
-case)
|
||||||
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
|
||||||
cd "$2" 2>/dev/null || usage "directory does not exist: '$2'"
|
cd "$2" 2>/dev/null || error "directory does not exist: '$2'"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-region)
|
-region)
|
||||||
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
|
||||||
regionName=$2
|
regionName=$2
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
@ -116,13 +119,13 @@ do
|
|||||||
break # Stop here, treat this and balance as paraview options
|
break # Stop here, treat this and balance as paraview options
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
usage "unknown option/argument: '$*'"
|
error "unknown option/argument: '$*'"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# Check that reader module has been built
|
# Check that reader module has been built
|
||||||
if [ $requirePV -eq 1 -a ! -f $PV_PLUGIN_PATH/libPVFoamReader_SM.so ]
|
if [ $requirePV -eq 1 -a ! -f "$PV_PLUGIN_PATH/libPVFoamReader_SM.so" ]
|
||||||
then
|
then
|
||||||
cat<< BUILDREADER
|
cat<< BUILDREADER
|
||||||
|
|
||||||
@ -153,7 +156,7 @@ hasDataArg()
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
hasDataArg $@
|
hasDataArg "$@"
|
||||||
|
|
||||||
|
|
||||||
# Get a sensible caseName from the directory name
|
# Get a sensible caseName from the directory name
|
||||||
@ -163,7 +166,7 @@ fvControls="system"
|
|||||||
|
|
||||||
if [ -n "$regionName" ]
|
if [ -n "$regionName" ]
|
||||||
then
|
then
|
||||||
if [ ! -d constant/$regionName ]
|
if [ ! -d constant/"$regionName" ]
|
||||||
then
|
then
|
||||||
echo "FATAL ERROR: Region $regionName does not exist"
|
echo "FATAL ERROR: Region $regionName does not exist"
|
||||||
exit 1
|
exit 1
|
||||||
@ -186,7 +189,7 @@ all)
|
|||||||
# Discover probable regions
|
# Discover probable regions
|
||||||
for region in constant/*
|
for region in constant/*
|
||||||
do
|
do
|
||||||
if [ -d $region -a -d $region/polyMesh ]
|
if [ -d "$region" -a -d "$region"/polyMesh ]
|
||||||
then
|
then
|
||||||
regionName=${region##*/}
|
regionName=${region##*/}
|
||||||
touch "$caseName{$regionName}.$extension"
|
touch "$caseName{$regionName}.$extension"
|
||||||
@ -258,14 +261,14 @@ else
|
|||||||
|
|
||||||
[ -n "$warn" ] || {
|
[ -n "$warn" ] || {
|
||||||
echo "Cannot locate OpenFOAM-format case files"
|
echo "Cannot locate OpenFOAM-format case files"
|
||||||
echo -n "Would you like to open ParaView anyway <Y|n>:"
|
printf "Would you like to open ParaView anyway <Y|n>:"
|
||||||
read open
|
read open
|
||||||
[ "$open" = "" ] || echo $open | grep -iqE "^y" && paraview
|
[ "$open" = "" ] || echo "$open" | grep -iqE "^y" && paraview
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
# Only create/remove caseFile if it didn't already exist
|
# Only create/remove caseFile if it didn't already exist
|
||||||
[ -e $caseFile ] || {
|
[ -e "$caseFile" ] || {
|
||||||
trap "rm -f $caseFile 2>/dev/null; exit 0" EXIT TERM INT
|
trap "rm -f $caseFile 2>/dev/null; exit 0" EXIT TERM INT
|
||||||
touch "$caseFile"
|
touch "$caseFile"
|
||||||
echo "Created temporary '$caseFile'"
|
echo "Created temporary '$caseFile'"
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
# ========= |
|
# ========= |
|
||||||
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
# \\ / O peration |
|
# \\ / O peration |
|
||||||
# \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
# \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
# \\/ M anipulation |
|
# \\/ M anipulation |
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# License
|
# License
|
||||||
@ -46,7 +46,7 @@ do
|
|||||||
if [ -d "$i" ]
|
if [ -d "$i" ]
|
||||||
then
|
then
|
||||||
echo "removing all core files: $i"
|
echo "removing all core files: $i"
|
||||||
find $i \( -type f -name 'core' -o -name 'core.[1-9]*' -o -name 'vgcore.*' \) -print | xargs -t rm 2>/dev/null
|
find $i \( -type f -name 'core' -o -name 'core.[1-9]*' -o -name 'vgcore.*' \) -print0 | xargs -t rm 2>/dev/null
|
||||||
else
|
else
|
||||||
echo "no directory: $i" 1>&2
|
echo "no directory: $i" 1>&2
|
||||||
fi
|
fi
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
# ========= |
|
# ========= |
|
||||||
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
# \\ / O peration |
|
# \\ / O peration |
|
||||||
# \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
# \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
# \\/ M anipulation |
|
# \\/ M anipulation |
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# License
|
# License
|
||||||
@ -46,7 +46,7 @@ do
|
|||||||
if [ -d "$i" ]
|
if [ -d "$i" ]
|
||||||
then
|
then
|
||||||
echo "removing all *~ files: $i"
|
echo "removing all *~ files: $i"
|
||||||
find $i \( -name '*~' -o -name '.*~' \) -print | xargs -t rm 2>/dev/null
|
find $i \( -name '*~' -o -name '.*~' \) -print0 | xargs -t rm 2>/dev/null
|
||||||
else
|
else
|
||||||
echo "no directory: $i" 1>&2
|
echo "no directory: $i" 1>&2
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user