xref: /petsc/src/vec/is/utils/isltog.h (revision d6a2e6ab466edbe4fea3985dcba6980b1d5f1b80)
1413f72f0SBarry Smith 
2413f72f0SBarry Smith /*
3413f72f0SBarry Smith      This is a terrible way of doing "templates" in C.
4413f72f0SBarry Smith */
5*d6a2e6abSJacob Faibussowitsch #define PETSCMAPNAME(a) PetscConcat(a,GTOLNAME)
6*d6a2e6abSJacob 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   PetscErrorCode                       ierr;
14413f72f0SBarry Smith 
15413f72f0SBarry Smith   PetscFunctionBegin;
16413f72f0SBarry Smith   PetscValidHeaderSpecific(mapping,IS_LTOGM_CLASSID,1);
17413f72f0SBarry Smith   if (!map) {
18413f72f0SBarry Smith     ierr = ISGlobalToLocalMappingSetUp(mapping);CHKERRQ(ierr);
19413f72f0SBarry Smith     map  = (PETSCMAPTYPE(ISLocalToGlobalMapping) *)mapping->data;
20413f72f0SBarry Smith   }
21413f72f0SBarry Smith   start = mapping->globalstart;
22413f72f0SBarry Smith   end   = mapping->globalend;
23541bf97eSAdrian Croucher   bs    = GTOLBS;
24413f72f0SBarry Smith 
25413f72f0SBarry Smith   if (type == IS_GTOLM_MASK) {
26413f72f0SBarry Smith     if (idxout) {
27413f72f0SBarry Smith       for (i=0; i<n; i++) {
28413f72f0SBarry Smith         if (idx[i] < 0)                 idxout[i] = idx[i];
29541bf97eSAdrian Croucher         else if (idx[i] < bs*start)     idxout[i] = -1;
30541bf97eSAdrian Croucher         else if (idx[i] > bs*(end+1)-1) idxout[i] = -1;
31413f72f0SBarry Smith         else                            GTOL(idx[i], idxout[i]);
32413f72f0SBarry Smith       }
33413f72f0SBarry Smith     }
34413f72f0SBarry Smith     if (nout) *nout = n;
35413f72f0SBarry Smith   } else {
36413f72f0SBarry Smith     if (idxout) {
37413f72f0SBarry Smith       for (i=0; i<n; i++) {
38413f72f0SBarry Smith         if (idx[i] < 0) continue;
39541bf97eSAdrian Croucher         if (idx[i] < bs*start) continue;
40541bf97eSAdrian Croucher         if (idx[i] > bs*(end+1)-1) continue;
41413f72f0SBarry Smith         GTOL(idx[i], tmp);
42413f72f0SBarry Smith         if (tmp < 0) continue;
43413f72f0SBarry Smith         idxout[nf++] = tmp;
44413f72f0SBarry Smith       }
45413f72f0SBarry Smith     } else {
46413f72f0SBarry Smith       for (i=0; i<n; i++) {
47413f72f0SBarry Smith         if (idx[i] < 0) continue;
48541bf97eSAdrian Croucher         if (idx[i] < bs*start) continue;
49541bf97eSAdrian Croucher         if (idx[i] > bs*(end+1)-1) continue;
50413f72f0SBarry Smith         GTOL(idx[i], tmp);
51413f72f0SBarry Smith         if (tmp < 0) continue;
52413f72f0SBarry Smith         nf++;
53413f72f0SBarry Smith       }
54413f72f0SBarry Smith     }
55413f72f0SBarry Smith     if (nout) *nout = nf;
56413f72f0SBarry Smith   }
57413f72f0SBarry Smith   PetscFunctionReturn(0);
58413f72f0SBarry Smith }
59413f72f0SBarry Smith 
60413f72f0SBarry Smith #undef PETSCMAPTYPE
61413f72f0SBarry Smith #undef PETSCMAPNAME
62413f72f0SBarry Smith #undef GTOLTYPE
63413f72f0SBarry Smith #undef GTOLNAME
64541bf97eSAdrian Croucher #undef GTOLBS
65413f72f0SBarry Smith #undef GTOL
66