From 8a72a28684122ebaadcb68327ec23de36f42d7d4 Mon Sep 17 00:00:00 2001 From: "James R. Maddison" Date: Thu, 18 Sep 2025 13:01:37 +0100 Subject: [PATCH 1/3] RieszMap boundary condition fixes --- firedrake/cofunction.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/firedrake/cofunction.py b/firedrake/cofunction.py index 47bb0b6ba4..f78c5626e4 100644 --- a/firedrake/cofunction.py +++ b/firedrake/cofunction.py @@ -426,6 +426,13 @@ def __init__(self, function_space_or_inner_product=None, sobolev_space, u, v ) + if bcs is None: + bcs = () + else: + bcs = tuple(bcs) + if len(bcs) > 0 and inner_product == "l2": + raise ValueError("Cannot supply boundary conditions with an l2 Riesz map") + self._function_space = function_space self._inner_product = inner_product self._bcs = bcs @@ -490,8 +497,13 @@ def __call__(self, value): for o, c in zip(output.subfunctions, value.subfunctions): o.dat.data[:] = c.dat.data_ro[:] else: + if len(self._bcs) > 0: + value = value.copy(deepcopy=True) + for bc in self._bcs: + bc.apply(value) output = firedrake.assemble( - firedrake.action(self._inner_product, value) + firedrake.action(self._inner_product, value), + bcs=self._bcs, zero_bc_nodes=True, ) else: raise ValueError( From 9d5b85cecc9f765336da69c6b31e3ddffc0f886e Mon Sep 17 00:00:00 2001 From: "James R. Maddison" Date: Thu, 18 Sep 2025 13:02:24 +0100 Subject: [PATCH 2/3] Remove extra Function instantiation --- firedrake/cofunction.py | 1 - 1 file changed, 1 deletion(-) diff --git a/firedrake/cofunction.py b/firedrake/cofunction.py index f78c5626e4..8328f1dd77 100644 --- a/firedrake/cofunction.py +++ b/firedrake/cofunction.py @@ -486,7 +486,6 @@ def __call__(self, value): solve, rhs, soln = self._solver rhs.assign(value) solve() - output = Function(self._function_space) output.assign(soln) elif ufl.duals.is_primal(value): if value.function_space() != self._function_space: From c04f182096f0b868ef9747c02a23b6b7c2be79f4 Mon Sep 17 00:00:00 2001 From: "James R. Maddison" Date: Thu, 18 Sep 2025 14:01:50 +0100 Subject: [PATCH 3/3] Zero guess the RieszMap solver --- firedrake/cofunction.py | 1 + 1 file changed, 1 insertion(+) diff --git a/firedrake/cofunction.py b/firedrake/cofunction.py index 8328f1dd77..864ddf4b6a 100644 --- a/firedrake/cofunction.py +++ b/firedrake/cofunction.py @@ -485,6 +485,7 @@ def __call__(self, value): else: solve, rhs, soln = self._solver rhs.assign(value) + soln.zero() solve() output.assign(soln) elif ufl.duals.is_primal(value):