<div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Thank you very much for your answer.</div><div>I tried to use the quasi-Newton method to solve some examples, except ex48(in src/snes/example/tutorial), the ex3 and the ex19 will produce the same error information. The error information is as follows. Is there anything I should pay attention to when using the quasi-Newton method?</div><div>args:<font size="2"> -snes_type qn -snes_qn_restart_type periodic -snes_qn_scale_type jacobian</font></div><div><font size="2"><br></font></div><div><font size="2">In ex3, it has a routine about Jacobian, while in ex19 without a Jacobian routine. <br></font></div><div><font size="2">Is the quasi-Newton method use the inverse of the initial Jacobian matrix by finite difference ?</font></div><div><font size="2"><br></font></div><div><font size="2">Error information in ex3:<br></font></div><div><div style="margin-left:40px"><font size="1">mpiexec -n 2 ./ex3 -snes_type qn -snes_qn_restart_type periodic -snes_qn_scale_type jacobian -snes_view <br>atol=1e-50, rtol=1e-08, stol=1e-08, maxit=10000, maxf=30000<br>iter = 0,SNES Function norm 5.41468<br>iter = 1,SNES Function norm 0.806152<br>iter = 2,SNES Function norm 0.459274<br>iter = 3,SNES Function norm 0.0562937<br>iter = 4,SNES Function norm 0.00756409<br>iter = 5,SNES Function norm 0.00153315<br>iter = 6,SNES Function norm 0.000108099<br>iter = 7,SNES Function norm 2.77778e-06<br>iter = 8,SNES Function norm 5.56429e-08<br>iter = 9,SNES Function norm 5.56429e-08<br>[0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------<br>[0]PETSC ERROR: Floating point exception<br>[0]PETSC ERROR: Vec entry at local location 0 is not-a-number or infinite at beginning of function: Parameter number 2<br>[0]PETSC ERROR: See <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html">http://www.mcs.anl.gov/petsc/documentation/faq.html</a> for trouble shooting.<br>[0]PETSC ERROR: Petsc Release Version 3.10.1, Sep, 26, 2018 <br>[0]PETSC ERROR: ./ex3 on a arch-linux2-c-debug named yjwu-XPS-8910 by yjwu Fri Jan 4 09:11:00 2019<br>[0]PETSC ERROR: Configure options --with-cc=gcc --with-cxx=g++ --with-fc=gfortran --download-mpich --download-fblaslapack<br>[0]PETSC ERROR: #1 VecValidValues() line 26 in /home/yjwu/petsc-3.10.1/src/vec/vec/interface/rvector.c<br>[0]PETSC ERROR: #2 SNESComputeFunction() line 2234 in /home/yjwu/petsc-3.10.1/src/snes/interface/snes.c<br>[1]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------<br>[1]PETSC ERROR: Floating point exception<br>[1]PETSC ERROR: Vec entry at local location 0 is not-a-number or infinite at beginning of function: Parameter number 2<br>[1]PETSC ERROR: See <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html">http://www.mcs.anl.gov/petsc/documentation/faq.html</a> for trouble shooting.<br>[1]PETSC ERROR: Petsc Release Version 3.10.1, Sep, 26, 2018 <br>[1]PETSC ERROR: ./ex3 on a arch-linux2-c-debug named yjwu-XPS-8910 by yjwu Fri Jan 4 09:11:00 2019<br>[1]PETSC ERROR: Configure options --with-cc=gcc --with-cxx=g++ --with-fc=gfortran --download-mpich --download-fblaslapack<br>[1]PETSC ERROR: #1 VecValidValues() line 26 in /home/yjwu/petsc-3.10.1/src/vec/vec/interface/rvector.c<br>[1]PETSC ERROR: #2 SNESComputeFunction() line 2234 in /home/yjwu/petsc-3.10.1/src/snes/interface/snes.c<br>[1]PETSC ERROR: #3 SNESLineSearchApply_CP() line 48 in /home/yjwu/petsc-3.10.1/src/snes/linesearch/impls/cp/linesearchcp.c<br>[1]PETSC ERROR: #4 SNESLineSearchApply() line 648 in /home/yjwu/petsc-3.10.1/src/snes/linesearch/interface/linesearch.c<br>[0]PETSC ERROR: #3 SNESLineSearchApply_CP() line 48 in /home/yjwu/petsc-3.10.1/src/snes/linesearch/impls/cp/linesearchcp.c<br>[0]PETSC ERROR: #4 SNESLineSearchApply() line 648 in /home/yjwu/petsc-3.10.1/src/snes/linesearch/interface/linesearch.c<br>[0]PETSC ERROR: #5 SNESSolve_QN() line 403 in /home/yjwu/petsc-3.10.1/src/snes/impls/qn/qn.c<br>[0]PETSC ERROR: [1]PETSC ERROR: #5 SNESSolve_QN() line 403 in /home/yjwu/petsc-3.10.1/src/snes/impls/qn/qn.c<br>[1]PETSC ERROR: #6 SNESSolve() line 4396 in /home/yjwu/petsc-3.10.1/src/snes/interface/snes.c<br>#6 SNESSolve() line 4396 in /home/yjwu/petsc-3.10.1/src/snes/interface/snes.c<br>[0]PETSC ERROR: [1]PETSC ERROR: #7 main() line 277 in /home/yjwu/petsc-3.10.1/src/snes/examples/tutorials/ex3.c<br>#7 main() line 277 in /home/yjwu/petsc-3.10.1/src/snes/examples/tutorials/ex3.c<br>[0]PETSC ERROR: PETSc Option Table entries:<br>[1]PETSC ERROR: PETSc Option Table entries:<br>[1]PETSC ERROR: [0]PETSC ERROR: -snes_qn_restart_type periodic<br>[0]PETSC ERROR: -snes_qn_restart_type periodic<br>[1]PETSC ERROR: -snes_qn_scale_type jacobian<br>[1]PETSC ERROR: -snes_qn_scale_type jacobian<br>[0]PETSC ERROR: -snes_type qn<br>[0]PETSC ERROR: -snes_type qn<br>[1]PETSC ERROR: -snes_view<br>-snes_view<br>[0]PETSC ERROR: ----------------End of Error Message -------send entire error message to petsc-maint@mcs.anl.gov----------<br>[1]PETSC ERROR: ----------------End of Error Message -------send entire error message to petsc-maint@mcs.anl.gov----------<br>application called MPI_Abort(MPI_COMM_WORLD, 72) - process 0<br>application called MPI_Abort(MPI_COMM_WORLD, 72) - process 1</font></div></div><div><br></div><div><font size="2">Error information in ex19</font></div><div><div style="margin-left:40px"> <font size="1">mpiexec -n 2 ./ex19 -snes_type qn -snes_qn_restart_type periodic -snes_qn_scale_type jacobian -snes_view </font><br><font size="1">lid velocity = 0.0625, prandtl # = 1., grashof # = 1.</font><br><font size="1">[0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------</font><br><font size="1">[0]PETSC ERROR: Floating point exception</font><br><font size="1">[0]PETSC ERROR: Vec entry at local location 0 is not-a-number or infinite at beginning of function: Parameter number 2</font><br><font size="1">[0]PETSC ERROR: See <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html">http://www.mcs.anl.gov/petsc/documentation/faq.html</a> for trouble shooting.</font><br><font size="1">[0]PETSC ERROR: Petsc Release Version 3.10.1, Sep, 26, 2018 </font><br><font size="1">[0]PETSC ERROR: ./ex19 on a arch-linux2-c-debug named yjwu-XPS-8910 by yjwu Fri Jan 4 09:05:10 2019</font><br><font size="1">[1]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------</font><br><font size="1">[1]PETSC ERROR: Floating point exception</font><br><font size="1">[1]PETSC ERROR: Vec entry at local location 0 is not-a-number or infinite at beginning of function: Parameter number 2</font><br><font size="1">[1]PETSC ERROR: See <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html">http://www.mcs.anl.gov/petsc/documentation/faq.html</a> for trouble shooting.</font><br><font size="1">[1]PETSC ERROR: Petsc Release Version 3.10.1, Sep, 26, 2018 </font><br><font size="1">[1]PETSC ERROR: ./ex19 on a arch-linux2-c-debug named yjwu-XPS-8910 by yjwu Fri Jan 4 09:05:10 2019</font><br><font size="1">[1]PETSC ERROR: Configure options --with-cc=gcc --with-cxx=g++ --with-fc=gfortran --download-mpich --download-fblaslapack</font><br><font size="1">[1]PETSC ERROR: #1 VecValidValues() line 26 in /home/yjwu/petsc-3.10.1/src/vec/vec/interface/rvector.c</font><br><font size="1">[1]PETSC ERROR: [0]PETSC ERROR: Configure options --with-cc=gcc --with-cxx=g++ --with-fc=gfortran --download-mpich --download-fblaslapack</font><br><font size="1">[0]PETSC ERROR: #1 VecValidValues() line 26 in /home/yjwu/petsc-3.10.1/src/vec/vec/interface/rvector.c</font><br><font size="1">[0]PETSC ERROR: #2 SNESComputeFunction() line 2234 in /home/yjwu/petsc-3.10.1/src/snes/interface/snes.c</font><br><font size="1">[0]PETSC ERROR: #3 SNESLineSearchApply_CP() line 48 in /home/yjwu/petsc-3.10.1/src/snes/linesearch/impls/cp/linesearchcp.c</font><br><font size="1">[0]PETSC ERROR: #2 SNESComputeFunction() line 2234 in /home/yjwu/petsc-3.10.1/src/snes/interface/snes.c</font><br><font size="1">[1]PETSC ERROR: #3 SNESLineSearchApply_CP() line 48 in /home/yjwu/petsc-3.10.1/src/snes/linesearch/impls/cp/linesearchcp.c</font><br><font size="1">[1]PETSC ERROR: #4 SNESLineSearchApply() line 648 in /home/yjwu/petsc-3.10.1/src/snes/linesearch/interface/linesearch.c</font><br><font size="1">[1]PETSC ERROR: #4 SNESLineSearchApply() line 648 in /home/yjwu/petsc-3.10.1/src/snes/linesearch/interface/linesearch.c</font><br><font size="1">[0]PETSC ERROR: #5 SNESSolve_QN() line 403 in /home/yjwu/petsc-3.10.1/src/snes/impls/qn/qn.c</font><br><font size="1">[0]PETSC ERROR: #5 SNESSolve_QN() line 403 in /home/yjwu/petsc-3.10.1/src/snes/impls/qn/qn.c</font><br><font size="1">[1]PETSC ERROR: #6 SNESSolve() line 4396 in /home/yjwu/petsc-3.10.1/src/snes/interface/snes.c</font><br><font size="1">[1]PETSC ERROR: #7 main() line 161 in /home/yjwu/petsc-3.10.1/src/snes/examples/tutorials/ex19.c</font><br><font size="1">#6 SNESSolve() line 4396 in /home/yjwu/petsc-3.10.1/src/snes/interface/snes.c</font><br><font size="1">[0]PETSC ERROR: #7 main() line 161 in /home/yjwu/petsc-3.10.1/src/snes/examples/tutorials/ex19.c</font><br><font size="1">[0]PETSC ERROR: PETSc Option Table entries:</font><br><font size="1">[1]PETSC ERROR: PETSc Option Table entries:</font><br><font size="1">[1]PETSC ERROR: -snes_qn_restart_type periodic</font><br><font size="1">[0]PETSC ERROR: -snes_qn_restart_type periodic</font><br><font size="1">[0]PETSC ERROR: -snes_qn_scale_type jacobian</font><br><font size="1">[0]PETSC ERROR: -snes_type qn</font><br><font size="1">[1]PETSC ERROR: -snes_qn_scale_type jacobian</font><br><font size="1">[1]PETSC ERROR: -snes_type qn</font><br><font size="1">[0]PETSC ERROR: -snes_view</font><br><font size="1">[0]PETSC ERROR: ----------------End of Error Message -------send entire error message to petsc-maint@mcs.anl.gov----------</font><br><font size="1">[1]PETSC ERROR: -snes_view</font><br><font size="1">[1]PETSC ERROR: ----------------End of Error Message -------send entire error message to petsc-maint@mcs.anl.gov----------</font><br><font size="1">application called MPI_Abort(MPI_COMM_WORLD, 72) - process 0</font><br><font size="1">application called MPI_Abort(MPI_COMM_WORLD, 72) - process 1</font></div><br></div><div>I am very interested in quasi-Newton method, which may not be well understood at the moment.</div><div>I look forward to your reply.</div><div><br></div><div>Thanks,</div><div>Yingjie<br></div><div><font size="2"><br></font></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">Matthew Knepley <<a href="mailto:knepley@gmail.com">knepley@gmail.com</a>> 于2019年1月3日周四 上午8:36写道:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Thu, Jan 3, 2019 at 7:36 AM Yingjie Wu via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Thanks for your reply.</div><div>I read the article you provided. This is my first contact with the quasi-Newton method.</div><div>I have some problem:</div><div>1. From the point of view of algorithm, the quasi-Newton method does not need to be solved by linear equations, so why would KSP be used?</div><div></div></div></blockquote><div><br></div><div>It is solving the equations, but we know the analytical answer. KSP is our abstraction for linear equation solver,</div><div>so we also use it in this case.</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 dir="ltr"><div>2. Where and how to use preconditioner in quasi-Newton method? </div></div></blockquote><div><br></div><div>You do not need a PC here. Note that this is only going to work well if you have a good initial</div><div>guess for the inverse of your Jacobian. The optimization people who invented have that (it is</div><div>the identity). In Jed's paper, they use a V-cycle as the good initial guess.</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 dir="ltr"><div>Thanks,</div><div>Yingjie<br></div></div><br><div class="gmail_quote"><div dir="ltr">Jed Brown <<a href="mailto:jed@jedbrown.org" target="_blank">jed@jedbrown.org</a>> 于2018年12月27日周四 上午10:11写道:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Yingjie Wu via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>> writes:<br>
<br>
> I my opinion, the difficulty in constructing my Jacobian matrix is complex<br>
> coefficient.(eg, thermal conductivity* λ* , density )<br>
> For example, in temperature equation(T):<br>
> ∇(*λ*∇T) - ∇(ρ* Cp* u ) + Q = 0<br>
> *λ* is thermal conductivity , ρ* is density Cp* is specific heat , u is<br>
> velocity, Q is source.<br>
> *λ = *1.9*(1.0e-3)*pow(T+273.0-150.0,1.29) function of T<br>
> ρ=<br>
> (0.4814*P/1.0e3/(T+273.15))/(1.0+0.446*(1.0e-2)*P/1.0e3/(pow(T+273.15,1.2)))<br>
> function of T and P<br>
><br>
> In theory, the coefficient contain variable. So it is complicated to<br>
> calculate the element of Jacobian.<br>
> In my snes_mf_operator method, I treat λ,ρ as constant. In every nonlinear<br>
> step, I use the solution update the λ,ρ and thus update the<br>
> preconditioning matrix. At each residual function call(in<br>
> SNESFormFunction), I also update the coefficient to ensure the correction<br>
> of the residual function.<br>
<br>
If those Jacobian entries are really that hard to get right, you can try<br>
using quasi-Newton as an alternative to -snes_mf_operator; similar to<br>
<br>
<a href="https://jedbrown.org/files/BrownBrune-LowRankQuasiNewtonRobustJacobianLagging-2013.pdf" rel="noreferrer" target="_blank">https://jedbrown.org/files/BrownBrune-LowRankQuasiNewtonRobustJacobianLagging-2013.pdf</a><br>
<br>
<br>
In general, I would start with an exact Jacobian (computed by coloring,<br>
AD, or just in one specific material/configuration). Test Newton using<br>
direct solvers to see your "best case" convergence (globalization may be<br>
needed). Test fieldsplit using direct solvers on the blocks so you know<br>
how much error is attributable to that approximation. Only then look at<br>
backing off on the approximation of the Jacobian and the preconditioner.<br>
</blockquote></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail-m_3997598157145034162gmail_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="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>
</blockquote></div>