Alltest 6.55 KB
Newer Older
Henry's avatar
Henry committed
1
2
3
4
5
#!/bin/sh
#------------------------------------------------------------------------------
# =========                 |
# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
#  \\    /   O peration     |
6
#   \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
mark's avatar
mark committed
7
#    \\/     M anipulation  | Copyright (C) 2017 OpenCFD Ltd.
Henry's avatar
Henry committed
8
9
#------------------------------------------------------------------------------
# License
10
11
#     This file is part of OpenFOAM, licensed under GNU General Public License
#     <http://www.gnu.org/licenses/>.
Henry's avatar
Henry committed
12
13
14
15
16
#
# Script
#     Alltest
#
# Description
mark's avatar
mark committed
17
#     Quickly test the tutorials and write out the scheme/solver information
Henry's avatar
Henry committed
18
19
#
#------------------------------------------------------------------------------
Henry's avatar
Henry committed
20
cd ${0%/*} || exit 1    # Run from this directory
Henry's avatar
Henry committed
21
22
23

usage()
{
mark's avatar
mark committed
24
    exec 1>&2
Henry's avatar
Henry committed
25
26
27
28
29
30
    while [ "$#" -ge 1 ]; do echo "$1"; shift; done
    cat<<USAGE

usage: ${0##*/} [OPTION]

options:
mark's avatar
mark committed
31
32
  -git              use git to retrieve the tutorials
  -root dir         specify root directory to run tests from
Henry's avatar
Henry committed
33
34
35
36
37
38
39
40
41
  -default          sets up a default scheme on all schemes
  -help             print the usage

* quickly tests the tutorials and writes out the scheme/solver information

USAGE
    exit 1
}

mark's avatar
mark committed
42
43
44
45
46
47
48
49
50
51
52
53
# Report error and exit
die()
{
    exec 1>&2
    echo
    echo "Error encountered:"
    while [ "$#" -ge 1 ]; do echo "    $1"; shift; done
    echo
    echo "See '${0##*/} -help' for usage"
    echo
    exit 1
}
Henry's avatar
Henry committed
54

mark's avatar
mark committed
55
#------------------------------------------------------------------------------
Henry's avatar
Henry committed
56
57

ROOT="./"
mark's avatar
mark committed
58
59
unset DEFAULT_SCHEMES
unset useGit
Henry's avatar
Henry committed
60
61
62
63
64

# parse options
while [ "$#" -gt 0 ]
do
    case "$1" in
mark's avatar
mark committed
65
66
67
    -h | -help)
        usage
        ;;
Henry's avatar
Henry committed
68
69
70
71
72
    -r | -root)
        [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
        ROOT="$2"
        shift
        ;;
mark's avatar
mark committed
73
74
    -git)
        useGit=true
Henry's avatar
Henry committed
75
76
77
78
79
        ;;
    -d | -default)
        DEFAULT_SCHEMES=true
        ;;
    *)
mark's avatar
mark committed
80
        usage "unknown option/argument: '$1'"
Henry's avatar
Henry committed
81
82
83
84
85
        ;;
    esac
    shift
done

mark's avatar
mark committed
86
87
88
89
90
91
# Set tutorial locations (as required)
. $WM_PROJECT_DIR/bin/tools/RunFunctions


#------------------------------------------------------------------------------

mark's avatar
mark committed
92
#
93
# Set up a default scheme on all schemes
mark's avatar
mark committed
94
#
Henry's avatar
Henry committed
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
setDefaultFvSchemes()
{
cat<<EOF
gradSchemes { default Gauss linear; }
divSchemes
{
    default Gauss linear;
    div(phi,fu_ft_ha) Gauss multivariateSelection
    {
        fu upwind;
        ft upwind;
        h  upwind;
    };
    div(phi,ft_b_ha_hau) Gauss multivariateSelection
    {
        fu upwind;
        ft upwind;
        b  upwind;
        h  upwind;
        hu upwind;
    };
}
laplacianSchemes { default Gauss linear corrected; }
interpolationSchemes { default linear; }
snGradSchemes { default corrected; }
EOF
}

#
mark's avatar
mark committed
124
# Location of the main controlDict
Henry's avatar
Henry committed
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#
unset MAIN_CONTROL_DICT

for i in \
    $HOME/.$WM_PROJECT/$WM_PROJECT_VERSION \
    $HOME/.$WM_PROJECT \
    $WM_PROJECT_DIR/etc \
    ;
do
    if [ -f "$i/controlDict" ]
    then
        MAIN_CONTROL_DICT="$i/controlDict"
        break
    fi
done

[ -f "$MAIN_CONTROL_DICT" ] || usage "main controlDict not found"


TUTORIALS_DIR=$ROOT
TEST_RUN_DIR=../tutorialsTest
FV_SCHEMES=\
" \
    gradScheme \
    divScheme \
    laplacianScheme \
    interpolationScheme \
    snGradScheme \
"
SCHEMES_FILE="FvSchemes"
SCHEMES_TEMP="FvSchemes.temp"
SOLVERS_FILE="FvSolution"
SOLVERS_TEMP="FvSolution.temp"


#
# MAIN
#

