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