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

Matthew Knepley knepley at gmail.com
Tue Mar 11 07:41:42 CDT 2014


On Tue, Mar 11, 2014 at 12:46 AM, Fande Kong <fd.kong at siat.ac.cn> wrote:

> Thanks,
>

Never mail me personally. That is what the list is for.


> If we follow a),  we can not change any options from command line for the
> second solve.
>

No, you miss the whole point of changing the prefix:

  SNESSetOptionsPrefix(snes, "second_");

so that afterwards

  second_pc_type lu

will be picked up by the second call to SNESSetFromOptions(). However, as I
said before,
I think there is no reason to do this.

   Matt


> On Mon, Mar 10, 2014 at 10:35 PM, Matthew Knepley <knepley at gmail.com>wrote:
>
>> 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
>> solve
>>
>>   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.
>>
>>    Thanks,
>>
>>      Matt
>>
>>
>>> 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
>>
>
>


-- 
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/20140311/c1a44214/attachment.html>


More information about the petsc-users mailing list