www.cemf.ir
contactSearchFunctions.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 __broadSearchFunctions_hpp__
22 #define __broadSearchFunctions_hpp__
23 
24 #include "types.hpp"
25 #include "iBox.hpp"
26 
27 namespace pFlow
28 {
29 
31 uint64_t splitBy3(const uint64_t val){
32  uint64_t x = val;
33  x = (x | x << 32) & 0x1f00000000ffff;
34  x = (x | x << 16) & 0x1f0000ff0000ff;
35  x = (x | x << 8) & 0x100f00f00f00f00f;
36  x = (x | x << 4) & 0x10c30c30c30c30c3;
37  x = (x | x << 2) & 0x1249249249249249;
38  return x;
39 }
40 
42 uint64_t xyzToMortonCode64(uint64_t x, uint64_t y, uint64_t z)
43 {
44  return splitBy3(x) | (splitBy3(y) << 1) | (splitBy3(z) << 2);
45 }
46 
47 
49 uint64_t getThirdBits(uint64_t x)
50 {
51  x = x & 0x9249249249249249;
52  x = (x | (x >> 2)) & 0x30c30c30c30c30c3;
53  x = (x | (x >> 4)) & 0xf00f00f00f00f00f;
54  x = (x | (x >> 8)) & 0x00ff0000ff0000ff;
55  x = (x | (x >> 16)) & 0xffff00000000ffff;
56  x = (x | (x >> 32)) & 0x00000000ffffffff;
57  return x;
58 
59 }
60 
62 void mortonCode64Toxyz(uint64_t morton, uint64_t& x, uint64_t& y, uint64_t& z)
63 {
64  x = getThirdBits(morton);
65  y = getThirdBits(morton >> 1);
66  z = getThirdBits(morton >> 2);
67 }
68 
69 template<typename indexType, typename cellIndexType>
71 void indexToCell(const indexType idx, const triple<cellIndexType>& extent, triple<cellIndexType>& cell)
72 {
73  indexType nxny = extent.x()*extent.y();
74  cell.z() = static_cast<cellIndexType>(idx / nxny);
75  auto rem = idx % nxny;
76  cell.y() = static_cast<cellIndexType>(rem / extent.x());
77  cell.x() = static_cast<cellIndexType>(rem % extent.x());
78 }
79 
80 template<typename cellIndexType>
83 {
84  return triple<cellIndexType>(
85  box.maxPoint().x() - box.minPoint().x() + 1,
86  box.maxPoint().y() - box.minPoint().y() + 1,
87  box.maxPoint().z() - box.minPoint().z() + 1);
88 }
89 
90 template<typename indexType, typename cellIndexType>
92 void indexToCell(const indexType idx, const iBox<cellIndexType>& box, triple<cellIndexType>& cell)
93 {
94  auto extent = boxExtent(box);
95  indexToCell(idx, extent, cell);
96  cell+= box.minPoint();
97 }
98 
99 }
100 
101 #endif //__broadSearchFunctions_hpp__
types.hpp
pFlow::indexToCell
INLINE_FUNCTION_HD void indexToCell(const indexType idx, const triple< cellIndexType > &extent, triple< cellIndexType > &cell)
Definition: contactSearchFunctions.hpp:71
pFlow::box::maxPoint
const INLINE_FUNCTION_HD realx3 & maxPoint() const
Definition: box.hpp:97
pFlow::mortonCode64Toxyz
INLINE_FUNCTION_HD void mortonCode64Toxyz(uint64_t morton, uint64_t &x, uint64_t &y, uint64_t &z)
Definition: contactSearchFunctions.hpp:62
pFlow::triple::y
INLINE_FUNCTION_HD T & y()
access component
Definition: triple.hpp:144
pFlow
Definition: demGeometry.hpp:27
iBox.hpp
pFlow::boxExtent
INLINE_FUNCTION_HD triple< cellIndexType > boxExtent(const iBox< cellIndexType > &box)
Definition: contactSearchFunctions.hpp:82
pFlow::xyzToMortonCode64
INLINE_FUNCTION_HD uint64_t xyzToMortonCode64(uint64_t x, uint64_t y, uint64_t z)
Definition: contactSearchFunctions.hpp:42
pFlow::triple::z
INLINE_FUNCTION_HD T & z()
access component
Definition: triple.hpp:156
pFlow::box::minPoint
const INLINE_FUNCTION_HD realx3 & minPoint() const
Definition: box.hpp:91
pFlow::getThirdBits
INLINE_FUNCTION_HD uint64_t getThirdBits(uint64_t x)
Definition: contactSearchFunctions.hpp:49
pFlow::box
Definition: box.hpp:32
pFlow::splitBy3
INLINE_FUNCTION_HD uint64_t splitBy3(const uint64_t val)
Definition: contactSearchFunctions.hpp:31
pFlow::iBox
Definition: iBox.hpp:33
pFlow::triple::x
INLINE_FUNCTION_HD T & x()
access component
Definition: triple.hpp:132
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:55
pFlow::triple
A set of 3 variables that can be used for vector variables.
Definition: triple.hpp:36