[petsc-users] Help with KSPSetConvergenceTest

Matthew Knepley knepley at gmail.com
Sun May 7 08:32:18 CDT 2023


On Sun, May 7, 2023 at 9:21 AM Edoardo alinovi <edoardo.alinovi at gmail.com>
wrote:

> Hello guys,
>
> Today I am about to write a custom convergence test for KSP doing the
> following job:
>
> - if the number of ksp iterations is less than a given threshold, iterate
> until that threshold is met
> - if the number of ksp iterations is bigger than the threshold, use the
> standard convergence checks.
>
> As far as I understood from the examples, this is the function I need to
> use:
>
> KSPSetConvergenceTest <https://petsc.org/main/manualpages/KSP/KSPSetConvergenceTest/>(ksp,MyKSPConverged,0,PETSC_NULL_FUNCTION,ierr)
>
> With MyKSPConverge a subroutine (I am in fortran) where my custom checks are implemented.
>
> Here is how I have coded  MyKSPConverged:
>
>
>
>
>
>
>
>
>
>
>
> *    subroutine MyKSPConverged(ksp,n,rnorm,flag,dummy,ierr)       KSP              ksp       PetscErrorCode ierr       PetscInt n,dummy       KSPConvergedReason flag       PetscReal rnorm       if (n>1) then         call KSPConvergedDefault(ksp, n, rnorm, flag, ierr)*
>
>
Isn't this call missing an argument?

  THanks,

    Matt


>
>
>
>
>
> *       else         flag = 0       endif       ierr = 0    end subroutine MyKSPConverged*
>
> However I get this error:
> [0]PETSC ERROR: KSPSolve has not converged, reason DIVERGED_DTOL
> which I believe to be triggered by *KSPConvergedDefault. *This is odd, as this simulation converge perfectly if I comment ou my dodgy convergence test.
>
> *Do you have any advice for me?*
>
> *thank you! *
>
>
>
>
>
>

-- 
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

https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20230507/f31f878c/attachment.html>


More information about the petsc-users mailing list