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