@@ -78,39 +78,51 @@ def vom(mesh):
78
78
return VertexOnlyMesh (mesh , [(0.5 , 0.5 ), (0.31 , 0.72 )])
79
79
80
80
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 ()
82
84
degree = V .ufl_element ().degree ()
83
85
x , y = SpatialCoordinate (mesh )
84
86
expr = (x + y )** degree
85
87
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 )
92
88
if which == "coefficient" :
93
89
P0 = FunctionSpace (vom , "DG" , 0 )
94
90
elif which == "grad" :
95
- fexpr = grad (fexpr )
96
- vexpr = grad (vexpr )
97
91
expr = ufl .algorithms .expand_derivatives (grad (expr ))
98
92
P0 = VectorFunctionSpace (vom , "DG" , 0 )
99
93
100
- expected = Function (P0 )
101
- point = Constant ([0 ]* mesh .geometric_dimension ())
94
+ fvom = Function (P0 )
95
+ point = Constant ([0 ] * mesh .geometric_dimension ())
102
96
expr_at_pt = ufl .replace (expr , {SpatialCoordinate (mesh ): point })
103
97
for i , pt in enumerate (vom .coordinates .dat .data_ro ):
104
98
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 ()
106
118
107
119
# Interpolate a Function into P0(vom)
108
120
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 )
110
122
111
123
# Construct a Cofunction on P0(vom)*
112
124
Fvom = Cofunction (P0 .dual ()).assign (1 )
113
- expected_action = assemble (action (Fvom , expected ))
125
+ expected_action = assemble (action (Fvom , expr_at_vom ))
114
126
115
127
# Interpolate a Function into Fvom
116
128
f_at_vom = assemble (Interpolate (fexpr , Fvom ))
@@ -120,14 +132,3 @@ def test_interpolate_zany_into_vom(V, mesh, which, vom):
120
132
expr_vom = assemble (Interpolate (vexpr , Fvom ))
121
133
f_at_vom = assemble (action (expr_vom , f ))
122
134
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