[petsc-users] [KSP] PETSc not reporting a KSP fail when true residual is NaN

Matthew Knepley knepley at gmail.com
Fri Feb 25 10:37:14 CST 2022


On Fri, Feb 25, 2022 at 11:06 AM Giovane Avancini via petsc-users <
petsc-users at mcs.anl.gov> wrote:

> Dear PETSc users,
>
> 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.
>
> 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?
>
> 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.
>

We check for NaN or Inf, for example, in KSPCheckDot(). if you have the KSP
set to error (
https://petsc.org/main/docs/manualpages/KSP/KSPSetErrorIfNotConverged.html)
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.

  Thanks,

     Matt


> Kind regards,
> Giovane
>
>
>
> --
> Giovane Avancini
> Doutorando em Engenharia de Estruturas - Escola de Engenharia de São
> Carlos, USP
>
> PhD researcher in Structural Engineering - School of Engineering of São
> Carlos. USP
>


-- 
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://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20220225/8534c27e/attachment.html>


More information about the petsc-users mailing list