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

2024-11-21 Thread Matthew Knepley
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.206

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

2024-11-21 Thread David Jiawei LUO LIANG
Coincidentally, Matt. I am gonna write the 2d heat dynamic problem.  Now I still not that much understand how DM mesh works. It is a good chance to learn DM by studying your example.  Hope you the best! David Jiawei LUO LIANG 南方科技大学/学生/研究生/2024 广东省深圳市南山区学苑大道1088号       ---

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

2024-11-21 Thread Matthew Knepley
One more suggestion email. I solve the linear version myself in ts/tutorials/ex45.c Thanks, Matt On Thu, Nov 21, 2024 at 10:35 AM Jed Brown wrote: > You should add VecZeroEntries(f) near the top of your FormFunction (it's > currently accumulating into whatever was there last) and MatZer

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

2024-11-21 Thread David Jiawei LUO LIANG
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 南方科技大学/学

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

2024-11-21 Thread David Jiawei LUO LIANG
Hi Matt,     Yes, the residual and Jacobin function are both incorrect.  Both of the Vec f and Mat B haven't initialized as zeros. Jed caught that bug, thanks Jed. Anyway, thank you for your method to debug my program for the next time bug.. Hope you the best! David Jiawei LUO LIAN

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

2024-11-21 Thread David Jiawei LUO LIANG
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:  "Jed Brown"

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

2024-11-21 Thread Barry Smith
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!au7FVXP89CeLcvEPaqyMevQ8XXBThUgOilXB2BskyYlAyPKwckhOPoT_TGVv_IKuZQTSFDRMPe3F09zTuhtno2k$ Next use -snes_test_jacobian - compare the use

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

2024-11-21 Thread Jed Brown
You should add VecZeroEntries(f) near the top of your FormFunction (it's currently accumulating into whatever was there last) and MatZeroEntries(B) to FormJacobian. I reduced to nElem = 5 for ease of viewing. With these changes, I see quadratic convergence but the problem is still nonlinear. To

[petsc-users] Cannot iterate well when using Newton iteration of SNES

2024-11-21 Thread David Jiawei LUO LIANG
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