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

numpydoc #576

Merged
merged 4 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
37 changes: 24 additions & 13 deletions tlm_adjoint/block_system.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
r"""Solvers for linear systems defined in mixed spaces.
r"""Mixed space linear algebra utilities.

Given a linear problem with a potentially singular matrix :math:`A`

Expand Down Expand Up @@ -161,8 +161,22 @@ def zip_sub(*iterables):
class TypedSpace:
"""A space with an associated space type.

:arg space: The space.
:arg space_types: The space type.
Parameters
----------
space : space
The backend space.
space_type : str
The space type.

Attributes
----------

comm : communicator
The communicator associated with the space.
space : space
The backend space.
space_type : str
The space type.
"""

def __init__(self, space, *, space_type=None):
Expand Down Expand Up @@ -190,27 +204,24 @@ def __ne__(self, other):

@property
def comm(self):
"""The communicator associated with the space.
"""

return space_comm(self.space)

@property
def space(self):
"""The backend space.
"""

return self._space

@property
def space_type(self):
"""The space type.
"""

return self._space_type

def new(self):
"""Return a new variable in the space.
"""Create a new variable in the space.

Returns
-------

variable
The new variable.
"""

return space_new(self.space, space_type=self.space_type)
Expand Down
64 changes: 44 additions & 20 deletions tlm_adjoint/firedrake/block_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,17 @@ def apply_bcs(u, bcs):


class ConstantNullspace(Nullspace):
r"""A nullspace and left nullspace spanned by the vector of ones.
r"""Nullspace and left nullspace spanned by the vector of ones.

Here :math:`V = U`, :math:`U` is a single column matrix whose elements are
ones, :math:`C = M`, and :math:`M` is an identity matrix.

:arg alpha: Defines the linear constraint matrix :math:`S = \left( \alpha /
N \right)` where :math:`N` is the length of the vector of ones.
Parameters
----------

alpha : scalar
Defines the linear constraint matrix :math:`S = \left( \alpha / N
\right)` where :math:`N` is the length of the vector of ones.
"""

def __init__(self, *, alpha=1.0):
Expand Down Expand Up @@ -95,16 +99,20 @@ def pc_constraint_correct_soln(self, u, b):


class UnityNullspace(Nullspace):
r"""A nullspace and left nullspace defined by the unity-valued function.
r"""Nullspace and left nullspace spanned by the unity-valued function.

Here :math:`V = U`, :math:`U` is a single column matrix containing the
degree-of-freedom vector for the unity-valued function, :math:`C = M`,
and :math:`M` is the mass matrix.

:arg space: A scalar-valued function space containing the unity-valued
function.
:arg alpha: Defines the linear constraint matrix :math:`S = \alpha \left(
U^* M U \right)^{-1}`.
Parameters
----------

space : :class:`firedrake.functionspaceimpl.WithGeometry`
A scalar-valued function space containing the unity-valued function.
alpha : scalar
Defines the linear constraint matrix :math:`S = \alpha \left( U^* M U
\right)^{-1}`.
"""

def __init__(self, space, *, alpha=1.0):
Expand Down Expand Up @@ -154,16 +162,21 @@ def pc_constraint_correct_soln(self, u, b):


class DirichletBCNullspace(Nullspace):
r"""A nullspace and left nullspace associated with homogeneous Dirichlet
"""Nullspace and left nullspace associated with homogeneous Dirichlet
boundary conditions.

Here :math:`V = U`, :math:`U` is a zero-one matrix with exactly one
non-zero per column corresponding to one boundary condition
degree-of-freedom, :math:`C = M`, and :math:`M` is an identity matrix.

:arg bcs: A :class:`firedrake.bcs.DirichletBC`, or a :class:`Sequence` of
:class:`firedrake.bcs.DirichletBC` objects.
:arg alpha: Defines the linear constraint matrix :math:`S = \alpha M`.
Parameters
----------

bcs : :class:`firedrake.bcs.DirichletBC` or \
Sequence[:class:`firedrake.bcs.DirichletBC`]
Homogeneous Dirichlet boundary conditions
alpha : scalar
Defines the linear constraint matrix :math:`S = \\alpha M`.
"""

def __init__(self, bcs, *, alpha=1.0):
Expand Down Expand Up @@ -206,7 +219,10 @@ class PETScMatrix(Matrix):
:class:`firedrake.matrix.Matrix` :math:`A` defining a mapping
:math:`V \rightarrow W`.

:arg a: The :class:`firedrake.matrix.Matrix`.
Parameters
----------

A : :class:`firedrake.matrix.Matrix`
"""

def __init__(self, A):
Expand All @@ -223,11 +239,19 @@ def form_matrix(a, *args, **kwargs):
"""Construct a :class:`.PETScMatrix` associated with a given sesquilinear
form.

:arg a: A :class:`ufl.Form` defining the sesquilinear form.
:returns: The :class:`.PETScMatrix`.
Parameters
----------

a : :class:`ufl.Form`
Defines the sesquilinear form.
args, kwargs
Passed to the :func:`firedrake.assemble.assemble` function.

Returns
-------

Remaining arguments are passed to the :func:`firedrake.assemble.assemble`
function.
:class:`.PETScMatrix`.
:class:`.PETScMatrix` defined by the assembled sesquilinear form.
"""

return PETScMatrix(backend_assemble(a, *args, **kwargs))
Expand Down Expand Up @@ -271,7 +295,7 @@ class WhiteNoiseSampler:

space : :class:`firedrake.functionspaceimpl.WithGeometry`
The function space.
rng : :class:`numpy.random._generator.Generator`
rng : :class:`numpy.random.Generator`
Pseudorandom number generator.
precondition : :class:`bool`
If `True` then :math:`\Xi` is set equal to the inverse of the
Expand All @@ -287,7 +311,7 @@ class WhiteNoiseSampler:

space : :class:`firedrake.functionspaceimpl.WithGeometry`
The function space.
rng : :class:`numpy.random._generator.Generator`
rng : :class:`numpy.random.Generator`
Pseudorandom number generator.
"""

Expand Down Expand Up @@ -346,7 +370,7 @@ def sample(self):

Returns
-------
X : :class:`firedrake.function.Function` or \
:class:`firedrake.function.Function` or \
:class:`firedrake.cofunction.Cofunction`
The sample.
"""
Expand Down
Loading