@@ -24,11 +24,17 @@ def jrc(a, b, n):
2424
2525
2626@pytest .fixture
27- def hierarchy (request ):
27+ def hierarchy_2d (request ):
2828 msh = UnitSquareMesh (2 , 2 )
2929 return MeshHierarchy (msh , 4 )
3030
3131
32+ @pytest .fixture
33+ def hierarchy_3d (request ):
34+ n = 2
35+ return [UnitCubeMesh (n * 2 ** r , n * 2 ** r , n * 2 ** r ) for r in range (3 )]
36+
37+
3238def do_projection (mesh , el_type , degree ):
3339 V = FunctionSpace (mesh , el_type , degree )
3440
@@ -57,6 +63,12 @@ def do_projection(mesh, el_type, degree):
5763 return sqrt (assemble (inner (fh - f , fh - f ) * dx ))
5864
5965
66+ def run_convergence_test (mh , el , degree , convrate ):
67+ err = [do_projection (m , el , degree ) for m in mh ]
68+ conv = np .diff (- np .log2 (err ))
69+ assert (conv > convrate ).all ()
70+
71+
6072@pytest .mark .parametrize (('el' , 'deg' , 'convrate' ),
6173 [('Johnson-Mercier' , 1 , 1.8 ),
6274 ('Morley' , 2 , 2.4 ),
@@ -69,10 +81,15 @@ def do_projection(mesh, el_type, degree):
6981 ('Bell' , 5 , 4.7 ),
7082 ('Argyris' , 5 , 5.8 ),
7183 ('Argyris' , 6 , 6.7 )])
72- def test_projection_zany_convergence_2d (hierarchy , el , deg , convrate ):
73- diff = np .array ([do_projection (m , el , deg ) for m in hierarchy [2 :]])
74- conv = np .log2 (diff [:- 1 ] / diff [1 :])
75- assert (np .array (conv ) > convrate ).all ()
84+ def test_projection_zany_convergence_2d (hierarchy_2d , el , deg , convrate ):
85+ run_convergence_test (hierarchy_2d [2 :], el , deg , convrate )
86+
87+
88+ @pytest .mark .parametrize (('el' , 'deg' , 'convrate' ),
89+ [('Johnson-Mercier' , 1 , 1.8 ),
90+ ('Morley' , 2 , 2.4 )])
91+ def test_projection_zany_convergence_3d (hierarchy_3d , el , deg , convrate ):
92+ run_convergence_test (hierarchy_3d , el , deg , convrate )
7693
7794
7895@pytest .mark .parametrize (('element' , 'degree' ),
@@ -81,9 +98,9 @@ def test_projection_zany_convergence_2d(hierarchy, el, deg, convrate):
8198 ('HCT' , 4 ),
8299 ('Argyris' , 5 ),
83100 ('Argyris' , 6 )])
84- def test_mass_conditioning (element , degree , hierarchy ):
101+ def test_mass_conditioning (element , degree , hierarchy_2d ):
85102 mass_cond = []
86- for msh in hierarchy [1 :4 ]:
103+ for msh in hierarchy_2d [1 :4 ]:
87104 V = FunctionSpace (msh , element , degree )
88105 u = TrialFunction (V )
89106 v = TestFunction (V )
0 commit comments