<div dir="ltr"><div><div>Thanks a lot Barry : it works perfectly for me !<br></div>Best regards <br></div>Natacha <br><div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 20, 2015 at 8:25 PM, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
It will be very similar to usage from C. You should be able to do something like<br>
<br>
PetscFortranAddress ctx<br>
<br>
call KSPConvergedDefaultCreate(ctx,ierr)<br>
<br>
call KSPMonitorSet(ksp, MyKSPConverged,ctx,kspconvergeddefaultdestroy,ierr)<br>
<br>
then in your MyKSPConverged pass the argument called "dummy" to the default monitor.<br>
<br>
Barry<br>
<div><div class="h5"><br>
<br>
<br>
<br>
<br>
> On Oct 20, 2015, at 3:36 AM, Natacha BEREUX <<a href="mailto:natacha.bereux@gmail.com">natacha.bereux@gmail.com</a>> wrote:<br>
><br>
> Dear PETSc users,<br>
><br>
><br>
> I am using PETSc Fortran API.<br>
> I try to solve a linear system, and would like to define my own convergence test.<br>
> More precisely, my convergence test calls the default convergence test<br>
> and then checks the true residual norm :<br>
> subroutine MyKSPConverged(ksp,n,rnorm,flag,dummy,ierr)<br>
><br>
> implicit none<br>
><br>
> #include <petsc/finclude/petscsys.h><br>
> #include <petsc/finclude/petscvec.h><br>
> #include <petsc/finclude/petscksp.h><br>
><br>
> KSP ksp<br>
> PetscErrorCode ierr<br>
> PetscInt n,dummy<br>
> KSPConvergedReason flag<br>
> PetscReal rnorm, true_rnorm<br>
> Vec true_res<br>
> !<br>
> call KSPConvergedDefault(ksp,n,rnorm,flag,PETSC_NULL_OBJECT,ierr)<br>
> !<br>
> ! If convergence test succeeds<br>
> if ( (flag == KSP_CONVERGED_ATOL) .or. &<br>
> & (flag == KSP_CONVERGED_RTOL)) then<br>
> ! Compute true residual<br>
> call KSPBuildResidual( ksp , PETSC_NULL_OBJECT, &<br>
> & PETSC_NULL_OBJECT, true_res, ierr )<br>
> ! Compute true residual norm<br>
> call VecNorm(true_res,NORM_2,true_rnorm,ierr)<br>
> ! And check again convergence with respect to the true residual norm<br>
> call KSPConvergedDefault(ksp,n,true_rnorm,flag, &<br>
> & PETSC_NULL_OBJECT, ierr)<br>
> ! Free memory<br>
> call VecDestroy(true_res, ierr)<br>
> endif<br>
> !<br>
> ierr = 0<br>
><br>
> end<br>
><br>
> I get the following error message<br>
><br>
> [0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------<br>
> [0]PETSC ERROR: Null argument, when expecting valid pointer<br>
> [0]PETSC ERROR: Convergence context must have been created with KSPConvergedDefaultCreate()<br>
> [0]PETSC ERROR: See <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html" rel="noreferrer" target="_blank">http://www.mcs.anl.gov/petsc/documentation/faq.html</a> for trouble shooting.<br>
> [0]PETSC ERROR: Petsc Release Version 3.6.2, Oct, 02, 2015<br>
><br>
> I understand that I should have call KSPConvergedDefaultCreate() before calling KSConvergedDefault( ....)<br>
><br>
> Am I right ?<br>
><br>
> If so what is the Fortran calling sequence for KSPConvergedDefaultCreate ? It is supposed to return a valid pointer and I don't succeed in doing so from Fortran.<br>
><br>
> If you have any idea, I'd greatly appreciate it<br>
> Thank you!<br>
> Natacha<br>
><br>
><br>
> PS I have attached my code (it's a slightly modified version of ex2f.F showing the convergence test code )<br>
</div></div>> <ex2f.F><br>
<br>
</blockquote></div><br></div>