initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / meshes / meshShapes / cellMatcher / cellMatcher.H
blobb2f02e37beb6df4a60b8faa7e5ca38237e702633
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
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::cellMatcher
28 Description
29     Base class for cellshape matchers (hexMatch, prismMatch, etc.). These are
30     classes which given a mesh and cell number find out the orientation of
31     the cellShape and construct cell-vertex to mesh-vertex mapping and
32     cell-face to mesh-face mapping.
34     For example,
35     @verbatim
36         hexMatcher hex(mesh);
37         cellShape shape;
38         ..
39         bool isHex = hex.match(cellI, shape);
40     @endverbatim
41     Now shape is set to the correct Hex cellShape (if @a isHex is true)
43     Alternatively there is direct access to the vertex and face mapping:
44     @verbatim
45         const labelList& hexVertLabels = hex.vertLabels();
46         const labelList& hexFaceLabels = hex.faceLabels();
47     @endverbatim
48     Now
49       - @c hexVertLabels[n] is vertex label of hex vertex n
50       - @c hexFaceLabels[n] is face   label of hex vertex n
52     Process of cellShape recognition consists of following steps:
53     - renumber vertices of cell to local vertex numbers
54     - construct (local to cell) addressing edge-to-faces
55     - construct (local to cell) addressing vertex and face to index in face
56     - find most unique face shape (e.g. triangle for prism)
57     - walk (following either vertices in face or jumping from face to other
58       face) to other faces and checking face sizes.
59     - if nessecary try other rotations of this face
60       (only nessecary for wedge, tet-wedge)
61     - if nessecary try other faces which most unique face shape
62       (never nessecary for hex degenerates)
64     The whole calculation is done such that no lists are allocated during
65     cell checking. E.g. localFaces_ are always sized to hold max. number
66     of possible face vertices and a separate list is filled which holds
67     the actusl face sizes.
69     For now all hex-degenerates implemented. Numbering taken from picture in
70     demoGuide.
72 SourceFiles
73     cellMatcherI.H
74     cellMatcher.C
76 \*---------------------------------------------------------------------------*/
78 #ifndef cellMatcher_H
79 #define cellMatcher_H
81 #include "labelList.H"
82 #include "faceList.H"
83 #include "boolList.H"
84 #include "Map.H"
86 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
88 namespace Foam
91 // Forward declaration of classes
92 class primitiveMesh;
93 class cell;
94 class cellShape;
95 class cellModel;
97 /*---------------------------------------------------------------------------*\
98                            Class cellMatcher Declaration
99 \*---------------------------------------------------------------------------*/
101 class cellMatcher
103 protected:
105     // Static functions
107         //- Given start and end of edge generate unique key
108         inline static label edgeKey
109         (
110             const label numVert,
111             const label v0,
112             const label v1
113         );
115         //- Step along face either in righthand or lefthand direction
116         inline static label nextVert(const label, const label, const bool);
118     // Protected data
120         // Map from mesh to local vertex numbering
121         Map<label> localPoint_;
123         //- Faces using local vertex numbering
124         faceList localFaces_;
126         //- Number of vertices per face in localFaces_
127         labelList faceSize_;
129         //- Map from local to mesh vertex numbering
130         labelList pointMap_;
132         //- Map from local to mesh face numbering
133         labelList faceMap_;
135         //- Map from 'edge' to neighbouring faces
136         labelList edgeFaces_;
138         //- pointFaceIndex[localVertI][localFaceI] is index in localFace
139         //  where localVertI is.
140         labelListList pointFaceIndex_;
142         //- After matching: holds mesh vertices in cellmodel order
143         labelList vertLabels_;
145         //- After matching: holds mesh faces in cellmodel order
146         labelList faceLabels_;
148         //- CellModel name
149         const word cellModelName_;
151         mutable const cellModel* cellModelPtr_;
154     // Protected Member Functions
156         //- Calculates localFaces. Returns number of local vertices (or -1
157         //  if more than vertPerCell).
158         label calcLocalFaces(const faceList& faces, const labelList& myFaces);
160         //- Fill edge (start, end) to face number
161         void calcEdgeAddressing(const label numVert);
163         //- Fill vertex/face to index in face data structure
164         void calcPointFaceIndex();
166         //- Given start,end of edge lookup both faces sharing it and return
167         //  face != localFaceI
168         label otherFace
169         (
170             const label numVert,
171             const label v0,
172             const label v1,
173             const label localFaceI
174         ) const;
177 private:
179     // Private Member Functions
181         //- Disallow default bitwise copy construct and assignment
182         cellMatcher(const cellMatcher&);
183         void operator=(const cellMatcher&);
186 public:
188     // Static functions
190         //- Create list with incrementing labels
191         static labelList makeIdentity(const label nElems);
194     // Constructors
196         //- Construct given mesh and shape factors
197         cellMatcher
198         (
199             const label vertPerCell,
200             const label facePerCell,
201             const label maxVertPerFace,
202             const word& cellModelName
203         );
206     // Destructor
208         virtual ~cellMatcher()
209         {}
212     // Member Functions
214         // Access
216             inline const Map<label>& localPoint() const;
217             inline const faceList& localFaces() const;
218             inline const labelList& faceSize() const;
219             inline const labelList& pointMap() const;
220             inline const labelList& faceMap() const;
221             inline const labelList& edgeFaces() const;
222             inline const labelListList& pointFaceIndex() const;
223             inline const labelList& vertLabels() const;
224             inline const labelList& faceLabels() const;
225             inline const cellModel& model() const;
228         // Write
230             void write(Ostream& os) const;
232         // Cell shape dependent
234             virtual label nVertPerCell() const = 0;
236             virtual label nFacePerCell() const = 0;
238             virtual label nMaxVertPerFace() const = 0;
240             //- Hash value of all face sizes of this shape. Can be used for
241             //  quick initial recognition.
242             virtual label faceHashValue() const = 0;
244             //- Check whether number of face sizes match the shape.
245             virtual bool faceSizeMatch(const faceList&, const labelList&)
246                 const = 0;
248             //- Low level shape recognition. Return true if matches.
249             //  Works in detection mode only (checkOnly=true) or in exact
250             //  matching. Returns true and sets vertLabels_.
251             //  Needs faces, faceOwner of all faces in 'mesh' and cell number
252             //  and labels of faces for this cell.
253             //  cellI only used in combination with faceOwner to detect owner
254             //  status.
255             virtual bool matchShape
256             (
257                 const bool checkOnly,
258                 const faceList& faces,
259                 const labelList& faceOwner,
260                 const label cellI,
261                 const labelList& myFaces
262             ) = 0;
264             //- Exact match. Uses faceSizeMatch.
265             //  Returns true if cell matches shape exactly.
266             virtual bool isA(const primitiveMesh& mesh, const label cellI) = 0;
268             //- Exact match given all the faces forming a cell. No checks
269             //  on whether faces match up and form a closed shape.
270             virtual bool isA(const faceList&) = 0;
272             //- Like isA but also constructs a cellShape (if shape matches)
273             virtual bool matches
274             (
275                 const primitiveMesh& mesh,
276                 const label cellI,
277                 cellShape& shape
278             ) = 0;
283 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
285 } // End namespace Foam
287 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
289 #include "cellMatcherI.H"
291 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
293 #endif
295 // ************************************************************************* //