Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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<CurvaturePointSharedPtr> &cplist);
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<CurvaturePointSharedPtr> GetCPList()
151  {
152  return m_localCPList;
153  }
154 
155  /**
156  * @brief Get the number of points in the octants cp list
157  */
159  {
160  return m_localCPList.size();
161  }
162 
163  /**
164  * @brief Get the number of valid cp points in the octants list
165  */
167  {
168  return m_numValidPoints;
169  }
170 
171  /**
172  * @brief Set the value for delta for this octant
173  */
175  {
176  m_delta.first = true;
177  m_delta.second = d;
178  }
179 
180  /**
181  * @brief Get value of delta
182  */
184  {
185  ASSERTL0(m_delta.first,
186  "Tried to acsess delta of octant"
187  "which has not been set");
188 
189  return m_delta.second;
190  }
191 
192  /**
193  * @brief Set the children of this octant
194  */
196  {
197  m_children = c;
198  }
199 
200  /**
201  * @brief Get whether the octant is a leaf or not
202  */
203  bool IsLeaf()
204  {
205  return m_leaf;
206  }
207 
208  /**
209  * @brief Get the far dimension in a given direction f
210  */
212  {
213  switch (f)
214  {
215  case eUp:
216  return m_loc[1] + m_hd;
217  break;
218  case eDown:
219  return m_loc[1] - m_hd;
220  break;
221  case eForward:
222  return m_loc[0] + m_hd;
223  break;
224  case eBack:
225  return m_loc[0] - m_hd;
226  break;
227  case eLeft:
228  return m_loc[2] + m_hd;
229  break;
230  case eRight:
231  return m_loc[2] - m_hd;
232  break;
233  }
234  }
235 
236  /**
237  * @brief Remove a neigbour from this octants list
238  */
239  void RemoveNeigbour(int id, OctantFace f);
240 
241  void SetNeigbour(OctantSharedPtr o, OctantFace f)
242  {
243  m_neigbours[f].push_back(o);
244  }
245 
246  /**
247  * @brief Get the map of neigbours
248  */
249  std::map<OctantFace, std::vector<OctantSharedPtr> > GetNeigbours()
250  {
251  return m_neigbours;
252  }
253 
254  /**
255  * @brief Get whether this octants needs to divide based on the curvature
256  * sampling
257  */
258  bool NeedDivide()
259  {
260  return m_needToDivide;
261  }
262 
263  /**
264  * @brief Get the distance from this octant to another
265  */
266  NekDouble Distance(OctantSharedPtr o)
267  {
268  Array<OneD, NekDouble> loc = o->GetLoc();
269  return sqrt((loc[0] - m_loc[0]) * (loc[0] - m_loc[0]) +
270  (loc[1] - m_loc[1]) * (loc[1] - m_loc[1]) +
271  (loc[2] - m_loc[2]) * (loc[2] - m_loc[2]));
272  }
273 
274  /**
275  * @brief Get whether a value of delta has been set or not
276  */
278  {
279  return m_delta.first;
280  }
281 
282  /**
283  * @brief set the location of the octant with respect to the CAD
284  */
286  {
287  m_location = l;
288  }
289 
290  /**
291  * @brief Get the first cp point in the list
292  */
294  {
295  ASSERTL0(m_localCPList.size() > 0,
296  "tried to get cp point where there is none");
297  return m_localCPList[0];
298  }
299 
300  /**
301  * @brief Get the location of the octant with respect to the geometry
302  */
304  {
305  return m_location;
306  }
307 
308  /**
309  * @brief Get a specific child of this octant
310  */
311  OctantSharedPtr GetChild(int q)
312  {
313  return m_children[q];
314  }
315 
317  {
318  return m_numBoundaryPoints;
319  }
320 
321 private:
322  /// id
323  int m_id;
324  /// leaf identifer
325  bool m_leaf;
326  /// parent id
327  OctantSharedPtr m_parent;
328  /// list of child ids
330  /// x,y,z location of the octant
332  /// half dimension of the octant
334  /// curvature sampling point list
335  std::vector<CurvaturePointSharedPtr> m_localCPList;
336  /// number of valid cp points
339  /// mesh sizing parameter
340  std::pair<bool, NekDouble> m_delta;
341  /// idenify if division is needed
342  bool m_needToDivide; // asume no need to divide
343  /// idenify if delta has ben set
345  /// list of neighbours
346  std::map<OctantFace, std::vector<OctantSharedPtr> > m_neigbours;
347 };
348 
349 bool operator==(OctantSharedPtr const &p1, OctantSharedPtr const &p2);
350 }
351 }
352 
353 #endif
std::map< OctantFace, std::vector< OctantSharedPtr > > GetNeigbours()
Get the map of neigbours.
Definition: Octant.h:249
NekDouble GetDelta()
Get value of delta.
Definition: Octant.h:183
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
bool NeedDivide()
Get whether this octants needs to divide based on the curvature sampling.
Definition: Octant.h:258
void SetNeigbour(OctantSharedPtr o, OctantFace f)
Definition: Octant.h:241
std::vector< CurvaturePointSharedPtr > GetCPList()
Get the list of curvature points that are within this octant.
Definition: Octant.h:150
OctantLocation m_location
idenify if delta has ben set
Definition: Octant.h:344
bool IsDeltaKnown()
Get whether a value of delta has been set or not.
Definition: Octant.h:277
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:494
OctantSharedPtr GetChild(int q)
Get a specific child of this octant.
Definition: Octant.h:311
bool m_leaf
leaf identifer
Definition: Octant.h:325
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:327
void SetDelta(NekDouble d)
Set the value for delta for this octant.
Definition: Octant.h:174
NekDouble m_hd
half dimension of the octant
Definition: Octant.h:333
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:63
NekDouble Distance(OctantSharedPtr o)
Get the distance from this octant to another.
Definition: Octant.h:266
std::vector< CurvaturePointSharedPtr > m_localCPList
curvature sampling point list
Definition: Octant.h:335
bool operator==(ElmtConfig const &c1, ElmtConfig const &c2)
boost::shared_ptr< CurvaturePoint > CurvaturePointSharedPtr
OctantLocation GetLocation()
Get the location of the octant with respect to the geometry.
Definition: Octant.h:303
void Subdivide(OctantSharedPtr p, int &numoct)
Subdivide the octant.
Definition: Octant.cpp:212
Array< OneD, OctantSharedPtr > m_children
list of child ids
Definition: Octant.h:329
int m_numValidPoints
number of valid cp points
Definition: Octant.h:337
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:203
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:166
double NekDouble
NekDouble FX(OctantFace f)
Get the far dimension in a given direction f.
Definition: Octant.h:211
Array< OneD, NekDouble > m_loc
x,y,z location of the octant
Definition: Octant.h:331
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
int NumCurvePoint()
Get the number of points in the octants cp list.
Definition: Octant.h:158
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:285
CurvaturePointSharedPtr GetCPPoint()
Get the first cp point in the list.
Definition: Octant.h:293
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:342
void SetChildren(Array< OneD, OctantSharedPtr > c)
Set the children of this octant.
Definition: Octant.h:195
std::map< OctantFace, std::vector< OctantSharedPtr > > m_neigbours
list of neighbours
Definition: Octant.h:346
std::pair< bool, NekDouble > m_delta
mesh sizing parameter
Definition: Octant.h:340