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