[petsc-users] Unable to use SNESSetConvergenceTest()

Matthew Knepley knepley at gmail.com
Mon Dec 26 07:22:53 CST 2011


I notice you do not have a corect return value below.

  Matt

On Mon, Dec 26, 2011 at 6:03 AM, behzad baghapour <
behzad.baghapour at gmail.com> wrote:

> Dear Developers,
>
> I need to change "rtol" manually  for each KSP linear solver in each SNES
> iteration (some sort of inexact Newton method).
>
> I decided to use SNESSetConvergenceTest() as bellow:
>
> in main code:
>
> ierr = SNESSetConvergenceTest( snes, SNESConvTest, PETSC_NULL, PETSC_NULL
> ); CHKERRQ( ierr );
>
> in convergence function:
>
> PetscErrorCode SNESConvTest( SNES snes, PetscInt it, PetscReal xn,
> PetscReal pn, PetscReal fn, SNESConvergedReason* res, void* ctx)
> {
>     KSP ksp2;
>     PetscReal rtol, atol;
>     SNESGetKSP ( snes, &ksp2 );
>     KSPGetTolerances  ( ksp2, &rtol, PETSC_NULL, PETSC_NULL, PETSC_NULL );
>     SNESGetTolerances ( snes, &atol, PETSC_NULL, PETSC_NULL, PETSC_NULL,
> PETSC_NULL );
>     if( fn > 1e-3 ){
>         rtol = 0.01;
>     }else{
>         rtol = 1e-5;
>     }
>     KSPSetTolerances( ksp2, rtol, PETSC_NULL, PETSC_NULL, PETSC_NULL );
>     if( fn < atol ){
>         *res = SNES_CONVERGED_FNORM_ABS;
>         return 0;
>     }else{
>         *res = SNES_CONVERGED_ITERATING;
>     }
> }
>
> BUT I really don't know how to control the convergence criterion for SNES.
> So when I run my previous code with the new convergence test I received
> divergence error after "first iteration":
>
> Linear solve did not converge due to DIVERGED_DTOL iterations 0
> Nonlinear solve did not converge due to DIVERGED_LINEAR_SOLVE
>
> How should I possibly deal with this??
>
> Thanks a lot,
> BehZad
>



-- 
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/20111226/e1cf5e6b/attachment.htm>


More information about the petsc-users mailing list