Skip to content

Commit

Permalink
LinearSolver: check function spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrubeck committed Dec 11, 2024
1 parent aef7886 commit 8e5603e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions firedrake/linear_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ 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.")

if len(self.trial_space) > 1 and self.nullspace is not None:
self.nullspace._apply(self.trial_space.dof_dset.field_ises)
if len(self.test_space) > 1 and self.transpose_nullspace is not None:
Expand Down
1 change: 1 addition & 0 deletions tests/firedrake/regression/test_assemble_baseform.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def test_zero_form(M, f, one):
assert abs(zero_form - 0.5 * np.prod(f.ufl_shape)) < 1.0e-12


@pytest.mark.xfail(reason="action(M, M) causes primal-dual error")
def test_preprocess_form(M, a, f):
from ufl.algorithms import expand_indices, expand_derivatives

Expand Down

0 comments on commit 8e5603e

Please sign in to comment.