module context_module #include use petsc implicit none private type, public :: context_type private PetscInt :: foo contains procedure, public :: init => context_init end type context_type contains subroutine context_init(self, foo) class(context_type), intent(in out) :: self PetscInt, intent(in) :: foo self%foo = foo end subroutine context_init end module context_module !------------------------------------------------------------------------ program test_snes ! tests SNESSetConvergenceTest() #include use petsc use context_module implicit none SNES :: snes type(context_type) :: context PetscErrorCode :: ierr call PetscInitialize(PETSC_NULL_CHARACTER, ierr) call SNESCreate(PETSC_COMM_WORLD, snes, ierr) call context%init(1) call SNESSetConvergenceTest(snes, convergence, context, & PETSC_NULL_FUNCTION, ierr) call SNESDestroy(snes, ierr) call PetscFinalize(ierr) contains subroutine convergence(snes, num_iterations, xnorm, pnorm, & fnorm, reason, context, ierr) SNES, intent(in) :: snes PetscInt, intent(in) :: num_iterations PetscReal, intent(in) :: xnorm, pnorm, fnorm SNESConvergedReason, intent(out) :: reason type(context_type), intent(in out) :: context PetscErrorCode, intent(out) :: ierr reason = 0 ierr = 0 end subroutine convergence end program test_snes