-
Notifications
You must be signed in to change notification settings - Fork 0
/
thermal-square.sh
executable file
·213 lines (164 loc) · 6.71 KB
/
thermal-square.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
87
88
89
90
91
92
93
94
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
124
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/bin/bash -e
# proposed solution temperature and conductivity
T="1 + sin(2*x)^2 * cos(3*y)^2"
k="1 + x - 0.5*y"
# combinations
ints="full reduced extended"
bcs="dirichlet neumann"
elems="tri quad"
algos="struct frontal delaunay"
orders="1 2"
# cs="8 10 12 14 16 20 24 28 32 36 40 48 52 56 58 60"
cs="8 10 12 14 16"
# --------------------------------------
# sanity check
for i in reflexCLI feenox gmsh maxima meshio tr sed; do
if [ -z "$(which ${i})" ]; then
echo "error: ${i} not installed"
exit 1
fi
done
. styles.sh
# call maxima to compute source term
maxima --very-quiet << EOF > /dev/null
T(x,y) := ${T};
k(x,y) := ${k};
q(x,y) := -(diff(k(x,y) * diff(T(x,y), x), x) + diff(k(x,y) * diff(T(x,y), y), y));
stringout("thermal-square-q.txt", q(x,y));
stringout("thermal-square-qx.txt", -k(x,y) * diff(T(x,y),x));
stringout("thermal-square-qy.txt", -k(x,y) * diff(T(x,y),y));
EOF
# read back the string with q(x,y) and the partial derivatives
q=$(cat thermal-square-q.txt | tr -d ';\n')
qx=$(cat thermal-square-qx.txt | tr -d ';\n')
qy=$(cat thermal-square-qy.txt | tr -d ';\n')
# report what we found
cat << EOF
# manufactured solution
${T}
${k}
# source terms
q(x,y) = ${q}
qx(x,y) = ${qx}
qy(x,y) = ${qy}
EOF
# empty ppls
rm -f thermal-square-fits.ppl
echo "plot \\" > thermal-square-einf.ppl
echo "plot \\" > thermal-square-e2.ppl
for bc in ${bcs}; do
for int in ${ints}; do
echo "plot \\" > thermal-square-${bc}-${int}-einf.ppl
echo "plot \\" > thermal-square-${bc}-${int}-e2.ppl
for elem in ${elems}; do
for order in ${orders}; do
for algo in ${algos}; do
if [[ "x${elem}" != "xtri" || "x${int}" != "xreduced" || "x${order}" != "x2" ]]; then
dat="thermal-square-${bc}-${int}-${elem}-${order}-${algo}"
rm -f ${dat}.dat
echo ${dat}
echo "-----------------------------------------------------------"
for c in ${cs}; do
name="thermal-square-${bc}-${int}-${elem}-${order}-${algo}-${c}"
if [ ! -e square-${elem}-${algo}-${c}.msh ]; then
lc=$(echo "PRINT 1/${c}" | feenox -)
gmsh -v 0 -2 square.geo ${elem}.geo ${algo}.geo -clscale ${lc} -o square-${elem}-${algo}-${c}.msh
fi
# prepare input JSON
if [ ! -e ${name}.json ]; then
cp thermal-square_${bc}.json ${name}.json
sed -i "s/\$m\\$/square-${elem}-${algo}-${c}.msh/g" ${name}.json
sed -i "s/\$i\\$/${int^}/g" ${name}.json
sed -i "s/\$o\\$/${order}/g" ${name}.json
sed -i "s/\$T\\$/${T}/g" ${name}.json
sed -i "s/\$qx\\$/${qx}/g" ${name}.json
sed -i "s/\$qy\\$/${qy}/g" ${name}.json
sed -i "s/\$q\\$/${q}/g" ${name}.json
sed -i "s/\$k\\$/${k}/g" ${name}.json
fi
# call reflex (if needed, otherwise we use a cached result)
if [ ! -e output/${name}_result1.vtu ]; then
reflexCLI -i ${name}.json > /dev/null
fi
# compute errors out of the vtu
if [ -e output/${name}_result_1.vtu ]; then
# meshio warns about different size in python and in C
meshio convert output/${name}_result_1.vtu --output-format=gmsh ${name}.msh 2> /dev/null
feenox error2d.fee ${name} "${T}" ${c} | tee -a ${dat}.dat
fi
done # c
feenox fit.fee ${dat} | sed 's/-/_/g' | sed 's/e_0/e-0/' | sed 's/* _/* -/' >> thermal-square-fits.ppl
cat << EOF >> thermal-square-einf.ppl
"${dat}.dat" u 1:2 w lp pt ${pt[${elem}${order}]} lw ${lw[${bc}]} lt ${lt[${algo}]} color ${co[${int}]} ti "${bc}-${int}-${elem}${order}-${algo} = " + e_inf_thermal_square_${bc}_${int}_${elem}_${order}_${algo}_title,\\
EOF
cat << EOF >> thermal-square-e2.ppl
"${dat}.dat" u 1:3 w lp pt ${pt[${elem}${order}]} lw ${lw[${bc}]} lt ${lt[${algo}]} color ${co[${int}]} ti "${bc}-${int}-${elem}${order}-${algo} = " + e_2_thermal_square_${bc}_${int}_${elem}_${order}_${algo}_title,\\
EOF
cat << EOF >> thermal-square-${bc}-${int}-einf.ppl
"${dat}.dat" u 1:2 w lp pt ${pt[${elem}${order}]} lw ${lw[${bc}]} lt ${lt[${algo}]} color ${co[${int}]} ti "${bc}-${int}-${elem}${order}-${algo} = " + e_inf_thermal_square_${bc}_${int}_${elem}_${order}_${algo}_title,\\
EOF
cat << EOF >> thermal-square-${bc}-${int}-e2.ppl
"${dat}.dat" u 1:3 w lp pt ${pt[${elem}${order}]} lw ${lw[${bc}]} lt ${lt[${algo}]} color ${co[${int}]} ti "${bc}-${int}-${elem}${order}-${algo} = " + e_2_thermal_square_${bc}_${int}_${elem}_${order}_${algo}_title,\\
EOF
fi
done # algo
done # order
done # elem
done # int
done # bc
cat << EOF >> thermal-square-einf.ppl
x**2 w l lt 3 lw 4 color gray ti "\$h^2\$",\\
x**3 w l lt 4 lw 4 color gray ti "\$h^3\$"
EOF
cat << EOF >> thermal-square-e2.ppl
x**2 w l lt 3 lw 4 color gray ti "\$h^2\$",\\
x**3 w l lt 4 lw 4 color gray ti "\$h^3\$"
EOF
cat << EOF >> thermal-square-dirichlet-full-einf.ppl
x**2 w l lt 3 lw 4 color gray ti "\$h^2\$",\\
x**3 w l lt 4 lw 4 color gray ti "\$h^3\$"
EOF
cat << EOF >> thermal-square-dirichlet-reduced-einf.ppl
x**2 w l lt 3 lw 4 color gray ti "\$h^2\$",\\
x**3 w l lt 4 lw 4 color gray ti "\$h^3\$"
EOF
# cat << EOF >> thermal-square-dirichlet-extended-einf.ppl
# x**2 w l lt 3 lw 4 color gray ti "\$h^2\$",\\
# x**3 w l lt 4 lw 4 color gray ti "\$h^3\$"
# EOF
cat << EOF >> thermal-square-neumann-full-einf.ppl
x**2 w l lt 3 lw 4 color gray ti "\$h^2\$",\\
x**3 w l lt 4 lw 4 color gray ti "\$h^3\$"
EOF
cat << EOF >> thermal-square-neumann-reduced-einf.ppl
x**2 w l lt 3 lw 4 color gray ti "\$h^2\$",\\
x**3 w l lt 4 lw 4 color gray ti "\$h^3\$"
EOF
# cat << EOF >> thermal-square-neumann-extended-einf.ppl
# x**2 w l lt 3 lw 4 color gray ti "\$h^2\$",\\
# x**3 w l lt 4 lw 4 color gray ti "\$h^3\$"
# EOF
cat << EOF >> thermal-square-dirichlet-full-e2.ppl
x**2 w l lt 3 lw 4 color gray ti "\$h^2\$",\\
x**3 w l lt 4 lw 4 color gray ti "\$h^3\$"
EOF
cat << EOF >> thermal-square-dirichlet-reduced-e2.ppl
x**2 w l lt 3 lw 4 color gray ti "\$h^2\$",\\
x**3 w l lt 4 lw 4 color gray ti "\$h^3\$"
EOF
# cat << EOF >> thermal-square-dirichlet-extended-e2.ppl
# x**2 w l lt 3 lw 4 color gray ti "\$h^2\$",\\
# x**3 w l lt 4 lw 4 color gray ti "\$h^3\$"
# EOF
cat << EOF >> thermal-square-neumann-full-e2.ppl
x**2 w l lt 3 lw 4 color gray ti "\$h^2\$",\\
x**3 w l lt 4 lw 4 color gray ti "\$h^3\$"
EOF
cat << EOF >> thermal-square-neumann-reduced-e2.ppl
x**2 w l lt 3 lw 4 color gray ti "\$h^2\$",\\
x**3 w l lt 4 lw 4 color gray ti "\$h^3\$"
EOF
# cat << EOF >> thermal-square-neumann-extended-e2.ppl
# x**2 w l lt 3 lw 4 color gray ti "\$h^2\$",\\
# x**3 w l lt 4 lw 4 color gray ti "\$h^3\$"
# EOF