9
9
10
10
11
11
#%% Tests for Shape functions and derivatives
12
- def test_shape_tri3 ():
12
+ result = np .eye (3 )
13
+ @pytest .mark .parametrize ("r, s, res" ,[
14
+ [0.0 , 0.0 ,result [0 ]],
15
+ [1.0 , 0.0 ,result [1 ]],
16
+ [0.0 , 1.0 ,result [2 ]]
17
+ ])
18
+ def test_shape_tri3 (r ,s ,res ):
13
19
# Interpolation condition check
14
- coords = np .array ([
15
- [0.0 , 0.0 ],
16
- [1.0 , 0.0 ],
17
- [0.0 , 1.0 ]])
18
- N , _ = fem .shape_tri3 (coords [:, 0 ], coords [:, 1 ])
19
- assert np .allclose (N , np .eye (3 ))
20
-
21
-
22
- def test_shape_tri6 ():
20
+ N , _ = fem .shape_tri3 (r ,s )
21
+ assert np .allclose (N ,res )
22
+
23
+ result = np .eye (6 )
24
+ @pytest .mark .parametrize ("r, s, res" ,[
25
+ [0.0 , 0.0 ,result [0 ]],
26
+ [1.0 , 0.0 ,result [1 ]],
27
+ [0.0 , 1.0 ,result [2 ]],
28
+ [0.5 , 0.0 ,result [3 ]],
29
+ [0.5 , 0.5 ,result [4 ]],
30
+ [0.0 , 0.5 ,result [5 ]]])
31
+ def test_shape_tri6_N (r ,s ,res ):
23
32
# Interpolation condition check
24
- coords = np .array ([
25
- [0.0 , 0.0 ],
26
- [1.0 , 0.0 ],
27
- [0.0 , 1.0 ],
28
- [0.5 , 0.0 ],
29
- [0.5 , 0.5 ],
30
- [0.0 , 0.5 ]])
31
- N , _ = fem .shape_tri6 (coords [:, 0 ], coords [:, 1 ])
32
- assert np .allclose (N , np .eye (6 ))
33
+ N , _ = fem .shape_tri6 (r ,s )
34
+ assert np .allclose (N , res )
33
35
36
+ def test_shape_tri6_dNdr ():
34
37
# Evaluation at (1/3, 1/3)
35
38
N , dNdr = fem .shape_tri6 (1 / 3 , 1 / 3 )
36
39
N_exp = np .array ([- 1. , - 1. , - 1. , 4. , 4. , 4. ])/ 9
@@ -40,38 +43,41 @@ def test_shape_tri6():
40
43
assert np .allclose (N , N_exp )
41
44
assert np .allclose (dNdr , dNdr_exp )
42
45
43
-
44
- def test_shape_quad4 ():
46
+ result = np .eye (4 )
47
+ @pytest .mark .parametrize ("r, s, res" ,[
48
+ [- 1.0 , - 1.0 ,result [0 ]],
49
+ [1.0 , - 1.0 ,result [1 ]],
50
+ [1.0 , 1.0 ,result [2 ]],
51
+ [- 1.0 , 1.0 ,result [3 ]]])
52
+ def test_shape_quad4_N (r ,s ,res ):
45
53
# Interpolation condition check
46
- coords = np .array ([
47
- [- 1.0 , - 1.0 ],
48
- [1.0 , - 1.0 ],
49
- [1.0 , 1.0 ],
50
- [- 1.0 , 1.0 ]])
51
- N , _ = fem .shape_quad4 (coords [:, 0 ], coords [:, 1 ])
52
- assert np .allclose (N , np .eye (4 ))
54
+ N , _ = fem .shape_quad4 (r ,s )
55
+ assert np .allclose (N , res )
53
56
57
+ def test_shape_quad4_dNdr ():
54
58
# For point (0, 0)
55
59
N , _ = fem .shape_quad4 (0 , 0 )
56
60
N_ex = 0.25 * np .array ([[1 , 1 , 1 , 1 ]])
57
61
assert np .allclose (N , N_ex )
58
62
59
63
60
- def test_shape_quad9 ():
64
+ result = np .eye (9 )
65
+ @pytest .mark .parametrize ("r, s, res" ,[
66
+ [- 1.0 , - 1.0 ,result [0 ]],
67
+ [ 1.0 , - 1.0 ,result [1 ]],
68
+ [ 1.0 , 1.0 ,result [2 ]],
69
+ [- 1.0 , 1.0 ,result [3 ]],
70
+ [ 0.0 , - 1.0 ,result [4 ]],
71
+ [ 1.0 , 0.0 ,result [5 ]],
72
+ [ 0.0 , 1.0 ,result [6 ]],
73
+ [- 1.0 , 0.0 ,result [7 ]],
74
+ [ 0.0 , 0.0 ,result [8 ]]])
75
+ def test_shape_quad9_N (r ,s ,res ):
61
76
# Interpolation condition check
62
- coords = np .array ([
63
- [- 1.0 , - 1.0 ],
64
- [ 1.0 , - 1.0 ],
65
- [ 1.0 , 1.0 ],
66
- [- 1.0 , 1.0 ],
67
- [ 0.0 , - 1.0 ],
68
- [ 1.0 , 0.0 ],
69
- [ 0.0 , 1.0 ],
70
- [- 1.0 , 0.0 ],
71
- [ 0.0 , 0.0 ]])
72
- N , _ = fem .shape_quad9 (coords [:, 0 ], coords [:, 1 ])
73
- assert np .allclose (N , np .eye (9 ))
77
+ N , _ = fem .shape_quad9 (r , s )
78
+ assert np .allclose (N , res )
74
79
80
+ def test_shape_quad9_dNdr ():
75
81
# Evaluation at (1/4, 1/4)
76
82
N , dNdr = fem .shape_quad9 (0.25 , 0.25 )
77
83
N_exp = np .array (
@@ -87,47 +93,49 @@ def test_shape_quad9():
87
93
assert np .allclose (N , N_exp )
88
94
assert np .allclose (dNdr , dNdr_exp )
89
95
90
-
91
- def test_shape_quad8 ():
96
+ result = np .eye (8 )
97
+ @pytest .mark .parametrize ("r, s, res" ,[
98
+ [- 1.0 , - 1.0 ,result [0 ]],
99
+ [ 1.0 , - 1.0 ,result [1 ]],
100
+ [ 1.0 , 1.0 ,result [2 ]],
101
+ [- 1.0 , 1.0 ,result [3 ]],
102
+ [ 0.0 , - 1.0 ,result [4 ]],
103
+ [ 1.0 , 0.0 ,result [5 ]],
104
+ [ 0.0 , 1.0 ,result [6 ]],
105
+ [- 1.0 , 0.0 ,result [7 ]]])
106
+ def test_shape_quad8 (r ,s ,res ):
92
107
# Interpolation condition check
93
- coords = np .array ([
94
- [- 1.0 , - 1.0 ],
95
- [ 1.0 , - 1.0 ],
96
- [ 1.0 , 1.0 ],
97
- [- 1.0 , 1.0 ],
98
- [ 0.0 , - 1.0 ],
99
- [ 1.0 , 0.0 ],
100
- [ 0.0 , 1.0 ],
101
- [- 1.0 , 0.0 ]])
102
- N , _ = fem .shape_quad8 (coords [:, 0 ], coords [:, 1 ])
103
- assert np .allclose (N , np .eye (8 ))
108
+ N , _ = fem .shape_quad8 (r ,s )
109
+ assert np .allclose (N , res )
104
110
105
111
106
112
# 3D elements
107
- def test_shape_tet4 ():
113
+ result = np .eye (4 )
114
+ @pytest .mark .parametrize ("r, s, t, res" ,[
115
+ [0.0 , 0.0 , 0.0 ,result [0 ]],
116
+ [1.0 , 0.0 , 0.0 ,result [1 ]],
117
+ [0.0 , 1.0 , 0.0 ,result [2 ]],
118
+ [0.0 , 0.0 , 1.0 ,result [3 ]]
119
+ ])
120
+ def test_shape_tet4 (r ,s ,t ,res ):
108
121
# Interpolation condition check
109
- coords = np .array ([
110
- [0.0 , 0.0 , 0.0 ],
111
- [1.0 , 0.0 , 0.0 ],
112
- [0.0 , 1.0 , 0.0 ],
113
- [0.0 , 0.0 , 1.0 ]])
114
- N , _ = fem .shape_tet4 (coords [:, 0 ], coords [:, 1 ], coords [:, 2 ])
115
- assert np .allclose (N , np .eye (4 ))
116
-
117
-
118
- def test_shape_hex ():
122
+ N , _ = fem .shape_tet4 (r , s , t )
123
+ assert np .allclose (N , res )
124
+
125
+ result = np .eye (8 )
126
+ @pytest .mark .parametrize ("r, s, t, res" ,[
127
+ [- 1.0 , - 1.0 , - 1.0 ,result [0 ]],
128
+ [ 1.0 , - 1.0 , - 1.0 ,result [1 ]],
129
+ [ 1.0 , 1.0 , - 1.0 ,result [2 ]],
130
+ [- 1.0 , 1.0 , - 1.0 ,result [3 ]],
131
+ [- 1.0 , - 1.0 , 1.0 ,result [4 ]],
132
+ [ 1.0 , - 1.0 , 1.0 ,result [5 ]],
133
+ [ 1.0 , 1.0 , 1.0 ,result [6 ]],
134
+ [- 1.0 , 1.0 , 1.0 ,result [7 ]]])
135
+ def test_shape_hex (r ,s ,t ,res ):
119
136
# Interpolation condition check
120
- coords = np .array ([
121
- [- 1.0 , - 1.0 , - 1.0 ],
122
- [ 1.0 , - 1.0 , - 1.0 ],
123
- [ 1.0 , 1.0 , - 1.0 ],
124
- [- 1.0 , 1.0 , - 1.0 ],
125
- [- 1.0 , - 1.0 , 1.0 ],
126
- [ 1.0 , - 1.0 , 1.0 ],
127
- [ 1.0 , 1.0 , 1.0 ],
128
- [- 1.0 , 1.0 , 1.0 ]])
129
- N , _ = fem .shape_hex8 (coords [:, 0 ], coords [:, 1 ], coords [:, 2 ])
130
- assert np .allclose (N , np .eye (8 ))
137
+ N , _ = fem .shape_hex8 (r , s , t )
138
+ assert np .allclose (N , res )
131
139
132
140
133
141
#%% Jacobian
0 commit comments