xref: /petsc/src/ksp/pc/impls/shell/ftn-custom/zshellpcf.c (revision 84df9cb40eca90ea9b18a456fab7a4ecc7f6c1a4)
1 #include <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 pcshellsetcontext_         PCSHELLSETCONTEXT
12 #define pcshellgetcontext_         PCSHELLGETCONTEXT
13 #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
14 #define pcshellsetapply_           pcshellsetapply
15 #define pcshellsetapplyrichardson_ pcshellsetapplyrichardson
16 #define pcshellsetapplytranspose_  pcshellsetapplytranspose
17 #define pcshellsetsetup_           pcshellsetsetup
18 #define pcshellsetdestroy_         pcshellsetdestroy
19 #define pcshellsetname_            pcshellsetname
20 #define pcshellsetcontext_         pcshellsetcontext
21 #define pcshellgetcontext_         pcshellgetcontext
22 #endif
23 
24 /* These are not extern C because they are passed into non-extern C user level functions */
25 static PetscErrorCode ourshellapply(PC pc,Vec x,Vec y)
26 {
27   PetscErrorCode ierr = 0;
28   (*(void (PETSC_STDCALL *)(PC*,Vec*,Vec*,PetscErrorCode*))(((PetscObject)pc)->fortran_func_pointers[0]))(&pc,&x,&y,&ierr);CHKERRQ(ierr);
29   return 0;
30 }
31 
32 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)
33 {
34   PetscErrorCode ierr = 0;
35   (*(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);
36   return 0;
37 }
38 
39 static PetscErrorCode ourshellapplytranspose(PC pc,Vec x,Vec y)
40 {
41   PetscErrorCode ierr = 0;
42   (*(void (PETSC_STDCALL *)(void*,Vec*,Vec*,PetscErrorCode*))(((PetscObject)pc)->fortran_func_pointers[2]))(&pc,&x,&y,&ierr);CHKERRQ(ierr);
43   return 0;
44 }
45 
46 static PetscErrorCode ourshellsetup(PC pc)
47 {
48   PetscErrorCode ierr = 0;
49   (*(void (PETSC_STDCALL *)(PC*,PetscErrorCode*))(((PetscObject)pc)->fortran_func_pointers[3]))(&pc,&ierr);CHKERRQ(ierr);
50   return 0;
51 }
52 
53 static PetscErrorCode ourshelldestroy(PC pc)
54 {
55   PetscErrorCode ierr = 0;
56   (*(void (PETSC_STDCALL *)(void*,PetscErrorCode*))(((PetscObject)pc)->fortran_func_pointers[4]))(&pc,&ierr);CHKERRQ(ierr);
57   return 0;
58 }
59 
60 EXTERN_C_BEGIN
61 
62 void PETSC_STDCALL pcshellgetcontext_(PC *pc,void **ctx,PetscErrorCode *ierr)
63 {
64   *ierr = PCShellGetContext(*pc,ctx);
65 }
66 
67 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   *ierr = PCShellSetApply(*pc,ourshellapply);
72 }
73 
74 void PETSC_STDCALL pcshellsetapplyrichardson_(PC *pc,void (PETSC_STDCALL *apply)(void*,Vec *,Vec *,Vec *,PetscReal*,PetscReal*,PetscReal*,PetscInt*,PetscBool *,PetscInt*,PCRichardsonConvergedReason*,PetscErrorCode*),PetscErrorCode *ierr)
75 {
76   PetscObjectAllocateFortranPointers(*pc,5);
77   ((PetscObject)*pc)->fortran_func_pointers[1] = (PetscVoidFunction)apply;
78   *ierr = PCShellSetApplyRichardson(*pc,ourapplyrichardson);
79 }
80 
81 void PETSC_STDCALL pcshellsetapplytranspose_(PC *pc,void (PETSC_STDCALL *applytranspose)(void*,Vec *,Vec *,PetscErrorCode*), PetscErrorCode *ierr)
82 {
83   PetscObjectAllocateFortranPointers(*pc,5);
84   ((PetscObject)*pc)->fortran_func_pointers[2] = (PetscVoidFunction)applytranspose;
85   *ierr = PCShellSetApplyTranspose(*pc,ourshellapplytranspose);
86 }
87 
88 void PETSC_STDCALL pcshellsetsetup_(PC *pc,void (PETSC_STDCALL *setup)(void*,PetscErrorCode*),PetscErrorCode *ierr)
89 {
90   PetscObjectAllocateFortranPointers(*pc,5);
91   ((PetscObject)*pc)->fortran_func_pointers[3] = (PetscVoidFunction)setup;
92   *ierr = PCShellSetSetUp(*pc,ourshellsetup);
93 }
94 
95 void PETSC_STDCALL pcshellsetdestroy_(PC *pc,void (PETSC_STDCALL *setup)(void*,PetscErrorCode*),PetscErrorCode *ierr)
96 {
97   PetscObjectAllocateFortranPointers(*pc,5);
98   ((PetscObject)*pc)->fortran_func_pointers[4] = (PetscVoidFunction)setup;
99   *ierr = PCShellSetDestroy(*pc,ourshelldestroy);
100 }
101 
102 void PETSC_STDCALL pcshellsetname_(PC *pc,CHAR name PETSC_MIXED_LEN(len), PetscErrorCode *ierr PETSC_END_LEN(len))
103 {
104   char *c;
105   FIXCHAR(name,len,c);
106   *ierr = PCShellSetName(*pc,c);
107   FREECHAR(name,c);
108 }
109 
110 /* -----------------------------------------------------------------*/
111 
112 EXTERN_C_END
113