Skip to content

Preconditioners

preconditioners

This module contains classes that augment default Firedrake preconditioners.

FreeSurfaceMassInvPC

Bases: MassInvPC

Version of MassInvPC that includes free surface variables.

form(pc, tests, trials)

Sets the form.

Parameters:

Name Type Description Default
pc PC

PETSc preconditioner

required
tests list[Argument | Indexed]

List of Firedrake test functions

required
trials list[Argument | Indexed | Function]

List of Firedrake trial functions

required
Source code in g-adopt/gadopt/preconditioners.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def form(
    self,
    pc: fd.PETSc.PC,
    tests: list[fd.Argument | fd.ufl.indexed.Indexed],
    trials: list[fd.Argument | fd.ufl.indexed.Indexed | fd.Function],
) -> tuple[fd.Form, list[fd.DirichletBC]]:
    """Sets the form.

    Args:
      pc:
        PETSc preconditioner
      tests:
        List of Firedrake test functions
      trials:
        List of Firedrake trial functions
    """
    appctx = self.get_appctx(pc)

    # N.B. trials[0] is pressure
    mu = appctx.get("mu", 1.0)
    a = fd.inner(1 / mu * trials[0], tests[0]) * fd.dx

    ds = appctx["ds"]
    bcs = []
    for bc_id, eta_ind in appctx["free_surface"].items():
        a += 1 / mu * fd.inner(trials[eta_ind - 1], tests[eta_ind - 1]) * ds(bc_id)

        bcs.append(InteriorBC(trials.function_space()[eta_ind - 1], 0, bc_id))

    return a, bcs

SPDAssembledPC

Bases: AssembledPC

Version of AssembledPC that sets the SPD flag for the matrix.

For use in the velocity fieldsplit_0 block in combination with gamg. Setting PETSc MatOption MAT_SPD (for Symmetric Positive Definite matrices) at the moment only changes the Krylov method for the eigenvalue estimate in the Chebyshev smoothers to CG.

Users can provide this class as a pc_python_type entry to a PETSc solver option dictionary.

initialize(pc)

Initialises the preconditioner.

Parameters:

Name Type Description Default
pc PC

PETSc preconditioner.

required
Source code in g-adopt/gadopt/preconditioners.py
57
58
59
60
61
62
63
64
65
def initialize(self, pc: PETSc.PC):
    """Initialises the preconditioner.

    Args:
      pc: PETSc preconditioner.
    """
    super().initialize(pc)
    mat = self.P.petscmat
    mat.setOption(mat.Option.SPD, True)