Skip to content

Commit

Permalink
more suggestions from review
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrubeck committed Dec 19, 2024
1 parent 40cf6d7 commit fe30b48
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion firedrake/assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions firedrake/linear_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fe30b48

Please sign in to comment.