Fix tutorials: coupled/conjugateHeatFoam/conjugateCavity: fix Allrun file
[OpenFOAM-1.6-ext.git] / src / meshTools / meshSearch / meshSearch.H
blob9e1f3d6161c793b9c79789725c941eedaa83aa45
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Class
26     Foam::meshSearch
28 Description
29     Various (local, not parallel) searches on polyMesh;
30     uses (demand driven) octree to search.
32 SourceFiles
33     meshSearch.C
35 \*---------------------------------------------------------------------------*/
37 #ifndef meshSearch_H
38 #define meshSearch_H
40 #include "pointIndexHit.H"
41 #include "Cloud.H"
42 #include "passiveParticle.H"
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 namespace Foam
49 // Forward declaration of classes
50 class polyMesh;
51 class treeDataCell;
52 class treeDataFace;
53 class treeDataPoint;
54 template<class Type> class indexedOctree;
56 /*---------------------------------------------------------------------------*\
57                            Class meshSearch Declaration
58 \*---------------------------------------------------------------------------*/
60 class meshSearch
62     // Private data
64         //- Reference to mesh
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
84         (
85             const point& sample,
86             const pointField& points,
87             label& nearestI,
88             scalar& nearestDistSqr
89         );
91         //- Updates nearestI, nearestDistSqr from any selected closer ones.
92         static bool findNearer
93         (
94             const point& sample,
95             const pointField& points,
96             const labelList& indices,
97             label& nearestI,
98             scalar& nearestDistSqr
99         );
102         // Cells
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;
118         // Cells
120             label findNearestFaceTree(const point&) const;
122             label findNearestFaceLinear(const point&) const;
124             label findNearestFaceWalk(const point&, const label) const;
128         // Boundary faces
130             //- Walk from seed to find nearest boundary face. Gets stuck in
131             //  local minimum.
132             label findNearestBoundaryFaceWalk
133             (
134                 const point& location,
135                 const label seedFaceI
136             ) const;
138             //- Calculate offset vector in direction dir with as length a
139             //  fraction of the cell size (of the cell straddling boundary face)
140             vector offset
141             (
142                 const point& bPoint,
143                 const label bFaceI,
144                 const vector& dir
145             ) const;
148         //- Disallow default bitwise copy construct
149         meshSearch(const meshSearch&);
151         //- Disallow default bitwise assignment
152         void operator=(const meshSearch&);
155 public:
157     // Declare name of the class and its debug switch
158     ClassName("meshSearch");
161     // Static data members
163         //- tolerance on linear dimensions
164         static scalar tol_;
167     // Constructors
169         //- Construct from components
170         meshSearch(const polyMesh& mesh, const bool faceDecomp = true);
173     // Destructor
175         ~meshSearch();
178     // Member Functions
180         // Access
182             const polyMesh& mesh() const
183             {
184                 return mesh_;
185             }
187             //- Get (demand driven) reference to octree holding all
188             //  boundary faces
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;
198         // Queries
200             //- test for point in cell. Does not handle cells with center
201             //  outside cell.
202             bool pointInCell(const point& p, const label celli) const;
204             //- Find nearest cell in terms of cell centre.
205             // - use octree
206             // - use linear search
207             // - if seed is provided walk. (uses findNearestCellWalk; 
208             //   does not handle holes in domain)
209             label findNearestCell
210             (
211                 const point& location,
212                 const label seedCellI = -1,
213                 const bool useTreeSearch = true
214             ) const;
216             label findNearestFace
217             (
218                 const point& location,
219                 const label seedFaceI = -1,
220                 const bool useTreeSearch = true
221             ) const;
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.
227             label findCell
228             (
229                 const point& location,
230                 const label seedCellI = -1,
231                 const bool useTreeSearch = true
232             ) const;
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
237             //  the next.
238             label findNearestBoundaryFace
239             (
240                 const point& location,
241                 const label seedFaceI = -1,
242                 const bool useTreeSearch = true
243             ) const;
245             //- Find first intersection of boundary in segment [pStart, pEnd]
246             //  (so inclusive of endpoints). Always octree for now
247             pointIndexHit intersection
248             (
249                 const point& pStart,
250                 const point& pEnd
251             ) const;
253             //- Find all intersections of boundary within segment pStart .. pEnd
254             //  Always octree for now
255             List<pointIndexHit> intersections
256             (
257                 const point& pStart,
258                 const point& pEnd
259             ) const;
261             //- Determine inside/outside status
262             bool isInside(const point&) const;
265         //- delete all storage
266         void clearOut();
268         //- Correct for mesh geom/topo changes
269         void correct();
273 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
275 } // End namespace Foam
277 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
279 #endif
281 // ************************************************************************* //