[petsc-users] Is it possible to add a hook function after SNES_DIVERGED_LINEAR_SOLVE

Matthew Knepley knepley at gmail.com
Thu Jan 27 08:32:23 CST 2011


2011/1/27 Gong Ding <gdiso at ustc.edu>

> Hello,
> I sometimes try to use iterative solvers in the SENS.
> However, it may fail to convergence for some difficult problems.
> SNES will report SNES_DIVERGED_LINEAR_SOLVE for this situation.
>
> Is it possible to add a hook function here?
> i.e. I'd like to change the linear solver to LU and solve the
> Newton step again instead of break the nonlinear solver.
>

I believe the complexity is best controlled by changing the linear solver
rather than adding
another generic hook to the nonlinear solver. You can create your own KSP.
It holds a KSP
which you set from options and another which is LU. If the first returns
kspreason < 0, you
solve with the second.

A slightly easier, but more hacky way to do this is to override the
ConvergenceTest for your
current KSP, so that it solves with LU on failure.

    Matt


> Here is the code from ls.c which report the SNES_DIVERGED_LINEAR_SOLVE
>
> if (kspreason < 0) {
>      if (++snes->numLinearSolveFailures >= snes->maxLinearSolveFailures) {
>        ierr = PetscInfo2(snes,"iter=%D, number linear solve failures %D
> greater than current SNES allowed, stopping
> solve\n",snes->iter,snes->numLinearSolveFailures);CHKERRQ(ierr);
>        snes->reason = SNES_DIVERGED_LINEAR_SOLVE;
>        break;
>      }
>    }
> The hook function may be added befour the break.
>
> Regards,
>
> Gong Ding
>
>


-- 
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110127/9629fcea/attachment.htm>


More information about the petsc-users mailing list