Lagrangian Particle Code for The Simulation of 2D/3D Fluid Dynamics
 All Classes Files Functions Variables Typedefs Friends Pages
octree.h
Go to the documentation of this file.
1 
20 #ifndef __OCTREE_H__
21 #define __OCTREE_H__
22 
23 
24 #ifdef _MSC_VER
25 typedef __int32 int32_t;
26 typedef unsigned __int32 uint32_t;
27 typedef __int64 int64_t;
28 typedef unsigned __int64 uint64_t;
29 #else
30 #include <stdint.h>
31 #endif
32 
33 #include <deque>
34 #include <vector>
35 
36 #ifdef _OPENMP
37 //#include <thrust/sort.h>
38 //#include <thrust/host_vector.h>
39 //#include <thrust/system/omp/vector.h>
40 #endif
41 
42 
43 //#include "particle_bunch.h"
44 
45 
46 using namespace std;
47 
52 struct SearchResult {
53  double distance;
54  int index;
55  bool operator < (const SearchResult& sr) const {
57  return (distance < sr.distance);
58  }
59 };
60 
61 
62 
63 
64 
69 struct KeyIndex
70 {
71  int key;//Should be a 32/64 bit integer. With a 32 bit integer we can use Octrees of depth 10. With a 64 bit integer we can use octrees of depth 20.
72  int index;
73  bool operator < (const KeyIndex& a) const
74  {
75  return (key < a.key);
76  }
77 };
78 
79 
80 
94 class Octree {
95 
96 private:
97 
98  size_t m_iMaxParticleNum;
99 
100  //vector<ParticleBunch*> *m_vParticleBunchList;
101 
105  const double *m_vCoordX;
109  const double *m_vCoordY;
113  const double *m_vCoordZ;
114 
118  int m_iTotalNumberOfParticles;
119 
123 #ifdef _OPENMP
124  //thrust::omp::vector<KeyIndex> m_vParticleKeyIndex;
125  //thrust::host_vector<KeyIndex> m_vParticleKeyIndex;
126  //std::vector<KeyIndex> m_vParticleKeyIndex;
127  KeyIndex *m_vParticleKeyIndex;
128 #else
129  KeyIndex *m_vParticleKeyIndex;
130 #endif
131 
136  int m_iMaxDepth;
137 
141  int m_iLinearSearchDepth;
142  //int maxParticleNumInCell;
143 
147  double m_dBoundingBox_min_x ;
148 
152  double m_dBoundingBox_max_x ;
153 
157  double m_dBoundingBox_min_y ;
158 
162  double m_dBoundingBox_max_y ;
163 
167  double m_dBoundingBox_min_z ;
168 
172  double m_dBoundingBox_max_z ;
173 
174 
178  int m_iTreeLength;
179 
180 
181 
197  int* m_vNodeKey;
198 
203  int* m_vDepth;
204 
210  int* m_vFirstParticleIndex;
211 
216  int* m_vNumberOfContainedParticles;
217 
224  int* m_vFirstChildIndex;
225 
231  int* m_vNumberOfChildren;
232 
236  double* m_vLowerLimitOfX;
237 
241  double* m_vLowerLimitOfY;
242 
246  double* m_vLowerLimitOfZ;
247 
251  double* m_vUpperLimitOfX;
252 
256  double* m_vUpperLimitOfY;
257 
261  double* m_vUpperLimitOfZ;
262 
263 
264  //vector<int>* m_vParticleNumList;
265 
266 public:
267  //Octree(int treedepth, int numOfParticles);
268  Octree(int treedepth, size_t maxParticleNum);
269  virtual ~Octree();
270 
271 
272  //int initialize();
276  int buildOctree(const double* x, const double* y, const double* z, size_t numParticles);
277  //int buildOctree(const double *xp, const double *yp, const double *zp);
278 
279  int searchNeighbor(const double search_x, const double search_y, const double search_z, const double radius, int* result, size_t& result_length);
280 
281  int searchNeighbor(const double search_x, const double search_y, const double search_z, const double radius, SearchResult* result, size_t& result_length);
282 
283 private:
287  inline uint32_t computeKey(const double& x, const double& y, const double& z);
288 
289  //void oneDimIndexTo2DimPair(vector<int>* numParticles, int index, int& clusterIndex, int& particleIndex);
290 };
291 
292 
293 #endif // __OCTREE_H__
294 
295 
This struct contains the morton key and the index of a particle. a vector of such structs is then sor...
Definition: octree.h:69
int index
Definition: octree.h:54
This class contains the Octree data structure and algorithm for nearest neighbour search of particles...
Definition: octree.h:94
A simple struct for the neighbour search result.
Definition: octree.h:52
double distance
The distance between the target particle and its neighbour.
Definition: octree.h:53