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-2020 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 Declarations
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<treeDataFace>> nonCoupledBoundaryTreePtr_;
77  mutable autoPtr<indexedOctree<treeDataCell>> cellTreePtr_;
78 
79 
80  // Private Member Functions
81 
82  //- Updates nearestI, nearestDistSqr from any closer ones.
83  static bool findNearer
84  (
85  const point& sample,
86  const pointField& points,
87  label& nearestI,
88  scalar& nearestDistSqr
89  );
90 
91  //- Updates nearestI, nearestDistSqr from any selected closer ones.
92  static bool findNearer
93  (
94  const point& sample,
95  const pointField& points,
96  const labelList& indices,
97  label& nearestI,
98  scalar& nearestDistSqr
99  );
100 
101 
102  // Points
103 
104  //- Demand-driven bounding box for mesh points
105  const treeBoundBox& dataBoundBox() const;
106 
107 
108  // Cells
109 
110  //- Nearest cell centre using octree
111  label findNearestCellTree(const point&) const;
112 
113  //- Nearest cell centre going through all cells
114  label findNearestCellLinear(const point&) const;
115 
116  //- Walk from seed. Does not 'go around' boundary, just returns
117  // last cell before boundary.
118  label findNearestCellWalk(const point&, const label) const;
119 
120  //- Cell containing location. Linear search.
121  label findCellLinear(const point&) const;
122 
123  //- Walk from seed. Does not 'go around' boundary, just returns
124  // last cell before boundary.
125  label findCellWalk(const point&, const label) const;
126 
127 
128  // Faces
129 
130  label findNearestFaceTree(const point&) const;
131 
132  label findNearestFaceLinear(const point&) const;
133 
134  label findNearestFaceWalk(const point&, const label) const;
135 
136 
137  // Boundary faces
138 
139  //- Walk from seed to find nearest boundary face. Gets stuck in
140  // local minimum.
141  label findNearestBoundaryFaceWalk
142  (
143  const point& location,
144  const label seedFacei
145  ) const;
146 
147 
148  //- No copy construct
149  meshSearch(const meshSearch&) = delete;
150 
151  //- No copy assignment
152  void operator=(const meshSearch&) = delete;
153 
154 
155 public:
156 
157  //- Declare type-name (with debug switch)
158  ClassName("meshSearch");
159 
160 
161  // Static Data
162 
163  //- Tolerance on linear dimensions
164  static scalar tol_;
165 
166 
167  // Constructors
168 
169  //- Construct from components.
170  // Constructs bb slightly bigger than mesh points bb.
171  explicit meshSearch
172  (
173  const polyMesh& mesh,
175  );
176 
177  //- Construct with a custom bounding box.
178  // Any mesh element outside bb will not be found.
179  // Up to user to ensure bb extends slightly beyond wanted elements.
180  meshSearch
181  (
182  const polyMesh& mesh,
183  const treeBoundBox& bb,
185  );
186 
187 
188  //- Destructor
189  ~meshSearch();
190 
191 
192  // Member Functions
193 
194  // Access
195 
196  const polyMesh& mesh() const
197  {
198  return mesh_;
199  }
200 
202  {
203  return cellDecompMode_;
204  }
205 
206  //- Demand-driven reference to octree holding all boundary faces
208 
209  //- Demand-driven reference to octree holding all
210  //- non-coupled boundary faces
212 
213  //- Demand-driven reference to octree holding all cells
214  const indexedOctree<treeDataCell>& cellTree() const;
215 
216 
217  // Queries
218 
219  //- Find nearest cell in terms of cell centre.
220  // Options:
221  // - use octree
222  // - use linear search
223  // - if seed is provided walk. (uses findNearestCellWalk;
224  // does not handle holes in domain)
225  label findNearestCell
226  (
227  const point& location,
228  const label seedCelli = -1,
229  const bool useTreeSearch = true
230  ) const;
231 
232  label findNearestFace
233  (
234  const point& location,
235  const label seedFacei = -1,
236  const bool useTreeSearch = true
237  ) const;
238 
239  //- Find cell containing location.
240  // If seed provided walks and falls back to linear/tree search.
241  // (so handles holes correctly)s
242  // Returns -1 if not in domain.
243  label findCell
244  (
245  const point& location,
246  const label seedCelli = -1,
247  const bool useTreeSearch = true
248  ) const;
249 
250  //- Find nearest boundary face
251  // If seed provided walks but then does not pass local minima
252  // in distance. Also does not jump from one connected region to
253  // the next.
255  (
256  const point& location,
257  const label seedFacei = -1,
258  const bool useTreeSearch = true
259  ) const;
260 
261  //- Find first intersection of boundary in segment [pStart, pEnd]
262  // (so inclusive of endpoints). Always octree for now
263  pointIndexHit intersection(const point& pStart, const point& pEnd)
264  const;
265 
266  //- Find all intersections of boundary within segment pStart .. pEnd
267  // Always octree for now
269  (
270  const point& pStart,
271  const point& pEnd
272  ) const;
273 
274  //- Determine inside/outside status
275  bool isInside(const point&) const;
276 
277 
278  //- Delete all storage
279  void clearOut();
280 
281  //- Correct for mesh geom/topo changes
282  void correct();
283 };
284 
285 
286 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
287 
288 } // End namespace Foam
289 
290 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
291 
292 #endif
293 
294 // ************************************************************************* //
pointIndexHit.H
Foam::polyMesh::cellDecomposition
cellDecomposition
Enumeration defining the decomposition of the cell for.
Definition: polyMesh.H:100
Foam::meshSearch::nonCoupledBoundaryTree
const indexedOctree< treeDataFace > & nonCoupledBoundaryTree() const
Definition: meshSearch.C:662
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:86
Foam::meshSearch::findCell
label findCell(const point &location, const label seedCelli=-1, const bool useTreeSearch=true) const
Find cell containing location.
Definition: meshSearch.C:780
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:887
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::meshSearch::ClassName
ClassName("meshSearch")
Declare type-name (with debug switch)
Foam::meshSearch::cellTree
const indexedOctree< treeDataCell > & cellTree() const
Demand-driven reference to octree holding all cells.
Definition: meshSearch.C:707
Foam::meshSearch::decompMode
polyMesh::cellDecomposition decompMode() const
Definition: meshSearch.H:200
Foam::meshSearch::findNearestFace
label findNearestFace(const point &location, const label seedFacei=-1, const bool useTreeSearch=true) const
Definition: meshSearch.C:757
Foam::PointIndexHit
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Definition: PointIndexHit.H:52
Foam::meshSearch::clearOut
void clearOut()
Delete all storage.
Definition: meshSearch.C:919
Foam::meshSearch::correct
void correct()
Correct for mesh geom/topo changes.
Definition: meshSearch.C:927
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:804
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:913
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:109
Foam::Vector< scalar >
Foam::List< label >
Foam::meshSearch::~meshSearch
~meshSearch()
Destructor.
Definition: meshSearch.C:597
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::meshSearch::mesh
const polyMesh & mesh() const
Definition: meshSearch.H:195
Foam::meshSearch::intersection
pointIndexHit intersection(const point &pStart, const point &pEnd) const
Find first intersection of boundary in segment [pStart, pEnd].
Definition: meshSearch.C:870
Foam::meshSearch::boundaryTree
const indexedOctree< treeDataFace > & boundaryTree() const
Demand-driven reference to octree holding all boundary faces.
Definition: meshSearch.C:628
sample
Minimal example by using system/controlDict.functions:
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:734
Foam::meshSearch::tol_
static scalar tol_
Tolerance on linear dimensions.
Definition: meshSearch.H:163