forked from markcmiller86/hello-numerical-world
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_lss.sh
executable file
·86 lines (80 loc) · 1.94 KB
/
check_lss.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
#
# Checks output from heat application to confirm
# linear, steady state
#
if [[ -z "$1" ]]; then
echo "Specify input file as 1rst arg"
exit 1
fi
rdfile=$1
#
# Use absolute error by default. Relative
# error if specified tolerance is negative.
#
relerr=0
errbnd=1e-7
if [[ -n "$2" ]]; then
errbnd=$2
t=$(perl -e "print $2<0")
if [[ "$t" == "1" ]]; then
errbnd=$(perl -e "print - $2")
relerr=1
fi
fi
#
# Default boundary conditions
#
Len=1
bc0=0
bc1=1
#
# Handle non-default boundary conditions
#
if [[ -n "$3" ]]; then
if [[ -z "$4" ]]; then
echo "Missing left-end boundary condition arg"
exit 1
fi
if [[ -z "$5" ]]; then
echo "Missing right-end boundary condition arg"
exit 1
fi
Len=$3
bc0=$4
bc1=$5
fi
#
# Loop over lines. Use perl's arithmetic functions to
# do needed arithmetic operations. Handle absolute and
# relative diffs and special case at zero.
#
while IFS= read line; do
if [[ "$line" =~ "#" ]]; then
continue
fi
xval=$(echo $line | tr -s ' ' | cut -d' ' -f1)
yval=$(echo $line | tr -s ' ' | cut -d' ' -f2)
if [[ "$xval" == "0" ]]; then
t=$(perl -e "print abs($bc0-$yval)>($2)")
r=$(perl -e "print abs($bc0-$yval)")
if [[ "$t" -eq 1 ]]; then
echo "Check failed at x=$xval y=$yval yexp=$bc0, diff=$r"
exit 1
fi
continue
fi
exact_yval=$(perl -e "print $bc0 + ($bc1-$bc0)*$xval/$Len")
if [[ $relerr -eq 1 ]]; then
diffr=$(perl -e "print abs(($yval-$exact_yval)/$exact_yval)")
diffl=$(perl -e "print abs(($yval-$exact_yval)/$exact_yval)<=($errbnd)")
else
diffr=$(perl -e "print abs($yval-$exact_yval)")
diffl=$(perl -e "print abs($yval-$exact_yval)<=($errbnd)")
fi
if [[ $diffl -ne 1 ]]; then
echo "Check failed at x=$xval y=$yval yexp=$exact_yval, diff=$diffr"
exit 1
fi
done < $rdfile
exit 0