[petsc-users] how to update the matrix in KSP

Jed Brown jed at 59A2.org
Thu Mar 17 06:08:12 CDT 2011


On Thu, Mar 17, 2011 at 05:16, Gu Shiyuan <gshy2014 at gmail.com> wrote:

>  I want to solve a linear eq. Kx=b where K is changed at each time step and
> the preconditioner is a shell function and doesn't change. After I change K,
> do I need to explicitly call KSP/PCSetOperator again to reset the matrix
> inside the KSP solver?
> Does KSP hold copies of the matrices or just pointers to the matrices?
> i.e.,
>
> PCSetOperator(pc,K,K,SAME_PRECONDITIONER);
>

It is "PCSetOperators". SAME_PRECONDITIONER means that the PC will not be
updated for the new matrix.


>  ..............///other setup
> KSPSolve(..);
> ...........////change K;
> /////////Is  PCSetOperator(......) needed here?
>

You should be calling KSPSetOperators() to inform the KSP that the operator
has changed. Rebuilding the preconditioner is a separate matter which you
control using the MatStructure flag.


> And what about if I want to change the preconditioner? do I need to destroy
> the PC/KSP object and re-create and setup everything?
>

No, when you pass in SAME_NONZERO_PATTERN, numeric factorization is
performed again using the same data structures. With
DIFFERENT_NONZERO_PATTERN, some internal structures are reallocated. For
many preconditioners, there is very little performance difference between
these.

If you want to change the type of the preconditioner, just call PCSetType().
This will free things like ILU factors and then switch to the new PCType.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110317/d701379c/attachment.htm>


More information about the petsc-users mailing list