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