<div dir="ltr"><div dir="ltr">On Fri, Feb 25, 2022 at 11:06 AM Giovane Avancini via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>> wrote:<br></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 dir="ltr">Dear PETSc users,<div><br></div><div>I'm working on an inhouse code that solves the Navier-Stokes equation in a Lagrangian fashion for free surface flows. Because of the large distortions and pressure gradients, it is quite common to encounter some issues with iterative solvers for some time steps, and because of that, I implemented a function that changes the solver type based on the flag KSPConvergedReason. If this flag is negative after a call to KSPSolve, I solve the same linear system again using a direct method.</div><div><br></div><div>The problem is that, sometimes, KSP keeps converging even though the residual is NaN, and because of that, I'm not able to identify the problem and change the solver, which leads to a solution vector equals to INF and obviously the code ends up crashing. Is it normal to observe this kind of behaviour?</div><div><br></div><div>Please find attached the log produced with the options -ksp_monitor_lg_residualnorm -ksp_log -ksp_view -ksp_monitor_true_residual -ksp_converged_reason and the function that changes the solver. I'm currently using FGMRES and BJACOBI preconditioner with LU for each block. The problem still happens with ILU for example. We can see in the log file that for the time step 921, the true residual is NaN and within just one iteration, the solver fails and it gives the reason DIVERGED_PC_FAILED. I simply changed the solver to MUMPS and it converged for that time step. However, when solving time step 922 we can see that FGMRES converges while the true residual is NaN. Why is that possible? I would appreciate it if someone could clarify this issue to me.</div></div></blockquote><div><br></div><div>We check for NaN or Inf, for example, in KSPCheckDot(). if you have the KSP set to error (<a href="https://petsc.org/main/docs/manualpages/KSP/KSPSetErrorIfNotConverged.html">https://petsc.org/main/docs/manualpages/KSP/KSPSetErrorIfNotConverged.html</a>)</div><div>then we throw an error, but the return codes do not seem to be checked in your implementation. If not, then we set the flag for divergence.</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>Kind regards,</div><div>Giovane</div><div><br></div><div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><font size="1" face="tahoma, sans-serif">Giovane Avancini</font><div><font size="1" face="tahoma, sans-serif">Doutorando em Engenharia de Estruturas - Escola de Engenharia de São Carlos, USP</font></div><div><font size="1" face="tahoma, sans-serif"><br></font></div><div><font size="1" face="tahoma, sans-serif">PhD researcher in Structural Engineering - School of Engineering of São Carlos. USP</font></div></div></div></div></div></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <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="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>