Allrun 4.23 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
7
#    \\/     M anipulation  | Copyright (C) 2017 OpenCFD Ltd.
Henry's avatar
Henry committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#------------------------------------------------------------------------------
# License
#     This file is part of OpenFOAM.
#
#     OpenFOAM is free software: you can redistribute it and/or modify it
#     under the terms of the GNU General Public License as published by
#     the Free Software Foundation, either version 3 of the License, or
#     (at your option) any later version.
#
#     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
#     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
#     for more details.
#
#     You should have received a copy of the GNU General Public License
#     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
#
# Script
#     Allrun
#
# Description
29
#     Runs tutorial cases and summarizes the outcome as 'testLoopReport'
Henry's avatar
Henry committed
30
31
#
#------------------------------------------------------------------------------
Henry's avatar
Henry committed
32
cd ${0%/*} || exit 1    # Run from this directory
Henry's avatar
Henry committed
33

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
usage()
{
    exec 1>&2
    while [ "$#" -ge 1 ]; do echo "$1"; shift; done
    cat<<USAGE

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

options:
  -collect          Collect logs only. Can be useful for aborted runs.
  -help             print the usage

* Runs tutorial cases and summarizes the outcome as 'testLoopReport'

USAGE
    exit 1
}

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

unset optCollectOnly

# parse options
while [ "$#" -gt 0 ]
do
    case "$1" in
    -h | -help)
        usage
        ;;
    -collect)
        optCollectOnly=true
        ;;
66
67
68
    -test)   # Known options that should be passed through
        break
        ;;
69
70
71
72
73
74
75
76
77
78
79
    -*)
        usage "unknown option: $1"
        ;;
    *)
        break
        ;;
    esac
    shift
done

#------------------------------------------------------------------------------
Henry's avatar
Henry committed
80
81
82
83
84

# logReport <logfile>
# Extracts useful info from log file.
logReport()
{
85
    local logfile=$1
Henry's avatar
Henry committed
86

87
88
89
90
    # logfile is path/to/case/log.application
    caseName=$(dirname $logfile | sed -e 's/\(.*\)\.\///g')
    app=$(echo $logfile | sed -e 's/\(.*\)log\.//g')
    appAndCase="Application $app - case $caseName"
Henry's avatar
Henry committed
91

92
    if grep -q "FOAM FATAL" $logfile
Henry's avatar
Henry committed
93
94
    then
        echo "$appAndCase: ** FOAM FATAL ERROR **"
95
96
97
98
99
100
101
        return 1
    fi

    # Check for solution singularity on U equation
    for eqn in Ux Uy Uz
    do
        if grep -q -E "${eqn}[:| ]*solution singularity" $logfile
Henry's avatar
Henry committed
102
        then
103
104
105
106
107
108
109
110
            if [ "$eqn" = Uz ]
            then
                # Can only get here if Ux,Uy,Uz all failed
                echo "$appAndCase: ** Solution singularity **"
                return 1
            fi
        else
            break
Henry's avatar
Henry committed
111
        fi
112
113
114
115
116
117
118
119
120
121
    done

    if grep -q -E "^[\t ]*[Ee]nd" $logfile
    then
        # Extract time from this type of content
        ## ExecutionTime = 60.2 s  ClockTime = 63 s --> "60.2 s"
        completionTime=$(tail -10 $logfile | \
            sed -n -e '/Execution/{s/^[^=]*=[ \t]*//; s/\( s\) .*$/\1/; p}')

        echo "$appAndCase: completed${completionTime:+ in }$completionTime"
Henry's avatar
Henry committed
122
123
124
125
126
    else
        echo "$appAndCase: unconfirmed completion"
    fi
}

127
128
129
if [ -z "$optCollectOnly" ]
then
    # Recursively run all tutorials
130
    foamRunTutorials -skipFirst $*
131
fi
Henry's avatar
Henry committed
132
133
134


# Analyse all log files
135
136
137
echo "Collecting log files..." 1>&2
rm -f logs testLoopReport > /dev/null 2>&1
touch logs testLoopReport
Henry's avatar
Henry committed
138
139
140

for appDir in *
do
141
142
    [ -d $appDir ] || continue
    echo -n "    $appDir..." 1>&2
Henry's avatar
Henry committed
143

144
    logs=$(find -L $appDir -name 'log.*' -type f)
145
146
147
148
149
150
151
    if [ -n "$logs" ]
    then
        echo 1>&2
    else
        echo " (no logs)" 1>&2
        continue
    fi
Henry's avatar
Henry committed
152

153
154
    # Sort logs by time-stamp
    for log in $(echo $logs | xargs ls -rt)
Henry's avatar
Henry committed
155
    do
156
157
158
        # Concatenate and summarize logs
        cat "$log" >> logs 2>/dev/null
        logReport $log
Henry's avatar
Henry committed
159
    done
160
161
    echo
done > testLoopReport
Henry's avatar
Henry committed
162

163
#------------------------------------------------------------------------------