Thanks Barry, with -snes_qn_m 0 it gives exact convergence as -snes_type newtonls -snes_linesearch_type basic
Giang On Tue, May 25, 2021 at 10:51 PM Barry Smith <[email protected]> wrote: > > Yes, with your options I would expect the first SNES iteration of QN to > produce the same result as the first iteration of SNES Newton ls. > > I have fixed an error that crept (well actually I put it there) in where > KSPSetFromOptions() was not being called with the QN and Jacobian option, > hence only the default PC (ilu) was being used so if you changed the PC it > only affected Newton not QN. I also made it possible to run with a history > of length 0 so that with the Jacobian option it should exactly match Newton > for all iterations. > > You can access my fixes with > > get fetch > git checkout barry/2021-05-25/fix-qn-jacobian-setfromoptions/release > > The merge request with the fixes for release is here > https://gitlab.com/petsc/petsc/-/merge_requests/4018 > > I checked it with the runs below. Using first -pc_type lu then the > default PC. > > ~/Src/petsc/src/snes/tutorials* > (barry/2021-05-25/fix-qn-jacobian-setfromoptions/release *=)* > arch-fix-qn-jacobian-setfromoptions > $ ./ex19 -pc_type lu -snes_monitor -snes_type qn -snes_qn_type lbfgs > -snes_qn_m 0 -snes_qn_restart_type periodic -snes_qn_scale_type jacobian > -snes_linesearch_type basic > lid velocity = 0.0625, prandtl # = 1., grashof # = 1. > 0 SNES Function norm 2.391552133017e-01 > 1 SNES Function norm 6.819684624592e-05 > 2 SNES Function norm 4.203401869625e-12 > Number of SNES iterations = 2 > ~/Src/petsc/src/snes/tutorials* > (barry/2021-05-25/fix-qn-jacobian-setfromoptions/release *=)* > arch-fix-qn-jacobian-setfromoptions > $ ./ex19 -pc_type lu -snes_monitor -snes_linesearch_type basic > lid velocity = 0.0625, prandtl # = 1., grashof # = 1. > 0 SNES Function norm 2.391552133017e-01 > 1 SNES Function norm 6.819684624592e-05 > 2 SNES Function norm 4.203401869625e-12 > Number of SNES iterations = 2 > ~/Src/petsc/src/snes/tutorials* > (barry/2021-05-25/fix-qn-jacobian-setfromoptions/release *=)* > arch-fix-qn-jacobian-setfromoptions > $ ./ex19 -snes_monitor -snes_linesearch_type basic > lid velocity = 0.0625, prandtl # = 1., grashof # = 1. > 0 SNES Function norm 2.391552133017e-01 > 1 SNES Function norm 6.839858507066e-05 > 2 SNES Function norm 8.558777232425e-11 > Number of SNES iterations = 2 > ~/Src/petsc/src/snes/tutorials* > (barry/2021-05-25/fix-qn-jacobian-setfromoptions/release *=)* > arch-fix-qn-jacobian-setfromoptions > $ ./ex19 -snes_monitor -snes_type qn -snes_qn_type lbfgs -snes_qn_m 0 > -snes_qn_restart_type periodic -snes_qn_scale_type jacobian > -snes_linesearch_type basic > lid velocity = 0.0625, prandtl # = 1., grashof # = 1. > 0 SNES Function norm 2.391552133017e-01 > 1 SNES Function norm 6.839858507066e-05 > 2 SNES Function norm 8.558777232425e-11 > Number of SNES iterations = 2 > ~/Src/petsc/src/snes/tutorials* > (barry/2021-05-25/fix-qn-jacobian-setfromoptions/release *=)* > arch-fix-qn-jacobian-setfromoptions > $ ./ex19 -snes_monitor -snes_type qn -snes_qn_type lbfgs -snes_qn_m 1 > -snes_qn_restart_type periodic -snes_qn_scale_type jacobian > -snes_linesearch_type basic > lid velocity = 0.0625, prandtl # = 1., grashof # = 1. > 0 SNES Function norm 2.391552133017e-01 > 1 SNES Function norm 6.839858507066e-05 > 2 SNES Function norm 1.977614824765e-05 > 3 SNES Function norm 1.286952209377e-10 > Number of SNES iterations = 3 > > If you still have trouble with the branch you can run with -ksp_monitor > -snes_linesearch_monitor -info -snes_view to see what may be different with > your runs with Newton and with QN. > > Barry > > > > On May 25, 2021, at 12:15 PM, hg <[email protected]> wrote: > > Hello > > I would expect the setting below would give the same behaviour like > -snes_type newtonls -snes_linesearch_type basic: > > -snes_type qn > -snes_qn_type lbfgs > -snes_qn_m 1 > -snes_qn_restart_type periodic > -snes_qn_scale_type jacobian > -snes_linesearch_type basic > > But it's not, below is the convergence log: > entering BuildRHS > 0 SNES Function norm 7.450427214612e+03 > entering BuildLHS > entering BuildRHS > 1 SNES Function norm 7.902262148182e+03 > entering BuildRHS > 2 SNES Function norm 8.426417730274e+03 > Periodic restart! i_r = 1 > entering BuildLHS > entering BuildRHS > 3 SNES Function norm 5.571513092130e+04 > entering BuildRHS > 4 SNES Function norm 4.019723509872e+05 > Periodic restart! i_r = 1 > entering BuildLHS > entering BuildRHS > 5 SNES Function norm 9.259722791615e+05 > entering BuildRHS > 6 SNES Function norm 3.985884724278e+08 > Nonlinear solve did not converge due to DIVERGED_DTOL iterations 6 > > For -snes_type newtonls -snes_linesearch_type basic: > > entering BuildRHS > 0 SNES Function norm 7.450427214612e+03 > entering BuildLHS > entering BuildRHS > 1 SNES Function norm 1.937109245338e+01 > entering BuildLHS > entering BuildRHS > 2 SNES Function norm 8.126736406257e-01 > entering BuildLHS > entering BuildRHS > 3 SNES Function norm 1.143237968970e-03 > entering BuildLHS > entering BuildRHS > 4 SNES Function norm 2.706184329411e-09 > Nonlinear solve converged due to CONVERGED_FNORM_RELATIVE iterations 4 > > Would it be the parameters not the same? My idea is first starting with a > good configuration of lbfgs then increase the restart (m) to see how the > convergence going (and save time). > > Thanks > Giang > > >
