Thank you Jed. It works, and the result is identical to the exact 
solution! 


Hope you best!










David Jiawei LUO LIANG



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



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




 
 
 
------------------ Original ------------------
From: &nbsp;"Jed&nbsp;Brown"<j...@jedbrown.org&gt;;
Date: &nbsp;Thu, Nov 21, 2024 11:05 PM
To: &nbsp;"David Jiawei LUO LIANG"<12431...@mail.sustech.edu.cn&gt;; 
"petsc-users"<petsc-users@mcs.anl.gov&gt;; 

Subject: &nbsp;Re: [petsc-users] Cannot iterate well when using Newton 
iteration of SNES

&nbsp;

 
You&nbsp;should&nbsp;add&nbsp;VecZeroEntries(f)&nbsp;near&nbsp;the&nbsp;top&nbsp;of&nbsp;your&nbsp;FormFunction&nbsp;(it's&nbsp;currently&nbsp;accumulating&nbsp;into&nbsp;whatever&nbsp;was&nbsp;there&nbsp;last)&nbsp;and&nbsp;MatZeroEntries(B)&nbsp;to&nbsp;FormJacobian.

I&nbsp;reduced&nbsp;to&nbsp;nElem&nbsp;=&nbsp;5&nbsp;for&nbsp;ease&nbsp;of&nbsp;viewing.&nbsp;With&nbsp;these&nbsp;changes,&nbsp;I&nbsp;see&nbsp;quadratic&nbsp;convergence&nbsp;but&nbsp;the&nbsp;problem&nbsp;is&nbsp;still&nbsp;nonlinear.&nbsp;To&nbsp;explore&nbsp;further,&nbsp;consider&nbsp;using&nbsp;these&nbsp;diagnostics

./SNES_heat&nbsp;-{snes,ksp}_monitor&nbsp;-{snes,ksp}_converged_reason&nbsp;-snes_linesearch_monitor&nbsp;-ksp_view_mat

with&nbsp;and&nbsp;without&nbsp;-snes_fd.

For&nbsp;readability,&nbsp;I&nbsp;would&nbsp;suggest&nbsp;consistency&nbsp;in&nbsp;"u"&nbsp;vs&nbsp;"x".

"David&nbsp;Jiawei&nbsp;LUO&nbsp;LIANG" 
<12431...@mail.sustech.edu.cn&gt;&nbsp;writes:

&gt;&nbsp;I&nbsp;am&nbsp;using&nbsp;the&nbsp;Newton&nbsp;iteration&nbsp;to&nbsp;solve&nbsp;a&nbsp;nonlinear&nbsp;1D&nbsp;heat&nbsp;equation&nbsp;problem&nbsp;by&nbsp;using&nbsp;FEM.
&gt;
&gt;
&gt;&nbsp;I&nbsp;attached&nbsp;my&nbsp;source&nbsp;code&nbsp;named&nbsp;"SNES_heat.cpp"&amp;nbsp;
&gt;
&gt;
&gt;&nbsp;when&nbsp;I&nbsp;run&nbsp;the&nbsp;code
&gt;
&gt;&nbsp;&amp;nbsp;&nbsp;0&nbsp;SNES&nbsp;Function&nbsp;norm&nbsp;1.206289245288e+01
&gt;&nbsp;&nbsp;
&gt;&nbsp;&amp;nbsp;&nbsp;1&nbsp;SNES&nbsp;Function&nbsp;norm&nbsp;7.128802192789e+00
&gt;&nbsp;&nbsp;
&gt;&nbsp;&amp;nbsp;&nbsp;2&nbsp;SNES&nbsp;Function&nbsp;norm&nbsp;6.608812909525e+00
&gt;
&gt;
&gt;
&gt;&nbsp;you&nbsp;can&nbsp;find&nbsp;that&nbsp;it&nbsp;only&nbsp;iterate&nbsp;3&nbsp;steps,&nbsp;and&nbsp;then&nbsp;do&nbsp;all&nbsp;the&nbsp;function&nbsp;evaluation&nbsp;and&nbsp;finally&nbsp;just&nbsp;stop&nbsp;the&nbsp;program.&amp;nbsp;
&gt;
&gt;
&gt;&nbsp;I&nbsp;think&nbsp;it&nbsp;is&nbsp;not&nbsp;reasonble.&nbsp;I&nbsp;check&nbsp;my&nbsp;code,&nbsp;it&nbsp;is&nbsp;correct&nbsp;if&nbsp;I&nbsp;set&nbsp;it&nbsp;as&nbsp;a&nbsp;linear&nbsp;problem.&nbsp;it&nbsp;means&nbsp;my&nbsp;Jacobian&nbsp;and&nbsp;Residual&nbsp;function&nbsp;is&nbsp;correct.
&gt;
&gt;
&gt;&nbsp;But&nbsp;when&nbsp;I&nbsp;set&nbsp;it&nbsp;as&nbsp;a&nbsp;nonlinear,&nbsp;the&nbsp;residual&nbsp;seems&nbsp;reduces&nbsp;as&nbsp;not&nbsp;expected.&amp;nbsp;
&gt;
&gt;
&gt;&nbsp;I&nbsp;doubt&nbsp;that&nbsp;whether&nbsp;my&nbsp;understanding&nbsp;of&nbsp;the&nbsp;newton&nbsp;iteration&nbsp;is&nbsp;different&nbsp;from&nbsp;SNES's&nbsp;newton&nbsp;iteration&nbsp;process.
&gt;
&gt;
&gt;
&gt;
&gt;
&gt;
&gt;
&gt;
&gt;&nbsp;David&nbsp;Jiawei&nbsp;LUO&nbsp;LIANG
&gt;
&gt;
&gt;
&gt;&nbsp;南方科技大学/学生/研究生/2024
&gt;
&gt;
&gt;
&gt;&nbsp;广东省深圳市南山区学苑大道1088号
&gt;
&gt;
&gt;
&gt;
&gt;&nbsp;&amp;nbsp;

Reply via email to