Most users will obtain their preconditioner contexts from the SLES
context with the command SLESGetPC(). It is possible to create,
manipulate, and destroy PC contexts directly, although this capability
should rarely be needed. To create a PC context, one uses the command
ierr = PCCreate(MPI_Comm comm,PC *pc);The routine
ierr = PCSetType(PC pc,PCType method);sets the preconditioner method to be used. The two routines
ierr = PCSetOperators(PC pc,Mat mat,Mat pmat,MatStructure flag); ierr = PCSetVector(PC pc,Vec vec);set the matrices and type of vector that are to be used with the preconditioner. The vec argument is needed by the PC routines to determine the format of the vectors. The routine
ierr = PCGetOperators(PC pc,Mat *mat,Mat *pmat,MatStructure *flag);returns the values set with PCSetOperators().
The preconditioners in PETSc can be used in several ways. The two
most basic routines simply apply the preconditioner or its transpose
and are given, respectively, by
ierr = PCApply(PC pc,Vec x,Vec y); ierr = PCApplyTrans(PC pc,Vec x,Vec y);In particular, for a preconditioner matrix, B, that has been set via PCSetOperators(pc,A,B,flag), the routine PCApply(pc,x,y) computes y = B-1 x by solving the linear system By = x with the specified preconditioner method.
Additional preconditioner routines are
ierr = PCApplyBAorAB(PC pc,int right,Vec x,Vec y,Vec work,int its); ierr = PCApplyBAorABTrans(PC pc,int right,Vec x,Vec y,Vec work,int its); ierr = PCApplyRichardson(PC pc,Vec x,Vec y,Vec work,int its);The first two routines apply the action of the matrix followed by the preconditioner or the preconditioner followed by the matrix depending on whether the integer right is zero or one. The final routine applies its iterations of Richardson's method. The last three routines are provided to improve efficiency for certain Krylov subspace methods.
A PC context that is no longer needed can be destroyed with the
command
ierr = PCDestroy(PC pc);