1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
28 Various (local, not parallel) searches on polyMesh;
29 uses (demand driven) octree to search.
34 \*---------------------------------------------------------------------------*/
39 #include "pointIndexHit.H"
40 #include "pointField.H"
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 // Forward declaration of classes
51 template<class Type> class indexedOctree;
53 /*---------------------------------------------------------------------------*\
54 Class meshSearch Declaration
55 \*---------------------------------------------------------------------------*/
62 const polyMesh& mesh_;
64 //- Whether to use face decomposition for all geometric tests
65 const bool faceDecomp_;
67 //- demand driven octrees
69 mutable autoPtr<indexedOctree<treeDataFace> > boundaryTreePtr_;
70 mutable autoPtr<indexedOctree<treeDataCell> > cellTreePtr_;
73 // Private Member Functions
75 //- Updates nearestI, nearestDistSqr from any closer ones.
76 static bool findNearer
79 const pointField& points,
81 scalar& nearestDistSqr
84 //- Updates nearestI, nearestDistSqr from any selected closer ones.
85 static bool findNearer
88 const pointField& points,
89 const labelList& indices,
91 scalar& nearestDistSqr
97 //- nearest cell centre using octree
98 label findNearestCellTree(const point&) const;
100 //- nearest cell centre going through all cells
101 label findNearestCellLinear(const point&) const;
103 //- walk from seed. Does not 'go around' boundary, just returns
104 // last cell before boundary.
105 label findNearestCellWalk(const point&, const label) const;
107 //- cell containing location. Linear search.
108 label findCellLinear(const point&) const;
110 //- walk from seed. Does not 'go around' boundary, just returns
111 // last cell before boundary.
112 label findCellWalk(const point&, const label) const;
117 label findNearestFaceTree(const point&) const;
119 label findNearestFaceLinear(const point&) const;
121 label findNearestFaceWalk(const point&, const label) const;
127 //- walk from seed to find nearest boundary face. Gets stuck in
129 label findNearestBoundaryFaceWalk
131 const point& location,
132 const label seedFaceI
135 //- Calculate offset vector in direction dir with as length a
136 // fraction of the cell size (of the cell straddling boundary face)
145 //- Disallow default bitwise copy construct
146 meshSearch(const meshSearch&);
148 //- Disallow default bitwise assignment
149 void operator=(const meshSearch&);
154 // Declare name of the class and its debug switch
155 ClassName("meshSearch");
158 // Static data members
160 //- tolerance on linear dimensions
166 //- Construct from components
167 meshSearch(const polyMesh& mesh, const bool faceDecomp = true);
178 const polyMesh& mesh() const
183 //- Get (demand driven) reference to octree holding all
185 const indexedOctree<treeDataFace>& boundaryTree() const;
187 //- Get (demand driven) reference to octree holding all cells
188 const indexedOctree<treeDataCell>& cellTree() const;
193 //- test for point in cell. Does not handle cells with center
195 bool pointInCell(const point& p, const label celli) const;
197 //- Find nearest cell in terms of cell centre.
200 // - use linear search
201 // - if seed is provided walk. (uses findNearestCellWalk;
202 // does not handle holes in domain)
203 label findNearestCell
205 const point& location,
206 const label seedCellI = -1,
207 const bool useTreeSearch = true
210 label findNearestFace
212 const point& location,
213 const label seedFaceI = -1,
214 const bool useTreeSearch = true
217 //- Find cell containing (using pointInCell) location.
218 // If seed provided walks and falls back to linear/tree search.
219 // (so handles holes correctly)s
220 // Returns -1 if not in domain.
223 const point& location,
224 const label seedCellI = -1,
225 const bool useTreeSearch = true
228 //- Find nearest boundary face
229 // If seed provided walks but then does not pass local minima
230 // in distance. Also does not jump from one connected region to
232 label findNearestBoundaryFace
234 const point& location,
235 const label seedFaceI = -1,
236 const bool useTreeSearch = true
239 //- Find first intersection of boundary in segment [pStart, pEnd]
240 // (so inclusive of endpoints). Always octree for now
241 pointIndexHit intersection(const point& pStart, const point& pEnd)
244 //- Find all intersections of boundary within segment pStart .. pEnd
245 // Always octree for now
246 List<pointIndexHit> intersections
252 //- Determine inside/outside status
253 bool isInside(const point&) const;
256 //- delete all storage
259 //- Correct for mesh geom/topo changes
264 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
266 } // End namespace Foam
268 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 // ************************************************************************* //