xref: /petsc/src/vec/is/utils/isltog.h (revision 9566063d113dddea24716c546802770db7481bc0)
1413f72f0SBarry Smith 
2413f72f0SBarry Smith /*
3413f72f0SBarry Smith      This is a terrible way of doing "templates" in C.
4413f72f0SBarry Smith */
5d6a2e6abSJacob Faibussowitsch #define PETSCMAPNAME(a) PetscConcat(a,GTOLNAME)
6d6a2e6abSJacob Faibussowitsch #define PETSCMAPTYPE(a) PetscConcat(a,GTOLTYPE)
7413f72f0SBarry Smith 
8413f72f0SBarry Smith static PetscErrorCode PETSCMAPNAME(ISGlobalToLocalMappingApply)(ISLocalToGlobalMapping mapping,ISGlobalToLocalMappingMode type,
9413f72f0SBarry Smith                                                       PetscInt n,const PetscInt idx[],PetscInt *nout,PetscInt idxout[])
10413f72f0SBarry Smith {
11413f72f0SBarry Smith   PetscInt                             i,nf = 0,tmp,start,end,bs;
12413f72f0SBarry Smith   PETSCMAPTYPE(ISLocalToGlobalMapping) *map = (PETSCMAPTYPE(ISLocalToGlobalMapping)*)mapping->data;
13413f72f0SBarry Smith 
14413f72f0SBarry Smith   PetscFunctionBegin;
15413f72f0SBarry Smith   PetscValidHeaderSpecific(mapping,IS_LTOGM_CLASSID,1);
16413f72f0SBarry Smith   if (!map) {
17*9566063dSJacob Faibussowitsch     PetscCall(ISGlobalToLocalMappingSetUp(mapping));
18413f72f0SBarry Smith     map  = (PETSCMAPTYPE(ISLocalToGlobalMapping) *)mapping->data;
19413f72f0SBarry Smith   }
20413f72f0SBarry Smith   start = mapping->globalstart;
21413f72f0SBarry Smith   end   = mapping->globalend;
22541bf97eSAdrian Croucher   bs    = GTOLBS;
23413f72f0SBarry Smith 
24413f72f0SBarry Smith   if (type == IS_GTOLM_MASK) {
25413f72f0SBarry Smith     if (idxout) {
26413f72f0SBarry Smith       for (i=0; i<n; i++) {
27413f72f0SBarry Smith         if (idx[i] < 0)                 idxout[i] = idx[i];
28541bf97eSAdrian Croucher         else if (idx[i] < bs*start)     idxout[i] = -1;
29541bf97eSAdrian Croucher         else if (idx[i] > bs*(end+1)-1) idxout[i] = -1;
30413f72f0SBarry Smith         else                            GTOL(idx[i], idxout[i]);
31413f72f0SBarry Smith       }
32413f72f0SBarry Smith     }
33413f72f0SBarry Smith     if (nout) *nout = n;
34413f72f0SBarry Smith   } else {
35413f72f0SBarry Smith     if (idxout) {
36413f72f0SBarry Smith       for (i=0; i<n; i++) {
37413f72f0SBarry Smith         if (idx[i] < 0) continue;
38541bf97eSAdrian Croucher         if (idx[i] < bs*start) continue;
39541bf97eSAdrian Croucher         if (idx[i] > bs*(end+1)-1) continue;
40413f72f0SBarry Smith         GTOL(idx[i], tmp);
41413f72f0SBarry Smith         if (tmp < 0) continue;
42413f72f0SBarry Smith         idxout[nf++] = tmp;
43413f72f0SBarry Smith       }
44413f72f0SBarry Smith     } else {
45413f72f0SBarry Smith       for (i=0; i<n; i++) {
46413f72f0SBarry Smith         if (idx[i] < 0) continue;
47541bf97eSAdrian Croucher         if (idx[i] < bs*start) continue;
48541bf97eSAdrian Croucher         if (idx[i] > bs*(end+1)-1) continue;
49413f72f0SBarry Smith         GTOL(idx[i], tmp);
50413f72f0SBarry Smith         if (tmp < 0) continue;
51413f72f0SBarry Smith         nf++;
52413f72f0SBarry Smith       }
53413f72f0SBarry Smith     }
54413f72f0SBarry Smith     if (nout) *nout = nf;
55413f72f0SBarry Smith   }
56413f72f0SBarry Smith   PetscFunctionReturn(0);
57413f72f0SBarry Smith }
58413f72f0SBarry Smith 
59413f72f0SBarry Smith #undef PETSCMAPTYPE
60413f72f0SBarry Smith #undef PETSCMAPNAME
61413f72f0SBarry Smith #undef GTOLTYPE
62413f72f0SBarry Smith #undef GTOLNAME
63541bf97eSAdrian Croucher #undef GTOLBS
64413f72f0SBarry Smith #undef GTOL
65