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 14 PetscFunctionBegin; 15 PetscValidHeaderSpecific(mapping,IS_LTOGM_CLASSID,1); 16 if (!map) { 17 CHKERRQ(ISGlobalToLocalMappingSetUp(mapping)); 18 map = (PETSCMAPTYPE(ISLocalToGlobalMapping) *)mapping->data; 19 } 20 start = mapping->globalstart; 21 end = mapping->globalend; 22 bs = GTOLBS; 23 24 if (type == IS_GTOLM_MASK) { 25 if (idxout) { 26 for (i=0; i<n; i++) { 27 if (idx[i] < 0) idxout[i] = idx[i]; 28 else if (idx[i] < bs*start) idxout[i] = -1; 29 else if (idx[i] > bs*(end+1)-1) idxout[i] = -1; 30 else GTOL(idx[i], idxout[i]); 31 } 32 } 33 if (nout) *nout = n; 34 } else { 35 if (idxout) { 36 for (i=0; i<n; i++) { 37 if (idx[i] < 0) continue; 38 if (idx[i] < bs*start) continue; 39 if (idx[i] > bs*(end+1)-1) continue; 40 GTOL(idx[i], tmp); 41 if (tmp < 0) continue; 42 idxout[nf++] = tmp; 43 } 44 } else { 45 for (i=0; i<n; i++) { 46 if (idx[i] < 0) continue; 47 if (idx[i] < bs*start) continue; 48 if (idx[i] > bs*(end+1)-1) continue; 49 GTOL(idx[i], tmp); 50 if (tmp < 0) continue; 51 nf++; 52 } 53 } 54 if (nout) *nout = nf; 55 } 56 PetscFunctionReturn(0); 57 } 58 59 #undef PETSCMAPTYPE 60 #undef PETSCMAPNAME 61 #undef GTOLTYPE 62 #undef GTOLNAME 63 #undef GTOLBS 64 #undef GTOL 65