On Wed, Mar 7, 2012 at 8:18 AM, Gaetan Kenway <span dir="ltr"><<a href="mailto:kenway@utias.utoronto.ca">kenway@utias.utoronto.ca</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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></blockquote><div><br></div><div>It is no-copy. You can use a 'with block, which is a little nicer, and I think you mean restoreArray().</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<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" target="_blank">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><div>On 7 March 2012 02:22, Gaetan Kenway <<a href="mailto:kenway@utias.utoronto.ca" target="_blank">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><font color="#888888"><br>
<br><span class="HOEnZb"><font color="#888888">
<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" target="_blank">+54-342-4511594</a> (ext 1011)<br>
Tel/Fax: <a href="tel:%2B54-342-4511169" value="+543424511169" target="_blank">+54-342-4511169</a><br>
<br>
</font></span></font></span></blockquote></div><br></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener<br>