[petsc-users] Abort SNES Mid-iteration

Hongrui Yu yuhongrui at utexas.edu
Wed Jul 5 20:42:40 CDT 2023


Thanks Barry, this is exactly what I was looking for!

 

Hongrui

 

From: Barry Smith <bsmith at petsc.dev> 
Sent: Wednesday, July 5, 2023 8:23 PM
To: Hongrui Yu <yuhongrui at utexas.edu>
Cc: petsc-users at mcs.anl.gov
Subject: Re: [petsc-users] Abort SNES Mid-iteration

 

 

   I assume you want to stop the SNES solve, but you do not want the program to end immediately? Instead, you want SNESSolve() to end immediately with a very useful message?

 

    This is done with https://petsc.org/release/manualpages/SNES/SNESSetFunctionDomainError/#snessetfunctiondomainerror or https://petsc.org/release/manualpages/SNES/SNESSetJacobianDomainError/#snessetjacobiandomainerror

 

    In conjunction with using this, you must call https://petsc.org/release/manualpages/SNES/SNESGetConvergedReason/#snesgetconvergedreason immediately after each SNESSolve() and check if the reason is negative. The specific values   <https://petsc.org/release/manualpages/SNES/SNESConvergedReason/> SNES_DIVERGED_FUNCTION_DOMAIN will be set if you had called SNESSetFunctionDomainError() and  <https://petsc.org/release/manualpages/SNES/SNESConvergedReason/> SNES_DIVERGED_JACOBIAN_DOMAIN will be set if you had called SNESSetJacobianDomainError().





   Also take a look at the Note in https://petsc.org/release/manualpages/SNES/SNESSetFunctionDomainError/#snessetfunctiondomainerror. This provides two alternatives to simply giving up on the nonlinear solve but provides ways to either bound the tentative solutions into their physical regime or to "nudge" the tentative solutions back into their physical regime.

 

   PETSc errors are hard, meaning when one is encountered the program ends! Thus one cannot use the error handler infrastructure to recover from errors, even user created errors; that is why we provide the SNES domain "error" mechanism since it does not involve the PETSc error handlers.

 

   Good luck.









On Jul 5, 2023, at 8:54 PM, Hongrui Yu <yuhongrui at utexas.edu <mailto:yuhongrui at utexas.edu> > wrote:

 

Hello PETSc users,

 

I’d like to use the error handling mechanism to abort SNES mid-iteration if certain quantities become nonphysical by calling SETERRQ() inside FormFunction() or FormJacobian(). I’m wondering if users can define their own error handler routines to use with PetscPushErrorHandler() and PetscPopErrorHandler()? I’m also open to any suggestion on better ways to quit SNES mid-iteration.

 

Thanks in advance for any help or advice!

 

Hongrui

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20230705/258460fc/attachment.html>


More information about the petsc-users mailing list