@@ -51,7 +51,7 @@ def expect(V, which):
5151 return a + b
5252
5353
54- def test_interpolate (V , mesh , which , expect , tolerance ):
54+ def test_interpolate_zany_into_cg (V , mesh , which , expect , tolerance ):
5555 degree = V .ufl_element ().degree ()
5656 Vcg = FunctionSpace (mesh , "P" , degree )
5757
@@ -71,3 +71,64 @@ def test_interpolate(V, mesh, which, expect, tolerance):
7171 g .interpolate (a + b )
7272
7373 assert numpy .allclose (norm (g - expect ), 0 , atol = tolerance )
74+
75+
76+ @pytest .fixture
77+ def vom (mesh ):
78+ return VertexOnlyMesh (mesh , [(0.5 , 0.5 ), (0.31 , 0.72 )])
79+
80+
81+ @pytest .fixture
82+ def expr_at_vom (V , which , vom ):
83+ mesh = V .mesh ()
84+ degree = V .ufl_element ().degree ()
85+ x , y = SpatialCoordinate (mesh )
86+ expr = (x + y )** degree
87+
88+ if which == "coefficient" :
89+ P0 = FunctionSpace (vom , "DG" , 0 )
90+ elif which == "grad" :
91+ expr = ufl .algorithms .expand_derivatives (grad (expr ))
92+ P0 = VectorFunctionSpace (vom , "DG" , 0 )
93+
94+ fvom = Function (P0 )
95+ point = Constant ([0 ] * mesh .geometric_dimension ())
96+ expr_at_pt = ufl .replace (expr , {SpatialCoordinate (mesh ): point })
97+ for i , pt in enumerate (vom .coordinates .dat .data_ro ):
98+ point .assign (pt )
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 ()
118+
119+ # Interpolate a Function into P0(vom)
120+ f_at_vom = assemble (Interpolate (fexpr , P0 ))
121+ assert numpy .allclose (f_at_vom .dat .data_ro , expr_at_vom .dat .data_ro )
122+
123+ # Construct a Cofunction on P0(vom)*
124+ Fvom = Cofunction (P0 .dual ()).assign (1 )
125+ expected_action = assemble (action (Fvom , expr_at_vom ))
126+
127+ # Interpolate a Function into Fvom
128+ f_at_vom = assemble (Interpolate (fexpr , Fvom ))
129+ assert numpy .allclose (f_at_vom , expected_action )
130+
131+ # Interpolate a TestFunction into Fvom
132+ expr_vom = assemble (Interpolate (vexpr , Fvom ))
133+ f_at_vom = assemble (action (expr_vom , f ))
134+ assert numpy .allclose (f_at_vom , expected_action )
0 commit comments