hi Martin,

Sure, here it is.

- Adrian

On 9/11/18 12:34 PM, Martin Diehl wrote:
Dear Adrian,

I looked into the issue of passing in derived types with type bound
procedures again and it seems that casting to C pointers is a suitable
alternative.

To investigate that, I modified ex5f.F90 from
src/snes/examples/tutorials in a branch of my PETSc fork:

https://bitbucket.org/m_diehl/petsc/src/5172a911a5cc8a6228f00f2435cc5cfe6ec569d9/?at=m.diehl%2FSNESSetConvergenceTestTypeFortran


Could you please send me your original minimal working example again?
I've deleted it and would like to test the new approach there also.

many thanks
Martin

--
Dr Adrian Croucher
Senior Research Fellow
Department of Engineering Science
University of Auckland, New Zealand
email: [email protected]
tel: +64 (0)9 923 4611

module context_module

#include <petsc/finclude/petsc.h>

  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 <petsc/finclude/petsc.h>

  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

Reply via email to