You most definitely want to call KSPGetConvergedReason() after every solve
KSPConvergedReason reason .... call KSPSolve(ksp,b,x,ierr) call KSPGetConvergedReason(ksp,reason,ierr) if (reason .lt. 0) then printf*,'KSPSolve() has not converged' return endif > On May 30, 2019, at 5:13 AM, Edoardo alinovi <edoardo.alin...@gmail.com> > wrote: > > Hello Barry, > > I am solving ns eqs using the standard simple algorithm. > > As example let's say the the u velocity compoment diverges, the output of ksp > is a nan as solution vector, but the program keeps going ahead solving also > for the other components and for the pressure where again I get NaN. The only > way to stop it is by hand using ctrl+C. > > I am not using kspConvergedReason, maybe can you provide me an example in > fortran? > > Many thanks as always! > > On Wed, 29 May 2019, 23:54 Smith, Barry F., <bsm...@mcs.anl.gov> wrote: > > > > On May 29, 2019, at 2:54 PM, Edoardo alinovi <edoardo.alin...@gmail.com> > > wrote: > > > > Hello Barry, > > > > Using Matt's fix KSP stops exactly at the first NaN. Otherwise the > > simulation continues > > Yes, but what do you mean by the simulation? Are you calling > KSPGetConvergedReason() after each solve to check if it was valid? Is the > particular linear solver continuing to run with Nan? > > > > > even if everything is a NaN. I am using version 3.10.4, is this not enough > > up to date maybe? > > > > Tomorrow, I will run the monitor and get back to you. For today I have got > > my "safe working limit" :) > > > > Thanks a lot guys for the help! > > > > ------ > > > > Edoardo Alinovi, Ph.D. > > > > DICCA, Scuola Politecnica, > > Universita' degli Studi di Genova, > > 1, via Montallegro, > > 16145 Genova, Italy > > > > Email: edoardo.alin...@dicca.unige.it > > Tel: +39 010 353 2540 > > Website: https://www.edoardoalinovi.com/ > > > > > > > > > > Il giorno mer 29 mag 2019 alle ore 20:22 Smith, Barry F. > > <bsm...@mcs.anl.gov> ha scritto: > > > > Hmm, in the lastest couple of releases of PETSc the KSPSolve is suppose > > to end as soon as it hits a NaN or Infinity. Is that not happening for you? > > If you run with -ksp_monitor does it print multiple lines with Nan or Inf? > > If so please send use the -ksp_view output so we can track down which > > solver is not correctly handling the Nan or Info. > > > > That said if you call KSPSolve() multiple times in a loop or from > > SNESSolve() each new solve may have Nan or Inf (from the previous) but it > > should only do one iteration before exiting. > > > > You should always call KSPGetConvergedReason() after KSPSolve() and > > confirm that the reason is positive, if it is native it indicates something > > failed in the solve. > > > > Barry > > > > > > > On May 29, 2019, at 2:06 AM, Edoardo alinovi via petsc-users > > > <petsc-users@mcs.anl.gov> wrote: > > > > > > Dear PETSc friends, > > > > > > Hope you are doing all well. > > > > > > I have a quick question for you that I am not able to solve by my self. > > > Time to time, while testing new code features, it happens that KSP > > > diverges but it does not stop automatically and the iterations continue > > > even after getting a NaN. > > > > > > In the KSP setup I use the following instruction to set the divergence > > > stopping criteria (div = 10000): > > > > > > call KSPSetTolerances(myksp, rel_tol, abs_tol, div, itmax, ierr) > > > > > > But is does not help. Looking into the documentation I have found also: > > > KSPConvergedDefault(KSP ksp,PetscInt n,PetscReal rnorm,KSPConvergedReason > > > *reason,void *ctx) > > > Which I am not calling in the code. Is this maybe the reason of my > > > problem? If yes how can I use KSPConvergedDefault in FORTRAN? > > > > > > Thanks, > > > > > > Edo > > > > > > ------ > > > > > > Edoardo Alinovi, Ph.D. > > > > > > DICCA, Scuola Politecnica, > > > Universita' degli Studi di Genova, > > > 1, via Montallegro, > > > 16145 Genova, Italy > > > > > > Email: edoardo.alin...@dicca.unige.it > > > Tel: +39 010 353 2540 > > > Website: https://www.edoardoalinovi.com/ > > > > > > > > >