xref: /petsc/src/ksp/pc/impls/shell/ftn-custom/zshellpcf.c (revision ccf40c83d7334776fd6a44572b86a0020c069932)
1b45d2f2cSJed Brown #include <petsc-private/fortranimpl.h>
2c6db04a5SJed Brown #include <petscpc.h>
3a425a105SElliott Sales de Andrade #include <petscksp.h>
4e54e4138SSatish Balay 
5e54e4138SSatish Balay #if defined(PETSC_HAVE_FORTRAN_CAPS)
6e54e4138SSatish Balay #define pcshellsetapply_           PCSHELLSETAPPLY
7*ccf40c83SElliott Sales de Andrade #define pcshellsetapplyba_         PCSHELLSETAPPLYBA
8e54e4138SSatish Balay #define pcshellsetapplyrichardson_ PCSHELLSETAPPLYRICHARDSON
9e54e4138SSatish Balay #define pcshellsetapplytranspose_  PCSHELLSETAPPLYTRANSPOSE
10e54e4138SSatish Balay #define pcshellsetsetup_           PCSHELLSETSETUP
117c54600cSBarry Smith #define pcshellsetdestroy_         PCSHELLSETDESTROY
12a425a105SElliott Sales de Andrade #define pcshellsetpresolve_        PCSHELLSETPRESOLVE
13a425a105SElliott Sales de Andrade #define pcshellsetpostsolve_       PCSHELLSETPOSTSOLVE
141d2e4005SSatish Balay #define pcshellsetname_            PCSHELLSETNAME
15e63f14baSBarry Smith #define pcshellgetname_            PCSHELLGETNAME
166895c445SBarry Smith #define pcshellsetcontext_         PCSHELLSETCONTEXT
176895c445SBarry Smith #define pcshellgetcontext_         PCSHELLGETCONTEXT
18e54e4138SSatish Balay #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
19e54e4138SSatish Balay #define pcshellsetapply_           pcshellsetapply
20*ccf40c83SElliott Sales de Andrade #define pcshellsetapplyba_         pcshellsetapplyba
21e54e4138SSatish Balay #define pcshellsetapplyrichardson_ pcshellsetapplyrichardson
22e54e4138SSatish Balay #define pcshellsetapplytranspose_  pcshellsetapplytranspose
23e54e4138SSatish Balay #define pcshellsetsetup_           pcshellsetsetup
247c54600cSBarry Smith #define pcshellsetdestroy_         pcshellsetdestroy
25a425a105SElliott Sales de Andrade #define pcshellsetpresolve_        pcshellsetpresolve
26a425a105SElliott Sales de Andrade #define pcshellsetpostsolve_       pcshellsetpostsolve
271d2e4005SSatish Balay #define pcshellsetname_            pcshellsetname
28e63f14baSBarry Smith #define pcshellgetname_            pcshellgetname
296895c445SBarry Smith #define pcshellsetcontext_         pcshellsetcontext
306895c445SBarry Smith #define pcshellgetcontext_         pcshellgetcontext
31e54e4138SSatish Balay #endif
32e54e4138SSatish Balay 
33e54e4138SSatish Balay /* These are not extern C because they are passed into non-extern C user level functions */
346891c3e4SJed Brown static PetscErrorCode ourshellapply(PC pc,Vec x,Vec y)
35e54e4138SSatish Balay {
36e54e4138SSatish Balay   PetscErrorCode ierr = 0;
376891c3e4SJed Brown   (*(void (PETSC_STDCALL *)(PC*,Vec*,Vec*,PetscErrorCode*))(((PetscObject)pc)->fortran_func_pointers[0]))(&pc,&x,&y,&ierr);CHKERRQ(ierr);
38e54e4138SSatish Balay   return 0;
39e54e4138SSatish Balay }
40e54e4138SSatish Balay 
41*ccf40c83SElliott Sales de Andrade static PetscErrorCode ourshellapplyba(PC pc,PCSide side,Vec x,Vec y,Vec work)
42*ccf40c83SElliott Sales de Andrade {
43*ccf40c83SElliott Sales de Andrade   PetscErrorCode ierr = 0;
44*ccf40c83SElliott Sales de Andrade   (*(void (PETSC_STDCALL *)(PC*,PCSide*,Vec*,Vec*,Vec*,PetscErrorCode*))(((PetscObject)pc)->fortran_func_pointers[1]))(&pc,&side,&x,&y,&work,&ierr);CHKERRQ(ierr);
45*ccf40c83SElliott Sales de Andrade   return 0;
46*ccf40c83SElliott Sales de Andrade }
47*ccf40c83SElliott Sales de Andrade 
48ace3abfcSBarry Smith 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)
49e54e4138SSatish Balay {
50e54e4138SSatish Balay   PetscErrorCode ierr = 0;
51*ccf40c83SElliott Sales de Andrade   (*(void (PETSC_STDCALL *)(PC*,Vec*,Vec*,Vec*,PetscReal*,PetscReal*,PetscReal*,PetscInt*,PetscBool *,PetscInt*,PCRichardsonConvergedReason*,PetscErrorCode*))(((PetscObject)pc)->fortran_func_pointers[2]))(&pc,&x,&y,&w,&rtol,&abstol,&dtol,&m,&guesszero,outits,reason,&ierr);CHKERRQ(ierr);
52e54e4138SSatish Balay   return 0;
53e54e4138SSatish Balay }
54e54e4138SSatish Balay 
556891c3e4SJed Brown static PetscErrorCode ourshellapplytranspose(PC pc,Vec x,Vec y)
56e54e4138SSatish Balay {
57e54e4138SSatish Balay   PetscErrorCode ierr = 0;
58*ccf40c83SElliott Sales de Andrade   (*(void (PETSC_STDCALL *)(void*,Vec*,Vec*,PetscErrorCode*))(((PetscObject)pc)->fortran_func_pointers[3]))(&pc,&x,&y,&ierr);CHKERRQ(ierr);
59e54e4138SSatish Balay   return 0;
60e54e4138SSatish Balay }
61e54e4138SSatish Balay 
626891c3e4SJed Brown static PetscErrorCode ourshellsetup(PC pc)
63e54e4138SSatish Balay {
64e54e4138SSatish Balay   PetscErrorCode ierr = 0;
65*ccf40c83SElliott Sales de Andrade   (*(void (PETSC_STDCALL *)(PC*,PetscErrorCode*))(((PetscObject)pc)->fortran_func_pointers[4]))(&pc,&ierr);CHKERRQ(ierr);
66e54e4138SSatish Balay   return 0;
67e54e4138SSatish Balay }
68e54e4138SSatish Balay 
696891c3e4SJed Brown static PetscErrorCode ourshelldestroy(PC pc)
707c54600cSBarry Smith {
717c54600cSBarry Smith   PetscErrorCode ierr = 0;
72*ccf40c83SElliott Sales de Andrade   (*(void (PETSC_STDCALL *)(void*,PetscErrorCode*))(((PetscObject)pc)->fortran_func_pointers[5]))(&pc,&ierr);CHKERRQ(ierr);
737c54600cSBarry Smith   return 0;
747c54600cSBarry Smith }
757c54600cSBarry Smith 
76a425a105SElliott Sales de Andrade static PetscErrorCode ourshellpresolve(PC pc,KSP ksp,Vec x,Vec y)
77a425a105SElliott Sales de Andrade {
78a425a105SElliott Sales de Andrade   PetscErrorCode ierr = 0;
79*ccf40c83SElliott Sales de Andrade   (*(void (PETSC_STDCALL *)(PC*,KSP*,Vec*,Vec*,PetscErrorCode*))(((PetscObject)pc)->fortran_func_pointers[6]))(&pc,&ksp,&x,&y,&ierr);CHKERRQ(ierr);
80a425a105SElliott Sales de Andrade   return 0;
81a425a105SElliott Sales de Andrade }
82a425a105SElliott Sales de Andrade 
83a425a105SElliott Sales de Andrade static PetscErrorCode ourshellpostsolve(PC pc,KSP ksp,Vec x,Vec y)
84a425a105SElliott Sales de Andrade {
85a425a105SElliott Sales de Andrade   PetscErrorCode ierr = 0;
86*ccf40c83SElliott Sales de Andrade   (*(void (PETSC_STDCALL *)(PC*,KSP*,Vec*,Vec*,PetscErrorCode*))(((PetscObject)pc)->fortran_func_pointers[7]))(&pc,&ksp,&x,&y,&ierr);CHKERRQ(ierr);
87a425a105SElliott Sales de Andrade   return 0;
88a425a105SElliott Sales de Andrade }
89a425a105SElliott Sales de Andrade 
908cc058d9SJed Brown PETSC_EXTERN void PETSC_STDCALL pcshellgetcontext_(PC *pc,void **ctx,PetscErrorCode *ierr)
91e54e4138SSatish Balay {
926891c3e4SJed Brown   *ierr = PCShellGetContext(*pc,ctx);
93e54e4138SSatish Balay }
94e54e4138SSatish Balay 
958cc058d9SJed Brown PETSC_EXTERN void PETSC_STDCALL pcshellsetapply_(PC *pc,void (PETSC_STDCALL *apply)(void*,Vec*,Vec*,PetscErrorCode*),PetscErrorCode *ierr)
96e54e4138SSatish Balay {
97*ccf40c83SElliott Sales de Andrade   PetscObjectAllocateFortranPointers(*pc,8);
986891c3e4SJed Brown   ((PetscObject)*pc)->fortran_func_pointers[0] = (PetscVoidFunction)apply;
992fa5cd67SKarl Rupp 
1006891c3e4SJed Brown   *ierr = PCShellSetApply(*pc,ourshellapply);
1016895c445SBarry Smith }
1026895c445SBarry Smith 
103*ccf40c83SElliott Sales de Andrade PETSC_EXTERN void PETSC_STDCALL pcshellsetapplyba_(PC *pc,void (PETSC_STDCALL *apply)(void*,PCSide*,Vec*,Vec*,Vec*,PetscErrorCode*),PetscErrorCode *ierr)
104*ccf40c83SElliott Sales de Andrade {
105*ccf40c83SElliott Sales de Andrade   PetscObjectAllocateFortranPointers(*pc,8);
106*ccf40c83SElliott Sales de Andrade   ((PetscObject)*pc)->fortran_func_pointers[1] = (PetscVoidFunction)apply;
107*ccf40c83SElliott Sales de Andrade 
108*ccf40c83SElliott Sales de Andrade   *ierr = PCShellSetApplyBA(*pc,ourshellapplyba);
109*ccf40c83SElliott Sales de Andrade }
110*ccf40c83SElliott Sales de Andrade 
1118cc058d9SJed Brown 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)
1126895c445SBarry Smith {
113*ccf40c83SElliott Sales de Andrade   PetscObjectAllocateFortranPointers(*pc,8);
114*ccf40c83SElliott Sales de Andrade   ((PetscObject)*pc)->fortran_func_pointers[2] = (PetscVoidFunction)apply;
1156891c3e4SJed Brown   *ierr = PCShellSetApplyRichardson(*pc,ourapplyrichardson);
1166895c445SBarry Smith }
1176895c445SBarry Smith 
1188cc058d9SJed Brown PETSC_EXTERN void PETSC_STDCALL pcshellsetapplytranspose_(PC *pc,void (PETSC_STDCALL *applytranspose)(void*,Vec *,Vec *,PetscErrorCode*), PetscErrorCode *ierr)
1196895c445SBarry Smith {
120*ccf40c83SElliott Sales de Andrade   PetscObjectAllocateFortranPointers(*pc,8);
121*ccf40c83SElliott Sales de Andrade   ((PetscObject)*pc)->fortran_func_pointers[3] = (PetscVoidFunction)applytranspose;
1222fa5cd67SKarl Rupp 
1236891c3e4SJed Brown   *ierr = PCShellSetApplyTranspose(*pc,ourshellapplytranspose);
124e54e4138SSatish Balay }
125e54e4138SSatish Balay 
1268cc058d9SJed Brown PETSC_EXTERN void PETSC_STDCALL pcshellsetsetup_(PC *pc,void (PETSC_STDCALL *setup)(void*,PetscErrorCode*),PetscErrorCode *ierr)
127e54e4138SSatish Balay {
128*ccf40c83SElliott Sales de Andrade   PetscObjectAllocateFortranPointers(*pc,8);
129*ccf40c83SElliott Sales de Andrade   ((PetscObject)*pc)->fortran_func_pointers[4] = (PetscVoidFunction)setup;
1302fa5cd67SKarl Rupp 
1316891c3e4SJed Brown   *ierr = PCShellSetSetUp(*pc,ourshellsetup);
132e54e4138SSatish Balay }
133e54e4138SSatish Balay 
1348cc058d9SJed Brown PETSC_EXTERN void PETSC_STDCALL pcshellsetdestroy_(PC *pc,void (PETSC_STDCALL *setup)(void*,PetscErrorCode*),PetscErrorCode *ierr)
1357c54600cSBarry Smith {
136*ccf40c83SElliott Sales de Andrade   PetscObjectAllocateFortranPointers(*pc,8);
137*ccf40c83SElliott Sales de Andrade   ((PetscObject)*pc)->fortran_func_pointers[5] = (PetscVoidFunction)setup;
1382fa5cd67SKarl Rupp 
1396891c3e4SJed Brown   *ierr = PCShellSetDestroy(*pc,ourshelldestroy);
1407c54600cSBarry Smith }
1417c54600cSBarry Smith 
142a425a105SElliott Sales de Andrade PETSC_EXTERN void PETSC_STDCALL pcshellsetpresolve_(PC *pc,void (PETSC_STDCALL *presolve)(void*,void*,Vec*,Vec*,PetscErrorCode*),PetscErrorCode *ierr)
143a425a105SElliott Sales de Andrade {
144*ccf40c83SElliott Sales de Andrade   PetscObjectAllocateFortranPointers(*pc,8);
145*ccf40c83SElliott Sales de Andrade   ((PetscObject)*pc)->fortran_func_pointers[6] = (PetscVoidFunction)presolve;
146a425a105SElliott Sales de Andrade 
147a425a105SElliott Sales de Andrade   *ierr = PCShellSetPreSolve(*pc,ourshellpresolve);
148a425a105SElliott Sales de Andrade }
149a425a105SElliott Sales de Andrade 
150a425a105SElliott Sales de Andrade PETSC_EXTERN void PETSC_STDCALL pcshellsetpostsolve_(PC *pc,void (PETSC_STDCALL *postsolve)(void*,void*,Vec*,Vec*,PetscErrorCode*),PetscErrorCode *ierr)
151a425a105SElliott Sales de Andrade {
152*ccf40c83SElliott Sales de Andrade   PetscObjectAllocateFortranPointers(*pc,8);
153*ccf40c83SElliott Sales de Andrade   ((PetscObject)*pc)->fortran_func_pointers[7] = (PetscVoidFunction)postsolve;
154a425a105SElliott Sales de Andrade 
155a425a105SElliott Sales de Andrade   *ierr = PCShellSetPostSolve(*pc,ourshellpostsolve);
156a425a105SElliott Sales de Andrade }
157a425a105SElliott Sales de Andrade 
1588cc058d9SJed Brown PETSC_EXTERN void PETSC_STDCALL pcshellsetname_(PC *pc,CHAR name PETSC_MIXED_LEN(len), PetscErrorCode *ierr PETSC_END_LEN(len))
1591d2e4005SSatish Balay {
1601d2e4005SSatish Balay   char *c;
1611d2e4005SSatish Balay   FIXCHAR(name,len,c);
1621d2e4005SSatish Balay   *ierr = PCShellSetName(*pc,c);
1631d2e4005SSatish Balay   FREECHAR(name,c);
1641d2e4005SSatish Balay }
1651d2e4005SSatish Balay 
1668cc058d9SJed Brown PETSC_EXTERN void PETSC_STDCALL pcshellgetname_(PC *pc,CHAR name PETSC_MIXED_LEN(len), PetscErrorCode *ierr PETSC_END_LEN(len))
167e63f14baSBarry Smith {
168ccaf0856SBarry Smith   const char *c;
169e63f14baSBarry Smith 
170e63f14baSBarry Smith   *ierr = PCShellGetName(*pc,&c);if (*ierr) return;
171e63f14baSBarry Smith   *ierr = PetscStrncpy(name,c,len);
172e63f14baSBarry Smith }
173e63f14baSBarry Smith 
174e54e4138SSatish Balay /* -----------------------------------------------------------------*/
175e54e4138SSatish Balay 
176