xref: /petsc/src/ksp/pc/impls/asm/ftn-custom/zasmf.c (revision 0e9bae810fdaeb60e2713eaa8ddb89f42e079fd1)
1 #include <petsc-private/fortranimpl.h>
2 #include <petscksp.h>
3 
4 #if defined(PETSC_HAVE_FORTRAN_CAPS)
5 #define pcasmgetsubksp_            PCASMGETSUBKSP
6 #define pcasmsetlocalsubdomains_   PCASMSETLOCALSUBDOMAINS
7 #define pcasmsetglobalsubdomains_  PCASMSETGLOBALSUBDOMAINS
8 #define pcasmgetlocalsubmatrices_  PCASMGETLOCALSUBMATRICES
9 #define pcasmgetlocalsubdomains_   PCASMGETLOCALSUBDOMAINS
10 #define pcasmcreatesubdomains_     PCASMCREATESUBDOMAINS
11 #define pcasmdestroysubdomains_    PCASMDESTROYSUBDOMAINS
12 #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
13 #define pcasmgetsubksp_            pcasmgetsubksp
14 #define pcasmsetlocalsubdomains_   pcasmsetlocalsubdomains
15 #define pcasmsetglobalsubdomains_  pcasmsetglobalsubdomains
16 #define pcasmgetlocalsubmatrices_  pcasmgetlocalsubmatrices
17 #define pcasmgetlocalsubdomains_   pcasmgetlocalsubdomains
18 #define pcasmcreatesubdomains_     pcasmcreatesubdomains
19 #define pcasmdestroysubdomains_    pcasmdestroysubdomains
20 #endif
21 
22 EXTERN_C_BEGIN
23 void PETSC_STDCALL pcasmcreatesubdomains_(Mat *mat,PetscInt *n,IS *subs,PetscErrorCode *ierr)
24 {
25   PetscInt i;
26   IS       *insubs;
27 
28   *ierr = PCASMCreateSubdomains(*mat,*n,&insubs);if (*ierr) return;
29   for (i=0; i<*n; i++) {
30     subs[i] = insubs[i];
31   }
32   *ierr = PetscFree(insubs);
33 }
34 
35 
36 void PETSC_STDCALL pcasmdestroysubdomains_(Mat *mat,PetscInt *n,IS *subs,PetscErrorCode *ierr)
37 {
38   PetscInt i;
39 
40   for (i=0; i<*n; i++) {
41     *ierr = ISDestroy(&subs[i]);if (*ierr) return;
42   }
43 }
44 
45 void PETSC_STDCALL pcasmgetsubksp_(PC *pc,PetscInt *n_local,PetscInt *first_local,KSP *ksp,PetscErrorCode *ierr)
46 {
47   KSP *tksp;
48   PetscInt  i,nloc;
49   CHKFORTRANNULLINTEGER(n_local);
50   CHKFORTRANNULLINTEGER(first_local);
51   CHKFORTRANNULLOBJECT(ksp);
52   *ierr = PCASMGetSubKSP(*pc,&nloc,first_local,&tksp);
53   if (n_local) *n_local = nloc;
54   if (ksp) {
55     for (i=0; i<nloc; i++){
56       ksp[i] = tksp[i];
57     }
58   }
59 }
60 
61 void PETSC_STDCALL pcasmsetlocalsubdomains_(PC *pc,PetscInt *n,IS *is,IS *is_local, PetscErrorCode *ierr)
62 {
63   CHKFORTRANNULLOBJECT(is);
64   CHKFORTRANNULLOBJECT(is_local);
65   *ierr = PCASMSetLocalSubdomains(*pc,*n,is,is_local);
66 }
67 
68 void PETSC_STDCALL pcasmsettotalsubdomains_(PC *pc,PetscInt *N,IS *is,IS *is_local, PetscErrorCode *ierr)
69 {
70   CHKFORTRANNULLOBJECT(is);
71   CHKFORTRANNULLOBJECT(is_local);
72   *ierr = PCASMSetTotalSubdomains(*pc,*N,is,is_local);
73 }
74 
75 void PETSC_STDCALL pcasmgetlocalsubmatrices_(PC *pc,PetscInt *n,Mat *mat, PetscErrorCode *ierr)
76 {
77   PetscInt nloc,i;
78   Mat  *tmat;
79   CHKFORTRANNULLOBJECT(mat);
80   CHKFORTRANNULLINTEGER(n);
81   *ierr = PCASMGetLocalSubmatrices(*pc,&nloc,&tmat);
82   if (n) *n = nloc;
83   if (mat) {
84     for (i=0; i<nloc; i++){
85       mat[i] = tmat[i];
86     }
87   }
88 }
89 void PETSC_STDCALL pcasmgetlocalsubdomains_(PC *pc,PetscInt *n,IS *is,IS *is_local, PetscErrorCode *ierr)
90 {
91   PetscInt nloc,i;
92   IS  *tis, *tis_local;
93   CHKFORTRANNULLOBJECT(is);
94   CHKFORTRANNULLOBJECT(is_local);
95   CHKFORTRANNULLINTEGER(n);
96   *ierr = PCASMGetLocalSubdomains(*pc,&nloc,&tis,&tis_local);
97   if (n) *n = nloc;
98   if (is) {
99     for (i=0; i<nloc; i++){
100       is[i] = tis[i];
101     }
102   }
103   if (is_local && tis_local) {
104     for (i=0; i<nloc; i++){
105       is[i] = tis_local[i];
106     }
107   }
108 }
109 
110 EXTERN_C_END
111