Skip to content

Commit 7533d4b

Browse files
authored
Warn users about interpolate expression renumbering (#4572)
* add warning * update tests
1 parent 60f5947 commit 7533d4b

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

firedrake/interpolation.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,8 @@ def interpolate(expr, V, subset=None, access=op2.WRITE, allow_missing_dofs=False
175175
dual_arg = Coargument(V.dual(), 0)
176176
expr_args = extract_arguments(expr)
177177
if expr_args and expr_args[0].number() == 0:
178-
# In this case we are doing adjoint interpolation
179-
# When V is a FunctionSpace and expr contains Argument(0),
180-
# we need to change expr argument number to 1 (in our current implementation)
178+
warnings.warn("Passing argument numbered 0 in expression for forward interpolation is deprecated. "
179+
"Use a TrialFunction in the expression.")
181180
v, = expr_args
182181
expr = replace(expr, {v: v.reconstruct(number=1)})
183182
else:

tests/firedrake/regression/test_interpolate_cross_mesh.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,14 +650,14 @@ def test_interpolate_matrix_cross_mesh():
650650
vom = VertexOnlyMesh(source_mesh, X.dat.data_ro, redundant=False)
651651
P0DG = FunctionSpace(vom, "DG", 0)
652652
# We get the interpolation matrix U -> P0DG which performs point evaluation
653-
A = assemble(interpolate(TestFunction(U), P0DG))
653+
A = assemble(interpolate(TrialFunction(U), P0DG))
654654
f_at_points = assemble(A @ f)
655655
f_at_points2 = assemble(interpolate(f, P0DG))
656656
assert np.allclose(f_at_points.dat.data_ro, f_at_points2.dat.data_ro)
657657
# To get the points in the correct order in V we interpolate into vom.input_ordering
658658
# We pass matfree=False which constructs the permutation matrix instead of using SFs
659659
P0DG_io = FunctionSpace(vom.input_ordering, "DG", 0)
660-
B = assemble(interpolate(TestFunction(P0DG), P0DG_io, matfree=False))
660+
B = assemble(interpolate(TrialFunction(P0DG), P0DG_io, matfree=False))
661661
f_at_points_correct_order = assemble(B @ f_at_points)
662662
f_at_points_correct_order2 = assemble(interpolate(f_at_points, P0DG_io))
663663
assert np.allclose(f_at_points_correct_order.dat.data_ro, f_at_points_correct_order2.dat.data_ro)

tests/firedrake/vertexonly/test_vertex_only_fs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def functionspace_tests(vm, petsc_raises):
121121
assert np.allclose(h.dat.data_ro_with_halos[idxs_to_include], np.prod(vm.input_ordering.coordinates.dat.data_ro_with_halos[idxs_to_include].reshape(-1, vm.input_ordering.geometric_dimension()), axis=1))
122122
assert np.all(h.dat.data_ro_with_halos[~idxs_to_include] == -1)
123123
# Using permutation matrix
124-
perm_mat = assemble(interpolate(TestFunction(V), W, matfree=False))
124+
perm_mat = assemble(interpolate(TrialFunction(V), W, matfree=False))
125125
h2 = assemble(perm_mat @ g)
126126
assert np.allclose(h2.dat.data_ro_with_halos[idxs_to_include], h.dat.data_ro_with_halos[idxs_to_include])
127127
h2 = assemble(interpolate(g, W))
@@ -216,7 +216,7 @@ def vectorfunctionspace_tests(vm, petsc_raises):
216216
assert np.allclose(h.dat.data_ro[idxs_to_include], 2*vm.input_ordering.coordinates.dat.data_ro_with_halos[idxs_to_include])
217217
assert np.all(h.dat.data_ro_with_halos[~idxs_to_include] == -1)
218218
# Using permutation matrix
219-
perm_mat = assemble(interpolate(TestFunction(V), W, matfree=False))
219+
perm_mat = assemble(interpolate(TrialFunction(V), W, matfree=False))
220220
h2 = assemble(perm_mat @ g)
221221
assert np.allclose(h2.dat.data_ro_with_halos[idxs_to_include], h.dat.data_ro_with_halos[idxs_to_include])
222222
# check other interpolation APIs work identically
@@ -373,9 +373,9 @@ def test_tensorfs_permutation(tensorfs_and_expr):
373373
f = Function(V)
374374
f.interpolate(expr)
375375
f_in_W = assemble(interpolate(f, W))
376-
python_mat = assemble(interpolate(TestFunction(V), W, matfree=False))
376+
python_mat = assemble(interpolate(TrialFunction(V), W, matfree=False))
377377
f_in_W_2 = assemble(python_mat @ f)
378378
assert np.allclose(f_in_W.dat.data_ro, f_in_W_2.dat.data_ro)
379-
petsc_mat = assemble(interpolate(TestFunction(V), W, matfree=True))
379+
petsc_mat = assemble(interpolate(TrialFunction(V), W, matfree=True))
380380
f_in_W_petsc = assemble(petsc_mat @ f)
381381
assert np.allclose(f_in_W.dat.data_ro, f_in_W_petsc.dat.data_ro)

0 commit comments

Comments
 (0)