[petsc-users] petsc4py KSP Question
Gaetan Kenway
kenway at utias.utoronto.ca
Wed Mar 7 08:49:21 CST 2012
Thanks for the reply.
What is the 'with block' option. I don't see anything related to that when
I run help(PETSc.Vec()). Does it return a (N/bs,bs) array instead of an (N)
array? Also in petsc4py the call for resetting the pointer from getArray()
is actually resetArray() which is different from C/Fortran where it is
restoreArray(). I've got them confused as well.
Gaetan
On Wed, Mar 7, 2012 at 9:22 AM, Matthew Knepley <knepley at gmail.com> wrote:
> On Wed, Mar 7, 2012 at 8:18 AM, Gaetan Kenway <kenway at utias.utoronto.ca>wrote:
>
>> Thanks. I have both the SNES and the linear KSP solver working the way I
>> want.
>>
>> One more question: At the beginning of my non-linear SNES function I have
>> something like
>>
>> def formFunction(self, snes, X, F):
>>
>> states = X.getArray()
>>
>> and a X.resetArray() at the end. Am I correct to assume that this is an
>> efficient pointer assignment to the numpy array and does not involve a
>> memory copy?
>>
>
> It is no-copy. You can use a 'with block, which is a little nicer, and I
> think you mean restoreArray().
>
> Matt
>
>
>> Thanks
>>
>> Gaetan
>>
>>
>>
>> On Wed, Mar 7, 2012 at 3:16 AM, Lisandro Dalcin <dalcinl at gmail.com>wrote:
>>
>>> 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
>>>
>>>
>>
>
>
> --
> 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/20120307/e7fe163c/attachment.htm>
More information about the petsc-users
mailing list