On Wed, Mar 7, 2012 at 8:18 AM, Gaetan Kenway <span dir="ltr">&lt;<a href="mailto:kenway@utias.utoronto.ca">kenway@utias.utoronto.ca</a>&gt;</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 &#39;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">&lt;<a href="mailto:dalcinl@gmail.com" target="_blank">dalcinl@gmail.com</a>&gt;</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 &lt;<a href="mailto:kenway@utias.utoronto.ca" target="_blank">kenway@utias.utoronto.ca</a>&gt; wrote:<br>


&gt; Hello<br>
&gt;<br>
&gt; I&#39;m in the process of using petsc4py to solve a large multidisciplinary,<br>
&gt; non-linear system and its adjoint. I have the non-linear solution with<br>
&gt; snes() working correctly and I&#39;m now doing the linear solution.<br>
&gt;<br>
&gt; For the non-linear solve, I create the snes and set my user context as<br>
&gt; follows:<br>
&gt;    # Create SNES Object<br>
&gt;   ASContext = ASNKSolver(self) # Context to hold data<br>
&gt;   snes = PETSc.SNES().createPython(ASContext, comm=self.gcomm)<br>
&gt;   snes.setFunction(ASContext.formFunction, resVec)<br>
&gt;<br>
&gt; For the linear part, I&#39;m a little confused. I currently have<br>
&gt;<br>
&gt;     # Create Python Context and KSP Object<br>
&gt;     KSPContext = AdjointKSPSolver(self) # Context to hold data<br>
&gt;     ksp = PETSc.KSP().createPython(KSPContext, comm=self.gcomm)<br>
&gt;<br>
&gt; What I&#39;m not sure of is how to specify the operator for the KSP solver in<br>
&gt; the KSPContext object. Is this possible? Is there something like def apply()<br>
&gt; you must do?<br>
&gt;<br>
&gt; The petsc4py poisson2d.py example, first creates a Mat, then sets a context<br>
&gt; for that, and then uses ksp.setOperators() to use that matrix. Is this the<br>
&gt; only way to do it? If, so, what is the use of<br>
&gt; the  PETSc.KSP().createPython() command?<br>
&gt;<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>