if [ -d "$TEST_RUN_DIR" ]
then
mark's avatar
mark committed
166
    echo "Removing old directory: $TEST_RUN_DIR" 1>&2
Henry's avatar
Henry committed
167
168
169
    rm -rf $TEST_RUN_DIR
fi

170
171
172
173
174
175
176
177
# Remove old build/ directory
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
fi

mark's avatar
mark committed
178
echo "Modifying ${MAIN_CONTROL_DICT}" 1>&2
179
if [ -e ${MAIN_CONTROL_DICT}.orig ]
Henry's avatar
Henry committed
180
then
mark's avatar
mark committed
181
182
    die "File ${MAIN_CONTROL_DICT}.orig already exists" \
        "Did Alltest fail in some way and then run again?"
Henry's avatar
Henry committed
183
184
185
fi

# Clean up on termination and on Ctrl-C
186
trap 'mv ${MAIN_CONTROL_DICT}.orig ${MAIN_CONTROL_DICT} 2>/dev/null; exit 0' \
Henry's avatar
Henry committed
187
    EXIT TERM INT
188
cp ${MAIN_CONTROL_DICT} ${MAIN_CONTROL_DICT}.orig
Henry's avatar
Henry committed
189
190

sed \
mark's avatar
mark committed
191
192
193
    -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}
Henry's avatar
Henry committed
194

mark's avatar
mark committed
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
if [ -n "$useGit" ]
then
    echo "Copying the tutorials from current git branch" 1>&2
    if  git rev-parse --is-inside-work-tree > /dev/null 2>&1 && \
        base="$(git rev-parse --show-toplevel 2>/dev/null)"
    then
        mkdir -p ${TEST_RUN_DIR}
        ( cd $base/tutorials && git archive --format=tar HEAD . ) | \
        ( cd $TEST_RUN_DIR && tar -xf - )
    else
        die "Not in a git-repo"
    fi
else
    echo "Copying the tutorials" 1>&2
    cp -a ${TUTORIALS_DIR} ${TEST_RUN_DIR}
fi
Henry's avatar
Henry committed
211

mark's avatar
mark committed
212
echo "Modifying the controlDicts to run only one time step" 1>&2
Henry's avatar
Henry committed
213
214
cd ${TEST_RUN_DIR} || exit 1

215
for CD in $(find . -name "controlDict*" -type f)
Henry's avatar
Henry committed
216
do
217
    mv ${CD} ${CD}.orig
Henry's avatar
Henry committed
218
    sed \
mark's avatar
mark committed
219
220
221
222
223
        -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}
Henry's avatar
Henry committed
224
225
226
227
done

if [ "$DEFAULT_SCHEMES" = true ]
then
mark's avatar
mark committed
228
    echo "Modifying the fvSchemes to contain only default schemes" 1>&2
229
    for FV_SC in $(find . -name fvSchemes -type f)
Henry's avatar
Henry committed
230
231
232
    do
        for S in $FV_SCHEMES
        do
233
234
            mv ${FV_SC} ${FV_SC}.orig
            sed -e /"${S}"/,/$p/d ${FV_SC}.orig > ${FV_SC}
Henry's avatar
Henry committed
235
236
237
238
239
        done
        setDefaultFvSchemes >> ${FV_SC}
    done
fi

mark's avatar
mark committed
240

Henry's avatar
Henry committed
241
cp -f $FOAM_TUTORIALS/Allrun .
242
./Allrun -test
Henry's avatar
Henry committed
243
244
245

sed -e :a -e '/\\$/N; s/\\\n//; ta' Allrun > temp
APPLICATIONS=\
mark's avatar
mark committed
246
    $(grep "applications=" temp | sed 's/applications=\"\([A-Za-z \t]*\)\"/\1/g')
Henry's avatar
Henry committed
247
248
249
250
251
252
253
254
255
256

rm $SCHEMES_FILE > /dev/null 2>&1
for APP in $APPLICATIONS
do
    echo $APP >> $SCHEMES_FILE
    echo "$APP: " | tr -d "\n" >> $SOLVERS_FILE
    for ST in $FV_SCHEMES
    do
        rm $SCHEMES_TEMP $SOLVERS_TEMP > /dev/null 2>&1
        echo "  ${ST}" >> $SCHEMES_FILE
257
        for LOG in $(find ${APP} -name "log.${APP}" -type f)
Henry's avatar
Henry committed
258
        do
mark's avatar
mark committed
259
            for S in $(grep ${ST} ${LOG} | cut -d" " -f4)
Henry's avatar
Henry committed
260
261
262
            do
                echo "    ${S}" >> $SCHEMES_TEMP
            done
mark's avatar
mark committed
263
        echo $(grep solver ${LOG} | cut -d" " -f4) >> $SOLVERS_TEMP
Henry's avatar
Henry committed
264
265
266
267
268
269
270
271
272
273
        done
        if [ -f $SCHEMES_TEMP ]
        then
            cat $SCHEMES_TEMP | sort -u >> $SCHEMES_FILE
        fi
    done
    cat $SOLVERS_TEMP | tr " " "\n" | sort -u | tr "\n" " " >> $SOLVERS_FILE
    echo "" >> $SOLVERS_FILE
done

274
#------------------------------------------------------------------------------