xref: /petsc/src/ksp/pc/impls/shell/ftn-custom/zshellpcf.c (revision 3e1910f1ab6113d8365e15c6b8c907ccce7ce4ea)
1 #include <petsc-private/fortranimpl.h>
2 #include <petscpc.h>
3 
4 #if defined(PETSC_HAVE_FORTRAN_CAPS)
5 #define pcshellsetapply_           PCSHELLSETAPPLY
6 #define pcshellsetapplyrichardson_ PCSHELLSETAPPLYRICHARDSON
7 #define pcshellsetapplytranspose_  PCSHELLSETAPPLYTRANSPOSE
8 #define pcshellsetsetup_           PCSHELLSETSETUP
9 #define pcshellsetdestroy_         PCSHELLSETDESTROY
10 #define pcshellsetname_            PCSHELLSETNAME
11 #define pcshellgetname_            PCSHELLGETNAME
12 #define pcshellsetcontext_         PCSHELLSETCONTEXT
13 #define pcshellgetcontext_         PCSHELLGETCONTEXT
14 #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
15 #define pcshellsetapply_           pcshellsetapply
16 #define pcshellsetapplyrichardson_ pcshellsetapplyrichardson
17 #define pcshellsetapplytranspose_  pcshellsetapplytranspose
18 #define pcshellsetsetup_           pcshellsetsetup
19 #define pcshellsetdestroy_         pcshellsetdestroy
20 #define pcshellsetname_            pcshellsetname
21 #define pcshellgetname_            pcshellgetname
22 #define pcshellsetcontext_         pcshellsetcontext
23 #define pcshellgetcontext_         pcshellgetcontext
24 #endif
25 
26 /* These are not extern C because they are passed into non-extern C user level functions */
27 static PetscErrorCode ourshellapply(PC pc,Vec x,Vec y)
28 {
29   PetscErrorCode ierr = 0;
30   (*(void (PETSC_STDCALL *)(PC*,Vec*,Vec*,PetscErrorCode*))(((PetscObject)pc)->fortran_func_pointers[0]))(&pc,&x,&y,&ierr);CHKERRQ(ierr);
31   return 0;
32 }
33 
34 static PetscErrorCode ourapplyrichardson(PC pc,Vec x,Vec y,Vec w,PetscReal rtol,PetscReal abstol,PetscReal dtol,PetscInt m,PetscBool guesszero,PetscInt *outits,PCRichardsonConvergedReason *reason)
35 {
36   PetscErrorCode ierr = 0;
37   (*(void (PETSC_STDCALL *)(PC*,Vec*,Vec*,Vec*,PetscReal*,PetscReal*,PetscReal*,PetscInt*,PetscBool *,PetscInt*,PCRichardsonConvergedReason*,PetscErrorCode*))(((PetscObject)pc)->fortran_func_pointers[1]))(&pc,&x,&y,&w,&rtol,&abstol,&dtol,&m,&guesszero,outits,reason,&ierr);CHKERRQ(ierr);
38   return 0;
39 }
40 
41 static PetscErrorCode ourshellapplytranspose(PC pc,Vec x,Vec y)
42 {
43   PetscErrorCode ierr = 0;
44   (*(void (PETSC_STDCALL *)(void*,Vec*,Vec*,PetscErrorCode*))(((PetscObject)pc)->fortran_func_pointers[2]))(&pc,&x,&y,&ierr);CHKERRQ(ierr);
45   return 0;
46 }
47 
48 static PetscErrorCode ourshellsetup(PC pc)
49 {
50   PetscErrorCode ierr = 0;
51   (*(void (PETSC_STDCALL *)(PC*,PetscErrorCode*))(((PetscObject)pc)->fortran_func_pointers[3]))(&pc,&ierr);CHKERRQ(ierr);
52   return 0;
53 }
54 
55 static PetscErrorCode ourshelldestroy(PC pc)
56 {
57   PetscErrorCode ierr = 0;
58   (*(void (PETSC_STDCALL *)(void*,PetscErrorCode*))(((PetscObject)pc)->fortran_func_pointers[4]))(&pc,&ierr);CHKERRQ(ierr);
59   return 0;
60 }
61 
62 PETSC_EXTERN void PETSC_STDCALL pcshellgetcontext_(PC *pc,void **ctx,PetscErrorCode *ierr)
63 {
64   *ierr = PCShellGetContext(*pc,ctx);
65 }
66 
67 PETSC_EXTERN void PETSC_STDCALL pcshellsetapply_(PC *pc,void (PETSC_STDCALL *apply)(void*,Vec*,Vec*,PetscErrorCode*),PetscErrorCode *ierr)
68 {
69   PetscObjectAllocateFortranPointers(*pc,5);
70   ((PetscObject)*pc)->fortran_func_pointers[0] = (PetscVoidFunction)apply;
71 
72   *ierr = PCShellSetApply(*pc,ourshellapply);
73 }
74 
75 PETSC_EXTERN void PETSC_STDCALL pcshellsetapplyrichardson_(PC *pc,void (PETSC_STDCALL *apply)(void*,Vec*,Vec*,Vec*,PetscReal*,PetscReal*,PetscReal*,PetscInt*,PetscBool*,PetscInt*,PCRichardsonConvergedReason*,PetscErrorCode*),PetscErrorCode *ierr)
76 {
77   PetscObjectAllocateFortranPointers(*pc,5);
78   ((PetscObject)*pc)->fortran_func_pointers[1] = (PetscVoidFunction)apply;
79   *ierr = PCShellSetApplyRichardson(*pc,ourapplyrichardson);
80 }
81 
82 PETSC_EXTERN void PETSC_STDCALL pcshellsetapplytranspose_(PC *pc,void (PETSC_STDCALL *applytranspose)(void*,Vec *,Vec *,PetscErrorCode*), PetscErrorCode *ierr)
83 {
84   PetscObjectAllocateFortranPointers(*pc,5);
85   ((PetscObject)*pc)->fortran_func_pointers[2] = (PetscVoidFunction)applytranspose;
86 
87   *ierr = PCShellSetApplyTranspose(*pc,ourshellapplytranspose);
88 }
89 
90 PETSC_EXTERN void PETSC_STDCALL pcshellsetsetup_(PC *pc,void (PETSC_STDCALL *setup)(void*,PetscErrorCode*),PetscErrorCode *ierr)
91 {
92   PetscObjectAllocateFortranPointers(*pc,5);
93   ((PetscObject)*pc)->fortran_func_pointers[3] = (PetscVoidFunction)setup;
94 
95   *ierr = PCShellSetSetUp(*pc,ourshellsetup);
96 }
97 
98 PETSC_EXTERN void PETSC_STDCALL pcshellsetdestroy_(PC *pc,void (PETSC_STDCALL *setup)(void*,PetscErrorCode*),PetscErrorCode *ierr)
99 {
100   PetscObjectAllocateFortranPointers(*pc,5);
101   ((PetscObject)*pc)->fortran_func_pointers[4] = (PetscVoidFunction)setup;
102 
103   *ierr = PCShellSetDestroy(*pc,ourshelldestroy);
104 }
105 
106 PETSC_EXTERN void PETSC_STDCALL pcshellsetname_(PC *pc,CHAR name PETSC_MIXED_LEN(len), PetscErrorCode *ierr PETSC_END_LEN(len))
107 {
108   char *c;
109   FIXCHAR(name,len,c);
110   *ierr = PCShellSetName(*pc,c);
111   FREECHAR(name,c);
112 }
113 
114 PETSC_EXTERN void PETSC_STDCALL pcshellgetname_(PC *pc,CHAR name PETSC_MIXED_LEN(len), PetscErrorCode *ierr PETSC_END_LEN(len))
115 {
116   const char *c;
117 
118   *ierr = PCShellGetName(*pc,&c);if (*ierr) return;
119   *ierr = PetscStrncpy(name,c,len);
120 }
121 
122 /* -----------------------------------------------------------------*/
123 
124