xref: /petsc/src/mat/matfd/ftn-custom/zfdmatrixf.c (revision 390e1bf27627d887df99a9f4d0d0ad68037f55ec)
1af0996ceSBarry Smith #include <petsc/private/fortranimpl.h>
2af0996ceSBarry Smith #include <petsc/private/matimpl.h>
3fcfc5002SJed Brown 
4fcfc5002SJed Brown /* 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. */
5fcfc5002SJed Brown typedef struct _p_TS *TS;
6fcfc5002SJed Brown typedef struct _p_SNES *SNES;
7f4e70085SSatish Balay 
8f4e70085SSatish Balay #if defined(PETSC_HAVE_FORTRAN_CAPS)
9f4e70085SSatish Balay #define matfdcoloringsetfunctionts_      MATFDCOLORINGSETFUNCTIONTS
1089d42083SSatish Balay #define matfdcoloringsetfunction_        MATFDCOLORINGSETFUNCTION
111d2e4005SSatish Balay #define matfdcoloringview_               MATFDCOLORINGVIEW
1261ab5df0SBarry Smith #define matfdcoloingsettype_             MATFDCOLORINGSETTYPE
13f4e70085SSatish Balay #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
14f4e70085SSatish Balay #define matfdcoloringsetfunctionts_      matfdcoloringsetfunctionts
15372a5eeaSSatish Balay #define matfdcoloringsetfunction_        matfdcoloringsetfunction
161d2e4005SSatish Balay #define matfdcoloringview_               matfdcoloringview
1761ab5df0SBarry Smith #define matfdcoloingsettype_             matfdcoloringsettype
18f4e70085SSatish Balay #endif
19f4e70085SSatish Balay 
20f4e70085SSatish Balay 
21f4e70085SSatish Balay /* These are not extern C because they are passed into non-extern C user level functions */
227850c7c0SBarry Smith static PetscErrorCode ourmatfdcoloringfunctionts(TS ts,PetscReal t,Vec x,Vec y,MatFDColoring fd)
23f4e70085SSatish Balay {
24f4e70085SSatish Balay   PetscErrorCode ierr = 0;
257850c7c0SBarry Smith   (*(void (PETSC_STDCALL *)(TS*,PetscReal*,Vec*,Vec*,void*,PetscErrorCode*))(fd->ftn_func_pointer)) (&ts,&t,&x,&y,fd->ftn_func_cntx,&ierr);
26f4e70085SSatish Balay   return ierr;
27f4e70085SSatish Balay }
28f4e70085SSatish Balay 
297850c7c0SBarry Smith static PetscErrorCode ourmatfdcoloringfunctionsnes(SNES snes,Vec x,Vec y,MatFDColoring fd)
30f4e70085SSatish Balay {
31f4e70085SSatish Balay   PetscErrorCode ierr = 0;
327850c7c0SBarry Smith   (*(void (PETSC_STDCALL *)(SNES*,Vec*,Vec*,void*,PetscErrorCode*))(fd->ftn_func_pointer)) (&snes,&x,&y,fd->ftn_func_cntx,&ierr);
33f4e70085SSatish Balay   return ierr;
34f4e70085SSatish Balay }
35f4e70085SSatish Balay 
36f4e70085SSatish Balay /*
377850c7c0SBarry Smith         MatFDColoringSetFunction sticks the Fortran function and its context into the MatFDColoring structure and passes the MatFDColoring object
387850c7c0SBarry Smith     in as the function context. ourmafdcoloringfunctionsnes() and ourmatfdcoloringfunctionts()  then access the function and its context from the
397850c7c0SBarry Smith     MatFDColoring that is passed in. This is the same way that fortran_func_pointers is used in PETSc objects.
40f4e70085SSatish Balay 
41f4e70085SSatish Balay    NOTE: FORTRAN USER CANNOT PUT IN A NEW J OR B currently.
42f4e70085SSatish Balay */
43f4e70085SSatish Balay 
44f4e70085SSatish Balay 
458cc058d9SJed Brown PETSC_EXTERN void PETSC_STDCALL matfdcoloringsetfunctionts_(MatFDColoring *fd,void (PETSC_STDCALL *f)(TS*,double*,Vec*,Vec*,void*,PetscErrorCode*),void *ctx,PetscErrorCode *ierr)
46f4e70085SSatish Balay {
4778bd23c2SBarry Smith   (*fd)->ftn_func_pointer =  (void (*)(void)) f;
487850c7c0SBarry Smith   (*fd)->ftn_func_cntx    = ctx;
498865f1eaSKarl Rupp 
507850c7c0SBarry Smith   *ierr = MatFDColoringSetFunction(*fd,(PetscErrorCodeFunction)ourmatfdcoloringfunctionts,*fd);
51f4e70085SSatish Balay }
52f4e70085SSatish Balay 
538cc058d9SJed Brown PETSC_EXTERN void PETSC_STDCALL matfdcoloringsetfunction_(MatFDColoring *fd,void (PETSC_STDCALL *f)(SNES*,Vec*,Vec*,void*,PetscErrorCode*),void *ctx,PetscErrorCode *ierr)
54f4e70085SSatish Balay {
5578bd23c2SBarry Smith   (*fd)->ftn_func_pointer = (void (*)(void)) f;
567850c7c0SBarry Smith   (*fd)->ftn_func_cntx    = ctx;
578865f1eaSKarl Rupp 
587850c7c0SBarry Smith   *ierr = MatFDColoringSetFunction(*fd,(PetscErrorCodeFunction)ourmatfdcoloringfunctionsnes,*fd);
59f4e70085SSatish Balay }
60f4e70085SSatish Balay 
618cc058d9SJed Brown PETSC_EXTERN void PETSC_STDCALL matfdcoloringview_(MatFDColoring *c,PetscViewer *vin,PetscErrorCode *ierr)
621d2e4005SSatish Balay {
631d2e4005SSatish Balay   PetscViewer v;
641d2e4005SSatish Balay 
651d2e4005SSatish Balay   PetscPatchDefaultViewers_Fortran(vin,v);
661d2e4005SSatish Balay   *ierr = MatFDColoringView(*c,v);
671d2e4005SSatish Balay }
681d2e4005SSatish Balay 
69*390e1bf2SBarry Smith PETSC_EXTERN void PETSC_STDCALL matfdcoloringsettype_(MatFDColoring *matfdcoloring,char* type PETSC_MIXED_LEN(len),PetscErrorCode *ierr PETSC_END_LEN(len))
7061ab5df0SBarry Smith {
7161ab5df0SBarry Smith   char *t;
7261ab5df0SBarry Smith 
7361ab5df0SBarry Smith   FIXCHAR(type,len,t);
7461ab5df0SBarry Smith   *ierr = MatFDColoringSetType(*matfdcoloring,t);
7561ab5df0SBarry Smith   FREECHAR(type,t);
7661ab5df0SBarry Smith }
77