Nektar++
Octree.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Octree.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: octree object header
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #ifndef NEKTAR_MESHUTILS_OCTREE_OCTREE
36 #define NEKTAR_MESHUTILS_OCTREE_OCTREE
37 
38 #include "SourcePoint.hpp"
39 #include "Octant.h"
41 
42 #include <string>
43 
44 namespace Nektar
45 {
46 namespace NekMeshUtils
47 {
48 
49 //struct to assist in the creation of linesources in the code
50 struct linesource
51 {
56  NekDouble r,
57  NekDouble d)
58  : x1(p1), x2(p2), R(r), delta(d)
59  {
60  }
61 
63  {
64  Array<OneD, NekDouble> Le(3), Re(3), s(3);
65  for (int i = 0; i < 3; i++)
66  {
67  Le[i] = p[i] - x1[i];
68  Re[i] = p[i] - x2[i];
69  s[i] = x2[i] - x1[i];
70  }
72  dev[0] = Le[1] * Re[2] - Re[1] * Le[2];
73  dev[1] = Le[2] * Re[0] - Re[2] * Le[0];
74  dev[2] = Le[0] * Re[1] - Re[0] * Le[1];
75 
76  NekDouble dist =
77  sqrt(dev[0] * dev[0] + dev[1] * dev[1] + dev[2] * dev[2]) / Length();
78 
79  NekDouble t = -1.0 * ((x1[0] - p[0]) * s[0] + (x1[1] - p[1]) * s[1] +
80  (x1[2] - p[2]) * s[2]) / Length() / Length();
81 
82  if (dist < R && !(t > 1) && !(t < 0))
83  {
84  return true;
85  }
86  else
87  {
88  return false;
89  }
90  }
91 
93  {
94  return sqrt((x1[0] - x2[0]) * (x1[0] - x2[0]) +
95  (x1[1] - x2[1]) * (x1[1] - x2[1]) +
96  (x1[2] - x2[2]) * (x1[2] - x2[2]));
97  }
98 };
99 
100 /**
101  * @brief class for octree
102  *
103  * This class contains the routines to generate and query a automatically
104  * generated set of mesh spacing parameters based on the CAD
105  */
106 class Octree
107 {
108 public:
109 
110  Octree(MeshSharedPtr m) : m_mesh(m)
111  {
112  }
113 
114  /**
115  * @brief builds the octree based on curvature sampling and user defined
116  * spacing
117  */
118  void Process();
119 
120  /**
121  * @brief once constructed queryies the octree based on x,y,z location
122  * to get a mesh spacing
123  *
124  * @param loc array of x,y,z
125  * @return mesh spacing parameter
126  */
128 
129  /**
130  * @brief returns the miminum spacing in the octree (for meshing purposes)
131  *
132  * @return miminum delta in octree
133  */
134  NekDouble GetMinDelta();
135 
136  /**
137  * @brief sets the parameters used for curvature sampling
138  *
139  * @param min minimum spacing to be found in the mesh
140  * @param max maximum spacing to be found in the mesh
141  * @param eps curvature sensivity relating radius of curvature to spacing
142  */
144  {
145  m_minDelta = min;
146  m_maxDelta = max;
147  m_eps = ep;
148  }
149 
150  /**
151  * @brief populates the mesh m with a invalid hexahedral mesh based on the
152  * octree, used for visualisation
153  * @param nm name of the mesh file to be made
154  */
155  void WriteOctree(std::string nm);
156 
157  /**
158  * @brief informs the octree there is a user defined spacing file
159  *
160  * @param nm name of the user defined spacing file
161  */
162  void Refinement(std::string nm)
163  {
164  m_refinement = nm;
165  }
166 
167 private:
168 
169  /**
170  * @brief Smooths specification over all octants to a gradation criteria
171  */
172  void SmoothAllOctants();
173 
174  /**
175  * @brief gets an optimum number of curvature sampling points and
176  * calculates the curavture at these points
177  */
178  void CompileSourcePointList();
179 
180  /**
181  * @brief Function which initiates and controls the subdivision process
182  */
183  void SubDivide();
184 
185  /**
186  * @brief Smooths specification over the surface encompasing octants to a
187  * gradation criteria
188  */
189  void SmoothSurfaceOctants();
190 
191  /**
192  * @brief takes the mesh specification from surface octants and
193  * progates that through the domain so all octants have a
194  * specification
195  * using gradiation crieteria
196  */
197  void PropagateDomain();
198 
199  /**
200  * @brief estimates the number of elements to be created in the mesh
201  */
202  int CountElemt();
203 
204  /**
205  * @brief Calculates the difference in delta divided by the difference
206  * in location between two octants i and j
207  */
209 
210  /**
211  * @brief Looks over all leaf octants and checks that their neigbour
212  * assigments are valid
213  */
214  bool VerifyNeigbours();
215 
216  /// minimum delta in the octree
218  /// maximum delta in the octree
220  /// curavture sensivity paramter
222  /// x,y,z location of the center of the octree
224  /// physical size of the octree
226  /// list of source points
227  std::vector<SPBaseSharedPtr> m_SPList;
228  /// list of leaf octants
229  std::vector<OctantSharedPtr> m_octants;
230  /// master octant for searching
232  /// number of octants made, used for id index
233  int m_numoct;
234  /// Mesh object
236 
237  std::string m_refinement;
238  std::vector<linesource> m_lsources;
239 };
240 typedef std::shared_ptr<Octree> OctreeSharedPtr;
241 
242 }
243 }
244 
245 #endif
std::vector< SPBaseSharedPtr > m_SPList
list of source points
Definition: Octree.h:227
std::vector< OctantSharedPtr > m_octants
list of leaf octants
Definition: Octree.h:229
void SetParameters(NekDouble &min, NekDouble &max, NekDouble &ep)
sets the parameters used for curvature sampling
Definition: Octree.h:143
Array< OneD, NekDouble > x1
Definition: Octree.h:52
Array< OneD, NekDouble > x2
Definition: Octree.h:52
std::shared_ptr< Octree > OctreeSharedPtr
Definition: Mesh.h:51
NekDouble m_minDelta
minimum delta in the octree
Definition: Octree.h:217
std::shared_ptr< Mesh > MeshSharedPtr
Shared pointer to a mesh.
Definition: Mesh.h:156
OctantSharedPtr m_masteroct
master octant for searching
Definition: Octree.h:231
class for octree
Definition: Octree.h:106
std::string m_refinement
Definition: Octree.h:237
double NekDouble
int m_numoct
number of octants made, used for id index
Definition: Octree.h:233
linesource(Array< OneD, NekDouble > p1, Array< OneD, NekDouble > p2, NekDouble r, NekDouble d)
Definition: Octree.h:54
std::vector< linesource > m_lsources
Definition: Octree.h:238
NekDouble m_eps
curavture sensivity paramter
Definition: Octree.h:221
std::shared_ptr< Octant > OctantSharedPtr
Definition: Octant.h:73
NekDouble m_dim
physical size of the octree
Definition: Octree.h:225
Octree(MeshSharedPtr m)
Definition: Octree.h:110
Array< OneD, NekDouble > m_centroid
x,y,z location of the center of the octree
Definition: Octree.h:223
MeshSharedPtr m_mesh
Mesh object.
Definition: Octree.h:235
bool withinRange(Array< OneD, NekDouble > p)
Definition: Octree.h:62
void Refinement(std::string nm)
informs the octree there is a user defined spacing file
Definition: Octree.h:162
NekDouble m_maxDelta
maximum delta in the octree
Definition: Octree.h:219