xref: /petsc/src/ksp/pc/impls/shell/ftn-custom/zshellpcf.c (revision 8865f1ea4ea560cd84ab8db62e98b7095cdff96f)
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 EXTERN_C_BEGIN
63 
64 void PETSC_STDCALL pcshellgetcontext_(PC *pc,void **ctx,PetscErrorCode *ierr)
65 {
66   *ierr = PCShellGetContext(*pc,ctx);
67 }
68 
69 void PETSC_STDCALL pcshellsetapply_(PC *pc,void (PETSC_STDCALL *apply)(void*,Vec*,Vec*,PetscErrorCode*),PetscErrorCode *ierr)
70 {
71   PetscObjectAllocateFortranPointers(*pc,5);
72   ((PetscObject)*pc)->fortran_func_pointers[0] = (PetscVoidFunction)apply;
73 
74   *ierr = PCShellSetApply(*pc,ourshellapply);
75 }
76 
77 void PETSC_STDCALL pcshellsetapplyrichardson_(PC *pc,void (PETSC_STDCALL *apply)(void*,Vec*,Vec*,Vec*,PetscReal*,PetscReal*,PetscReal*,PetscInt*,PetscBool*,PetscInt*,PCRichardsonConvergedReason*,PetscErrorCode*),PetscErrorCode *ierr)
78 {
79   PetscObjectAllocateFortranPointers(*pc,5);
80   ((PetscObject)*pc)->fortran_func_pointers[1] = (PetscVoidFunction)apply;
81   *ierr = PCShellSetApplyRichardson(*pc,ourapplyrichardson);
82 }
83 
84 void PETSC_STDCALL pcshellsetapplytranspose_(PC *pc,void (PETSC_STDCALL *applytranspose)(void*,Vec *,Vec *,PetscErrorCode*), PetscErrorCode *ierr)
85 {
86   PetscObjectAllocateFortranPointers(*pc,5);
87   ((PetscObject)*pc)->fortran_func_pointers[2] = (PetscVoidFunction)applytranspose;
88 
89   *ierr = PCShellSetApplyTranspose(*pc,ourshellapplytranspose);
90 }
91 
92 void PETSC_STDCALL pcshellsetsetup_(PC *pc,void (PETSC_STDCALL *setup)(void*,PetscErrorCode*),PetscErrorCode *ierr)
93 {
94   PetscObjectAllocateFortranPointers(*pc,5);
95   ((PetscObject)*pc)->fortran_func_pointers[3] = (PetscVoidFunction)setup;
96 
97   *ierr = PCShellSetSetUp(*pc,ourshellsetup);
98 }
99 
100 void PETSC_STDCALL pcshellsetdestroy_(PC *pc,void (PETSC_STDCALL *setup)(void*,PetscErrorCode*),PetscErrorCode *ierr)
101 {
102   PetscObjectAllocateFortranPointers(*pc,5);
103   ((PetscObject)*pc)->fortran_func_pointers[4] = (PetscVoidFunction)setup;
104 
105   *ierr = PCShellSetDestroy(*pc,ourshelldestroy);
106 }
107 
108 void PETSC_STDCALL pcshellsetname_(PC *pc,CHAR name PETSC_MIXED_LEN(len), PetscErrorCode *ierr PETSC_END_LEN(len))
109 {
110   char *c;
111   FIXCHAR(name,len,c);
112   *ierr = PCShellSetName(*pc,c);
113   FREECHAR(name,c);
114 }
115 
116 void PETSC_STDCALL pcshellgetname_(PC *pc,CHAR name PETSC_MIXED_LEN(len), PetscErrorCode *ierr PETSC_END_LEN(len))
117 {
118   const char *c;
119 
120   *ierr = PCShellGetName(*pc,&c);if (*ierr) return;
121   *ierr = PetscStrncpy(name,c,len);
122 }
123 
124 /* -----------------------------------------------------------------*/
125 
126 EXTERN_C_END
127