From 3efd9df12f1a3e99e00aaeea0d06c80cc6fd6457 Mon Sep 17 00:00:00 2001 From: Connor Ward Date: Thu, 28 May 2026 15:58:05 +0100 Subject: [PATCH] Fix solver options for Real space The matrix type of a Real function space is now 'python' instead of 'nest' and this was failing to hit a case when we built our default solver options. --- firedrake/solving_utils.py | 2 +- tests/firedrake/adjoint/test_solving.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/firedrake/solving_utils.py b/firedrake/solving_utils.py index b1090d1111..09cbfafd03 100644 --- a/firedrake/solving_utils.py +++ b/firedrake/solving_utils.py @@ -48,7 +48,7 @@ def set_defaults(solver_parameters, arguments, *, ksp_defaults=None, snes_defaul if "pc_type" in keys: # Might reasonably expect to get petsc defaults skip.update({"pc_factor_mat_solver_type", "ksp_type"}) - if parameters.get("mat_type") in {"matfree", "nest"}: + if parameters.get("mat_type") in {"matfree", "nest", "python"}: # Non-LU defaults. ksp_defaults["ksp_type"] = "gmres" ksp_defaults["pc_type"] = "jacobi" diff --git a/tests/firedrake/adjoint/test_solving.py b/tests/firedrake/adjoint/test_solving.py index 81dfdc64ad..187f4ba0c9 100644 --- a/tests/firedrake/adjoint/test_solving.py +++ b/tests/firedrake/adjoint/test_solving.py @@ -314,6 +314,26 @@ def test_two_nonlinear_solves(): assert rf.tape.recompute_count == 5 +@pytest.mark.skipcomplex +def test_real_solve(rg): + mesh = UnitSquareMesh(8, 8) + V = FunctionSpace(mesh, "CG", 1) + R = FunctionSpace(mesh, "R", 0) + + u = TrialFunction(R) + v = TestFunction(R) + m = Function(V).assign(1.0) + + def J(m): + a = u * v * dx + L = m * v * dx + solution = Function(R) + solve(a == L, solution) + return assemble(solution**2 * dx) + + _test_adjoint(J, m, rg) + + def convergence_rates(E_values, eps_values): from numpy import log r = []