Thanks. I have both the SNES and the linear KSP solver working the way I want. <div><br></div><div>One more question: At the beginning of my non-linear SNES function I have something like<br><br><div> def formFunction(self, snes, X, F):</div>
<div><br></div><div> states = X.getArray()</div><div><br></div><div>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? </div>
<div><br></div><div>Thanks</div><div><br></div><div>Gaetan</div><div><br></div><div> </div><br><div class="gmail_quote">On Wed, Mar 7, 2012 at 3:16 AM, Lisandro Dalcin <span dir="ltr"><<a href="mailto:dalcinl@gmail.com">dalcinl@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 7 March 2012 02:22, Gaetan Kenway <<a href="mailto:kenway@utias.utoronto.ca">kenway@utias.utoronto.ca</a>> wrote:<br>
> Hello<br>
><br>
> I'm in the process of using petsc4py to solve a large multidisciplinary,<br>
> non-linear system and its adjoint. I have the non-linear solution with<br>
> snes() working correctly and I'm now doing the linear solution.<br>
><br>
> For the non-linear solve, I create the snes and set my user context as<br>
> follows:<br>
> # Create SNES Object<br>
> ASContext = ASNKSolver(self) # Context to hold data<br>
> snes = PETSc.SNES().createPython(ASContext, comm=self.gcomm)<br>
> snes.setFunction(ASContext.formFunction, resVec)<br>
><br>
> For the linear part, I'm a little confused. I currently have<br>
><br>
> # Create Python Context and KSP Object<br>
> KSPContext = AdjointKSPSolver(self) # Context to hold data<br>
> ksp = PETSc.KSP().createPython(KSPContext, comm=self.gcomm)<br>
><br>
> What I'm not sure of is how to specify the operator for the KSP solver in<br>
> the KSPContext object. Is this possible? Is there something like def apply()<br>
> you must do?<br>
><br>
> The petsc4py poisson2d.py example, first creates a Mat, then sets a context<br>
> for that, and then uses ksp.setOperators() to use that matrix. Is this the<br>
> only way to do it? If, so, what is the use of<br>
> the PETSc.KSP().createPython() command?<br>
><br>
<br>
</div></div>Unless you want to implement a custom KSP/SNES in Python, you should<br>
just use KSP/SNES.create(). KSP/SNES.createPython() is a rather<br>
advanced feature, it is not obvious at all how to use them, there are<br>
no demos nor documentation about it (however, there is some code in<br>
test/test_{ksp|snes}_py.py ).<br>
<br>
Please take a look at the demo/bratu2d and demo/bratu3d about how to<br>
setup a SNES solver. For KSP, take a look at<br>
demo/kspsolve/petsc-mat.py and demo/kspsolve/petsc-ksp.py<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
--<br>
Lisandro Dalcin<br>
---------------<br>
CIMEC (INTEC/CONICET-UNL)<br>
Predio CONICET-Santa Fe<br>
Colectora RN 168 Km 472, Paraje El Pozo<br>
3000 Santa Fe, Argentina<br>
Tel: <a href="tel:%2B54-342-4511594" value="+543424511594">+54-342-4511594</a> (ext 1011)<br>
Tel/Fax: <a href="tel:%2B54-342-4511169" value="+543424511169">+54-342-4511169</a><br>
<br>
</font></span></blockquote></div><br></div>