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.

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.

Jose


> El 26 oct 2024, a las 11:11, Vaishak Prasad <vaishakpra...@gmail.com> 
> escribió:
> 
> Hi,
> 
> Thanks for pointing me to the updated example. The example itself works fine.
> 
> 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?
> 
> Any help would be appreciated.
> 
> Thanks and Regards
> 
> 
> On Sat, Oct 26, 2024 at 12:42 PM Jose E. Roman <jro...@dsic.upv.es> wrote:
> 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.
> 
> Jose
> 
> > El 25 oct 2024, a las 19:58, Vaishak Prasad <vaishakpra...@gmail.com> 
> > escribió:
> > 
> > Dear All,
> > Greetings from India.
> > 
> > I am new to petsc4py. I was trying out the example on slides 18, and 19 at
> > 
> > https://urldefense.us/v3/__https://www.bu.edu/pasi/files/2011/01/Lisandro-Dalcin-petsc4py.pdf__;!!G_uCfscf7eWS!d-A7MAUVTgb6BEVbhTWgL1jYExkAYjqUU0OnPOv8BSXFQ1xC2M5NuiIo5WN7D2AITF0S3Zmq77m1KKOaKZdvpQn4$
> >  
> > 
> > However, I get a zero vector for the solution `x`.
> > 
> > I am using petsc4py 3.21.3 on Linux.
> > 
> > Any help would be appreciated.
> > 
> > With regards
> > 
> > -- 
> > Vaishak Prasad
> > Post Doctoral Fellow
> > Astrophysical Relativity Group
> > International Center for Theoretical Sciences
> > Tata Institute of Fundamental Research
> > Survey No. 151, Shivakote, Hesaraghatta Hobli,
> > Bengaluru, Karnataka, India, 
> > Earth, Solar system, 
> > Milky Way Galaxy, The Local Group
> 
> 
> 
> -- 
> Vaishak Prasad
> Post Doctoral Fellow
> Astrophysical Relativity Group
> International Center for Theoretical Sciences
> Tata Institute of Fundamental Research
> Survey No. 151, Shivakote, Hesaraghatta Hobli,
> Bengaluru, Karnataka, India, 
> Earth, Solar system, 
> Milky Way Galaxy, The Local Group
> <mwe.py>

Reply via email to