1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Various (local, not parallel) searches on polyMesh;
30 uses (demand driven) octree to search.
35 \*---------------------------------------------------------------------------*/
40 #include "pointIndexHit.H"
42 #include "passiveParticle.H"
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 // Forward declaration of classes
54 template<class Type> class indexedOctree;
56 /*---------------------------------------------------------------------------*\
57 Class meshSearch Declaration
58 \*---------------------------------------------------------------------------*/
65 const polyMesh& mesh_;
67 //- Whether to use face decomposition for all geometric tests
68 const bool faceDecomp_;
70 //- Dummy cloud to put particles on for tracking.
71 Cloud<passiveParticle> cloud_;
73 //- demand driven octrees
75 mutable indexedOctree<treeDataFace>* boundaryTreePtr_;
76 mutable indexedOctree<treeDataCell>* cellTreePtr_;
77 mutable indexedOctree<treeDataPoint>* cellCentreTreePtr_;
80 // Private Member Functions
82 //- Updates nearestI, nearestDistSqr from any closer ones.
83 static bool findNearer
86 const pointField& points,
88 scalar& nearestDistSqr
91 //- Updates nearestI, nearestDistSqr from any selected closer ones.
92 static bool findNearer
95 const pointField& points,
96 const labelList& indices,
98 scalar& nearestDistSqr
104 //- Nearest cell centre using octree
105 label findNearestCellTree(const point&) const;
107 //- Nearest cell centre going through all cells
108 label findNearestCellLinear(const point&) const;
110 //- Walk from seed. Does not 'go around' boundary, just returns
111 // last cell before boundary.
112 label findNearestCellWalk(const point&, const label) const;
114 //- Cell containing location. Linear search.
115 label findCellLinear(const point&) const;
120 label findNearestFaceTree(const point&) const;
122 label findNearestFaceLinear(const point&) const;
124 label findNearestFaceWalk(const point&, const label) const;
130 //- Walk from seed to find nearest boundary face. Gets stuck in
132 label findNearestBoundaryFaceWalk
134 const point& location,
135 const label seedFaceI
138 //- Calculate offset vector in direction dir with as length a
139 // fraction of the cell size (of the cell straddling boundary face)
148 //- Disallow default bitwise copy construct
149 meshSearch(const meshSearch&);
151 //- Disallow default bitwise assignment
152 void operator=(const meshSearch&);
157 // Declare name of the class and its debug switch
158 ClassName("meshSearch");
161 // Static data members
163 //- tolerance on linear dimensions
169 //- Construct from components
170 meshSearch(const polyMesh& mesh, const bool faceDecomp = true);
182 const polyMesh& mesh() const
187 //- Get (demand driven) reference to octree holding all
189 const indexedOctree<treeDataFace>& boundaryTree() const;
191 //- Get (demand driven) reference to octree holding all cells
192 const indexedOctree<treeDataCell>& cellTree() const;
194 //- Get (demand driven) reference to octree holding all cell centres
195 const indexedOctree<treeDataPoint>& cellCentreTree() const;
200 //- test for point in cell. Does not handle cells with center
202 bool pointInCell(const point& p, const label celli) const;
204 //- Find nearest cell in terms of cell centre.
206 // - use linear search
207 // - if seed is provided walk. (uses findNearestCellWalk;
208 // does not handle holes in domain)
209 label findNearestCell
211 const point& location,
212 const label seedCellI = -1,
213 const bool useTreeSearch = true
216 label findNearestFace
218 const point& location,
219 const label seedFaceI = -1,
220 const bool useTreeSearch = true
223 //- Find cell containing (using pointInCell) location.
224 // If seed provided walks and falls back to linear/tree search.
225 // (so handles holes correctly)s
226 // Returns -1 if not in domain.
229 const point& location,
230 const label seedCellI = -1,
231 const bool useTreeSearch = true
234 //- Find nearest boundary face
235 // If seed provided walks but then does not pass local minima
236 // in distance. Also does not jump from one connected region to
238 label findNearestBoundaryFace
240 const point& location,
241 const label seedFaceI = -1,
242 const bool useTreeSearch = true
245 //- Find first intersection of boundary in segment [pStart, pEnd]
246 // (so inclusive of endpoints). Always octree for now
247 pointIndexHit intersection
253 //- Find all intersections of boundary within segment pStart .. pEnd
254 // Always octree for now
255 List<pointIndexHit> intersections
261 //- Determine inside/outside status
262 bool isInside(const point&) const;
265 //- delete all storage
268 //- Correct for mesh geom/topo changes
273 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
275 } // End namespace Foam
277 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
281 // ************************************************************************* //