Nektar++
Octant.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Octant.h
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: class of individal octree octants
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #ifndef NEKTAR_MESHUTILS_OCTREE_OCTANT_H
36 #define NEKTAR_MESHUTILS_OCTREE_OCTANT_H
37 
39 
42 
43 namespace Nektar
44 {
45 namespace NekMeshUtils
46 {
47 
48 /**
49  * @brief enumeration of the 6 faces of a cube/octant
50  */
52 {
53  eUp,
59 };
60 
61 /**
62  * @brief enumeration of the possible locations of the octree with respect to
63  * the CAD
64  */
66 {
71 };
72 
73 class Octant; // have to forward declare the class for the sharedptr
74 typedef std::shared_ptr<Octant> OctantSharedPtr;
75 
76 /**
77  * @brief this class contains the infomration and methods for individal octants
78  * in the Octree
79  */
80 class Octant
81 {
82 public:
83  friend class MemoryManager<Octant>;
84 
85  /**
86  * @brief Defualt constructor
87  */
88  Octant(int i, OctantSharedPtr p, Array<OneD, OctantFace> dir);
89 
90  /**
91  * @brief constructor for master octant
92  */
93  Octant(int i,
94  NekDouble x,
95  NekDouble y,
96  NekDouble z,
97  NekDouble dx,
98  const std::vector<SPBaseSharedPtr> &splist);
99 
100  /**
101  * @brief Subdivide the octant
102  */
103  void Subdivide(OctantSharedPtr p, int &numoct);
104 
105  /**
106  * @brief Recursive method which gets a list of the leaf octants
107  * Moves down levels if octant is not a leaf
108  */
109  void CompileLeaves(std::vector<OctantSharedPtr> &Octants)
110  {
111  for (int i = 0; i < 8; i++)
112  {
113  if (m_children[i]->IsLeaf())
114  {
115  Octants.push_back(m_children[i]);
116  }
117  else
118  {
119  m_children[i]->CompileLeaves(Octants);
120  }
121  }
122  }
123 
124  /// Get the Id of the octant
125  int GetId()
126  {
127  return m_id;
128  }
129 
130  /**
131  * @brief Get the location of the center of the octant
132  */
134  {
135  return m_loc;
136  }
137 
138  /**
139  * @brief Get the octants half dimension
140  */
142  {
143  return m_hd;
144  }
145 
146  /**
147  * @brief Get the list of curvature points that are within this octant
148  */
149  std::vector<SPBaseSharedPtr> GetSPList()
150  {
151  return m_localSPList;
152  }
153 
155  {
156  SPBaseSharedPtr ret;
157  bool found = false;
158  for(int i = 0; i < m_localSPList.size(); i++)
159  {
160  if(m_localSPList[i]->GetType() == eCBoundary ||
161  m_localSPList[i]->GetType() == ePBoundary)
162  {
163  ret = m_localSPList[i];
164  found = true;
165  break;
166  }
167  }
168  ASSERTL0(found,"failed to find point");
169  return ret;
170  }
171 
172  /**
173  * @brief Get the number of points in the octants cp list
174  */
176  {
177  return m_localSPList.size();
178  }
179 
180  /**
181  * @brief Get the number of valid cp points in the octants list
182  */
184  {
185  return m_numValidPoints;
186  }
187 
188  /**
189  * @brief Set the value for delta for this octant
190  */
192  {
193  m_delta.first = true;
194  m_delta.second = d;
195  }
196 
197  /**
198  * @brief Get value of delta
199  */
201  {
202  ASSERTL0(m_delta.first,
203  "Tried to acsess delta of octant"
204  "which has not been set");
205 
206  return m_delta.second;
207  }
208 
209  /**
210  * @brief Set the children of this octant
211  */
213  {
214  m_children = c;
215  }
216 
217  /**
218  * @brief Get whether the octant is a leaf or not
219  */
220  bool IsLeaf()
221  {
222  return m_leaf;
223  }
224 
225  /**
226  * @brief Get the far dimension in a given direction f
227  */
229  {
230  switch (f)
231  {
232  case eUp:
233  return m_loc[1] + m_hd;
234  break;
235  case eDown:
236  return m_loc[1] - m_hd;
237  break;
238  case eForward:
239  return m_loc[0] + m_hd;
240  break;
241  case eBack:
242  return m_loc[0] - m_hd;
243  break;
244  case eLeft:
245  return m_loc[2] + m_hd;
246  break;
247  case eRight:
248  return m_loc[2] - m_hd;
249  break;
250  }
251  return 0.0;
252  }
253 
254  /**
255  * @brief Remove a neigbour from this octants list
256  */
257  void RemoveNeigbour(int id, OctantFace f);
258 
259  void SetNeigbour(OctantSharedPtr o, OctantFace f)
260  {
261  m_neigbours[f].push_back(o);
262  }
263 
264  /**
265  * @brief Get the map of neigbours
266  */
267  std::map<OctantFace, std::vector<OctantSharedPtr> > GetNeigbours()
268  {
269  return m_neigbours;
270  }
271 
272  /**
273  * @brief Get whether this octants needs to divide based on the curvature
274  * sampling
275  */
276  bool NeedDivide()
277  {
278  return m_needToDivide;
279  }
280 
281  /**
282  * @brief Get the distance from this octant to another
283  */
284  NekDouble Distance(OctantSharedPtr o)
285  {
286  Array<OneD, NekDouble> loc = o->GetLoc();
287  return sqrt((loc[0] - m_loc[0]) * (loc[0] - m_loc[0]) +
288  (loc[1] - m_loc[1]) * (loc[1] - m_loc[1]) +
289  (loc[2] - m_loc[2]) * (loc[2] - m_loc[2]));
290  }
291 
292  /**
293  * @brief Get whether a value of delta has been set or not
294  */
296  {
297  return m_delta.first;
298  }
299 
300  /**
301  * @brief set the location of the octant with respect to the CAD
302  */
304  {
305  m_location = l;
306  }
307 
308  /**
309  * @brief Get the location of the octant with respect to the geometry
310  */
312  {
313  return m_location;
314  }
315 
316  /**
317  * @brief Get a specific child of this octant
318  */
319  OctantSharedPtr GetChild(int q)
320  {
321  return m_children[q];
322  }
323 
325  {
326  return m_numBoundaryPoints;
327  }
328 
329 private:
330  /// id
331  int m_id;
332  /// leaf identifer
333  bool m_leaf;
334  /// parent id
335  OctantSharedPtr m_parent;
336  /// list of child ids
338  /// x,y,z location of the octant
340  /// half dimension of the octant
342  /// curvature sampling point list
343  std::vector<SPBaseSharedPtr> m_localSPList;
344  /// number of valid cp points
347  /// mesh sizing parameter
348  std::pair<bool, NekDouble> m_delta;
349  /// idenify if division is needed
350  bool m_needToDivide; // asume no need to divide
351  /// idenify if delta has ben set
353  /// list of neighbours
354  std::map<OctantFace, std::vector<OctantSharedPtr> > m_neigbours;
355 };
356 
357 bool operator==(OctantSharedPtr const &p1, OctantSharedPtr const &p2);
358 }
359 }
360 
361 #endif
std::map< OctantFace, std::vector< OctantSharedPtr > > GetNeigbours()
Get the map of neigbours.
Definition: Octant.h:267
NekDouble GetDelta()
Get value of delta.
Definition: Octant.h:200
std::vector< SPBaseSharedPtr > GetSPList()
Get the list of curvature points that are within this octant.
Definition: Octant.h:149
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
bool NeedDivide()
Get whether this octants needs to divide based on the curvature sampling.
Definition: Octant.h:276
void SetNeigbour(OctantSharedPtr o, OctantFace f)
Definition: Octant.h:259
std::vector< SPBaseSharedPtr > m_localSPList
curvature sampling point list
Definition: Octant.h:343
OctantLocation m_location
idenify if delta has ben set
Definition: Octant.h:352
bool IsDeltaKnown()
Get whether a value of delta has been set or not.
Definition: Octant.h:295
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
void RemoveNeigbour(int id, OctantFace f)
Remove a neigbour from this octants list.
Definition: Octant.cpp:496
OctantSharedPtr GetChild(int q)
Get a specific child of this octant.
Definition: Octant.h:319
bool m_leaf
leaf identifer
Definition: Octant.h:333
OctantLocation
enumeration of the possible locations of the octree with respect to the CAD
Definition: Octant.h:65
OctantSharedPtr m_parent
parent id
Definition: Octant.h:335
void SetDelta(NekDouble d)
Set the value for delta for this octant.
Definition: Octant.h:191
NekDouble m_hd
half dimension of the octant
Definition: Octant.h:341
NekDouble DX()
Get the octants half dimension.
Definition: Octant.h:141
Octant(int i, OctantSharedPtr p, Array< OneD, OctantFace > dir)
Defualt constructor.
Definition: Octant.cpp:64
NekDouble Distance(OctantSharedPtr o)
Get the distance from this octant to another.
Definition: Octant.h:284
bool operator==(ElmtConfig const &c1, ElmtConfig const &c2)
Compares two element config structs.
OctantLocation GetLocation()
Get the location of the octant with respect to the geometry.
Definition: Octant.h:311
void Subdivide(OctantSharedPtr p, int &numoct)
Subdivide the octant.
Definition: Octant.cpp:214
Array< OneD, OctantSharedPtr > m_children
list of child ids
Definition: Octant.h:337
int m_numValidPoints
number of valid cp points
Definition: Octant.h:345
Array< OneD, NekDouble > GetLoc()
Get the location of the center of the octant.
Definition: Octant.h:133
bool IsLeaf()
Get whether the octant is a leaf or not.
Definition: Octant.h:220
int GetId()
Get the Id of the octant.
Definition: Octant.h:125
int NumValidCurvePoint()
Get the number of valid cp points in the octants list.
Definition: Octant.h:183
double NekDouble
NekDouble FX(OctantFace f)
Get the far dimension in a given direction f.
Definition: Octant.h:228
Array< OneD, NekDouble > m_loc
x,y,z location of the octant
Definition: Octant.h:339
this class contains the infomration and methods for individal octants in the Octree ...
Definition: Octant.h:80
SPBaseSharedPtr GetABoundPoint()
Definition: Octant.h:154
int NumCurvePoint()
Get the number of points in the octants cp list.
Definition: Octant.h:175
void CompileLeaves(std::vector< OctantSharedPtr > &Octants)
Recursive method which gets a list of the leaf octants Moves down levels if octant is not a leaf...
Definition: Octant.h:109
std::shared_ptr< Octant > OctantSharedPtr
Definition: Octant.h:73
void SetLocation(OctantLocation l)
set the location of the octant with respect to the CAD
Definition: Octant.h:303
OctantFace
enumeration of the 6 faces of a cube/octant
Definition: Octant.h:51
bool m_needToDivide
idenify if division is needed
Definition: Octant.h:350
void SetChildren(Array< OneD, OctantSharedPtr > c)
Set the children of this octant.
Definition: Octant.h:212
std::map< OctantFace, std::vector< OctantSharedPtr > > m_neigbours
list of neighbours
Definition: Octant.h:354
std::pair< bool, NekDouble > m_delta
mesh sizing parameter
Definition: Octant.h:348
std::shared_ptr< SPBase > SPBaseSharedPtr