<div dir="ltr"><div dir="ltr">Dear Jose,<div><br></div><div>Thankyou very much for your response. </div><div><br></div></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Oct 26, 2024 at 3:32 PM Jose E. Roman <<a href="mailto:jroman@dsic.upv.es">jroman@dsic.upv.es</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Your residue() function is computing something (f) that is not returned to the calling function. So evalFunction() returns a zero residual and the solver stops in one iteration.<br></blockquote><div>Apologies, I am a little confused. The example bratu2d.py imports the residue function from bratu2dnpy.py and it also does not return anything (and it works). I was under the impression that</div><div>a pointer to `f` is passed to petsc, that overwrites it at each iteration. Please correct me if I am wrong.</div><div><br></div><div>I also tried returning `f` in my residue function but it does not change anything. Is this what you suggested?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Mixing numpy arrays and petsc4py vectors is going to be tricky unless you know what you are doing. It is simpler to manipulate petsc4py vectors directly, see for instance bratu3d.py or other examples.<br></blockquote><div>I have also tried this. I created a petsc vector for the input expected solution and then converted it into a numpy array using the `getArray` method. But noting changes.</div><div><br></div><div>I also printed some information about the convergence itself. I find </div><div>ConvergedReason is 2 (absolute tolerance)</div><div>getTolerances is [1e-8, 1e-50, 1e-8, 50] (default)</div><div>getErrorIfNotConverged is False</div><div>getIterationNumber is 0</div><div><br></div><div>In contrast, the convergence reason for the bratu2d example was 3 (relative tolerance).</div><div><br></div><div>I also tried increasing the `max_it` but to no avail.</div><div><br></div><div>I appreciate your valuable suggestion and advice in this regard.</div><div><br></div><div>Thanks and Regards</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Jose<br>
<br>
<br>
> El 26 oct 2024, a las 11:11, Vaishak Prasad <<a href="mailto:vaishakprasad@gmail.com" target="_blank">vaishakprasad@gmail.com</a>> escribió:<br>
> <br>
> Hi,<br>
> <br>
> Thanks for pointing me to the updated example. The example itself works fine.<br>
> <br>
> However, on adapting the example to a simple problem ( recovering a given 1D vector), I find that there is only one function call happening and the solution has not converged. I am attaching the modified example here. Is there something silly I am doing here?<br>
> <br>
> Any help would be appreciated.<br>
> <br>
> Thanks and Regards<br>
> <br>
> <br>
> On Sat, Oct 26, 2024 at 12:42 PM Jose E. Roman <<a href="mailto:jroman@dsic.upv.es" target="_blank">jroman@dsic.upv.es</a>> wrote:<br>
> The examples in those old slides might be outdated. Try with the examples that come with the PETSc repo or tarball. In particular, that example can be found in src/binding/petsc4py/demo/legacy/bratu2d/bratu2d.py.<br>
> <br>
> Jose<br>
> <br>
> > El 25 oct 2024, a las 19:58, Vaishak Prasad <<a href="mailto:vaishakprasad@gmail.com" target="_blank">vaishakprasad@gmail.com</a>> escribió:<br>
> > <br>
> > Dear All,<br>
> > Greetings from India.<br>
> > <br>
> > I am new to petsc4py. I was trying out the example on slides 18, and 19 at<br>
> > <br>
> > <a href="https://urldefense.us/v3/__https://www.bu.edu/pasi/files/2011/01/Lisandro-Dalcin-petsc4py.pdf__;!!G_uCfscf7eWS!bzL5mw0mqx-jt3BIhPqHNtxZUf469dbmQwxugUupECLT7CEMbk_vj-TZ_wEym_uN1O4CWKJKeODMn0a0tO72ky2PkUrV$" rel="noreferrer" target="_blank">https://www.bu.edu/pasi/files/2011/01/Lisandro-Dalcin-petsc4py.pdf</a><br>
> > <br>
> > However, I get a zero vector for the solution `x`.<br>
> > <br>
> > I am using petsc4py 3.21.3 on Linux.<br>
> > <br>
> > Any help would be appreciated.<br>
> > <br>
> > With regards<br>
> > <br>
> > -- <br>
> > Vaishak Prasad<br>
> > Post Doctoral Fellow<br>
> > Astrophysical Relativity Group<br>
> > International Center for Theoretical Sciences<br>
> > Tata Institute of Fundamental Research<br>
> > Survey No. 151, Shivakote, Hesaraghatta Hobli,<br>
> > Bengaluru, Karnataka, India, <br>
> > Earth, Solar system, <br>
> > Milky Way Galaxy, The Local Group<br>
> <br>
> <br>
> <br>
> -- <br>
> Vaishak Prasad<br>
> Post Doctoral Fellow<br>
> Astrophysical Relativity Group<br>
> International Center for Theoretical Sciences<br>
> Tata Institute of Fundamental Research<br>
> Survey No. 151, Shivakote, Hesaraghatta Hobli,<br>
> Bengaluru, Karnataka, India, <br>
> Earth, Solar system, <br>
> Milky Way Galaxy, The Local Group<br>
> <mwe.py><br>
<br>
</blockquote></div><div><br clear="all"></div><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div dir="ltr">Vaishak Prasad</div><div><span style="background-color:rgb(255,255,255);color:rgb(102,102,102)">Post Doctoral Fellow</span><br></div><div dir="ltr"><div><div><font color="#888888">Astrophysical Relativity Group<br>
</font></div><font color="#888888">International Center for Theoretical Sciences<br>
Tata Institute of Fundamental Research<br>
Survey No. 151, Shivakote, Hesaraghatta Hobli,<br>Bengaluru, Karnataka, India, <br>Earth, Solar system, </font></div><div><font color="#888888">Milky Way Galaxy, </font><span style="color:rgb(136,136,136)">The Local Group</span></div></div></div></div></div>