petsc-3.7.1 2016-05-15
Report Typos and Errors

KSPSetOperators

Sets the matrix associated with the linear system and a (possibly) different one associated with the preconditioner.

Synopsis

#include "petscksp.h" 
PetscErrorCode  KSPSetOperators(KSP ksp,Mat Amat,Mat Pmat)
Collective on KSP and Mat Many br

Input Parameters

ksp - the KSP context Many br
Amat - the matrix that defines the linear system Many br
Pmat - the matrix to be used in constructing the preconditioner, usually the same as Amat. Many br

Notes

If you know the operator Amat has a null space you can use MatSetNullSpace() and MatSetTransposeNullSpace() to supply the null Many brspace to Amat and the KSP solvers will automatically use that null space as needed during the solution process. Many br

All future calls to KSPSetOperators() must use the same size matrices! Many br

Passing a NULL for Amat or Pmat removes the matrix that is currently used. Many br

If you wish to replace either Amat or Pmat but leave the other one untouched then Many brfirst call KSPGetOperators() to get the one you wish to keep, call PetscObjectReference() Many bron it and then pass it back in in your call to KSPSetOperators(). Many br

Many br

Alternative usage: If the operators have NOT been set with KSP/PCSetOperators() then the operators Many brare created in PC and returned to the user. In this case, if both operators Many brmat and pmat are requested, two DIFFERENT operators will be returned. If Many bronly one is requested both operators in the PC will be the same (i.e. as Many brif one had called KSP/PCSetOperators() with the same argument for both Mats). Many brThe user must set the sizes of the returned matrices and their type etc just Many bras if the user created them with MatCreate(). For example, Many br

        KSP/PCGetOperators(ksp/pc,&mat,NULL); is equivalent to
          set size, type, etc of mat

        MatCreate(comm,&mat);
        KSP/PCSetOperators(ksp/pc,mat,mat);
        PetscObjectDereference((PetscObject)mat);
          set size, type, etc of mat

and Many br

        KSP/PCGetOperators(ksp/pc,&mat,&pmat); is equivalent to
          set size, type, etc of mat and pmat

        MatCreate(comm,&mat);
        MatCreate(comm,&pmat);
        KSP/PCSetOperators(ksp/pc,mat,pmat);
        PetscObjectDereference((PetscObject)mat);
        PetscObjectDereference((PetscObject)pmat);
          set size, type, etc of mat and pmat

The rational for this support is so that when creating a TS, SNES, or KSP the hierarchy Many brof underlying objects (i.e. SNES, KSP, PC, Mat) and their livespans can be completely Many brmanaged by the top most level object (i.e. the TS, SNES, or KSP). Another way to look Many brat this is when you create a SNES you do not NEED to create a KSP and attach it to Many brthe SNES object (the SNES object manages it for you). Similarly when you create a KSP Many bryou do not need to attach a PC to it (the KSP object manages the PC object for you). Many brThus, why should YOU have to create the Mat and attach it to the SNES/KSP/PC, when Many brit can be created for you? Many br

Keywords

KSP, set, operators, matrix, preconditioner, linear system

See Also

KSPSolve(), KSPGetPC(), PCGetOperators(), PCSetOperators(), KSPGetOperators(), KSPSetComputeOperators(), KSPSetComputeInitialGuess(), KSPSetComputeRHS()

Level:beginner
Location:
src/ksp/ksp/interface/itcreate.c
Index of all KSP routines
Table of Contents for all manual pages
Index of all manual pages

Examples

src/ksp/pc/examples/tutorials/ex1.c.html
src/ksp/pc/examples/tutorials/ex2.c.html
src/ksp/ksp/examples/tutorials/ex1.c.html
src/ksp/ksp/examples/tutorials/ex2.c.html
src/ksp/ksp/examples/tutorials/ex3.c.html
src/ksp/ksp/examples/tutorials/ex4.c.html
src/ksp/ksp/examples/tutorials/ex5.c.html
src/ksp/ksp/examples/tutorials/ex6.c.html
src/ksp/ksp/examples/tutorials/ex7.c.html
src/ksp/ksp/examples/tutorials/ex8.c.html
src/ksp/ksp/examples/tutorials/ex9.c.html