[petsc-users] Help with petsc4py and PC Python type

Jed Brown jed at jedbrown.org
Tue Jan 22 16:27:34 CST 2019


Justin Chang via petsc-users <petsc-users at mcs.anl.gov> writes:

> Hi all,
>
> I am attempting to write my own scour preconditioner for a FEniCS/petsc4py.
> I managed to attach a DMShell to the KSP so that I can employ command-line
> options for field splitting. Suppose I want to solve the Navier-Stokes
> equation and have the following command-line options:
>
> -ksp_type fgmres
> -pc_type fieldsplit
> -pc_fieldsplit_type schur
> -pc_fieldsplit_schur_fact_type full
> -fieldsplit_0_ksp_type gmres
> -fieldsplit_0_pc_type hypre
> -fieldsplit_1_ksp_type preonly
> -fieldsplit_1_pc_type python
> -fieldsplit_1_pc_python_type pfibs.MyPCD
>
> Where MyPCD is part of my pfibs module and looks something like this:
>
> class MyPCD(object):
>     def setUp(self, pc):
>           # Do something #
>              ....
>     def apply(self, pc, x, y):
>           # Do something #
>              ....
>
> The problem is that in my actual python code (mycode.py) I have a dict()

Where does this dict come from?  When is it available?

> object that I would like to pass into the setUp() call inside MyPCD to read
> in, but it is not clear how I can do this if I set the pc python type via
> command line options. If I hard-coded this, I would just call
> pc.setPythonContext(...) but I was wondering if there's a way to do this,
> e.g., attaching an appctx/dict to the pc itself. Does anyone have ideas or
> suggestions on how to go about doing this?
>
> Thanks,
> Justin


More information about the petsc-users mailing list