Skip to content

Commit 210b7c1

Browse files
authored
test assembly of composition of interpolates (#4710)
1 parent 7e1d8ad commit 210b7c1

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/firedrake/regression/test_interpolate.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,3 +620,42 @@ def test_mixed_space_bcs():
620620
expected = assemble(interpolate(sum(w), V), bcs=bcs[-1:])
621621

622622
assert np.allclose(result.dat.data, expected.dat.data)
623+
624+
625+
@pytest.mark.parallel([1, 3])
626+
@pytest.mark.parametrize("mode", ["forward", "adjoint"])
627+
def test_interpolate_composition(mode):
628+
mesh = UnitSquareMesh(4, 4)
629+
x, y = SpatialCoordinate(mesh)
630+
631+
V5 = FunctionSpace(mesh, "CG", 5)
632+
V4 = FunctionSpace(mesh, "CG", 4)
633+
V3 = FunctionSpace(mesh, "CG", 3)
634+
V2 = FunctionSpace(mesh, "CG", 2)
635+
V1 = FunctionSpace(mesh, "CG", 1)
636+
637+
if mode == "forward":
638+
u5 = Function(V5).interpolate(sin(x + y))
639+
u4 = interpolate(u5, V4)
640+
u3 = interpolate(u4, V3)
641+
u2 = interpolate(u3, V2)
642+
u1 = interpolate(u2, V1)
643+
644+
assert u1.function_space() == V1
645+
646+
res = assemble(u1)
647+
res2 = assemble(interpolate(sin(x + y), V1))
648+
assert np.allclose(res.dat.data_ro, res2.dat.data_ro)
649+
650+
if mode == "adjoint":
651+
u1 = conj(TestFunction(V1)) * dx
652+
u2 = interpolate(TestFunction(V2), u1)
653+
u3 = interpolate(TestFunction(V3), u2)
654+
u4 = interpolate(TestFunction(V4), u3)
655+
u5 = interpolate(TestFunction(V5), u4)
656+
657+
assert u5.function_space() == V5.dual()
658+
659+
res_adj = assemble(u5)
660+
res_adj2 = assemble(interpolate(TestFunction(V5), conj(TestFunction(V1)) * dx))
661+
assert np.allclose(res_adj.dat.data_ro, res_adj2.dat.data_ro)

0 commit comments

Comments
 (0)