meshOctree.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | cfMesh: A library for mesh generation
4  \\ / O peration |
5  \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6  \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of cfMesh.
10 
11  cfMesh is free software; you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by the
13  Free Software Foundation; either version 3 of the License, or (at your
14  option) any later version.
15 
16  cfMesh is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with cfMesh. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  meshOctree
26 
27 Description
28  Octree for mesh generation
29 
30 SourceFiles
31  meshOctree.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef meshOctree_H
36 #define meshOctree_H
37 
38 #include "DynList.H"
39 #include "meshOctreeSlot.H"
40 #include "meshOctreeCube.H"
41 #include "patchRefinementList.H"
42 #include "Pair.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 // Forward declarations
50 class triSurf;
51 
52 /*---------------------------------------------------------------------------*\
53  Class meshOctree Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 class meshOctree
57 {
58  // Private data
59  //- Reference to surface to work on
60  const triSurf& surface_;
61 
62  //- neighbouring processors which can exchange data with the current one
63  //- this is only used in case of parallel calculations
65 
66  //- this list contains the first the last octree box coordinates on
67  //- a neighbour processor. They are used for parallel runs when the
68  //- leaves are sorted in Morton's Z-order
70 
71  //- Root cube of the octree structure
75  bool isRootInitialised_;
76 
77  //- octree search range
78  scalar searchRange_;
79 
80  //- vectors pointing into each octant
81  //- they are useful during creation of vertex labels
85 
86  //- List of slots containing data generated by each processor
88 
89  //- list of cubes which are leaves of the octree
91 
92  //- a flag whether is true if is it a quadtree
93  const bool isQuadtree_;
94 
95  // Private member functions
96  //- set data needed for finding neighbours
98 
99  //- create initial octree box
100  void createInitialOctreeBox();
101 
102  //- return leaf cube for the given position
104  (
106  ) const;
107 
108  //- find leaves contained in the box
110  (
111  const boundBox&,
113  ) const;
114 
115  // Private copy constructor
116  //- Disallow default bitwise copy construct
117  meshOctree(const meshOctree&);
118 
119  //- Disallow default bitwise assignment
120  void operator=(const meshOctree&);
121 
122 public:
123 
124  friend class meshOctreeModifier;
125 
126  // Constructors
127 
128  //- Construct from surface
129  meshOctree(const triSurf&, const bool isQuadtree = false);
130 
131  // Destructor
132 
133  ~meshOctree();
134 
135 
136  // Member Functions
137 
138  //- find a cube containing the vertex
139  label findLeafContainingVertex(const point&) const;
140 
141  //- find leaves within the given range from the given point
142  void findLeavesInSphere
143  (
144  const point&,
145  const scalar,
147  ) const;
148 
149  //- is octree a quadtree or an octree
150  inline bool isQuadtree() const;
151 
152  //- return octant vectors
153  inline const FixedList<Vector<label>, 8>& octantVectors() const;
154 
155  //- return leaves of the octree
156  inline label numberOfLeaves() const;
157  inline const meshOctreeCubeBasic& returnLeaf(const label) const;
158  inline short leafAtProc(const label) const;
159  void findBoundaryPatchesForLeaf(const label, DynList<label>&) const;
160  inline bool hasContainedTriangles(const label) const;
161  inline void containedTriangles(const label, DynList<label>&) const;
162  inline bool hasContainedEdges(const label) const;
163  inline void containedEdges(const label, DynList<label>&) const;
164 
165 
166  //- checks if the point is inside or outside the surface
167  bool isPointInside(const point&) const;
168 
169  //- find nearest surface point for vertex and its region
171  (
172  point& nearest,
173  scalar& distSq,
174  label& nearestTriangle,
175  label& region,
176  const point& p
177  ) const;
178 
179  //- find nearest surface point for vertex in a given region
181  (
182  point& nearest,
183  scalar& distSq,
184  label& nearestTriangle,
185  const label region,
186  const point& p
187  ) const;
188 
189  //- find nearest feature-edges vertex to a given vertex
191  (
192  point& edgePoint,
193  scalar& distSq,
194  label& nearestEdge,
195  const point& p,
196  const DynList<label>& regions
197  ) const;
198 
200  (
201  point& nearest,
202  scalar& distSq,
203  label& nearestEdge,
204  const FixedList<point, 2>& edgePoints,
205  const FixedList<label, 2>& edgePointRegions
206  ) const;
207 
208  //- find nearest corner point
209  bool findNearestCorner
210  (
211  point& nearest,
212  scalar& distSq,
213  label& nearestPoint,
214  const point& p,
215  const DynList<label>& patches
216  ) const;
217 
218  //- find the nearest vertex to the given patches
220  (
221  point& nearest,
222  scalar& distSq,
223  const point& p,
224  const DynList<label>& patches,
225  const scalar tol = 1e-4
226  ) const;
227 
228  //- return a reference to the surface
229  inline const triSurf& surface() const;
230 
231  //- find a neighbour over a cube's node
233  (
235  const label nodeI
236  ) const;
237 
238  //- find neighbours over a cube's edge
240  (
242  const label eI,
243  DynList<label>& neighbourLeaves
244  ) const;
245 
246  //- find neighbours over a leaf cube face in the given direction
248  (
250  const label dir,
251  DynList<label>& neighbourLeaves
252  ) const;
253 
254  //- find neighbour leaf cubes over all faces
256  (
258  DynList<label>& neighbourLeaves
259  ) const;
260 
261  //- find neighbour leaves over nodes, edges and faces
263  (
265  DynList<label>& neighbourLeaves
266  ) const;
267 
268  //- find neighbours over a cube's node
270  (
271  const label leafI,
272  const label nodeI
273  ) const;
274 
275  //- find neighbours over a cube's edge
276  inline void findNeighboursOverEdge
277  (
278  const label leafI,
279  const label eI,
280  DynList<label>& neighbourLeaves
281  ) const;
282 
283  //- find neighbouring leaves of a leaf cube
284  inline void findNeighboursInDirection
285  (
286  const label leafI,
287  const label dir,
289  ) const;
290 
291  //- find neighbours over faces
292  inline void findNeighboursForLeaf
293  (
294  const label,
296  ) const;
297 
298  //- find neighbours over nodes, edges and faces
299  inline void findAllLeafNeighbours
300  (
301  const label,
303  ) const;
304 
305  //- return leaf cube for the given position
307  (
309  ) const;
310 
311  //- find neighbouring leaves of a vertex
313  (
314  const label,
315  const direction,
317  ) const;
318 
319  //- find all leaves contained within the given boundBox
320  void findLeavesContainedInBox(const boundBox&, labelList&) const;
321  void findLeavesContainedInBox(const boundBox&, DynList<label>&) const;
322 
323  void findEdgesInBox(const boundBox&, DynList<label>&) const;
324  void findTrianglesInBox(const boundBox&, DynList<label>&) const;
325 
326  //- return rootBox
327  inline const boundBox& rootBox() const;
328 
329  //- return positions which need to be searched
330  //- to achieve 1-irregular octree
332  regularityPositions() const;
333 
334  //- return positions to find the leaves at each cube node
336  positionsOfLeavesAtNodes() const;
337 
338  //- exchange requests with other processors generating the octree
340  (
341  const LongList<meshOctreeCubeCoordinates>& dataToSend,
343  ) const;
344 
345  //- exchange requests with other processors generating the octree
347  (
348  const LongList<meshOctreeCubeCoordinates>& dataToSend,
349  const LongList<scalar>& rangesToSend,
351  LongList<scalar>& receivedRanges
352  ) const;
353 
354  //- neighbour processors of the current one
355  inline const labelList& neiProcs() const;
356 };
357 
358 
359 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
360 
361 } // End namespace Foam
362 
363 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
364 
365 #include "meshOctreeI.H"
366 
367 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
368 
369 #endif
370 
371 // ************************************************************************* //
Foam::meshOctree::octantVectors_
FixedList< Vector< label >, 8 > octantVectors_
Definition: meshOctree.H:81
Foam::meshOctree::regularityPositions_
FixedList< meshOctreeCubeCoordinates, 26 > regularityPositions_
Definition: meshOctree.H:83
Foam::meshOctree::findAllLeafNeighbours
void findAllLeafNeighbours(const meshOctreeCubeCoordinates &, DynList< label > &neighbourLeaves) const
find neighbour leaves over nodes, edges and faces
Definition: meshOctreeNeighbourSearches.C:387
Foam::meshOctree::regularityPositions
const FixedList< meshOctreeCubeCoordinates, 26 > & regularityPositions() const
Definition: meshOctreeI.H:141
Foam::meshOctree::neiRange_
List< Pair< meshOctreeCubeCoordinates > > neiRange_
Definition: meshOctree.H:68
p
p
Definition: pEqn.H:62
Foam::meshOctreeCubeCoordinates
Definition: meshOctreeCubeCoordinates.H:55
Foam::meshOctree::findNearestSurfacePoint
void findNearestSurfacePoint(point &nearest, scalar &distSq, label &nearestTriangle, label &region, const point &p) const
find nearest surface point for vertex and its region
Definition: meshOctreeFindNearestSurfacePoint.C:44
meshOctreeCube.H
Foam::meshOctree::setOctantVectorsAndPositions
void setOctantVectorsAndPositions()
set data needed for finding neighbours
Definition: meshOctree.C:76
Foam::meshOctree::containedTriangles
void containedTriangles(const label, DynList< label > &) const
Definition: meshOctreeI.H:81
Foam::meshOctree::findNeighboursForLeaf
void findNeighboursForLeaf(const meshOctreeCubeCoordinates &, DynList< label > &neighbourLeaves) const
find neighbour leaf cubes over all faces
Definition: meshOctreeNeighbourSearches.C:372
Foam::meshOctree::findBoundaryPatchesForLeaf
void findBoundaryPatchesForLeaf(const label, DynList< label > &) const
Definition: meshOctreeCubePatches.C:42
Foam::meshOctree::isQuadtree
bool isQuadtree() const
is octree a quadtree or an octree
Definition: meshOctreeI.H:36
Foam::meshOctree::positionsOfLeavesAtNodes
const FixedList< FixedList< meshOctreeCubeCoordinates, 8 >, 8 > & positionsOfLeavesAtNodes() const
return positions to find the leaves at each cube node
Definition: meshOctreeI.H:147
Foam::meshOctree::neiProcs
const labelList & neiProcs() const
neighbour processors of the current one
Definition: meshOctreeI.H:152
Foam::meshOctree::dataSlots_
List< meshOctreeSlot > dataSlots_
List of slots containing data generated by each processor.
Definition: meshOctree.H:86
Foam::meshOctree::findNearestPointToEdge
bool findNearestPointToEdge(point &nearest, scalar &distSq, label &nearestEdge, const FixedList< point, 2 > &edgePoints, const FixedList< label, 2 > &edgePointRegions) const
Definition: meshOctreeFindNearestSurfacePoint.C:321
Pair.H
meshOctreeSlot.H
Foam::meshOctree::findEdgesInBox
void findEdgesInBox(const boundBox &, DynList< label > &) const
Definition: meshOctreeInsideCalculations.C:60
Foam::meshOctree::findLeavesContainedInBox
void findLeavesContainedInBox(const boundBox &, DynList< const meshOctreeCube *, 256 > &) const
find leaves contained in the box
Definition: meshOctreeInsideCalculations.C:131
Foam::meshOctree::vrtLeavesPos_
FixedList< FixedList< meshOctreeCubeCoordinates, 8 >, 8 > vrtLeavesPos_
Definition: meshOctree.H:82
Foam::meshOctree::~meshOctree
~meshOctree()
Definition: meshOctree.C:71
Foam::meshOctreeModifier
Definition: meshOctreeModifier.H:48
Foam::meshOctree::findLeavesForCubeVertex
void findLeavesForCubeVertex(const label, const direction, FixedList< label, 8 > &) const
find neighbouring leaves of a vertex
Definition: meshOctreeNeighbourSearches.C:422
Foam::meshOctree::findNeighboursInDirection
void findNeighboursInDirection(const meshOctreeCubeCoordinates &, const label dir, DynList< label > &neighbourLeaves) const
find neighbours over a leaf cube face in the given direction
Definition: meshOctreeNeighbourSearches.C:262
Foam::meshOctree::numberOfLeaves
label numberOfLeaves() const
return leaves of the octree
Definition: meshOctreeI.H:48
patchRefinementList.H
Foam::LongList
Definition: LongList.H:55
Foam::meshOctree::meshOctree
meshOctree(const meshOctree &)
Disallow default bitwise copy construct.
Foam::meshOctree::findLeafLabelForPosition
label findLeafLabelForPosition(const meshOctreeCubeCoordinates &) const
return leaf cube for the given position
Definition: meshOctreeNeighbourSearches.C:516
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::meshOctree::initialCubeRotation_
label initialCubeRotation_
Definition: meshOctree.H:72
Foam::meshOctree::findNearestEdgePoint
bool findNearestEdgePoint(point &edgePoint, scalar &distSq, label &nearestEdge, const point &p, const DynList< label > &regions) const
find nearest feature-edges vertex to a given vertex
Definition: meshOctreeFindNearestSurfacePoint.C:215
Foam::meshOctree::exchangeRequestsWithNeighbourProcessors
void exchangeRequestsWithNeighbourProcessors(const LongList< meshOctreeCubeCoordinates > &dataToSend, LongList< meshOctreeCubeCoordinates > &dataToReceive) const
exchange requests with other processors generating the octree
Definition: meshOctreeParallelCommunication.C:41
Foam::meshOctree::isQuadtree_
const bool isQuadtree_
a flag whether is true if is it a quadtree
Definition: meshOctree.H:92
Foam::meshOctree::hasContainedEdges
bool hasContainedEdges(const label) const
Definition: meshOctreeI.H:101
Foam::meshOctree::findNearestPointToPatches
bool findNearestPointToPatches(point &nearest, scalar &distSq, const point &p, const DynList< label > &patches, const scalar tol=1e-4) const
find the nearest vertex to the given patches
Definition: meshOctreeFindNearestSurfacePoint.C:535
meshOctreeI.H
Foam::meshOctree::findNeighboursOverEdge
void findNeighboursOverEdge(const meshOctreeCubeCoordinates &, const label eI, DynList< label > &neighbourLeaves) const
find neighbours over a cube's edge
Definition: meshOctreeNeighbourSearches.C:185
Foam::meshOctree::leaves_
LongList< meshOctreeCube * > leaves_
list of cubes which are leaves of the octree
Definition: meshOctree.H:89
Foam::meshOctree::containedEdges
void containedEdges(const label, DynList< label > &) const
Definition: meshOctreeI.H:110
Foam::meshOctree::findNeighbourOverNode
label findNeighbourOverNode(const meshOctreeCubeCoordinates &, const label nodeI) const
find a neighbour over a cube's node
Definition: meshOctreeNeighbourSearches.C:115
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::meshOctree::isPointInside
bool isPointInside(const point &) const
checks if the point is inside or outside the surface
Definition: meshOctreeInsideCalculations.C:42
Foam::meshOctree::findTrianglesInBox
void findTrianglesInBox(const boundBox &, DynList< label > &) const
Definition: meshOctreeInsideCalculations.C:98
Foam::meshOctree::neiProcs_
labelList neiProcs_
Definition: meshOctree.H:63
Foam::e
const double e
Elementary charge.
Definition: doubleFloat.H:94
Foam::DynList
Definition: DynList.H:53
Foam::meshOctree::rootBox_
boundBox rootBox_
Definition: meshOctree.H:73
Foam::meshOctree::rootBox
const boundBox & rootBox() const
return rootBox
Definition: meshOctreeI.H:135
Foam::meshOctree::findLeafContainingVertex
label findLeafContainingVertex(const point &) const
find a cube containing the vertex
Definition: meshOctreeNeighbourSearches.C:42
Foam::meshOctree::leafAtProc
short leafAtProc(const label) const
Definition: meshOctreeI.H:67
Foam::meshOctree::isRootInitialised_
bool isRootInitialised_
Definition: meshOctree.H:74
Foam::meshOctree::surface_
const triSurf & surface_
Reference to surface to work on.
Definition: meshOctree.H:59
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::meshOctree
Definition: meshOctree.H:55
triSurf
A class for triangulated surface used in the meshing process. It is derived from points and facets wi...
Foam::FixedList
A 1D vector of objects of type <T> with a fixed size <Size>.
Definition: FixedList.H:53
Foam::meshOctreeCube
Definition: meshOctreeCube.H:56
Foam::meshOctree::findCubeForPosition
meshOctreeCube * findCubeForPosition(const meshOctreeCubeCoordinates &) const
return leaf cube for the given position
Definition: meshOctreeNeighbourSearches.C:459
Foam::direction
unsigned char direction
Definition: direction.H:43
Foam::boundBox
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:55
Foam::meshOctree::hasContainedTriangles
bool hasContainedTriangles(const label) const
Definition: meshOctreeI.H:72
patches
patches[0]
Definition: createSingleCellMesh.H:36
Foam::meshOctree::initialCubePtr_
meshOctreeCube * initialCubePtr_
Root cube of the octree structure.
Definition: meshOctree.H:71
Foam::meshOctree::octantVectors
const FixedList< Vector< label >, 8 > & octantVectors() const
return octant vectors
Definition: meshOctreeI.H:42
Foam::meshOctree::findNearestCorner
bool findNearestCorner(point &nearest, scalar &distSq, label &nearestPoint, const point &p, const DynList< label > &patches) const
find nearest corner point
Definition: meshOctreeFindNearestSurfacePoint.C:405
Foam::meshOctree::findNearestSurfacePointInRegion
void findNearestSurfacePointInRegion(point &nearest, scalar &distSq, label &nearestTriangle, const label region, const point &p) const
find nearest surface point for vertex in a given region
Definition: meshOctreeFindNearestSurfacePoint.C:131
Foam::meshOctree::surface
const triSurf & surface() const
return a reference to the surface
Definition: meshOctreeI.H:130
Foam::meshOctree::createInitialOctreeBox
void createInitialOctreeBox()
create initial octree box
Definition: meshOctree.C:185
Foam::meshOctree::searchRange_
scalar searchRange_
octree search range
Definition: meshOctree.H:77
Foam::meshOctree::findLeavesInSphere
void findLeavesInSphere(const point &, const scalar, DynList< label > &) const
find leaves within the given range from the given point
Definition: meshOctreeNeighbourSearches.C:103
Foam::triSurf
Definition: triSurf.H:59
Foam::meshOctree::returnLeaf
const meshOctreeCubeBasic & returnLeaf(const label) const
Definition: meshOctreeI.H:60
DynList.H
Foam::meshOctreeCubeBasic
Definition: meshOctreeCubeBasic.H:49
Foam::meshOctree::operator=
void operator=(const meshOctree &)
Disallow default bitwise assignment.