forked from kinnala/scikit-fem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_examples.py
322 lines (197 loc) · 7.56 KB
/
test_examples.py
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
from unittest import TestCase, main
import numpy as np
class TestEx01(TestCase):
def runTest(self):
import docs.examples.ex01 as ex01
self.assertAlmostEqual(np.max(ex01.x), 0.07344576657)
class TestEx01Minimize(TestCase):
def runTest(self):
import docs.examples.ex01_minimize as ex01
self.assertAlmostEqual(np.max(ex01.x), 0.07344576657)
class TestEx02(TestCase):
def runTest(self):
import docs.examples.ex02 as ex02
self.assertAlmostEqual(np.max(ex02.x), 0.001217973811129439)
class TestEx03(TestCase):
def runTest(self):
import docs.examples.ex03 as ex03
self.assertAlmostEqual(ex03.L[0], 0.00418289)
class TestEx04(TestCase):
def runTest(self):
import docs.examples.ex04 as ex04
self.assertAlmostEqual(np.max(ex04.vonmises1), 64.57919816083539)
self.assertAlmostEqual(np.max(ex04.vonmises2), 67.91419767505899)
class TestEx05(TestCase):
def runTest(self):
import docs.examples.ex05 as ex05
self.assertAlmostEqual(np.max(ex05.x), 0.93570751751091152)
class TestEx06(TestCase):
def runTest(self):
import docs.examples.ex06 as ex06
self.assertAlmostEqual(np.max(ex06.x), 0.073651530833125131)
class TestEx07(TestCase):
def runTest(self):
import docs.examples.ex07 as ex07
self.assertAlmostEqual(np.max(ex07.x), 0.07869083767545548)
class TestEx08(TestCase):
def runTest(self):
import docs.examples.ex08 as ex08 # noqa
# only run the initialization, nothing to test
class TestEx09(TestCase):
def runTest(self):
import docs.examples.ex09 as ex09
self.assertAlmostEqual(np.max(ex09.x), 0.05528520791811886, places=6)
class TestEx10(TestCase):
def runTest(self):
import docs.examples.ex10 as ex10
self.assertAlmostEqual(np.mean(ex10.x), 0.277931521728906)
class TestEx10Minimize(TestCase):
def runTest(self):
import docs.examples.ex10_minimize as ex10
self.assertAlmostEqual(np.mean(ex10.x), 0.277931521728906)
class TestEx11(TestCase):
def runTest(self):
import docs.examples.ex11 as ex11
u = ex11.u
ib = ex11.ib
# since the mesh is symmetric, the mean values should equal to zero
self.assertAlmostEqual(np.mean(u[ib.nodal_dofs[2, :]]), 0.0)
self.assertAlmostEqual(np.mean(u[ib.nodal_dofs[1, :]]), 0.0)
class TestEx12(TestCase):
def runTest(self):
import docs.examples.ex12 as ex
self.assertAlmostEqual(ex.area, np.pi, delta=1e-2)
self.assertAlmostEqual(ex.k, 1 / 8 / np.pi, delta=1e-5)
self.assertAlmostEqual(ex.k1, 1 / 4 / np.pi, delta=1e-5)
class TestEx13(TestCase):
def runTest(self):
import docs.examples.ex13 as ex
u = ex.u
A = ex.A
self.assertAlmostEqual(u @ A @ u, 2 * np.log(2) / np.pi, delta=1e-3)
class TestEx14(TestCase):
def runTest(self):
import docs.examples.ex14
u = docs.examples.ex14.u
A = docs.examples.ex14.A
self.assertAlmostEqual(u @ A @ u, 8 / 3, delta=1e-2)
class TestEx15(TestCase):
def runTest(self):
import docs.examples.ex15 as ex15
self.assertTrue(np.max(ex15.x) - 0.1234567 < 1e-5)
class TestEx16(TestCase):
def runTest(self):
import docs.examples.ex16 as ex16
self.assertTrue(np.linalg.norm(np.array([0, 2, 6, 12, 20, 30])
- ex16.ks) < 0.4)
self.assertTrue(ex16.ks[-1], 30.309720458315521)
class TestEx17(TestCase):
def runTest(self):
import docs.examples.ex17 as ex # noqa
# TODO improve
class TestEx18(TestCase):
def runTest(self):
import docs.examples.ex18 as ex # noqa
# TODO improve
class TestEx19(TestCase):
def runTest(self):
import docs.examples.ex19 as ex # noqa
# TODO improve
class TestEx20(TestCase):
def runTest(self):
import docs.examples.ex20 as ex
psi0 = ex.psi0
self.assertAlmostEqual(psi0, 1 / 64, delta=1e-3)
class TestEx21(TestCase):
def runTest(self):
import docs.examples.ex21 as ex
x = ex.x
K = ex.K
L = ex.L[0]
self.assertAlmostEqual(L, 50194.51136114997, delta=1)
self.assertAlmostEqual(L, x[:, 0].T @ K @ x[:, 0], 4)
class TestEx22(TestCase):
def runTest(self):
import docs.examples.ex22 as ex
u = ex.u
K = ex.K
self.assertAlmostEqual(u.T @ K @ u, 0.2131280267335294)
class TestEx23(TestCase):
def runTest(self):
import docs.examples.ex23 as ex
self.assertAlmostEqual(max(ex.lmbda_list), ex.turning_point,
delta=5e-5)
class TestEx24(TestCase):
def runTest(self):
import docs.examples.ex24 as ex24 # noqa
class TestEx25(TestCase):
def runTest(self):
import docs.examples.ex25 as ex25
mu = np.mean(ex25.t)
self.assertAlmostEqual(mu, 0.4642600944590631, places=5)
self.assertAlmostEqual(np.mean(ex25.t0), mu, places=2)
class TestEx26(TestCase):
def runTest(self):
import docs.examples.ex26 as ex26 # noqa
class TestEx27(TestCase):
def runTest(self):
import docs.examples.ex27 as ex
_, psi = ex.psi.popitem()
self.assertAlmostEqual(min(psi), -0.027043, delta=1e-6)
self.assertAlmostEqual(max(psi), 0.6668, delta=1e-5)
class TestEx28(TestCase):
def runTest(self):
from docs.examples.ex28 import exit_interface_temperature as t
self.assertAlmostEqual(*t.values(), delta=2e-4)
class TestEx29(TestCase):
def runTest(self):
from docs.examples.ex29 import c
wavespeed = tuple(
np.array(sorted(wavespeed, key=np.imag, reverse=True))
for wavespeed in c.values())
self.assertLess(np.linalg.norm(wavespeed[1] - wavespeed[0], np.inf),
5e-3)
class TestEx30(TestCase):
def runTest(self):
from docs.examples.ex30 import psi0
self.assertAlmostEqual(psi0, 0.162/128, delta=1e-6)
class TestEx31(TestCase):
def runTest(self):
from docs.examples.ex31 import L
self.assertAlmostEqual(L[0], 22.597202568397734, delta=1e-6)
class TestEx32(TestCase):
def runTest(self):
from docs.examples.ex32 import l2error_p
self.assertLess(l2error_p, 1e-5)
class TestEx33(TestCase):
def runTest(self):
from docs.examples.ex33 import x
self.assertAlmostEqual(np.max(x), 0.12220233975847579, delta=1e-8)
class TestEx34(TestCase):
def runTest(self):
from docs.examples.ex34 import err
self.assertAlmostEqual(err, 0., delta=1e-13)
class TestEx35(TestCase):
def runTest(self):
from docs.examples.ex35 import Z
# exact value depends also on mesh generation,
# over which we don't have control.
# tolerance is low, but might still break if mesh is slightly different
self.assertAlmostEqual(Z, 52.563390368494424, delta=1e-1)
class TestEx36(TestCase):
def runTest(self):
from docs.examples.ex36 import du, dp
self.assertAlmostEqual(np.linalg.norm(du),
16.529402115680444,
delta=1e-5)
self.assertAlmostEqual(dp[0], -0.5, delta=1.e-8)
class TestEx37(TestCase):
def runTest(self):
from docs.examples.ex37 import u
self.assertAlmostEqual(np.max(u), 0.05594193697362236)
class TestEx38(TestCase):
def runTest(self):
from docs.examples.ex38 import l2error
self.assertLess(l2error, 3e-3)
if __name__ == '__main__':
main()