[petsc-users] How to reuse a snes object?

Matthew Knepley knepley at gmail.com
Mon Mar 10 23:35:51 CDT 2014

On Mon, Mar 10, 2014 at 11:29 PM, Fande Kong <fd.kong at siat.ac.cn> wrote:

> Hi all,
> I am trying to solve two different nonlinear equations. I first solve the
> first nonlinear equation using a snes within which a ksp is preconditioned
> by a pcasm. And then I want to use the solution of the first nonlinear
> equation as an initial guess  to solve the second nonlinear equation, but
> this time I want to switch the preconditioner to pcmg. How could I finish
> this by creating snes only once, then using snessolve() twice, and
> switching preconditioner for linear solvers?

It seems like you gain nothing at all by reusing the SNES, and complicate
your code. I would not do it.

If you insist, you can

  a) Change the prefix, and call SNESSetFromOptions() before the second

  b) Pull out the PC (SNESGetKSP, SNESGetPC) and set it there

Note that in any event, you will have to reset the function/Jacobian
methods for the second solve.



> Fande

What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20140310/3fb221e3/attachment.html>

More information about the petsc-users mailing list