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 | Copyright (C) 2011-2015 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
67 
68  //- Data bounding box
70 
71  //- Demand driven octrees
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.
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
194 
195  const polyMesh& mesh() const
196  {
197  return mesh_;
198  }
199 
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 // ************************************************************************* //
pointIndexHit.H
Foam::polyMesh::cellDecomposition
cellDecomposition
Enumeration defining the decomposition of the cell for.
Definition: polyMesh.H:98
Foam::meshSearch
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search.
Definition: meshSearch.H:57
Foam::meshSearch::findNearestFaceLinear
label findNearestFaceLinear(const point &) const
Definition: meshSearch.C:218
Foam::treeBoundBox
Standard boundBox + extra functionality for use in octree.
Definition: treeBoundBox.H:75
Foam::meshSearch::findNearestBoundaryFace
label findNearestBoundaryFace(const point &location, const label seedFaceI=-1, const bool useTreeSearch=true) const
Find nearest boundary face.
Definition: meshSearch.C:814
Foam::meshSearch::findNearer
static bool findNearer(const point &sample, const pointField &points, label &nearestI, scalar &nearestDistSqr)
Updates nearestI, nearestDistSqr from any closer ones.
Definition: meshSearch.C:47
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:899
Foam::meshSearch::overallBbPtr_
autoPtr< treeBoundBox > overallBbPtr_
Data bounding box.
Definition: meshSearch.H:68
Foam::meshSearch::findCellWalk
label findCellWalk(const point &, const label) const
Walk from seed. Does not 'go around' boundary, just returns.
Definition: meshSearch.C:327
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::meshSearch::ClassName
ClassName("meshSearch")
Foam::meshSearch::boundaryTreePtr_
autoPtr< indexedOctree< treeDataFace > > boundaryTreePtr_
Demand driven octrees.
Definition: meshSearch.H:71
Foam::meshSearch::cellTree
const indexedOctree< treeDataCell > & cellTree() const
Get (demand driven) reference to octree holding all cells.
Definition: meshSearch.C:605
Foam::meshSearch::decompMode
polyMesh::cellDecomposition decompMode() const
Definition: meshSearch.H:199
Foam::PointIndexHit
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Definition: PointIndexHit.H:53
Foam::meshSearch::clearOut
void clearOut()
Delete all storage.
Definition: meshSearch.C:953
Foam::meshSearch::correct
void correct()
Correct for mesh geom/topo changes.
Definition: meshSearch.C:961
Foam::meshSearch::findNearestFace
label findNearestFace(const point &location, const label seedFaceI=-1, const bool useTreeSearch=true) const
Definition: meshSearch.C:763
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::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::meshSearch::findCellLinear
label findCellLinear(const point &) const
Cell containing location. Linear search.
Definition: meshSearch.C:295
Foam::meshSearch::findNearestCellWalk
label findNearestCellWalk(const point &, const label) const
Walk from seed. Does not 'go around' boundary, just returns.
Definition: meshSearch.C:142
Foam::meshSearch::cellTreePtr_
autoPtr< indexedOctree< treeDataCell > > cellTreePtr_
Definition: meshSearch.H:72
Foam::indexedOctree
Non-pointer based hierarchical recursive searching.
Definition: treeDataTriSurface.H:47
Foam::meshSearch::mesh_
const polyMesh & mesh_
Reference to mesh.
Definition: meshSearch.H:62
Foam::meshSearch::cellDecompMode_
const polyMesh::cellDecomposition cellDecompMode_
Whether to use cell decomposition for all geometric tests.
Definition: meshSearch.H:65
Foam::meshSearch::findNearestBoundaryFaceWalk
label findNearestBoundaryFaceWalk(const point &location, const label seedFaceI) const
Walk from seed to find nearest boundary face. Gets stuck in.
Definition: meshSearch.C:398
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:738
Foam::meshSearch::isInside
bool isInside(const point &) const
Determine inside/outside status.
Definition: meshSearch.C:946
Foam::meshSearch::offset
vector offset(const point &bPoint, const label bFaceI, const vector &dir) const
Calculate offset vector in direction dir with as length a.
Definition: meshSearch.C:476
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::meshSearch::findNearestFaceTree
label findNearestFaceTree(const point &) const
Definition: meshSearch.C:178
pointField.H
Foam::meshSearch::findNearestCellLinear
label findNearestCellLinear(const point &) const
Nearest cell centre going through all cells.
Definition: meshSearch.C:121
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::polyMesh::CELL_TETS
@ CELL_TETS
Definition: polyMesh.H:107
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::meshSearch::findCell
label findCell(const point &location, const label seedCellI=-1, const bool useTreeSearch=true) const
Find cell containing location.
Definition: meshSearch.C:788
Foam::meshSearch::operator=
void operator=(const meshSearch &)
Disallow default bitwise assignment.
Foam::meshSearch::~meshSearch
~meshSearch()
Destructor.
Definition: meshSearch.C:544
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::meshSearch::mesh
const polyMesh & mesh() const
Definition: meshSearch.H:194
Foam::meshSearch::meshSearch
meshSearch(const meshSearch &)
Disallow default bitwise copy construct.
Foam::meshSearch::findNearestFaceWalk
label findNearestFaceWalk(const point &, const label) const
Definition: meshSearch.C:239
Foam::meshSearch::intersection
pointIndexHit intersection(const point &pStart, const point &pEnd) const
Find first intersection of boundary in segment [pStart, pEnd].
Definition: meshSearch.C:882
Foam::meshSearch::boundaryTree
const indexedOctree< treeDataFace > & boundaryTree() const
Get (demand driven) reference to octree holding all.
Definition: meshSearch.C:552
Foam::meshSearch::findNearestCellTree
label findNearestCellTree(const point &) const
Nearest cell centre using octree.
Definition: meshSearch.C:102
Foam::meshSearch::tol_
static scalar tol_
Tolerance on linear dimensions.
Definition: meshSearch.H:163