meshSearch.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::meshSearch
26 
27 Description
28  Various (local, not parallel) searches on polyMesh;
29  uses (demand driven) octree to search.
30 
31 SourceFiles
32  meshSearch.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef meshSearch_H
37 #define meshSearch_H
38 
39 #include "pointIndexHit.H"
40 #include "pointField.H"
41 #include "polyMesh.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 // Forward declaration of classes
49 class treeDataCell;
50 class treeDataFace;
51 template<class Type> class indexedOctree;
52 class treeBoundBox;
53 
54 /*---------------------------------------------------------------------------*\
55  Class meshSearch Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 class meshSearch
59 {
60  // Private Data
61 
62  //- Reference to mesh
63  const polyMesh& mesh_;
64 
65  //- Whether to use cell decomposition for all geometric tests
66  const polyMesh::cellDecomposition cellDecompMode_;
67 
68  //- Data bounding box
69  mutable autoPtr<treeBoundBox> overallBbPtr_;
70 
71  //- Demand driven octrees
72  mutable autoPtr<indexedOctree<treeDataFace>> boundaryTreePtr_;
73  mutable autoPtr<indexedOctree<treeDataCell>> cellTreePtr_;
74 
75 
76  // Private Member Functions
77 
78  //- Updates nearestI, nearestDistSqr from any closer ones.
79  static bool findNearer
80  (
81  const point& sample,
82  const pointField& points,
83  label& nearestI,
84  scalar& nearestDistSqr
85  );
86 
87  //- Updates nearestI, nearestDistSqr from any selected closer ones.
88  static bool findNearer
89  (
90  const point& sample,
91  const pointField& points,
92  const labelList& indices,
93  label& nearestI,
94  scalar& nearestDistSqr
95  );
96 
97 
98  // Cells
99 
100  //- Nearest cell centre using octree
101  label findNearestCellTree(const point&) const;
102 
103  //- Nearest cell centre going through all cells
104  label findNearestCellLinear(const point&) const;
105 
106  //- Walk from seed. Does not 'go around' boundary, just returns
107  // last cell before boundary.
108  label findNearestCellWalk(const point&, const label) const;
109 
110  //- Cell containing location. Linear search.
111  label findCellLinear(const point&) const;
112 
113  //- Walk from seed. Does not 'go around' boundary, just returns
114  // last cell before boundary.
115  label findCellWalk(const point&, const label) const;
116 
117 
118  // Faces
119 
120  label findNearestFaceTree(const point&) const;
121 
122  label findNearestFaceLinear(const point&) const;
123 
124  label findNearestFaceWalk(const point&, const label) const;
125 
126 
127 
128  // Boundary faces
129 
130  //- Walk from seed to find nearest boundary face. Gets stuck in
131  // local minimum.
132  label findNearestBoundaryFaceWalk
133  (
134  const point& location,
135  const label seedFacei
136  ) const;
137 
138 
139 public:
140 
141  // Declare name of the class and its debug switch
142  ClassName("meshSearch");
143 
144 
145  // Static Data Members
146 
147  //- Tolerance on linear dimensions
148  static scalar tol_;
149 
150 
151  // Constructors
152 
153  //- Construct from components. Constructs bb slightly bigger than
154  // mesh points bb.
155  meshSearch
156  (
157  const polyMesh& mesh,
159  );
160 
161  //- Construct with a custom bounding box. Any mesh element outside
162  // bb will not be found. Up to user to make sure bb
163  // extends slightly beyond wanted elements.
164  meshSearch
165  (
166  const polyMesh& mesh,
167  const treeBoundBox& bb,
169  );
170 
171  //- Disallow default bitwise copy construction
172  meshSearch(const meshSearch&) = delete;
173 
174 
175  //- Destructor
176  ~meshSearch();
177 
178 
179  // Member Functions
180 
181  // Access
183  const polyMesh& mesh() const
184  {
185  return mesh_;
186  }
189  {
190  return cellDecompMode_;
191  }
192 
193  //- Get (demand driven) reference to octree holding all
194  // boundary faces
196 
197  //- Get (demand driven) reference to octree holding all cells
198  const indexedOctree<treeDataCell>& cellTree() const;
199 
200 
201  // Queries
202 
203  //- Find nearest cell in terms of cell centre.
204  // Options:
205  // - use octree
206  // - use linear search
207  // - if seed is provided walk. (uses findNearestCellWalk;
208  // does not handle holes in domain)
210  (
211  const point& location,
212  const label seedCelli = -1,
213  const bool useTreeSearch = true
214  ) const;
215 
217  (
218  const point& location,
219  const label seedFacei = -1,
220  const bool useTreeSearch = true
221  ) const;
222 
223  //- Find cell containing location.
224  // If seed provided walks and falls back to linear/tree search.
225  // (so handles holes correctly)s
226  // Returns -1 if not in domain.
228  (
229  const point& location,
230  const label seedCelli = -1,
231  const bool useTreeSearch = true
232  ) const;
233 
234  //- Find nearest boundary face
235  // If seed provided walks but then does not pass local minima
236  // in distance. Also does not jump from one connected region to
237  // the next.
239  (
240  const point& location,
241  const label seedFacei = -1,
242  const bool useTreeSearch = true
243  ) const;
244 
245  //- Find first intersection of boundary in segment [pStart, pEnd]
246  // (so inclusive of endpoints). Always octree for now
247  pointIndexHit intersection(const point& pStart, const point& pEnd)
248  const;
249 
250  //- Find all intersections of boundary within segment pStart .. pEnd
251  // Always octree for now
253  (
254  const point& pStart,
255  const point& pEnd
256  ) const;
257 
258  //- Determine inside/outside status
259  bool isInside(const point&) const;
260 
261 
262  //- Delete all storage
263  void clearOut();
264 
265  //- Correct for mesh geom/topo changes
266  void correct();
267 
268 
269  // Member Operators
270 
271  //- Disallow default bitwise assignment
272  void operator=(const meshSearch&) = delete;
273 };
274 
275 
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
277 
278 } // End namespace Foam
279 
280 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
281 
282 #endif
283 
284 // ************************************************************************* //
polyMesh::cellDecomposition decompMode() const
Definition: meshSearch.H:187
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search...
Definition: meshSearch.H:57
meshSearch(const polyMesh &mesh, const polyMesh::cellDecomposition=polyMesh::CELL_TETS)
Construct from components. Constructs bb slightly bigger than.
Definition: meshSearch.C:551
const indexedOctree< treeDataCell > & cellTree() const
Get (demand driven) reference to octree holding all cells.
Definition: meshSearch.C:656
label findNearestCell(const point &location, const label seedCelli=-1, const bool useTreeSearch=true) const
Find nearest cell in terms of cell centre.
Definition: meshSearch.C:700
void operator=(const meshSearch &)=delete
Disallow default bitwise assignment.
static scalar tol_
Tolerance on linear dimensions.
Definition: meshSearch.H:147
label findNearestFace(const point &location, const label seedFacei=-1, const bool useTreeSearch=true) const
Definition: meshSearch.C:725
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Definition: PointIndexHit.H:53
const polyMesh & mesh() const
Definition: meshSearch.H:182
cellDecomposition
Enumeration defining the decomposition of the cell for.
Definition: polyMesh.H:100
void correct()
Correct for mesh geom/topo changes.
Definition: meshSearch.C:903
const pointField & points
label findCell(const point &location, const label seedCelli=-1, const bool useTreeSearch=true) const
Find cell containing location.
Definition: meshSearch.C:750
const indexedOctree< treeDataFace > & boundaryTree() const
Get (demand driven) reference to octree holding all.
Definition: meshSearch.C:605
void clearOut()
Delete all storage.
Definition: meshSearch.C:895
label findNearestBoundaryFace(const point &location, const label seedFacei=-1, const bool useTreeSearch=true) const
Find nearest boundary face.
Definition: meshSearch.C:776
Non-pointer based hierarchical recursive searching.
Definition: treeDataEdge.H:47
~meshSearch()
Destructor.
Definition: meshSearch.C:596
Standard boundBox + extra functionality for use in octree.
Definition: treeBoundBox.H:87
bool isInside(const point &) const
Determine inside/outside status.
Definition: meshSearch.C:889
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
List< pointIndexHit > intersections(const point &pStart, const point &pEnd) const
Find all intersections of boundary within segment pStart .. pEnd.
Definition: meshSearch.C:861
pointIndexHit intersection(const point &pStart, const point &pEnd) const
Find first intersection of boundary in segment [pStart, pEnd].
Definition: meshSearch.C:844
ClassName("meshSearch")
Namespace for OpenFOAM.