1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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
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.
39 bool isHex = hex.match(cellI, shape);
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:
45 const labelList& hexVertLabels = hex.vertLabels();
46 const labelList& hexFaceLabels = hex.faceLabels();
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
76 \*---------------------------------------------------------------------------*/
81 #include "labelList.H"
86 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
91 // Forward declaration of classes
97 /*---------------------------------------------------------------------------*\
98 Class cellMatcher Declaration
99 \*---------------------------------------------------------------------------*/
107 //- Given start and end of edge generate unique key
108 inline static label edgeKey
115 //- Step along face either in righthand or lefthand direction
116 inline static label nextVert(const label, const label, const bool);
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_
129 //- Map from local to mesh vertex numbering
132 //- Map from local to mesh face numbering
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_;
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
173 const label localFaceI
179 // Private Member Functions
181 //- Disallow default bitwise copy construct and assignment
182 cellMatcher(const cellMatcher&);
183 void operator=(const cellMatcher&);
190 //- Create list with incrementing labels
191 static labelList makeIdentity(const label nElems);
196 //- Construct given mesh and shape factors
199 const label vertPerCell,
200 const label facePerCell,
201 const label maxVertPerFace,
202 const word& cellModelName
208 virtual ~cellMatcher()
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;
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&)
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
255 virtual bool matchShape
257 const bool checkOnly,
258 const faceList& faces,
259 const labelList& faceOwner,
261 const labelList& myFaces
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)
275 const primitiveMesh& mesh,
283 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
285 } // End namespace Foam
287 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
289 #include "cellMatcherI.H"
291 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
295 // ************************************************************************* //