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

cellMatcher.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::cellMatcher
00026 
00027 Description
00028     Base class for cellshape matchers (hexMatch, prismMatch, etc.). These are
00029     classes which given a mesh and cell number find out the orientation of
00030     the cellShape and construct cell-vertex to mesh-vertex mapping and
00031     cell-face to mesh-face mapping.
00032 
00033     For example,
00034     @verbatim
00035         hexMatcher hex(mesh);
00036         cellShape shape;
00037         ..
00038         bool isHex = hex.match(cellI, shape);
00039     @endverbatim
00040     Now shape is set to the correct Hex cellShape (if @a isHex is true)
00041 
00042     Alternatively there is direct access to the vertex and face mapping:
00043     @verbatim
00044         const labelList& hexVertLabels = hex.vertLabels();
00045         const labelList& hexFaceLabels = hex.faceLabels();
00046     @endverbatim
00047     Now
00048       - @c hexVertLabels[n] is vertex label of hex vertex n
00049       - @c hexFaceLabels[n] is face   label of hex vertex n
00050 
00051     Process of cellShape recognition consists of following steps:
00052     - renumber vertices of cell to local vertex numbers
00053     - construct (local to cell) addressing edge-to-faces
00054     - construct (local to cell) addressing vertex and face to index in face
00055     - find most unique face shape (e.g. triangle for prism)
00056     - walk (following either vertices in face or jumping from face to other
00057       face) to other faces and checking face sizes.
00058     - if nessecary try other rotations of this face
00059       (only nessecary for wedge, tet-wedge)
00060     - if nessecary try other faces which most unique face shape
00061       (never nessecary for hex degenerates)
00062 
00063     The whole calculation is done such that no lists are allocated during
00064     cell checking. E.g. localFaces_ are always sized to hold max. number
00065     of possible face vertices and a separate list is filled which holds
00066     the actusl face sizes.
00067 
00068     For now all hex-degenerates implemented. Numbering taken from picture in
00069     demoGuide.
00070 
00071 SourceFiles
00072     cellMatcherI.H
00073     cellMatcher.C
00074 
00075 \*---------------------------------------------------------------------------*/
00076 
00077 #ifndef cellMatcher_H
00078 #define cellMatcher_H
00079 
00080 #include <OpenFOAM/labelList.H>
00081 #include <OpenFOAM/faceList.H>
00082 #include <OpenFOAM/boolList.H>
00083 #include <OpenFOAM/Map.H>
00084 
00085 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00086 
00087 namespace Foam
00088 {
00089 
00090 // Forward declaration of classes
00091 class primitiveMesh;
00092 class cell;
00093 class cellShape;
00094 class cellModel;
00095 
00096 /*---------------------------------------------------------------------------*\
00097                            Class cellMatcher Declaration
00098 \*---------------------------------------------------------------------------*/
00099 
00100 class cellMatcher
00101 {
00102 protected:
00103 
00104     // Static functions
00105 
00106         //- Given start and end of edge generate unique key
00107         inline static label edgeKey
00108         (
00109             const label numVert,
00110             const label v0,
00111             const label v1
00112         );
00113 
00114         //- Step along face either in righthand or lefthand direction
00115         inline static label nextVert(const label, const label, const bool);
00116 
00117     // Protected data
00118 
00119         // Map from mesh to local vertex numbering
00120         Map<label> localPoint_;
00121 
00122         //- Faces using local vertex numbering
00123         faceList localFaces_;
00124 
00125         //- Number of vertices per face in localFaces_
00126         labelList faceSize_;
00127 
00128         //- Map from local to mesh vertex numbering
00129         labelList pointMap_;
00130 
00131         //- Map from local to mesh face numbering
00132         labelList faceMap_;
00133 
00134         //- Map from 'edge' to neighbouring faces
00135         labelList edgeFaces_;
00136 
00137         //- pointFaceIndex[localVertI][localFaceI] is index in localFace
00138         //  where localVertI is.
00139         labelListList pointFaceIndex_;
00140 
00141         //- After matching: holds mesh vertices in cellmodel order
00142         labelList vertLabels_;
00143 
00144         //- After matching: holds mesh faces in cellmodel order
00145         labelList faceLabels_;
00146 
00147         //- CellModel name
00148         const word cellModelName_;
00149 
00150         mutable const cellModel* cellModelPtr_;
00151 
00152 
00153     // Protected Member Functions
00154 
00155         //- Calculates localFaces. Returns number of local vertices (or -1
00156         //  if more than vertPerCell).
00157         label calcLocalFaces(const faceList& faces, const labelList& myFaces);
00158 
00159         //- Fill edge (start, end) to face number
00160         void calcEdgeAddressing(const label numVert);
00161 
00162         //- Fill vertex/face to index in face data structure
00163         void calcPointFaceIndex();
00164 
00165         //- Given start,end of edge lookup both faces sharing it and return
00166         //  face != localFaceI
00167         label otherFace
00168         (
00169             const label numVert,
00170             const label v0,
00171             const label v1,
00172             const label localFaceI
00173         ) const;
00174 
00175 
00176 private:
00177 
00178     // Private Member Functions
00179 
00180         //- Disallow default bitwise copy construct and assignment
00181         cellMatcher(const cellMatcher&);
00182         void operator=(const cellMatcher&);
00183 
00184 
00185 public:
00186 
00187     // Static functions
00188 
00189         //- Create list with incrementing labels
00190         static labelList makeIdentity(const label nElems);
00191 
00192 
00193     // Constructors
00194 
00195         //- Construct given mesh and shape factors
00196         cellMatcher
00197         (
00198             const label vertPerCell,
00199             const label facePerCell,
00200             const label maxVertPerFace,
00201             const word& cellModelName
00202         );
00203 
00204 
00205     // Destructor
00206 
00207         virtual ~cellMatcher()
00208         {}
00209 
00210 
00211     // Member Functions
00212 
00213         // Access
00214 
00215             inline const Map<label>& localPoint() const;
00216             inline const faceList& localFaces() const;
00217             inline const labelList& faceSize() const;
00218             inline const labelList& pointMap() const;
00219             inline const labelList& faceMap() const;
00220             inline const labelList& edgeFaces() const;
00221             inline const labelListList& pointFaceIndex() const;
00222             inline const labelList& vertLabels() const;
00223             inline const labelList& faceLabels() const;
00224             inline const cellModel& model() const;
00225 
00226 
00227         // Write
00228 
00229             void write(Ostream& os) const;
00230 
00231         // Cell shape dependent
00232 
00233             virtual label nVertPerCell() const = 0;
00234 
00235             virtual label nFacePerCell() const = 0;
00236 
00237             virtual label nMaxVertPerFace() const = 0;
00238 
00239             //- Hash value of all face sizes of this shape. Can be used for
00240             //  quick initial recognition.
00241             virtual label faceHashValue() const = 0;
00242 
00243             //- Check whether number of face sizes match the shape.
00244             virtual bool faceSizeMatch(const faceList&, const labelList&)
00245                 const = 0;
00246 
00247             //- Low level shape recognition. Return true if matches.
00248             //  Works in detection mode only (checkOnly=true) or in exact
00249             //  matching. Returns true and sets vertLabels_.
00250             //  Needs faces, faceOwner of all faces in 'mesh' and cell number
00251             //  and labels of faces for this cell.
00252             //  cellI only used in combination with faceOwner to detect owner
00253             //  status.
00254             virtual bool matchShape
00255             (
00256                 const bool checkOnly,
00257                 const faceList& faces,
00258                 const labelList& faceOwner,
00259                 const label cellI,
00260                 const labelList& myFaces
00261             ) = 0;
00262 
00263             //- Exact match. Uses faceSizeMatch.
00264             //  Returns true if cell matches shape exactly.
00265             virtual bool isA(const primitiveMesh& mesh, const label cellI) = 0;
00266 
00267             //- Exact match given all the faces forming a cell. No checks
00268             //  on whether faces match up and form a closed shape.
00269             virtual bool isA(const faceList&) = 0;
00270 
00271             //- Like isA but also constructs a cellShape (if shape matches)
00272             virtual bool matches
00273             (
00274                 const primitiveMesh& mesh,
00275                 const label cellI,
00276                 cellShape& shape
00277             ) = 0;
00278 
00279 };
00280 
00281 
00282 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00283 
00284 } // End namespace Foam
00285 
00286 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00287 
00288 #include "cellMatcherI.H"
00289 
00290 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00291 
00292 #endif
00293 
00294 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines