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 #ifndef __mortonIndexing_hpp__
21 #define __mortonIndexing_hpp__
22 
23 #include "types.hpp"
24 #include "box.hpp"
25 #include "indexContainer.hpp"
26 #include "pointFlag.hpp"
27 
28 namespace pFlow
29 {
30 
32  box boundingBox,
33  real dx,
34  const ViewType1D<realx3>& pos,
35  const pFlagTypeDevice& flag);
36 
37 
39 uint64_t splitBy3(const uint64_t val){
40  uint64_t x = val;
41  x = (x | x << 32) & 0x1f00000000ffff;
42  x = (x | x << 16) & 0x1f0000ff0000ff;
43  x = (x | x << 8) & 0x100f00f00f00f00f;
44  x = (x | x << 4) & 0x10c30c30c30c30c3;
45  x = (x | x << 2) & 0x1249249249249249;
46  return x;
47 }
48 
50 uint64_t xyzToMortonCode64(uint64_t x, uint64_t y, uint64_t z)
51 {
52  return splitBy3(x) | (splitBy3(y) << 1) | (splitBy3(z) << 2);
53 }
54 
55 
57 uint64_t getThirdBits(uint64_t x)
58 {
59  x = x & 0x9249249249249249;
60  x = (x | (x >> 2)) & 0x30c30c30c30c30c3;
61  x = (x | (x >> 4)) & 0xf00f00f00f00f00f;
62  x = (x | (x >> 8)) & 0x00ff0000ff0000ff;
63  x = (x | (x >> 16)) & 0xffff00000000ffff;
64  x = (x | (x >> 32)) & 0x00000000ffffffff;
65  return x;
66 
67 }
68 
70 void mortonCode64Toxyz(uint64_t morton, uint64_t& x, uint64_t& y, uint64_t& z)
71 {
72  x = getThirdBits(morton);
73  y = getThirdBits(morton >> 1);
74  z = getThirdBits(morton >> 2);
75 }
76 
78 {
79  size_t morton;
80  size_t index;
81 };
82 
83 
84 }
85 
86 #endif //__mortonIndexing_hpp__
pFlow::real
float real
Definition: builtinTypes.hpp:45
types.hpp
box.hpp
pFlow::indexMorton
Definition: mortonIndexing.hpp:77
pFlow::mortonCode64Toxyz
INLINE_FUNCTION_HD void mortonCode64Toxyz(uint64_t morton, uint64_t &x, uint64_t &y, uint64_t &z)
Definition: contactSearchFunctions.hpp:62
pFlow::uint32IndexContainer
indexContainer< uint32 > uint32IndexContainer
Definition: indexContainer.hpp:286
pFlow::getSortedIndices
uint32IndexContainer getSortedIndices(box boundingBox, real dx, const ViewType1D< realx3 > &pos, const pFlagTypeDevice &flag)
Definition: mortonIndexing.cpp:24
pFlow
Definition: demGeometry.hpp:27
pFlow::indexMorton::index
size_t index
Definition: mortonIndexing.hpp:80
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:79
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
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:55
pFlow::pFlagTypeDevice
pointFlag< DefaultExecutionSpace > pFlagTypeDevice
Definition: pointFlag.hpp:387
indexContainer.hpp
pointFlag.hpp