[petsc-users] Set PC PythonContext within NPC

Asbjørn Nilsen Riseth riseth at maths.ox.ac.uk
Wed Jul 1 08:21:15 CDT 2015


Thanks Lawrence,

fixed my issue by calling snes.setUp(), so I can access the linear PC from
my NPC.
This requires pull request 339:
https://bitbucket.org/petsc/petsc/pull-request/339/make-sure-vec_sol-is-not-null-before

At some point I'll learn to use app contexts in my python shells. For now,
I'm using  _init_() to store any application-specific values in my class.

Asbjørn

On Thu, 25 Jun 2015 at 22:17 Lawrence Mitchell <
lawrence.mitchell at imperial.ac.uk> wrote:

>
> > On 24 Jun 2015, at 17:02, Asbjørn Nilsen Riseth <riseth at maths.ox.ac.uk>
> wrote:
> >
> > Hi all,
> >
> > I'm currently trying to set up a nonlinear solver that uses NGMRES with
> NEWTONLS as a right preconditioner. The NEWTONLS has a custom linear
> preconditioner. Everything is accessed through petsc4py.
> >
> > *Is there a way I can configure a NPC NEWTONLS KSP CompositePC without
> first calling solve on my outer snes?*
> >
> > My NEWTONLS has the following KSP setup:
> > FGMRES
> > | PCCOMPOSITE
> > || PYTHON
> > || ILU
> >
> > The way I understand things, the NPC is not created/set up until
> SNESSolve_NGMRES() is called. Therefore, I cannot call
> snes.getNPC().ksp.pc.getCompositePC(0).setPythonContext(ctx) before I have
> called snes.solve().
> >
> > What I currently do is a try/except on snes.solve to create/set up the
> pccomposite. Then I can set my pythoncontext and it runs fine. This is
> quite ugly though, so I was hoping anyone would have a better approach.
>
> I think you can do the following:
>
> Define a class in some module:
>
> # (in module foo)
> class MyPC(object):
>
>     def setUp(self, pc):
>         # do any setup here.
>         pass
>
>     def apply(self, pc, x, y):
>         # apply preconditioner
>         pass
>
> And pass:
>
> -npc_sub_1_pc_type python -npc_sub_1_pc_python_context foo.MyPC
>
> You can pull the app context out in the class's setUp method by doing:
>
> ctx = pc.getDM().getAppCtx()
>
> Assuming that you're running with a branch that contains
> origin/knepley/fix-pc-composite-dm.
>
> Cheers,
>
> Lawrence
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20150701/7b7f5a95/attachment.html>


More information about the petsc-users mailing list