@@ -75,13 +75,59 @@ def test_interpolate_zany_into_cg(V, mesh, which, expect, tolerance):
75
75
76
76
@pytest .fixture
77
77
def vom (mesh ):
78
- return VertexOnlyMesh (mesh , [(0.5 , 0.5 )])
78
+ return VertexOnlyMesh (mesh , [(0.5 , 0.5 ), ( 0.31 , 0.72 ) ])
79
79
80
80
81
- def test_interpolate_zany_into_vom (V , vom ):
81
+ def test_interpolate_zany_into_vom (V , mesh , which , vom ):
82
+ degree = V .ufl_element ().degree ()
83
+ x , y = SpatialCoordinate (mesh )
84
+ expr = (x + y )** degree
85
+
86
+ f = Function (V )
87
+ f .project (expr , solver_parameters = {"ksp_type" : "preonly" ,
88
+ "pc_type" : "lu" })
89
+ fexpr = f
90
+ vexpr = TestFunction (V )
82
91
P0 = FunctionSpace (vom , "DG" , 0 )
83
- vvom = TestFunction (P0 )
84
- Fvom = inner (1 , vvom ) * dx
92
+ if which == "coefficient" :
93
+ P0 = FunctionSpace (vom , "DG" , 0 )
94
+ elif which == "grad" :
95
+ fexpr = grad (fexpr )
96
+ vexpr = grad (vexpr )
97
+ expr = ufl .algorithms .expand_derivatives (grad (expr ))
98
+ P0 = VectorFunctionSpace (vom , "DG" , 0 )
99
+
100
+ expected = Function (P0 )
101
+ point = Constant ([0 ]* mesh .geometric_dimension ())
102
+ expr_at_pt = ufl .replace (expr , {SpatialCoordinate (mesh ): point })
103
+ for i , pt in enumerate (vom .coordinates .dat .data_ro ):
104
+ point .assign (pt )
105
+ expected .dat .data [i ] = numpy .asarray (expr_at_pt , dtype = float )
106
+
107
+ # Interpolate a Function into P0(vom)
108
+ f_at_vom = assemble (Interpolate (fexpr , P0 ))
109
+ assert numpy .allclose (f_at_vom .dat .data_ro , expected .dat .data_ro )
110
+
111
+ # Construct a Cofunction on P0(vom)*
112
+ Fvom = Cofunction (P0 .dual ()).assign (1 )
113
+ expected = assemble (action (Fvom , expected ))
114
+
115
+ # Interpolate a Function into Fvom
116
+ f_at_vom = assemble (Interpolate (fexpr , Fvom ))
117
+ assert numpy .allclose (f_at_vom , expected )
118
+
119
+ # Interpolate a TestFunction into Fvom
120
+ expr_vom = assemble (Interpolate (vexpr , Fvom ))
121
+ f_at_vom = assemble (action (expr_vom , f ))
122
+ assert numpy .allclose (f_at_vom , expected )
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
85
132
86
- v = TestFunction (V )
87
- assemble (Interpolate (v , Fvom ))
133
+ assert numpy .allclose (h1 .dat .data , h2 .dat .data )
0 commit comments