On Thu, Nov 21, 2024 at 8:57 AM David Jiawei LUO LIANG < 12431...@mail.sustech.edu.cn> 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 > > 0 SNES Function norm 1.206289245288e+01 > > 1 SNES Function norm 7.128802192789e+00 > > 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. > Here is what happens with the code as it is: master *:~/Downloads/tmp/Liang$ ./SNES_heat -snes_monitor -ksp_converged_reason -snes_converged_reason -pc_type lu -snes_view -snes_linesearch_monitor pp 1 nElem 10 nqp 2 n_np 11 n_en 2 n_eq 10 qp: 0.57735 -0.57735 wq: 1 1 IEN: 1 2 3 4 5 6 7 8 9 10 2 3 4 5 6 7 8 9 10 11 x_coor: 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 ID: 1 2 3 4 5 6 7 8 9 10 0 0 SNES Function norm 1.206289245288e+01 Linear solve converged due to CONVERGED_RTOL iterations 1 Line search: Using full step: fnorm 1.206289245288e+01 gnorm 7.128802192789e+00 1 SNES Function norm 7.128802192789e+00 Linear solve converged due to CONVERGED_RTOL iterations 1 Line search: Using full step: fnorm 7.128802192789e+00 gnorm 6.608812909525e+00 2 SNES Function norm 6.608812909525e+00 Linear solve converged due to CONVERGED_RTOL iterations 1 Line search: gnorm after quadratic fit 1.265375106867e+01 Line search: Cubic step no good, shrinking lambda, current gnorm 1.328962011911e+01 lambda=1.7500506382162818e-02 Line search: Cubic step no good, shrinking lambda, current gnorm 1.275802797864e+01 lambda=1.7500506382162819e-03 Line search: Cubic step no good, shrinking lambda, current gnorm 1.327920917220e+01 lambda=1.7500506382162821e-04 Line search: Cubic step no good, shrinking lambda, current gnorm 1.275906891232e+01 lambda=1.7500506382162820e-05 Line search: Cubic step no good, shrinking lambda, current gnorm 1.327910508109e+01 lambda=1.7500506382162821e-06 Line search: Cubic step no good, shrinking lambda, current gnorm 1.275907932147e+01 lambda=1.7500506382162822e-07 Line search: Cubic step no good, shrinking lambda, current gnorm 1.327910404018e+01 lambda=1.7500506382162823e-08 Line search: Cubic step no good, shrinking lambda, current gnorm 1.275907942556e+01 lambda=1.7500506382162823e-09 Line search: Cubic step no good, shrinking lambda, current gnorm 1.327910402977e+01 lambda=1.7500506382162824e-10 Line search: Cubic step no good, shrinking lambda, current gnorm 1.275907942660e+01 lambda=1.7500506382162825e-11 Line search: Cubic step no good, shrinking lambda, current gnorm 1.327910402966e+01 lambda=1.7500506382162826e-12 Line search: Cubic step no good, shrinking lambda, current gnorm 1.275907942661e+01 lambda=1.7500506382162828e-13 Line search: unable to find good step length! After 12 tries 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 Nonlinear solve did not converge due to DIVERGED_LINE_SEARCH iterations 2 Usually, we suspect that the Jacobian is incorrect in this case. Thus we can have it formed automatically, master *:~/Downloads/tmp/Liang$ ./SNES_heat -snes_monitor -ksp_converged_reason -snes_converged_reason -snes_fd -pc_type lu -snes_view -snes_linesearch_monitor pp 1 nElem 10 nqp 2 n_np 11 n_en 2 n_eq 10 qp: 0.57735 -0.57735 wq: 1 1 IEN: 1 2 3 4 5 6 7 8 9 10 2 3 4 5 6 7 8 9 10 11 x_coor: 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 ID: 1 2 3 4 5 6 7 8 9 10 0 0 SNES Function norm 1.206289245288e+01 Linear solve converged due to CONVERGED_RTOL iterations 1 Line search: Scaling step by 1.837216392007e-47 old ynorm 5.443016970405e+54 Line search: gnorm after quadratic fit 3.704240795372e+16 Line search: Cubic step no good, shrinking lambda, current gnorm 3.704614960636e+16 lambda=1.0000000000000002e-02 Line search: Cubic step no good, shrinking lambda, current gnorm 3.704611219026e+16 lambda=1.0000000000000002e-03 Line search: Cubic step no good, shrinking lambda, current gnorm 3.704611256438e+16 lambda=1.0000000000000003e-04 Line search: Cubic step no good, shrinking lambda, current gnorm 3.704611256064e+16 lambda=1.0000000000000004e-05 Line search: Cubic step no good, shrinking lambda, current gnorm 3.704611256068e+16 lambda=1.0000000000000004e-06 Line search: Cubic step no good, shrinking lambda, current gnorm 3.704611256068e+16 lambda=1.0000000000000005e-07 Line search: Cubic step no good, shrinking lambda, current gnorm 3.704611256068e+16 lambda=1.0000000000000005e-08 Line search: Cubic step no good, shrinking lambda, current gnorm 3.704611256068e+16 lambda=1.0000000000000005e-09 Line search: Cubic step no good, shrinking lambda, current gnorm 3.704611256068e+16 lambda=1.0000000000000006e-10 Line search: Cubic step no good, shrinking lambda, current gnorm 3.704611256068e+16 lambda=1.0000000000000006e-11 Line search: Cubic step no good, shrinking lambda, current gnorm 3.704611256068e+16 lambda=1.0000000000000006e-12 Line search: Cubic step no good, shrinking lambda, current gnorm 3.704611256068e+16 lambda=1.0000000000000007e-13 Line search: unable to find good step length! After 12 tries 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 Nonlinear solve did not converge due to DIVERGED_LINE_SEARCH iterations 0 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. Thanks, Matt > David Jiawei LUO LIANG > > 南方科技大学/学生/研究生/2024 > > 广东省深圳市南山区学苑大道1088号 > > -- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!bqnXB8rtlhm_qgLy5xeRj_mY4Rqfdgmupvjaqg3sArtduMag3ojG26K4cpDZok4CHJJwjxsl6911GOeurhJ1$ <https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!bqnXB8rtlhm_qgLy5xeRj_mY4Rqfdgmupvjaqg3sArtduMag3ojG26K4cpDZok4CHJJwjxsl6911GJCZvJG0$ >