[petsc-users] SNESSetFunctionDomainError

Barry Smith bsmith at mcs.anl.gov
Sun Aug 24 21:40:53 CDT 2014


On Aug 24, 2014, at 9:06 PM, Derek Gaston <friedmud at gmail.com> wrote:

> There must be something I'm missing about SNESSetFunctionDomainError().
> 
> I'm using a matrix free newton solve and I was hoping that calling SNESSetFunctionDomainError() would completely stop the nonlinear solver... but that doesn't appear to be the case.
> 
> Now - if I call that function during the initial residual computation it appears to work (the solve never starts).  However, if I call it during the _middle_ of a matrix free nonlinear solve during a residual calculation - it appears to do absolutely nothing.

   You are not missing anything. The way SNESSetFunctionDomainError() works is it merely sets a flag in the SNES object. The solver code then can check that flag after a function evaluation and generate an if that flag is set (or perhaps do some kind of recovery). So, for example, at the beginning of SNESSolve_NewtonLS() we have 

 } else {
    if (!snes->vec_func_init_set) {
      ierr = SNESComputeFunction(snes,X,F);CHKERRQ(ierr);
      ierr = SNESGetFunctionDomainError(snes, &domainerror);CHKERRQ(ierr);
      if (domainerror) {
        snes->reason = SNES_DIVERGED_FUNCTION_DOMAIN;
        PetscFunctionReturn(0);

Now the reason it is not erroring out for you is because

1) our MatMult_MFFD() totally ignores the SNES domain error business because it doesn’t even know about SNES

2) inside the various nonlinear solvers and many complicated line search codes we may not always be checking the domainerror flag.

  Both of these things, of course, should be fixed. We need to add support to the MatMult_MFFD() to indicate domain errors and we need to check all the code to make sure we always handle the domain error flag.

  Barry


> 
> Here's my stupid debugging code that's at the top of my residual callback method:
> 
>     static int count = 0;
>     count++;
> 
>     if (count == 5)
>     {
>       std::cout<<"stopping solve!"<<std::endl;
>       SNESSetFunctionDomainError(snes);
>     }
> 
> 
> During the solve "stopping solve!" gets printed out after computing the 3rd linear iteration of the first newton step... but the solve just continues without stopping...
> 
> Is there something more I need to do here?
> 
> Thanks!
> 
> Derek 



More information about the petsc-users mailing list