1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. 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 "CloudTemplate.H"
41 #include "passiveParticle.H"
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 // Forward declaration of classes
53 template<class Type> class indexedOctree;
55 /*---------------------------------------------------------------------------*\
56 Class meshSearch Declaration
57 \*---------------------------------------------------------------------------*/
64 const polyMesh& mesh_;
66 //- Whether to use face decomposition for all geometric tests
67 const bool faceDecomp_;
69 //- Dummy cloud to put particles on for tracking.
70 Cloud<passiveParticle> cloud_;
72 //- demand driven octrees
74 mutable indexedOctree<treeDataFace>* boundaryTreePtr_;
75 mutable indexedOctree<treeDataCell>* cellTreePtr_;
76 mutable indexedOctree<treeDataPoint>* cellCentreTreePtr_;
79 // Private Member Functions
81 //- Updates nearestI, nearestDistSqr from any closer ones.
82 static bool findNearer
85 const pointField& points,
87 scalar& nearestDistSqr
90 //- Updates nearestI, nearestDistSqr from any selected closer ones.
91 static bool findNearer
94 const pointField& points,
95 const labelList& indices,
97 scalar& nearestDistSqr
103 //- Nearest cell centre using octree
104 label findNearestCellTree(const point&) const;
106 //- Nearest cell centre going through all cells
107 label findNearestCellLinear(const point&) const;
109 //- Walk from seed. Does not 'go around' boundary, just returns
110 // last cell before boundary.
111 label findNearestCellWalk(const point&, const label) const;
113 //- Cell containing location. Linear search.
114 label findCellLinear(const point&) const;
119 label findNearestFaceTree(const point&) const;
121 label findNearestFaceLinear(const point&) const;
123 label findNearestFaceWalk(const point&, const label) const;
129 //- Walk from seed to find nearest boundary face. Gets stuck in
131 label findNearestBoundaryFaceWalk
133 const point& location,
134 const label seedFaceI
137 //- Calculate offset vector in direction dir with as length a
138 // fraction of the cell size of the cell straddling boundary face
147 //- Disallow default bitwise copy construct
148 meshSearch(const meshSearch&);
150 //- Disallow default bitwise assignment
151 void operator=(const meshSearch&);
156 // Declare name of the class and its debug switch
157 ClassName("meshSearch");
160 // Static data members
162 //- tolerance on linear dimensions
168 //- Construct from components
169 meshSearch(const polyMesh& mesh, const bool faceDecomp = true);
181 const polyMesh& mesh() const
186 //- Get demand driven reference to octree holding all
188 const indexedOctree<treeDataFace>& boundaryTree() const;
190 //- Get demand driven reference to octree holding all cells
191 const indexedOctree<treeDataCell>& cellTree() const;
193 //- Get demand driven reference to octree holding all cell centres
194 const indexedOctree<treeDataPoint>& cellCentreTree() const;
199 //- test for point in cell. Does not handle cells with center
201 bool pointInCell(const point& p, const label celli) const;
203 //- Find nearest cell in terms of cell centre.
205 // - use linear search
206 // - if seed is provided walk. (uses findNearestCellWalk;
207 // does not handle holes in domain)
208 label findNearestCell
210 const point& location,
211 const label seedCellI = -1,
212 const bool useTreeSearch = true
215 label findNearestFace
217 const point& location,
218 const label seedFaceI = -1,
219 const bool useTreeSearch = true
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.
228 const point& location,
229 const label seedCellI = -1,
230 const bool useTreeSearch = true
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
237 label findNearestBoundaryFace
239 const point& location,
240 const label seedFaceI = -1,
241 const bool useTreeSearch = true
244 //- Find first intersection of boundary in segment [pStart, pEnd]
245 // (so inclusive of endpoints). Always octree for now
246 pointIndexHit intersection
252 //- Find all intersections of boundary within segment pStart .. pEnd
253 // Always octree for now
254 List<pointIndexHit> intersections
260 //- Determine inside/outside status
261 bool isInside(const point&) const;
264 //- delete all storage
267 //- Correct for mesh geom/topo changes
272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
274 } // End namespace Foam
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
280 // ************************************************************************* //