OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

meshSearch.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Foam::meshSearch
00027 
00028 Description
00029     Various (local, not parallel) searches on polyMesh;
00030     uses (demand driven) octree to search.
00031 
00032 SourceFiles
00033     meshSearch.C
00034 
00035 \*---------------------------------------------------------------------------*/
00036 
00037 #ifndef meshSearch_H
00038 #define meshSearch_H
00039 
00040 #include "pointIndexHit.H"
00041 #include "Cloud.H"
00042 #include "passiveParticle.H"
00043 
00044 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00045 
00046 namespace Foam
00047 {
00048 
00049 // Forward declaration of classes
00050 class polyMesh;
00051 class treeDataCell;
00052 class treeDataFace;
00053 class treeDataPoint;
00054 template<class Type> class indexedOctree;
00055 
00056 /*---------------------------------------------------------------------------*\
00057                            Class meshSearch Declaration
00058 \*---------------------------------------------------------------------------*/
00059 
00060 class meshSearch
00061 {
00062     // Private data
00063 
00064         //- Reference to mesh
00065         const polyMesh& mesh_;
00066 
00067         //- Whether to use face decomposition for all geometric tests
00068         const bool faceDecomp_;
00069 
00070         //- Dummy cloud to put particles on for tracking.
00071         Cloud<passiveParticle> cloud_;
00072 
00073         //- demand driven octrees
00074 
00075         mutable indexedOctree<treeDataFace>* boundaryTreePtr_;
00076         mutable indexedOctree<treeDataCell>* cellTreePtr_;
00077         mutable indexedOctree<treeDataPoint>* cellCentreTreePtr_;
00078 
00079 
00080     // Private Member Functions
00081 
00082         //- Updates nearestI, nearestDistSqr from any closer ones.
00083         static bool findNearer
00084         (
00085             const point& sample,
00086             const pointField& points,
00087             label& nearestI,
00088             scalar& nearestDistSqr
00089         );
00090 
00091         //- Updates nearestI, nearestDistSqr from any selected closer ones.
00092         static bool findNearer
00093         (
00094             const point& sample,
00095             const pointField& points,
00096             const labelList& indices,
00097             label& nearestI,
00098             scalar& nearestDistSqr
00099         );
00100 
00101 
00102         // Cells
00103 
00104             //- nearest cell centre using octree
00105             label findNearestCellTree(const point&) const;
00106 
00107             //- nearest cell centre going through all cells
00108             label findNearestCellLinear(const point&) const;
00109 
00110             //- walk from seed. Does not 'go around' boundary, just returns
00111             //  last cell before boundary.
00112             label findNearestCellWalk(const point&, const label) const;
00113 
00114             //- cell containing location. Linear search.
00115             label findCellLinear(const point&) const;
00116 
00117 
00118         // Cells
00119 
00120             label findNearestFaceTree(const point&) const;
00121 
00122             label findNearestFaceLinear(const point&) const;
00123 
00124             label findNearestFaceWalk(const point&, const label) const;
00125 
00126 
00127 
00128         // Boundary faces
00129 
00130             //- walk from seed to find nearest boundary face. Gets stuck in
00131             //  local minimum.
00132             label findNearestBoundaryFaceWalk
00133             (
00134                 const point& location,
00135                 const label seedFaceI
00136             ) const;
00137 
00138             //- Calculate offset vector in direction dir with as length a
00139             //  fraction of the cell size (of the cell straddling boundary face)
00140             vector offset
00141             (
00142                 const point& bPoint,
00143                 const label bFaceI,
00144                 const vector& dir
00145             ) const;
00146 
00147 
00148         //- Disallow default bitwise copy construct
00149         meshSearch(const meshSearch&);
00150 
00151         //- Disallow default bitwise assignment
00152         void operator=(const meshSearch&);
00153 
00154 
00155 public:
00156 
00157     // Declare name of the class and its debug switch
00158     ClassName("meshSearch");
00159 
00160 
00161     // Static data members
00162 
00163         //- tolerance on linear dimensions
00164         static scalar tol_;
00165 
00166 
00167     // Constructors
00168 
00169         //- Construct from components
00170         meshSearch(const polyMesh& mesh, const bool faceDecomp = true);
00171 
00172 
00173     // Destructor
00174 
00175         ~meshSearch();
00176 
00177 
00178     // Member Functions
00179 
00180         // Access
00181 
00182             const polyMesh& mesh() const
00183             {
00184                 return mesh_;
00185             }
00186 
00187             //- Get (demand driven) reference to octree holding all
00188             //  boundary faces
00189             const indexedOctree<treeDataFace>& boundaryTree() const;
00190 
00191             //- Get (demand driven) reference to octree holding all cells
00192             const indexedOctree<treeDataCell>& cellTree() const;
00193 
00194             //- Get (demand driven) reference to octree holding all cell centres
00195             const indexedOctree<treeDataPoint>& cellCentreTree() const;
00196 
00197 
00198         // Queries
00199 
00200             //- test for point in cell. Does not handle cells with center
00201             //  outside cell.
00202             bool pointInCell(const point& p, const label celli) const;
00203 
00204             //- Find nearest cell in terms of cell centre.
00205             // - use octree
00206             // - use linear search
00207             // - if seed is provided walk. (uses findNearestCellWalk; 
00208             //   does not handle holes in domain)
00209             label findNearestCell
00210             (
00211                 const point& location,
00212                 const label seedCellI = -1,
00213                 const bool useTreeSearch = true
00214             ) const;
00215 
00216             label findNearestFace
00217             (
00218                 const point& location,
00219                 const label seedFaceI = -1,
00220                 const bool useTreeSearch = true
00221             ) const;
00222 
00223             //- Find cell containing (using pointInCell) location.
00224             //  If seed provided walks and falls back to linear/tree search.
00225             //  (so handles holes correctly)s
00226             //  Returns -1 if not in domain.
00227             label findCell
00228             (
00229                 const point& location,
00230                 const label seedCellI = -1,
00231                 const bool useTreeSearch = true
00232             ) const;
00233 
00234             //- Find nearest boundary face
00235             //  If seed provided walks but then does not pass local minima
00236             //  in distance. Also does not jump from one connected region to
00237             //  the next.
00238             label findNearestBoundaryFace
00239             (
00240                 const point& location,
00241                 const label seedFaceI = -1,
00242                 const bool useTreeSearch = true
00243             ) const;
00244 
00245             //- Find first intersection of boundary in segment [pStart, pEnd]
00246             //  (so inclusive of endpoints). Always octree for now
00247             pointIndexHit intersection(const point& pStart, const point& pEnd)
00248             const;
00249 
00250             //- Find all intersections of boundary within segment pStart .. pEnd
00251             //  Always octree for now
00252             List<pointIndexHit> intersections
00253             (
00254                 const point& pStart,
00255                 const point& pEnd
00256             ) const;
00257 
00258             //- Determine inside/outside status
00259             bool isInside(const point&) const;
00260 
00261 
00262         //- delete all storage
00263         void clearOut();
00264 
00265         //- Correct for mesh geom/topo changes
00266         void correct();
00267 };
00268 
00269 
00270 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00271 
00272 } // End namespace Foam
00273 
00274 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00275 
00276 #endif
00277 
00278 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd