Skip to content

Commit 765ade7

Browse files
committed
add a test
1 parent a8d4e16 commit 765ade7

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

tests/firedrake/multigrid/test_poisson_gtmg.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pytest
33

44

5-
def run_gtmg_mixed_poisson():
5+
def run_gtmg_mixed_poisson(custom_transfer=False):
66

77
m = UnitSquareMesh(10, 10)
88
nlevels = 2
@@ -14,7 +14,7 @@ def get_p1_space():
1414
return FunctionSpace(mesh, "CG", 1)
1515

1616
def get_p1_prb_bcs():
17-
return DirichletBC(get_p1_space(), Constant(0.0), "on_boundary")
17+
return DirichletBC(get_p1_space(), 0, "on_boundary")
1818

1919
def p1_callback():
2020
P1 = get_p1_space()
@@ -57,13 +57,28 @@ def p1_callback():
5757
appctx = {'get_coarse_operator': p1_callback,
5858
'get_coarse_space': get_p1_space,
5959
'coarse_space_bcs': get_p1_prb_bcs()}
60-
61-
solve(a == L, w, solver_parameters=params, appctx=appctx)
60+
if custom_transfer:
61+
P1 = get_p1_space()
62+
V = FunctionSpace(mesh, "DGT", degree - 1)
63+
I = assemble(Interpolate(TrialFunction(P1), V)).petscmat
64+
R = PETSc.Mat().createTranspose(I)
65+
appctx['interpolation_matrix'] = I
66+
appctx['restriction_matrix'] = R
67+
68+
problem = LinearVariationalProblem(a, L, w)
69+
solver = LinearVariationalSolver(problem, solver_parameters=params, appctx=appctx)
70+
solver.solve()
6271
_, uh = w.subfunctions
6372

6473
# Analytical solution
6574
f.interpolate(x[0]*(1-x[0])*x[1]*(1-x[1]))
6675

76+
if custom_transfer:
77+
hyb = solver.snes.ksp.pc.getPythonContext()
78+
gtmg = hyb.trace_ksp.pc.getPythonContext()
79+
assert I.handle != R.handle
80+
assert gtmg.pc.getMGInterpolation(1).handle == I.handle
81+
assert gtmg.pc.getMGRestriction(1).handle == R.handle
6782
return errornorm(f, uh, norm_type="L2")
6883

6984

@@ -144,8 +159,9 @@ def p1_callback():
144159

145160

146161
@pytest.mark.skipcomplexnoslate
147-
def test_mixed_poisson_gtmg():
148-
assert run_gtmg_mixed_poisson() < 1e-5
162+
@pytest.mark.parametrize("custom_transfer", [False, True])
163+
def test_mixed_poisson_gtmg(custom_transfer):
164+
assert run_gtmg_mixed_poisson(custom_transfer) < 1e-5
149165

150166

151167
@pytest.mark.skipcomplexnoslate

0 commit comments

Comments
 (0)