Skip to content

Commit

Permalink
Merge pull request #1257 from firedrakeproject/pefarrell/la-solve-mg
Browse files Browse the repository at this point in the history
* pefarrell/la-solve-mg:
  solving: Simplify assembled solve LVP setup
  solving: Allow literal zero for RHS of LVP
  Enable the use of MG etc for the algebraic solve interface. Fixes #1256.
  • Loading branch information
wence- committed Aug 2, 2018
2 parents 1951865 + 3e302ec commit ee7a253
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
16 changes: 15 additions & 1 deletion firedrake/solving.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import firedrake.linear_solver as ls
import firedrake.variational_solver as vs
from firedrake import solving_utils
from firedrake import dmhooks


def solve(*args, **kwargs):
Expand Down Expand Up @@ -221,7 +223,19 @@ def _la_solve(A, x, b, **kwargs):
near_nullspace=near_nullspace,
options_prefix=options_prefix)

solver.solve(x, b)
# linear MG doesn't need RHS, supply zero.
lvp = vs.LinearVariationalProblem(a=A.a, L=0, u=x, bcs=bcs)
mat_type = solver_parameters.get("mat_type")
appctx = solver_parameters.get("appctx", {})
ctx = solving_utils._SNESContext(lvp,
mat_type=mat_type,
pmat_type=mat_type,
appctx=appctx,
options_prefix=options_prefix)
dm = solver.ksp.dm

with dmhooks.appctx(dm, ctx):
solver.solve(x, b)


def _extract_linear_solver_args(*args, **kwargs):
Expand Down
14 changes: 8 additions & 6 deletions firedrake/variational_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,14 @@ def __init__(self, a, L, u, bcs=None, aP=None,
# In the linear case, the Jacobian is the equation LHS.
J = a
# Jacobian is checked in superclass, but let's check L here.
if not isinstance(L, (ufl.Form, slate.slate.TensorBase)):
raise TypeError("Provided RHS is a '%s', not a Form or Slate Tensor" % type(L).__name__)
if len(L.arguments()) != 1:
raise ValueError("Provided RHS is not a linear form")

F = ufl_expr.action(J, u) - L
if L is 0:
F = ufl_expr.action(J, u)
else:
if not isinstance(L, (ufl.Form, slate.slate.TensorBase)):
raise TypeError("Provided RHS is a '%s', not a Form or Slate Tensor" % type(L).__name__)
if len(L.arguments()) != 1:
raise ValueError("Provided RHS is not a linear form")
F = ufl_expr.action(J, u) - L

super(LinearVariationalProblem, self).__init__(F, u, bcs, J, aP,
form_compiler_parameters=form_compiler_parameters)
Expand Down

0 comments on commit ee7a253

Please sign in to comment.