mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
bin/script changes
foamUpdateCaseFileHeader:
- handle multiple files
- use fixed version width
- replace grep/tr/cut -> sed
foamUpgradeTurbulenceProperties:
- handle multiple files
This commit is contained in:
@ -33,85 +33,108 @@
|
||||
# Also removes consecutive blank lines from file.
|
||||
#
|
||||
#------------------------------------------------------------------------------
|
||||
foamVersion=$WM_PROJECT_VERSION
|
||||
|
||||
#
|
||||
# FUNCTIONS
|
||||
#
|
||||
printUsage () {
|
||||
cat <<EOF
|
||||
Usage: $0 <file>
|
||||
Updates the header of application files
|
||||
By default, writes current version in the header
|
||||
Alternatively version can be specified with -v option
|
||||
Also removes consecutive blank lines from file
|
||||
usage() {
|
||||
cat<<USAGE
|
||||
|
||||
Options are:
|
||||
usage: ${0##*/} [OPTION] <file1> ... <fileN>
|
||||
|
||||
options:
|
||||
-v "<version>" specifies the version to be written in the header
|
||||
-h help
|
||||
EOF
|
||||
|
||||
Updates the header of application files.
|
||||
By default, writes current version in the header.
|
||||
Alternatively version can be specified with -v option.
|
||||
Also removes consecutive blank lines from file.
|
||||
|
||||
USAGE
|
||||
exit 1
|
||||
}
|
||||
|
||||
printOpenFOAMheader () {
|
||||
cat<<EOF
|
||||
|
||||
printHeader() {
|
||||
cat<<HEADER
|
||||
/*--------------------------------*- C++ -*----------------------------------*\\
|
||||
| ========= | |
|
||||
| \\\\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
||||
| \\\\ / O peration | Version: ${1} |
|
||||
| \\\\ / O peration | Version: ${foamVersion} |
|
||||
| \\\\ / A nd | Web: http://www.OpenFOAM.org |
|
||||
| \\\\/ M anipulation | |
|
||||
\\*---------------------------------------------------------------------------*/
|
||||
FoamFile
|
||||
{
|
||||
version 2.0;
|
||||
format ${2};
|
||||
class ${3};
|
||||
object ${4};
|
||||
format ${1};
|
||||
class ${2};
|
||||
object ${3};
|
||||
}
|
||||
EOF
|
||||
HEADER
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# extract attribute '$1' from file '$2'
|
||||
#
|
||||
FoamFileAttribute() {
|
||||
grep $1 $2 | tr -s " " | cut -d" " -f3 | cut -d\; -f1
|
||||
sed -n -e 's/[ ;]*$//' -e "s/^ *$1 *//p" $2
|
||||
}
|
||||
|
||||
VERSION=$WM_PROJECT_VERSION
|
||||
|
||||
#
|
||||
# OPTIONS
|
||||
#
|
||||
OPTS=`getopt hv: $*`
|
||||
if [ $? -ne 0 ] ; then
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo "Aborting due to invalid option"
|
||||
printUsage
|
||||
exit 1
|
||||
usage
|
||||
fi
|
||||
eval set -- '$OPTS'
|
||||
while [ "$1" != "--" ]; do
|
||||
while [ "$1" != "--" ]
|
||||
do
|
||||
case $1 in
|
||||
-v) VERSION=$2; shift;;
|
||||
-h) printUsage; exit 1;;
|
||||
-v)
|
||||
foamVersion=$2
|
||||
shift
|
||||
;;
|
||||
-h)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
shift
|
||||
|
||||
[ $# -ge 1 ] || usage
|
||||
|
||||
|
||||
# constant width for version
|
||||
foamVersion=`printf %-36s $foamVersion`
|
||||
|
||||
#
|
||||
# MAIN
|
||||
#
|
||||
CASE_FILE=$1
|
||||
if [ "`grep FoamFile $CASE_FILE`" ] ; then
|
||||
echo "Updating case file:" $CASE_FILE
|
||||
sed -n '/FoamFile/,/}/p' $CASE_FILE > FoamFile
|
||||
for caseFile
|
||||
do
|
||||
if grep FoamFile $caseFile >/dev/null 2>&1
|
||||
then
|
||||
echo "Updating case file: $caseFile"
|
||||
sed -n '/FoamFile/,/}/p' $caseFile > FoamFile
|
||||
|
||||
CLASS=`FoamFileAttribute class FoamFile`
|
||||
OBJECT=`FoamFileAttribute object FoamFile`
|
||||
FORMAT=`FoamFileAttribute format FoamFile`
|
||||
printOpenFOAMheader $VERSION $FORMAT $CLASS $OBJECT > temp
|
||||
sed '1,/}/d' $CASE_FILE | sed '/./,/^$/!d' >> temp
|
||||
mv temp $1
|
||||
|
||||
printHeader $FORMAT $CLASS $OBJECT $NOTE > FoamFile.tmp
|
||||
sed '1,/}/d' $caseFile | sed '/./,/^$/!d' >> FoamFile.tmp
|
||||
|
||||
mv FoamFile.tmp $caseFile
|
||||
rm FoamFile
|
||||
else
|
||||
echo "The following file does not appear to be a case file:"
|
||||
echo " " $CASE_FILE
|
||||
echo " Invalid case file: $caseFile"
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
@ -44,21 +44,12 @@ usage: ${0##*/} <turbulenceProperties>
|
||||
Where <turbulenceProperties> is the full path to the
|
||||
turbulenceProperties dictionary
|
||||
|
||||
Note: can upgrade several files at once
|
||||
|
||||
USAGE
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ $# = 1 ] || usage
|
||||
|
||||
turbDict=$1
|
||||
if [ ! -f $turbDict ]
|
||||
then
|
||||
echo " Error: file $turbDict does not exist"
|
||||
echo ""
|
||||
usage
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# $1: turbulence model
|
||||
# $2: new properties type
|
||||
@ -66,7 +57,7 @@ fi
|
||||
#
|
||||
convertDict()
|
||||
{
|
||||
echo " Identified $1 turbulence model in $3"
|
||||
echo "Identified $1 turbulence model in '$3'"
|
||||
outputPath=`dirname $3`
|
||||
|
||||
sed -e "s/turbulenceProperties/$1Properties/" \
|
||||
@ -77,9 +68,13 @@ convertDict()
|
||||
echo " wrote $outputPath/$1Properties"
|
||||
}
|
||||
|
||||
#
|
||||
[ $# -ge 1 ] || usage
|
||||
|
||||
for turbDict
|
||||
do
|
||||
# Identify type of turbulence model and convert
|
||||
#
|
||||
if [ -f $turbDict ]
|
||||
then
|
||||
if grep turbulenceModel $turbDict >/dev/null 2>&1
|
||||
then
|
||||
convertDict RAS turbulenceModel $turbDict
|
||||
@ -87,10 +82,12 @@ elif grep LESmodel $turbDict >/dev/null 2>&1
|
||||
then
|
||||
convertDict LES LESmodel $turbDict
|
||||
else
|
||||
echo "Unable to determine turbulence model type - nothing changed"
|
||||
exit 1
|
||||
echo "Unable to determine turbulence model type in '$turbDict'"
|
||||
echo " - nothing changed"
|
||||
fi
|
||||
|
||||
echo "done."
|
||||
else
|
||||
echo "Error: file '$turbDict' does not exist"
|
||||
fi
|
||||
done
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user