Skip to content

Commit

Permalink
updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dc-luo committed Jul 13, 2023
1 parent 3e07821 commit 14b2ead
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
8 changes: 8 additions & 0 deletions doc/soupy.solver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@ soupy.solver.newtonBacktrackSolver
:members:
:undoc-members:
:show-inheritance:

soupy.solver.PETScLUSolver
-----------------------------------------------

.. automodule:: soupy.solver.PETScLUSolver
:members:
:undoc-members:
:show-inheritance:
42 changes: 32 additions & 10 deletions soupy/solver/PETScLUSolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,61 @@

class PETScLUSolver:
"""
Wrapper for `dolfin.PETScLUSolver` with methods
:code:`solve_transpose` and :code:`set_operator`
LU solver for linear systems :math:`Ax = b` and :math:`A^Tx = b`. \
It is a wrapper for :py:class:`dolfin.PETScLUSolver` \
providing custom implementations for methods :code:`solve_transpose` \
and :code:`set_operator` if they are unavailable in the \
:code:`dolfin` version being used.
"""
def __init__(self, mpi_comm=MPI.COMM_WORLD, method="mumps"):
"""
Constructor:
:param mpi_comm: MPI Communicator for the linear system
:type mpi_comm: :py:class:`MPI.Comm`
:param method: LU method
:type method: str
"""
self.mpi_comm = mpi_comm
self.method = method
self.solver = dl.PETScLUSolver(mpi_comm, method)
self.ksp = self.solver.ksp()

def set_operator(self, A):
"""
Set the linear operator
:param A: Matrix for the solves
:type A: :py:class:`dolfin.Matrix` or :py:class:`dolfin.PETScMatrix`
"""

if hasattr(A, 'mat'):
self.ksp.setOperators(A.mat())
else:
self.ksp.setOperators(dl.as_backend_type(A).mat())

def solve(self, x, b):
"""
Solve the linear system
Solve the linear system :math:`Ax = b` \
and stores result to :code:`x`
.. math:: `Ax = b`
and stores result to :code:`x`
:param x: Solution vector
:type x: :py:class:`dolfin.Vector` or :py:class:`dolfin.PETScVector`
:param b: Right hand side vector
:type b: :py:class:`dolfin.Vector` or :py:class:`dolfin.PETScVector`
"""

self.solver.solve(x, b)

def solve_transpose(self, x, b):
"""
Solve the linear system
.. math:: `A^T x = b`
Solve the linear system :math:`A^T x = b` \
and stores result to :code:`x`
and stores result to :code:`x`
:param x: Solution vector
:type x: :py:class:`dolfin.Vector` or :py:class:`dolfin.PETScVector`
:param b: Right hand side vector
:type b: :py:class:`dolfin.Vector` or :py:class:`dolfin.PETScVector`
"""
if hasattr(self.solver, 'solve_transpose'):
self.solver.solveTranspose(x, b)
Expand Down

0 comments on commit 14b2ead

Please sign in to comment.