Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add P argument to solve function #3555

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions firedrake/solving.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
:class:`.EquationBC`\s specifying, respectively, the strong boundary conditions
to apply and PDEs to solve on the boundaries.
For the format of `solver_parameters` see below.

Check failure on line 55 in firedrake/solving.py

View workflow job for this annotation

GitHub Actions / Run linter

W293

firedrake/solving.py:55:1: W293 blank line contains whitespace
Optionally, an argument `P` of type :class:`~.MatrixBase` can be passed to
construct any preconditioner from; if none is supplied `A` is used to
construct the preconditioner.
connorjward marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: python3

solve(A, x, b, P=P, bcs=bcs, solver_parameters={...})

*2. Solving linear variational problems*

Expand Down Expand Up @@ -190,6 +198,9 @@
r"""Solve a linear algebra problem.

:arg A: the assembled bilinear form, a :class:`.Matrix`.
:arg P: an optional :class:`~.MatrixBase` to construct any
juliusgh marked this conversation as resolved.
Show resolved Hide resolved
preconditioner from; if none is supplied ``A`` is
used to construct the preconditioner.
:arg x: the :class:`.Function` to write the solution into.
:arg b: the :class:`.Function` defining the right hand side values.
:kwarg solver_parameters: optional solver parameters.
Expand Down Expand Up @@ -224,7 +235,7 @@

_la_solve(A, x, b, solver_parameters=parameters_dict)."""

bcs, solver_parameters, nullspace, nullspace_T, near_nullspace, \
P, bcs, solver_parameters, nullspace, nullspace_T, near_nullspace, \
options_prefix = _extract_linear_solver_args(A, x, b, **kwargs)

# Check whether solution is valid
Expand All @@ -234,7 +245,7 @@
if bcs is not None:
raise RuntimeError("It is no longer possible to apply or change boundary conditions after assembling the matrix `A`; pass any necessary boundary conditions to `assemble` when assembling `A`.")

solver = ls.LinearSolver(A, solver_parameters=solver_parameters,
solver = ls.LinearSolver(A=A, P=P, solver_parameters=solver_parameters,
nullspace=nullspace,
transpose_nullspace=nullspace_T,
near_nullspace=near_nullspace,
Expand All @@ -257,7 +268,7 @@


def _extract_linear_solver_args(*args, **kwargs):
valid_kwargs = ["bcs", "solver_parameters", "nullspace",
valid_kwargs = ["P", "bcs", "solver_parameters", "nullspace",
"transpose_nullspace", "near_nullspace", "options_prefix"]
if len(args) != 3:
raise RuntimeError("Missing required arguments, expecting solve(A, x, b, **kwargs)")
Expand All @@ -267,14 +278,15 @@
raise RuntimeError("Illegal keyword argument '%s'; valid keywords are %s" %
(kwarg, ", ".join("'%s'" % kw for kw in valid_kwargs)))

P = kwargs.get("P", None)
bcs = kwargs.get("bcs", None)
solver_parameters = kwargs.get("solver_parameters", {})
nullspace = kwargs.get("nullspace", None)
nullspace_T = kwargs.get("transpose_nullspace", None)
near_nullspace = kwargs.get("near_nullspace", None)
options_prefix = kwargs.get("options_prefix", None)

return bcs, solver_parameters, nullspace, nullspace_T, near_nullspace, options_prefix
return P, bcs, solver_parameters, nullspace, nullspace_T, near_nullspace, options_prefix


def _extract_args(*args, **kwargs):
Expand Down
Loading