[petsc-users] petsc4py KSP Question
Lisandro Dalcin
dalcinl at gmail.com
Wed Mar 7 02:16:39 CST 2012
On 7 March 2012 02:22, Gaetan Kenway <kenway at utias.utoronto.ca> wrote:
> Hello
>
> I'm in the process of using petsc4py to solve a large multidisciplinary,
> non-linear system and its adjoint. I have the non-linear solution with
> snes() working correctly and I'm now doing the linear solution.
>
> For the non-linear solve, I create the snes and set my user context as
> follows:
> # Create SNES Object
> ASContext = ASNKSolver(self) # Context to hold data
> snes = PETSc.SNES().createPython(ASContext, comm=self.gcomm)
> snes.setFunction(ASContext.formFunction, resVec)
>
> For the linear part, I'm a little confused. I currently have
>
> # Create Python Context and KSP Object
> KSPContext = AdjointKSPSolver(self) # Context to hold data
> ksp = PETSc.KSP().createPython(KSPContext, comm=self.gcomm)
>
> What I'm not sure of is how to specify the operator for the KSP solver in
> the KSPContext object. Is this possible? Is there something like def apply()
> you must do?
>
> The petsc4py poisson2d.py example, first creates a Mat, then sets a context
> for that, and then uses ksp.setOperators() to use that matrix. Is this the
> only way to do it? If, so, what is the use of
> the PETSc.KSP().createPython() command?
>
Unless you want to implement a custom KSP/SNES in Python, you should
just use KSP/SNES.create(). KSP/SNES.createPython() is a rather
advanced feature, it is not obvious at all how to use them, there are
no demos nor documentation about it (however, there is some code in
test/test_{ksp|snes}_py.py ).
Please take a look at the demo/bratu2d and demo/bratu3d about how to
setup a SNES solver. For KSP, take a look at
demo/kspsolve/petsc-mat.py and demo/kspsolve/petsc-ksp.py
--
Lisandro Dalcin
---------------
CIMEC (INTEC/CONICET-UNL)
Predio CONICET-Santa Fe
Colectora RN 168 Km 472, Paraje El Pozo
3000 Santa Fe, Argentina
Tel: +54-342-4511594 (ext 1011)
Tel/Fax: +54-342-4511169
More information about the petsc-users
mailing list