xref: /petsc/src/mat/matfd/ftn-custom/zfdmatrixf.c (revision 609bdbee21ea3be08735c64dbe00a9ab27759925) !
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 #define matfdcoloingsettype_             MATFDCOLORINGSETTYPE
13 #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
14 #define matfdcoloringsetfunctionts_      matfdcoloringsetfunctionts
15 #define matfdcoloringsetfunction_        matfdcoloringsetfunction
16 #define matfdcoloringview_               matfdcoloringview
17 #define matfdcoloingsettype_             matfdcoloringsettype
18 #endif
19 
20 
21 /* These are not extern C because they are passed into non-extern C user level functions */
22 static PetscErrorCode ourmatfdcoloringfunctionts(TS ts,PetscReal t,Vec x,Vec y,MatFDColoring fd)
23 {
24   PetscErrorCode ierr = 0;
25   (*(void (PETSC_STDCALL *)(TS*,PetscReal*,Vec*,Vec*,void*,PetscErrorCode*))(fd->ftn_func_pointer)) (&ts,&t,&x,&y,fd->ftn_func_cntx,&ierr);
26   return ierr;
27 }
28 
29 static PetscErrorCode ourmatfdcoloringfunctionsnes(SNES snes,Vec x,Vec y,MatFDColoring fd)
30 {
31   PetscErrorCode ierr = 0;
32   (*(void (PETSC_STDCALL *)(SNES*,Vec*,Vec*,void*,PetscErrorCode*))(fd->ftn_func_pointer)) (&snes,&x,&y,fd->ftn_func_cntx,&ierr);
33   return ierr;
34 }
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 PETSC_EXTERN 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 (*)(void)) f;
48   (*fd)->ftn_func_cntx    = ctx;
49 
50   *ierr = MatFDColoringSetFunction(*fd,(PetscErrorCodeFunction)ourmatfdcoloringfunctionts,*fd);
51 }
52 
53 PETSC_EXTERN 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 (*)(void)) f;
56   (*fd)->ftn_func_cntx    = ctx;
57 
58   *ierr = MatFDColoringSetFunction(*fd,(PetscErrorCodeFunction)ourmatfdcoloringfunctionsnes,*fd);
59 }
60 
61 PETSC_EXTERN 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 PETSC_EXTERN void PETSC_STDCALL matfdcoloringsettype_(MatFDColoring *matfdcoloring,char* type PETSC_MIXED_LEN(len),PetscErrorCode *ierr PETSC_END_LEN(len))
70 {
71   char *t;
72 
73   FIXCHAR(type,len,t);
74   *ierr = MatFDColoringSetType(*matfdcoloring,t);
75   FREECHAR(type,t);
76 }
77