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.
|
# Also removes consecutive blank lines from file.
|
||||||
#
|
#
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
foamVersion=$WM_PROJECT_VERSION
|
||||||
|
|
||||||
#
|
usage() {
|
||||||
# FUNCTIONS
|
cat<<USAGE
|
||||||
#
|
|
||||||
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
|
|
||||||
|
|
||||||
Options are:
|
usage: ${0##*/} [OPTION] <file1> ... <fileN>
|
||||||
-v "<version>" specifies the version to be written in the header
|
|
||||||
-h help
|
options:
|
||||||
EOF
|
-v "<version>" specifies the version to be written in the header
|
||||||
|
-h help
|
||||||
|
|
||||||
|
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++ -*----------------------------------*\\
|
/*--------------------------------*- C++ -*----------------------------------*\\
|
||||||
| ========= | |
|
| ========= | |
|
||||||
| \\\\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
| \\\\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
||||||
| \\\\ / O peration | Version: ${1} |
|
| \\\\ / O peration | Version: ${foamVersion} |
|
||||||
| \\\\ / A nd | Web: http://www.OpenFOAM.org |
|
| \\\\ / A nd | Web: http://www.OpenFOAM.org |
|
||||||
| \\\\/ M anipulation | |
|
| \\\\/ M anipulation | |
|
||||||
\\*---------------------------------------------------------------------------*/
|
\\*---------------------------------------------------------------------------*/
|
||||||
FoamFile
|
FoamFile
|
||||||
{
|
{
|
||||||
version 2.0;
|
version 2.0;
|
||||||
format ${2};
|
format ${1};
|
||||||
class ${3};
|
class ${2};
|
||||||
object ${4};
|
object ${3};
|
||||||
}
|
}
|
||||||
EOF
|
HEADER
|
||||||
}
|
}
|
||||||
|
|
||||||
FoamFileAttribute () {
|
|
||||||
grep $1 $2 | tr -s " " | cut -d" " -f3 | cut -d\; -f1
|
#
|
||||||
|
# extract attribute '$1' from file '$2'
|
||||||
|
#
|
||||||
|
FoamFileAttribute() {
|
||||||
|
sed -n -e 's/[ ;]*$//' -e "s/^ *$1 *//p" $2
|
||||||
}
|
}
|
||||||
|
|
||||||
VERSION=$WM_PROJECT_VERSION
|
|
||||||
#
|
#
|
||||||
# OPTIONS
|
# OPTIONS
|
||||||
#
|
#
|
||||||
OPTS=`getopt hv: $*`
|
OPTS=`getopt hv: $*`
|
||||||
if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ]
|
||||||
echo "Aborting due to invalid option"
|
then
|
||||||
printUsage
|
echo "Aborting due to invalid option"
|
||||||
exit 1
|
usage
|
||||||
fi
|
fi
|
||||||
eval set -- '$OPTS'
|
eval set -- '$OPTS'
|
||||||
while [ "$1" != "--" ]; do
|
while [ "$1" != "--" ]
|
||||||
case $1 in
|
do
|
||||||
-v) VERSION=$2; shift;;
|
case $1 in
|
||||||
-h) printUsage; exit 1;;
|
-v)
|
||||||
esac
|
foamVersion=$2
|
||||||
shift
|
shift
|
||||||
|
;;
|
||||||
|
-h)
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
done
|
done
|
||||||
shift
|
shift
|
||||||
|
|
||||||
|
[ $# -ge 1 ] || usage
|
||||||
|
|
||||||
|
|
||||||
|
# constant width for version
|
||||||
|
foamVersion=`printf %-36s $foamVersion`
|
||||||
|
|
||||||
#
|
#
|
||||||
# MAIN
|
# MAIN
|
||||||
#
|
#
|
||||||
CASE_FILE=$1
|
for caseFile
|
||||||
if [ "`grep FoamFile $CASE_FILE`" ] ; then
|
do
|
||||||
echo "Updating case file:" $CASE_FILE
|
if grep FoamFile $caseFile >/dev/null 2>&1
|
||||||
sed -n '/FoamFile/,/}/p' $CASE_FILE > FoamFile
|
then
|
||||||
CLASS=`FoamFileAttribute class FoamFile`
|
echo "Updating case file: $caseFile"
|
||||||
OBJECT=`FoamFileAttribute object FoamFile`
|
sed -n '/FoamFile/,/}/p' $caseFile > FoamFile
|
||||||
FORMAT=`FoamFileAttribute format FoamFile`
|
|
||||||
printOpenFOAMheader $VERSION $FORMAT $CLASS $OBJECT > temp
|
|
||||||
sed '1,/}/d' $CASE_FILE | sed '/./,/^$/!d' >> temp
|
|
||||||
mv temp $1
|
|
||||||
rm FoamFile
|
|
||||||
else
|
|
||||||
echo "The following file does not appear to be a case file:"
|
|
||||||
echo " " $CASE_FILE
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
CLASS=`FoamFileAttribute class FoamFile`
|
||||||
|
OBJECT=`FoamFileAttribute object FoamFile`
|
||||||
|
FORMAT=`FoamFileAttribute format FoamFile`
|
||||||
|
|
||||||
|
printHeader $FORMAT $CLASS $OBJECT $NOTE > FoamFile.tmp
|
||||||
|
sed '1,/}/d' $caseFile | sed '/./,/^$/!d' >> FoamFile.tmp
|
||||||
|
|
||||||
|
mv FoamFile.tmp $caseFile
|
||||||
|
rm FoamFile
|
||||||
|
else
|
||||||
|
echo " Invalid case file: $caseFile"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|||||||
@ -41,24 +41,15 @@ usage() {
|
|||||||
|
|
||||||
usage: ${0##*/} <turbulenceProperties>
|
usage: ${0##*/} <turbulenceProperties>
|
||||||
|
|
||||||
Where <turbulenceProperties> is the full path to the
|
Where <turbulenceProperties> is the full path to the
|
||||||
turbulenceProperties dictionary
|
turbulenceProperties dictionary
|
||||||
|
|
||||||
|
Note: can upgrade several files at once
|
||||||
|
|
||||||
USAGE
|
USAGE
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
[ $# = 1 ] || usage
|
|
||||||
|
|
||||||
turbDict=$1
|
|
||||||
if [ ! -f $turbDict ]
|
|
||||||
then
|
|
||||||
echo " Error: file $turbDict does not exist"
|
|
||||||
echo ""
|
|
||||||
usage
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# $1: turbulence model
|
# $1: turbulence model
|
||||||
# $2: new properties type
|
# $2: new properties type
|
||||||
@ -66,7 +57,7 @@ fi
|
|||||||
#
|
#
|
||||||
convertDict()
|
convertDict()
|
||||||
{
|
{
|
||||||
echo " Identified $1 turbulence model in $3"
|
echo "Identified $1 turbulence model in '$3'"
|
||||||
outputPath=`dirname $3`
|
outputPath=`dirname $3`
|
||||||
|
|
||||||
sed -e "s/turbulenceProperties/$1Properties/" \
|
sed -e "s/turbulenceProperties/$1Properties/" \
|
||||||
@ -77,20 +68,26 @@ convertDict()
|
|||||||
echo " wrote $outputPath/$1Properties"
|
echo " wrote $outputPath/$1Properties"
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
[ $# -ge 1 ] || usage
|
||||||
# Identify type of turbulence model and convert
|
|
||||||
#
|
|
||||||
if grep turbulenceModel $turbDict >/dev/null 2>&1
|
|
||||||
then
|
|
||||||
convertDict RAS turbulenceModel $turbDict
|
|
||||||
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
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "done."
|
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
|
||||||
|
elif grep LESmodel $turbDict >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
convertDict LES LESmodel $turbDict
|
||||||
|
else
|
||||||
|
echo "Unable to determine turbulence model type in '$turbDict'"
|
||||||
|
echo " - nothing changed"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Error: file '$turbDict' does not exist"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user