Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / meshTools / meshSearch / meshSearch.H
blobbbccb2ae03cf42b6beda40b2ed84b9826ee4edef
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
8 License
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/>.
24 Class
25     Foam::meshSearch
27 Description
28     Various (local, not parallel) searches on polyMesh;
29     uses (demand driven) octree to search.
31 SourceFiles
32     meshSearch.C
34 \*---------------------------------------------------------------------------*/
36 #ifndef meshSearch_H
37 #define meshSearch_H
39 #include "pointIndexHit.H"
40 #include "CloudTemplate.H"
41 #include "passiveParticle.H"
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 namespace Foam
48 // Forward declaration of classes
49 class polyMesh;
50 class treeDataCell;
51 class treeDataFace;
52 class treeDataPoint;
53 template<class Type> class indexedOctree;
55 /*---------------------------------------------------------------------------*\
56                            Class meshSearch Declaration
57 \*---------------------------------------------------------------------------*/
59 class meshSearch
61     // Private data
63         //- Reference to mesh
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
83         (
84             const point& sample,
85             const pointField& points,
86             label& nearestI,
87             scalar& nearestDistSqr
88         );
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         );
101         // Cells
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;
117         // Cells
119             label findNearestFaceTree(const point&) const;
121             label findNearestFaceLinear(const point&) const;
123             label findNearestFaceWalk(const point&, const label) const;
127         // Boundary faces
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;
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;
147         //- Disallow default bitwise copy construct
148         meshSearch(const meshSearch&);
150         //- Disallow default bitwise assignment
151         void operator=(const meshSearch&);
154 public:
156     // Declare name of the class and its debug switch
157     ClassName("meshSearch");
160     // Static data members
162         //- tolerance on linear dimensions
163         static scalar tol_;
166     // Constructors
168         //- Construct from components
169         meshSearch(const polyMesh& mesh, const bool faceDecomp = true);
172     // Destructor
174         ~meshSearch();
177     // Member Functions
179         // Access
181             const polyMesh& mesh() const
182             {
183                 return mesh_;
184             }
186             //- Get demand driven reference to octree holding all
187             //  boundary faces
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;
197         // Queries
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;
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;
215             label findNearestFace
216             (
217                 const point& location,
218                 const label seedFaceI = -1,
219                 const bool useTreeSearch = true
220             ) const;
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;
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.
237             label findNearestBoundaryFace
238             (
239                 const point& location,
240                 const label seedFaceI = -1,
241                 const bool useTreeSearch = true
242             ) const;
244             //- Find first intersection of boundary in segment [pStart, pEnd]
245             //  (so inclusive of endpoints). Always octree for now
246             pointIndexHit intersection
247             (
248                 const point& pStart,
249                 const point& pEnd
250             ) const;
252             //- Find all intersections of boundary within segment pStart .. pEnd
253             //  Always octree for now
254             List<pointIndexHit> intersections
255             (
256                 const point& pStart,
257                 const point& pEnd
258             ) const;
260             //- Determine inside/outside status
261             bool isInside(const point&) const;
264         //- delete all storage
265         void clearOut();
267         //- Correct for mesh geom/topo changes
268         void correct();
272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
274 } // End namespace Foam
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
278 #endif
280 // ************************************************************************* //