FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 
40 #include <lagrangian/Cloud.H>
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 // Forward declaration of classes
49 class polyMesh;
50 class treeDataCell;
51 class treeDataFace;
52 class treeDataPoint;
53 template<class Type> class indexedOctree;
54 
55 /*---------------------------------------------------------------------------*\
56  Class meshSearch Declaration
57 \*---------------------------------------------------------------------------*/
58 
60 {
61  // Private data
62 
63  //- Reference to mesh
64  const polyMesh& mesh_;
65 
66  //- Whether to use face decomposition for all geometric tests
67  const bool faceDecomp_;
68 
69  //- Dummy cloud to put particles on for tracking.
71 
72  //- demand driven octrees
73 
74  mutable indexedOctree<treeDataFace>* boundaryTreePtr_;
75  mutable indexedOctree<treeDataCell>* cellTreePtr_;
76  mutable indexedOctree<treeDataPoint>* cellCentreTreePtr_;
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 
117  // Cells
118 
119  label findNearestFaceTree(const point&) const;
120 
121  label findNearestFaceLinear(const point&) const;
122 
123  label findNearestFaceWalk(const point&, const label) const;
124 
125 
126 
127  // Boundary faces
128 
129  //- walk from seed to find nearest boundary face. Gets stuck in
130  // local minimum.
131  label findNearestBoundaryFaceWalk
132  (
133  const point& location,
134  const label seedFaceI
135  ) const;
136 
137  //- Calculate offset vector in direction dir with as length a
138  // fraction of the cell size (of the cell straddling boundary face)
139  vector offset
140  (
141  const point& bPoint,
142  const label bFaceI,
143  const vector& dir
144  ) const;
145 
146 
147  //- Disallow default bitwise copy construct
148  meshSearch(const meshSearch&);
149 
150  //- Disallow default bitwise assignment
151  void operator=(const meshSearch&);
152 
153 
154 public:
155 
156  // Declare name of the class and its debug switch
157  ClassName("meshSearch");
158 
159 
160  // Static data members
161 
162  //- tolerance on linear dimensions
163  static scalar tol_;
164 
165 
166  // Constructors
167 
168  //- Construct from components
169  meshSearch(const polyMesh& mesh, const bool faceDecomp = true);
170 
171 
172  // Destructor
173 
174  ~meshSearch();
175 
176 
177  // Member Functions
178 
179  // Access
180 
181  const polyMesh& mesh() const
182  {
183  return mesh_;
184  }
185 
186  //- Get (demand driven) reference to octree holding all
187  // boundary faces
189 
190  //- Get (demand driven) reference to octree holding all cells
191  const indexedOctree<treeDataCell>& cellTree() const;
192 
193  //- Get (demand driven) reference to octree holding all cell centres
195 
196 
197  // Queries
198 
199  //- test for point in cell. Does not handle cells with center
200  // outside cell.
201  bool pointInCell(const point& p, const label celli) const;
202 
203  //- Find nearest cell in terms of cell centre.
204  // - use octree
205  // - use linear search
206  // - if seed is provided walk. (uses findNearestCellWalk;
207  // does not handle holes in domain)
208  label findNearestCell
209  (
210  const point& location,
211  const label seedCellI = -1,
212  const bool useTreeSearch = true
213  ) const;
214 
215  label findNearestFace
216  (
217  const point& location,
218  const label seedFaceI = -1,
219  const bool useTreeSearch = true
220  ) const;
221 
222  //- Find cell containing (using pointInCell) location.
223  // If seed provided walks and falls back to linear/tree search.
224  // (so handles holes correctly)s
225  // Returns -1 if not in domain.
226  label findCell
227  (
228  const point& location,
229  const label seedCellI = -1,
230  const bool useTreeSearch = true
231  ) const;
232 
233  //- Find nearest boundary face
234  // If seed provided walks but then does not pass local minima
235  // in distance. Also does not jump from one connected region to
236  // the next.
238  (
239  const point& location,
240  const label seedFaceI = -1,
241  const bool useTreeSearch = true
242  ) const;
243 
244  //- Find first intersection of boundary in segment [pStart, pEnd]
245  // (so inclusive of endpoints). Always octree for now
246  pointIndexHit intersection(const point& pStart, const point& pEnd)
247  const;
248 
249  //- Find all intersections of boundary within segment pStart .. pEnd
250  // Always octree for now
252  (
253  const point& pStart,
254  const point& pEnd
255  ) const;
256 
257  //- Determine inside/outside status
258  bool isInside(const point&) const;
259 
260 
261  //- delete all storage
262  void clearOut();
263 
264  //- Correct for mesh geom/topo changes
265  void correct();
266 };
267 
268 
269 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
270 
271 } // End namespace Foam
272 
273 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
274 
275 #endif
276 
277 // ************************ vim: set sw=4 sts=4 et: ************************ //