<div dir="ltr"><div dir="ltr">On Thu, Nov 21, 2024 at 8:57 AM David Jiawei LUO LIANG <<a href="mailto:12431140@mail.sustech.edu.cn">12431140@mail.sustech.edu.cn</a>> wrote:</div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>I am using the Newton iteration to solve a nonlinear 1D heat equation problem by using FEM.</div><div><br></div><div>I attached my source code named "SNES_heat.cpp" </div><div><br></div><div>when I run the code</div><div><p style="margin:0px;font-style:normal;font-variant-caps:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;background-color:rgb(254,244,139)"><span style="font-variant-ligatures:no-common-ligatures"> 0 SNES Function norm 1.206289245288e+01</span></p>
<p style="margin:0px;font-style:normal;font-variant-caps:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;background-color:rgb(254,244,139)"><span style="font-variant-ligatures:no-common-ligatures"> 1 SNES Function norm 7.128802192789e+00</span></p>
<p style="margin:0px;font-style:normal;font-variant-caps:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;background-color:rgb(254,244,139)"><span style="font-variant-ligatures:no-common-ligatures"> 2 SNES Function norm 6.608812909525e+00</span></p></div><div><font><br></font></div><div><u></u><div><font>you can find that it only iterate 3 steps, and then do all the function evaluation and finally just stop the program. </font></div><div><font><br></font></div><div><font>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.</font></div><div><font><br></font></div><div><font>But when I set it as a nonlinear, the residual seems reduces as not expected. </font></div><div><font><br></font></div><div><font>I doubt that whether my understanding of the newton iteration is different from SNES's newton iteration process.</font></div></div></blockquote><div><br></div><div>Here is what happens with the code as it is:</div><div><br></div><div>master *:~/Downloads/tmp/Liang$ ./SNES_heat -snes_monitor -ksp_converged_reason -snes_converged_reason -pc_type lu -snes_view -snes_linesearch_monitor<br>pp 1<br>nElem 10<br>nqp 2<br>n_np 11<br>n_en 2<br>n_eq 10<br>qp: <br>0.57735 -0.57735 <br>wq: <br>1 1 <br>IEN: <br>1 2 3 4 5 6 7 8 9 10 2 3 4 5 6 7 8 9 10 11 <br>x_coor: <br>0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 <br>ID: <br>1 2 3 4 5 6 7 8 9 10 0 <br> 0 SNES Function norm 1.206289245288e+01<br> Linear solve converged due to CONVERGED_RTOL iterations 1<br> Line search: Using full step: fnorm 1.206289245288e+01 gnorm 7.128802192789e+00<br> 1 SNES Function norm 7.128802192789e+00<br> Linear solve converged due to CONVERGED_RTOL iterations 1<br> Line search: Using full step: fnorm 7.128802192789e+00 gnorm 6.608812909525e+00<br> 2 SNES Function norm 6.608812909525e+00<br> Linear solve converged due to CONVERGED_RTOL iterations 1<br> Line search: gnorm after quadratic fit 1.265375106867e+01<br> Line search: Cubic step no good, shrinking lambda, current gnorm 1.328962011911e+01 lambda=1.7500506382162818e-02<br> Line search: Cubic step no good, shrinking lambda, current gnorm 1.275802797864e+01 lambda=1.7500506382162819e-03<br> Line search: Cubic step no good, shrinking lambda, current gnorm 1.327920917220e+01 lambda=1.7500506382162821e-04<br> Line search: Cubic step no good, shrinking lambda, current gnorm 1.275906891232e+01 lambda=1.7500506382162820e-05<br> Line search: Cubic step no good, shrinking lambda, current gnorm 1.327910508109e+01 lambda=1.7500506382162821e-06<br> Line search: Cubic step no good, shrinking lambda, current gnorm 1.275907932147e+01 lambda=1.7500506382162822e-07<br> Line search: Cubic step no good, shrinking lambda, current gnorm 1.327910404018e+01 lambda=1.7500506382162823e-08<br> Line search: Cubic step no good, shrinking lambda, current gnorm 1.275907942556e+01 lambda=1.7500506382162823e-09<br> Line search: Cubic step no good, shrinking lambda, current gnorm 1.327910402977e+01 lambda=1.7500506382162824e-10<br> Line search: Cubic step no good, shrinking lambda, current gnorm 1.275907942660e+01 lambda=1.7500506382162825e-11<br> Line search: Cubic step no good, shrinking lambda, current gnorm 1.327910402966e+01 lambda=1.7500506382162826e-12<br> Line search: Cubic step no good, shrinking lambda, current gnorm 1.275907942661e+01 lambda=1.7500506382162828e-13<br> Line search: unable to find good step length! After 12 tries <br> Line search: fnorm=6.6088129095253478e+00, gnorm=1.2759079426614502e+01, ynorm=5.3714153713436097e-01, minlambda=9.9999999999999998e-13, lambda=1.7500506382162828e-13, initial slope=-4.3676408073108860e+01<br> Nonlinear solve did not converge due to DIVERGED_LINE_SEARCH iterations 2<br></div><div><br></div><div>Usually, we suspect that the Jacobian is incorrect in this case. Thus we can have it formed automatically,</div><div><br></div><div>master *:~/Downloads/tmp/Liang$ ./SNES_heat -snes_monitor -ksp_converged_reason -snes_converged_reason -snes_fd -pc_type lu -snes_view -snes_linesearch_monitor<br>pp 1<br>nElem 10<br>nqp 2<br>n_np 11<br>n_en 2<br>n_eq 10<br>qp: <br>0.57735 -0.57735 <br>wq: <br>1 1 <br>IEN: <br>1 2 3 4 5 6 7 8 9 10 2 3 4 5 6 7 8 9 10 11 <br>x_coor: <br>0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 <br>ID: <br>1 2 3 4 5 6 7 8 9 10 0 <br> 0 SNES Function norm 1.206289245288e+01<br> Linear solve converged due to CONVERGED_RTOL iterations 1<br> Line search: Scaling step by 1.837216392007e-47 old ynorm 5.443016970405e+54<br> Line search: gnorm after quadratic fit 3.704240795372e+16<br> Line search: Cubic step no good, shrinking lambda, current gnorm 3.704614960636e+16 lambda=1.0000000000000002e-02<br> Line search: Cubic step no good, shrinking lambda, current gnorm 3.704611219026e+16 lambda=1.0000000000000002e-03<br> Line search: Cubic step no good, shrinking lambda, current gnorm 3.704611256438e+16 lambda=1.0000000000000003e-04<br> Line search: Cubic step no good, shrinking lambda, current gnorm 3.704611256064e+16 lambda=1.0000000000000004e-05<br> Line search: Cubic step no good, shrinking lambda, current gnorm 3.704611256068e+16 lambda=1.0000000000000004e-06<br> Line search: Cubic step no good, shrinking lambda, current gnorm 3.704611256068e+16 lambda=1.0000000000000005e-07<br> Line search: Cubic step no good, shrinking lambda, current gnorm 3.704611256068e+16 lambda=1.0000000000000005e-08<br> Line search: Cubic step no good, shrinking lambda, current gnorm 3.704611256068e+16 lambda=1.0000000000000005e-09<br> Line search: Cubic step no good, shrinking lambda, current gnorm 3.704611256068e+16 lambda=1.0000000000000006e-10<br> Line search: Cubic step no good, shrinking lambda, current gnorm 3.704611256068e+16 lambda=1.0000000000000006e-11<br> Line search: Cubic step no good, shrinking lambda, current gnorm 3.704611256068e+16 lambda=1.0000000000000006e-12<br> Line search: Cubic step no good, shrinking lambda, current gnorm 3.704611256068e+16 lambda=1.0000000000000007e-13<br> Line search: unable to find good step length! After 12 tries <br> Line search: fnorm=1.2062892452882465e+01, gnorm=3.7046112560677824e+16, ynorm=1.0000000000000000e+08, minlambda=9.9999999999999998e-13, lambda=1.0000000000000007e-13, initial slope=-4.6079597780656769e+00<br> Nonlinear solve did not converge due to DIVERGED_LINE_SEARCH iterations 0<br><br></div><div>So it is clear that the Jacobian do not match. Moreover, it appears that Newton is not going to converge from this initial guess. It suggests that the residual is wrong somehow. I suggest coding up a MMS to prove to yourself that the residual is correct.</div><div><br></div><div> Thanks,</div><div><br></div><div> Matt</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"><div><div><div style="color:rgb(144,144,144);font-family:"Arial Narrow";font-size:12px"></div></div><div style="font-size:14px;font-family:Verdana;color:rgb(0,0,0)"><div><div style="width:305px;height:35px;line-height:35px;margin:20px 0px 0px"><img src="https://exmail.qq.com/cgi-bin/viewfile?type=logo&domain=mail.sustech.edu.cn"></div><div style="margin:10px 0px 0px"><h4 style="margin:0px;font-size:14px;font-weight:bold;line-height:28px;zoom:1">David Jiawei LUO LIANG</h4><p style="margin:0px;line-height:22px;color:rgb(160,160,160)"></p><p style="margin:0px;line-height:22px;color:rgb(160,160,160)">南方科技大学/学生/研究生/2024</p><p style="margin:0px;line-height:22px;color:rgb(160,160,160)"></p><p style="margin:0px;line-height:22px;color:rgb(160,160,160)">广东省深圳市南山区学苑大道1088号</p></div></div></div><u></u></div><div> </div><div><u></u><u></u></div></blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>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</div><div><br></div><div><a href="https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!bqnXB8rtlhm_qgLy5xeRj_mY4Rqfdgmupvjaqg3sArtduMag3ojG26K4cpDZok4CHJJwjxsl6911GJCZvJG0$" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>