diff --git a/firedrake/assemble.py b/firedrake/assemble.py index 347f2aca90..875d27862e 100644 --- a/firedrake/assemble.py +++ b/firedrake/assemble.py @@ -1192,7 +1192,7 @@ def _apply_dirichlet_bc(self, tensor, bc): if self._diagonal: bc.set(tensor, self._weight) elif not self._zero_bc_nodes: - # We cannot set primal data on a dual Cofunction, this will throw an error + # NOTE this will only work if tensor is a Function and not a Cofunction bc.apply(tensor) else: bc.zero(tensor) diff --git a/firedrake/linear_solver.py b/firedrake/linear_solver.py index 7a9f7d807d..7721675a57 100644 --- a/firedrake/linear_solver.py +++ b/firedrake/linear_solver.py @@ -147,10 +147,12 @@ def solve(self, x, b): if not isinstance(b, (function.Function, cofunction.Cofunction)): raise TypeError("Provided RHS is a '%s', not a Function or Cofunction" % type(b).__name__) - if x.function_space() != self.trial_space or b.function_space() != self.test_space.dual(): - # When solving `Ax = b`, with A: V x U -> R, or equivalently A: V -> U*, - # we need to make sure that x and b belong to V and U*, respectively. - raise ValueError("Mismatching function spaces.") + # When solving `Ax = b`, with A: V x U -> R, or equivalently A: V -> U*, + # we need to make sure that x and b belong to V and U*, respectively. + if x.function_space() != self.trial_space: + raise ValueError(f"x must be a Function in {self.trial_space}.") + if b.function_space() != self.test_space.dual(): + raise ValueError(f"b must be a Cofunction in {self.test_space.dual()}.") if len(self.trial_space) > 1 and self.nullspace is not None: self.nullspace._apply(self.trial_space.dof_dset.field_ises)