Hi Barry,

The problem is I forgot (or say that I didn't know) to initialize the Vec f in 
residual function and Mat B in Jacobian function.


Anyway, thanks for sharing me the link, it is helpful for debugging the program 
next time. 


Hope you the best!







David Jiawei LUO LIANG



南方科技大学/学生/研究生/2024



广东省深圳市南山区学苑大道1088号




 
 
 
------------------ Original ------------------
From: &nbsp;"Barry&nbsp;Smith"<bsm...@petsc.dev&gt;;
Date: &nbsp;Thu, Nov 21, 2024 11:20 PM
To: &nbsp;"David Jiawei LUO LIANG"<12431...@mail.sustech.edu.cn&gt;; 
Cc: &nbsp;"petsc-users"<petsc-users@mcs.anl.gov&gt;; 
Subject: &nbsp;Re: [petsc-users] Cannot iterate well when using Newton 
iteration of SNES

&nbsp;



&nbsp; &nbsp;Start with 
https://urldefense.us/v3/__https://petsc.org/release/faq/*why-is-newton-s-method-snes-not-converging-or-converges-slowly__;Iw!!G_uCfscf7eWS!au7QiobP2j0-OKe-njT2UpUI_j99PsLuftq54OhM2bkB2zJCddsS-MGvmfw6WAVUuB7I6eKa5HKddgjoBcaMZ7dJRVaq7MyA$
 

&nbsp; &nbsp; Next use




-snes_test_jacobian -&nbsp;compare the user provided Jacobian with one computed 
via finite differences to check for errors. If a threshold is given, display 
only those entries whose difference is greater than the threshold.



-snes_test_jacobian_view -&nbsp;display the user provided Jacobian, the finite 
difference Jacobian and the difference between them to help users detect the 
location of errors in the user provided Jacobian.







There are many, many reasons Newton can fail, usually they are due to bugs in 
the function evaluation or Jacobian evaluation. Occasionly they are due to it 
being a very difficult non-linear problem. You first need to use the tools 
above to verify there are no bugs anywhere.




Barry





On Nov 21, 2024, at 7:11 AM, David Jiawei LUO LIANG 
<12431...@mail.sustech.edu.cn&gt; wrote:

I am using the Newton iteration to solve a nonlinear 1D heat equation problem 
by using FEM.


I attached my source code named "SNES_heat.cpp" 


when I run the code
&nbsp; 0 SNES Function norm 1.206289245288e+01
&nbsp; 1 SNES Function norm 7.128802192789e+00
&nbsp; 2 SNES Function norm 6.608812909525e+00



you can find that it only iterate 3 steps, and then do all the function 
evaluation and finally just stop the program. 


I think it is not reasonble. I check my code, it is correct if I set it as a 
linear problem. it means my Jacobian and Residual function is correct.


But when I set it as a nonlinear, the residual seems reduces as not expected. 


I doubt that whether my understanding of the newton iteration is different from 
SNES's newton iteration process.








David Jiawei LUO LIANG


南方科技大学/学生/研究生/2024


广东省深圳市南山区学苑大道1088号




&nbsp;

<SNES_heat.cpp&gt;

Reply via email to