1 #include <petsc-private/fortranimpl.h> 2 #include <petsc-private/matimpl.h> 3 4 /* Declare these pointer types instead of void* for clarity, but do not include petscts.h so that this code does have an actual reverse dependency. */ 5 typedef struct _p_TS *TS; 6 typedef struct _p_SNES *SNES; 7 8 #if defined(PETSC_HAVE_FORTRAN_CAPS) 9 #define matfdcoloringsetfunctionts_ MATFDCOLORINGSETFUNCTIONTS 10 #define matfdcoloringsetfunction_ MATFDCOLORINGSETFUNCTION 11 #define matfdcoloringview_ MATFDCOLORINGVIEW 12 #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE) 13 #define matfdcoloringsetfunctionts_ matfdcoloringsetfunctionts 14 #define matfdcoloringsetfunction_ matfdcoloringsetfunction 15 #define matfdcoloringview_ matfdcoloringview 16 #endif 17 18 19 /* These are not extern C because they are passed into non-extern C user level functions */ 20 static PetscErrorCode ourmatfdcoloringfunctionts(TS ts,PetscReal t,Vec x,Vec y,MatFDColoring fd) 21 { 22 PetscErrorCode ierr = 0; 23 (*(void (PETSC_STDCALL *)(TS*,PetscReal*,Vec*,Vec*,void*,PetscErrorCode*))(fd->ftn_func_pointer)) (&ts,&t,&x,&y,fd->ftn_func_cntx,&ierr); 24 return ierr; 25 } 26 27 static PetscErrorCode ourmatfdcoloringfunctionsnes(SNES snes,Vec x,Vec y,MatFDColoring fd) 28 { 29 PetscErrorCode ierr = 0; 30 (*(void (PETSC_STDCALL *)(SNES*,Vec*,Vec*,void*,PetscErrorCode*))(fd->ftn_func_pointer)) (&snes,&x,&y,fd->ftn_func_cntx,&ierr); 31 return ierr; 32 } 33 34 EXTERN_C_BEGIN 35 36 /* 37 MatFDColoringSetFunction sticks the Fortran function and its context into the MatFDColoring structure and passes the MatFDColoring object 38 in as the function context. ourmafdcoloringfunctionsnes() and ourmatfdcoloringfunctionts() then access the function and its context from the 39 MatFDColoring that is passed in. This is the same way that fortran_func_pointers is used in PETSc objects. 40 41 NOTE: FORTRAN USER CANNOT PUT IN A NEW J OR B currently. 42 */ 43 44 45 void PETSC_STDCALL matfdcoloringsetfunctionts_(MatFDColoring *fd,void (PETSC_STDCALL *f)(TS*,double*,Vec*,Vec*,void*,PetscErrorCode*),void *ctx,PetscErrorCode *ierr) 46 { 47 (*fd)->ftn_func_pointer = (void*) f; 48 (*fd)->ftn_func_cntx = ctx; 49 50 *ierr = MatFDColoringSetFunction(*fd,(PetscErrorCodeFunction)ourmatfdcoloringfunctionts,*fd); 51 } 52 53 void PETSC_STDCALL matfdcoloringsetfunction_(MatFDColoring *fd,void (PETSC_STDCALL *f)(SNES*,Vec*,Vec*,void*,PetscErrorCode*),void *ctx,PetscErrorCode *ierr) 54 { 55 (*fd)->ftn_func_pointer = (void*) f; 56 (*fd)->ftn_func_cntx = ctx; 57 58 *ierr = MatFDColoringSetFunction(*fd,(PetscErrorCodeFunction)ourmatfdcoloringfunctionsnes,*fd); 59 } 60 61 void PETSC_STDCALL matfdcoloringview_(MatFDColoring *c,PetscViewer *vin,PetscErrorCode *ierr) 62 { 63 PetscViewer v; 64 65 PetscPatchDefaultViewers_Fortran(vin,v); 66 *ierr = MatFDColoringView(*c,v); 67 } 68 69 70 EXTERN_C_END 71