www.cemf.ir
mortonIndexing.hpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 
21 #ifndef __mortonIndexing_hpp__
22 #define __mortonIndexing_hpp__
23 
24 #include "types.hpp"
25 #include "box.hpp"
26 #include "indexContainer.hpp"
27 
28 namespace pFlow
29 {
30 
31 bool getSortedIndex(
32  box boundingBox,
33  real dx,
34  range activeRange,
35  ViewType1D<realx3> pos,
36  ViewType1D<int8> flag,
37  int32IndexContainer& sortedIndex);
38 
39 
41 uint64_t splitBy3(const uint64_t val){
42  uint64_t x = val;
43  x = (x | x << 32) & 0x1f00000000ffff;
44  x = (x | x << 16) & 0x1f0000ff0000ff;
45  x = (x | x << 8) & 0x100f00f00f00f00f;
46  x = (x | x << 4) & 0x10c30c30c30c30c3;
47  x = (x | x << 2) & 0x1249249249249249;
48  return x;
49 }
50 
52 uint64_t xyzToMortonCode64(uint64_t x, uint64_t y, uint64_t z)
53 {
54  return splitBy3(x) | (splitBy3(y) << 1) | (splitBy3(z) << 2);
55 }
56 
57 
59 uint64_t getThirdBits(uint64_t x)
60 {
61  x = x & 0x9249249249249249;
62  x = (x | (x >> 2)) & 0x30c30c30c30c30c3;
63  x = (x | (x >> 4)) & 0xf00f00f00f00f00f;
64  x = (x | (x >> 8)) & 0x00ff0000ff0000ff;
65  x = (x | (x >> 16)) & 0xffff00000000ffff;
66  x = (x | (x >> 32)) & 0x00000000ffffffff;
67  return x;
68 
69 }
70 
72 void mortonCode64Toxyz(uint64_t morton, uint64_t& x, uint64_t& y, uint64_t& z)
73 {
74  x = getThirdBits(morton);
75  y = getThirdBits(morton >> 1);
76  z = getThirdBits(morton >> 2);
77 }
78 
80 {
81  size_t morton;
82  size_t index;
83 };
84 
85 
86 }
87 
88 #endif //__mortonIndexing_hpp__
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::range
kRange< int > range
Definition: KokkosTypes.hpp:59
types.hpp
box.hpp
pFlow::getSortedIndex
bool getSortedIndex(box boundingBox, real dx, range activeRange, ViewType1D< realx3 > pos, ViewType1D< int8 > flag, int32IndexContainer &sortedIndex)
Definition: mortonIndexing.cpp:26
pFlow::indexMorton
Definition: mortonIndexing.hpp:79
pFlow::mortonCode64Toxyz
INLINE_FUNCTION_HD void mortonCode64Toxyz(uint64_t morton, uint64_t &x, uint64_t &y, uint64_t &z)
Definition: contactSearchFunctions.hpp:62
pFlow
Definition: demComponent.hpp:28
pFlow::indexMorton::index
size_t index
Definition: mortonIndexing.hpp:82
pFlow::xyzToMortonCode64
INLINE_FUNCTION_HD uint64_t xyzToMortonCode64(uint64_t x, uint64_t y, uint64_t z)
Definition: contactSearchFunctions.hpp:42
pFlow::indexMorton::morton
size_t morton
Definition: mortonIndexing.hpp:81
pFlow::getThirdBits
INLINE_FUNCTION_HD uint64_t getThirdBits(uint64_t x)
Definition: contactSearchFunctions.hpp:49
pFlow::splitBy3
INLINE_FUNCTION_HD uint64_t splitBy3(const uint64_t val)
Definition: contactSearchFunctions.hpp:31
pFlow::int32IndexContainer
indexContainer< int32 > int32IndexContainer
Definition: indexContainer.hpp:221
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
indexContainer.hpp