xref: /petsc/src/vec/is/utils/isltog.h (revision 5c6496ba940341816c82c3b7fcda2e06e7ddfa20)
1 
2 /*
3      This is a terrible way of doing "templates" in C.
4 */
5 #define PETSCMAPNAME(a) PetscConcat(a,GTOLNAME)
6 #define PETSCMAPTYPE(a) PetscConcat(a,GTOLTYPE)
7 
8 static PetscErrorCode PETSCMAPNAME(ISGlobalToLocalMappingApply)(ISLocalToGlobalMapping mapping,ISGlobalToLocalMappingMode type,
9                                                       PetscInt n,const PetscInt idx[],PetscInt *nout,PetscInt idxout[])
10 {
11   PetscInt                             i,nf = 0,tmp,start,end,bs;
12   PETSCMAPTYPE(ISLocalToGlobalMapping) *map = (PETSCMAPTYPE(ISLocalToGlobalMapping)*)mapping->data;
13   PetscErrorCode                       ierr;
14 
15   PetscFunctionBegin;
16   PetscValidHeaderSpecific(mapping,IS_LTOGM_CLASSID,1);
17   if (!map) {
18     ierr = ISGlobalToLocalMappingSetUp(mapping);CHKERRQ(ierr);
19     map  = (PETSCMAPTYPE(ISLocalToGlobalMapping) *)mapping->data;
20   }
21   start = mapping->globalstart;
22   end   = mapping->globalend;
23   bs    = GTOLBS;
24 
25   if (type == IS_GTOLM_MASK) {
26     if (idxout) {
27       for (i=0; i<n; i++) {
28         if (idx[i] < 0)                 idxout[i] = idx[i];
29         else if (idx[i] < bs*start)     idxout[i] = -1;
30         else if (idx[i] > bs*(end+1)-1) idxout[i] = -1;
31         else                            GTOL(idx[i], idxout[i]);
32       }
33     }
34     if (nout) *nout = n;
35   } else {
36     if (idxout) {
37       for (i=0; i<n; i++) {
38         if (idx[i] < 0) continue;
39         if (idx[i] < bs*start) continue;
40         if (idx[i] > bs*(end+1)-1) continue;
41         GTOL(idx[i], tmp);
42         if (tmp < 0) continue;
43         idxout[nf++] = tmp;
44       }
45     } else {
46       for (i=0; i<n; i++) {
47         if (idx[i] < 0) continue;
48         if (idx[i] < bs*start) continue;
49         if (idx[i] > bs*(end+1)-1) continue;
50         GTOL(idx[i], tmp);
51         if (tmp < 0) continue;
52         nf++;
53       }
54     }
55     if (nout) *nout = nf;
56   }
57   PetscFunctionReturn(0);
58 }
59 
60 #undef PETSCMAPTYPE
61 #undef PETSCMAPNAME
62 #undef GTOLTYPE
63 #undef GTOLNAME
64 #undef GTOLBS
65 #undef GTOL
66