Skip to content

Commit de5f5ee

Browse files
committed
More extensive tests
1 parent 4849fcd commit de5f5ee

File tree

3 files changed

+52
-18
lines changed

3 files changed

+52
-18
lines changed

firedrake/interpolation.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,9 +1013,6 @@ def callable():
10131013
# Make sure we have an expression of the right length i.e. a value for
10141014
# each component in the value shape of each function space
10151015
loops = []
1016-
if numpy.prod(expr.ufl_shape, dtype=int) != V.value_size:
1017-
raise RuntimeError('Expression of length %d required, got length %d'
1018-
% (V.value_size, numpy.prod(expr.ufl_shape, dtype=int)))
10191016

10201017
if len(V) == 1:
10211018
loops.extend(_interpolator(V, tensor, expr, subset, arguments, access, bcs=bcs))

tests/firedrake/meshes/test_meshes_volume.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,3 @@ def test_meshes_volume_solidtorusmesh():
2020
vol = assemble(Constant(1., domain=mesh) * dx)
2121
exact = (pi * r * r) * (2 * pi * R)
2222
assert abs(vol - exact) / exact < .0005
23-
24-
25-
def test_meshes_cell_sizes():
26-
msh = UnitDiskMesh(4)
27-
msh.cell_sizes
28-
29-
V = msh.coordinates.function_space().reconstruct(degree=2)
30-
msh = Mesh(Function(V).interpolate(msh.coordinates))
31-
msh.cell_sizes

tests/firedrake/regression/test_interpolate_zany.py

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,59 @@ def test_interpolate_zany_into_cg(V, mesh, which, expect, tolerance):
7575

7676
@pytest.fixture
7777
def vom(mesh):
78-
return VertexOnlyMesh(mesh, [(0.5, 0.5)])
78+
return VertexOnlyMesh(mesh, [(0.5, 0.5), (0.31, 0.72)])
7979

8080

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)
8291
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
85132

86-
v = TestFunction(V)
87-
assemble(Interpolate(v, Fvom))
133+
assert numpy.allclose(h1.dat.data, h2.dat.data)

0 commit comments

Comments
 (0)