@@ -78,39 +78,51 @@ def vom(mesh):
7878 return VertexOnlyMesh (mesh , [(0.5 , 0.5 ), (0.31 , 0.72 )])
7979
8080
81- def test_interpolate_zany_into_vom (V , mesh , which , vom ):
81+ @pytest .fixture
82+ def expr_at_vom (V , which , vom ):
83+ mesh = V .mesh ()
8284 degree = V .ufl_element ().degree ()
8385 x , y = SpatialCoordinate (mesh )
8486 expr = (x + y )** degree
8587
86- f = Function (V )
87- f .project (expr , solver_parameters = {"ksp_type" : "preonly" ,
88- "pc_type" : "lu" })
89- fexpr = f
90- vexpr = TestFunction (V )
91- P0 = FunctionSpace (vom , "DG" , 0 )
9288 if which == "coefficient" :
9389 P0 = FunctionSpace (vom , "DG" , 0 )
9490 elif which == "grad" :
95- fexpr = grad (fexpr )
96- vexpr = grad (vexpr )
9791 expr = ufl .algorithms .expand_derivatives (grad (expr ))
9892 P0 = VectorFunctionSpace (vom , "DG" , 0 )
9993
100- expected = Function (P0 )
101- point = Constant ([0 ]* mesh .geometric_dimension ())
94+ fvom = Function (P0 )
95+ point = Constant ([0 ] * mesh .geometric_dimension ())
10296 expr_at_pt = ufl .replace (expr , {SpatialCoordinate (mesh ): point })
10397 for i , pt in enumerate (vom .coordinates .dat .data_ro ):
10498 point .assign (pt )
105- expected .dat .data [i ] = numpy .asarray (expr_at_pt , dtype = float )
99+ fvom .dat .data [i ] = numpy .asarray (expr_at_pt , dtype = float )
100+ return fvom
101+
102+
103+ def test_interpolate_zany_into_vom (V , mesh , which , expr_at_vom ):
104+ degree = V .ufl_element ().degree ()
105+ x , y = SpatialCoordinate (mesh )
106+ expr = (x + y )** degree
107+
108+ f = Function (V )
109+ f .project (expr , solver_parameters = {"ksp_type" : "preonly" ,
110+ "pc_type" : "lu" })
111+ fexpr = f
112+ vexpr = TestFunction (V )
113+ if which == "grad" :
114+ fexpr = grad (fexpr )
115+ vexpr = grad (vexpr )
116+
117+ P0 = expr_at_vom .function_space ()
106118
107119 # Interpolate a Function into P0(vom)
108120 f_at_vom = assemble (Interpolate (fexpr , P0 ))
109- assert numpy .allclose (f_at_vom .dat .data_ro , expected .dat .data_ro )
121+ assert numpy .allclose (f_at_vom .dat .data_ro , expr_at_vom .dat .data_ro )
110122
111123 # Construct a Cofunction on P0(vom)*
112124 Fvom = Cofunction (P0 .dual ()).assign (1 )
113- expected_action = assemble (action (Fvom , expected ))
125+ expected_action = assemble (action (Fvom , expr_at_vom ))
114126
115127 # Interpolate a Function into Fvom
116128 f_at_vom = assemble (Interpolate (fexpr , Fvom ))
@@ -120,14 +132,3 @@ def test_interpolate_zany_into_vom(V, mesh, which, vom):
120132 expr_vom = assemble (Interpolate (vexpr , Fvom ))
121133 f_at_vom = assemble (action (expr_vom , f ))
122134 assert numpy .allclose (f_at_vom , expected_action )
123-
124-
125- def test_high_order_mesh_cell_sizes ():
126- msh1 = UnitSquareMesh (2 , 2 )
127- h1 = msh1 .cell_sizes
128-
129- P2 = msh1 .coordinates .function_space ().reconstruct (degree = 2 )
130- msh2 = Mesh (Function (P2 ).interpolate (msh1 .coordinates ))
131- h2 = msh2 .cell_sizes
132-
133- assert numpy .allclose (h1 .dat .data , h2 .dat .data )
0 commit comments