1! 2! Demonstrates use of MatShellSetContext() and MatShellGetContext() 3! 4! Contributed by: Samuel Lanthaler 5! 6#include "petsc/finclude/petscmat.h" 7module solver_context_ex6f 8 use petscsys 9 implicit none 10 type :: MatCtx 11 PetscReal :: lambda, kappa 12 PetscReal :: h 13 end type MatCtx 14end module solver_context_ex6f 15 16! ---------------------------------------------------- 17! main program 18! ---------------------------------------------------- 19program main 20 use petscmat 21 use solver_context_ex6f 22 implicit none 23 24 Mat :: F 25 type(MatCtx) :: ctxF 26 type(MatCtx), pointer :: ctxF_pt 27 PetscErrorCode :: ierr 28 PetscInt :: n = 128 29 30 PetscCallA(PetscInitialize(ierr)) 31 ctxF%lambda = 3.14d0 32 PetscCallA(MatCreateShell(PETSC_COMM_WORLD, n, n, n, n, ctxF, F, ierr)) 33 PetscCallA(MatShellSetContext(F, ctxF, ierr)) 34 print *, 'ctxF%lambda = ', ctxF%lambda 35 36 PetscCallA(MatShellGetContext(F, ctxF_pt, ierr)) 37 print *, 'ctxF_pt%lambda = ', ctxF_pt%lambda 38 39 PetscCallA(MatDestroy(F, ierr)) 40 PetscCallA(PetscFinalize(ierr)) 41end program main 42 43!/*TEST 44! 45! build: 46! requires: double 47! 48! test: 49! 50!TEST*/ 51