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-2018 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  //- Calculate offset vector in direction dir with as length a
139  // fraction of the cell size (of the cell straddling boundary face)
140  vector offset
141  (
142  const point& bPoint,
143  const label bFacei,
144  const vector& dir
145  ) const;
146 
147 
148  //- Disallow default bitwise copy construct
149  meshSearch(const meshSearch&);
150 
151  //- Disallow default bitwise assignment
152  void operator=(const meshSearch&);
153 
154 
155 public:
156 
157  // Declare name of the class and its debug switch
158  ClassName("meshSearch");
159 
160 
161  // Static data members
162 
163  //- Tolerance on linear dimensions
164  static scalar tol_;
165 
166 
167  // Constructors
168 
169  //- Construct from components. Constructs bb slightly bigger than
170  // mesh points bb.
171  meshSearch
172  (
173  const polyMesh& mesh,
175  );
176 
177  //- Construct with a custom bounding box. Any mesh element outside
178  // bb will not be found. Up to user to make sure bb
179  // extends slightly beyond wanted elements.
180  meshSearch
181  (
182  const polyMesh& mesh,
183  const treeBoundBox& bb,
185  );
186 
187  //- Destructor
188  ~meshSearch();
189 
190 
191  // Member Functions
192 
193  // Access
195  const polyMesh& mesh() const
196  {
197  return mesh_;
198  }
201  {
202  return cellDecompMode_;
203  }
204 
205  //- Get (demand driven) reference to octree holding all
206  // boundary faces
208 
209  //- Get (demand driven) reference to octree holding all cells
210  const indexedOctree<treeDataCell>& cellTree() const;
211 
212 
213  // Queries
214 
215  //- Find nearest cell in terms of cell centre.
216  // Options:
217  // - use octree
218  // - use linear search
219  // - if seed is provided walk. (uses findNearestCellWalk;
220  // does not handle holes in domain)
222  (
223  const point& location,
224  const label seedCelli = -1,
225  const bool useTreeSearch = true
226  ) const;
227 
229  (
230  const point& location,
231  const label seedFacei = -1,
232  const bool useTreeSearch = true
233  ) const;
234 
235  //- Find cell containing location.
236  // If seed provided walks and falls back to linear/tree search.
237  // (so handles holes correctly)s
238  // Returns -1 if not in domain.
240  (
241  const point& location,
242  const label seedCelli = -1,
243  const bool useTreeSearch = true
244  ) const;
245 
246  //- Find nearest boundary face
247  // If seed provided walks but then does not pass local minima
248  // in distance. Also does not jump from one connected region to
249  // the next.
251  (
252  const point& location,
253  const label seedFacei = -1,
254  const bool useTreeSearch = true
255  ) const;
256 
257  //- Find first intersection of boundary in segment [pStart, pEnd]
258  // (so inclusive of endpoints). Always octree for now
259  pointIndexHit intersection(const point& pStart, const point& pEnd)
260  const;
261 
262  //- Find all intersections of boundary within segment pStart .. pEnd
263  // Always octree for now
265  (
266  const point& pStart,
267  const point& pEnd
268  ) const;
269 
270  //- Determine inside/outside status
271  bool isInside(const point&) const;
272 
273 
274  //- Delete all storage
275  void clearOut();
276 
277  //- Correct for mesh geom/topo changes
278  void correct();
279 };
280 
281 
282 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
283 
284 } // End namespace Foam
285 
286 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
287 
288 #endif
289 
290 // ************************************************************************* //
polyMesh::cellDecomposition decompMode() const
Definition: meshSearch.H:199
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search...
Definition: meshSearch.H:57
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
const indexedOctree< treeDataCell > & cellTree() const
Get (demand driven) reference to octree holding all cells.
Definition: meshSearch.C:596
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:640
static scalar tol_
Tolerance on linear dimensions.
Definition: meshSearch.H:163
label findNearestFace(const point &location, const label seedFacei=-1, const bool useTreeSearch=true) const
Definition: meshSearch.C:665
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:194
cellDecomposition
Enumeration defining the decomposition of the cell for.
Definition: polyMesh.H:98
void correct()
Correct for mesh geom/topo changes.
Definition: meshSearch.C:862
const pointField & points
label findCell(const point &location, const label seedCelli=-1, const bool useTreeSearch=true) const
Find cell containing location.
Definition: meshSearch.C:690
const indexedOctree< treeDataFace > & boundaryTree() const
Get (demand driven) reference to octree holding all.
Definition: meshSearch.C:545
void clearOut()
Delete all storage.
Definition: meshSearch.C:854
label findNearestBoundaryFace(const point &location, const label seedFacei=-1, const bool useTreeSearch=true) const
Find nearest boundary face.
Definition: meshSearch.C:716
Non-pointer based hierarchical recursive searching.
Definition: treeDataEdge.H:47
~meshSearch()
Destructor.
Definition: meshSearch.C:536
Standard boundBox + extra functionality for use in octree.
Definition: treeBoundBox.H:87
bool isInside(const point &) const
Determine inside/outside status.
Definition: meshSearch.C:848
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:74
List< pointIndexHit > intersections(const point &pStart, const point &pEnd) const
Find all intersections of boundary within segment pStart .. pEnd.
Definition: meshSearch.C:801
pointIndexHit intersection(const point &pStart, const point &pEnd) const
Find first intersection of boundary in segment [pStart, pEnd].
Definition: meshSearch.C:784
ClassName("meshSearch")
Namespace for OpenFOAM.