petsctools.pc module¶
- class petsctools.pc.PCBase¶
Bases:
ABCAbstract base class for python type PETSc PCs.
This is a convenience base class that provides two common functionalities for python type preconditioners.
Checking whether the PC operators are of python type.
Often a python type preconditioner will rely on the Mat operators also being of python type. If the
needs_python_amatand/orneeds_python_pmatattributes are set then the type of thepc.getOperators()will be checked, and an error raised if they are not python type. If they are python type then their python contexts will be added as the attributesamatand/orpmat(e.g.A.getPythonContext()).Separating code to initialize and update the preconditioner.
Often there are operations to set up the preconditioner which only need to be run once, and operations that are needed each time the preconditioner is updated. The
setUpmethod will call the user implementedinitializemethod only on the first time it is called, but will call theupdatemethod on every subsequent call.
Inheriting classes should also set the
prefixattribute. The attributesparent_prefixandfull_prefixwill then be set, whereparent_prefixis the unqualified pc prefix andfull_prefixis the qualified prefix of this context (i.e.pc.getOptionsPrefix()andparent_prefix+self.prefix).Inheriting classes should implement the following methods:
initializeupdateapply
They should also set the following class attributes:
prefixneeds_python_amat(optional, defaults to False).needs_python_pmat(optional, defaults to False).
Notes
The
updatemethod is not called on the first call tosetUp(), so for some preconditioners it may be necessary to callupdateat the end of theinitializemethod.If the
prefixattribute does not end in an underscore ("_") then one will automatically be appended to thefull_prefixattribute.- abstractmethod apply(pc, x, y)¶
Apply the preconditioner to x, putting the result in y.
Both x and y are PETSc Vecs, y is not guaranteed to be zero on entry.
- applyTranspose(pc, x, y)¶
Apply the preconditioner transpose to x, putting the result in y.
Both x and y are PETSc Vecs, y is not guaranteed to be zero on entry.
- abstractmethod initialize(pc)¶
Initialize any state in this preconditioner.
This method is only called on the first time that the
setUpmethod is called.
- needs_python_amat = False¶
Set this to True if the A matrix needs to be Python (matfree).
- needs_python_pmat = False¶
Set this to False if the P matrix needs to be Python (matfree).
- prefix = None¶
The options prefix of this PC.
- setUp(pc)¶
Called by PETSc to update the PC.
The first time
setUpis called, theinitializemethod will be called followed by theupdatemethod. In subsequent calls tosetUponly theupdatemethod will be called.
- abstractmethod update(pc)¶
Update any state in this preconditioner.
This method is called the on second and later times that the
setUpmethod is called.This method is not needed for all preconditioners and can often be a no-op.
- view(pc, viewer=None)¶
Write a basic description of this PC.