FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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