Ignore:
Timestamp:
01/31/18 15:14:35 (6 years ago)
Author:
dubos
Message:

devel/unstructured : mesh reordering (Morton)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • codes/icosagcm/devel/Python/src/partition.c

    r620 r674  
    2929                       tpwgts, ubvec, options, &edgecut, part, &comm);  
    3030} 
     31 
     32 
     33// http://www.forceflow.be/2013/10/07/morton-encodingdecoding-through-bit-interleaving-implementations/  
     34// method to seperate bits from a given integer 3 positions apart 
     35static inline uint64_t splitBy3(unsigned int a){ 
     36  uint64_t x = a & 0x1fffff; // we only look at the first 21 bits 
     37  x = (x | x << 32) & 0x1f00000000ffff;  // shift left 32 bits, OR with self, and 00011111000000000000000000000000000000001111111111111111 
     38  x = (x | x << 16) & 0x1f0000ff0000ff;  // shift left 32 bits, OR with self, and 00011111000000000000000011111111000000000000000011111111 
     39  x = (x | x << 8) & 0x100f00f00f00f00f; // shift left 32 bits, OR with self, and 0001000000001111000000001111000000001111000000001111000000000000 
     40  x = (x | x << 4) & 0x10c30c30c30c30c3; // shift left 32 bits, OR with self, and 0001000011000011000011000011000011000011000011000011000100000000 
     41  x = (x | x << 2) & 0x1249249249249249; 
     42  return x; 
     43} 
     44  
     45static inline uint64_t mortonEncode_magicbits(unsigned int x, unsigned int y, unsigned int z){ 
     46  uint64_t answer = 0; 
     47  answer |= splitBy3(x) | splitBy3(y) << 1 | splitBy3(z) << 2; 
     48  return answer; 
     49} 
     50 
     51void dynamico_morton_encode(int n, const int *x, const int *y, const int *z, uint64_t *m) 
     52{ 
     53  for(int i=0; i<n; i++) 
     54    m[i]=mortonEncode_magicbits(x[i],y[i],z[i]); 
     55} 
Note: See TracChangeset for help on using the changeset viewer.