FreeFOAM The Cross-Platform CFD Toolkit
cellMatcher.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::cellMatcher
26 
27 Description
28  Base class for cellshape matchers (hexMatch, prismMatch, etc.). These are
29  classes which given a mesh and cell number find out the orientation of
30  the cellShape and construct cell-vertex to mesh-vertex mapping and
31  cell-face to mesh-face mapping.
32 
33  For example,
34  @verbatim
35  hexMatcher hex(mesh);
36  cellShape shape;
37  ..
38  bool isHex = hex.match(cellI, shape);
39  @endverbatim
40  Now shape is set to the correct Hex cellShape (if @a isHex is true)
41 
42  Alternatively there is direct access to the vertex and face mapping:
43  @verbatim
44  const labelList& hexVertLabels = hex.vertLabels();
45  const labelList& hexFaceLabels = hex.faceLabels();
46  @endverbatim
47  Now
48  - @c hexVertLabels[n] is vertex label of hex vertex n
49  - @c hexFaceLabels[n] is face label of hex vertex n
50 
51  Process of cellShape recognition consists of following steps:
52  - renumber vertices of cell to local vertex numbers
53  - construct (local to cell) addressing edge-to-faces
54  - construct (local to cell) addressing vertex and face to index in face
55  - find most unique face shape (e.g. triangle for prism)
56  - walk (following either vertices in face or jumping from face to other
57  face) to other faces and checking face sizes.
58  - if nessecary try other rotations of this face
59  (only nessecary for wedge, tet-wedge)
60  - if nessecary try other faces which most unique face shape
61  (never nessecary for hex degenerates)
62 
63  The whole calculation is done such that no lists are allocated during
64  cell checking. E.g. localFaces_ are always sized to hold max. number
65  of possible face vertices and a separate list is filled which holds
66  the actusl face sizes.
67 
68  For now all hex-degenerates implemented. Numbering taken from picture in
69  demoGuide.
70 
71 SourceFiles
72  cellMatcherI.H
73  cellMatcher.C
74 
75 \*---------------------------------------------------------------------------*/
76 
77 #ifndef cellMatcher_H
78 #define cellMatcher_H
79 
80 #include <OpenFOAM/labelList.H>
81 #include <OpenFOAM/faceList.H>
82 #include <OpenFOAM/boolList.H>
83 #include <OpenFOAM/Map.H>
84 
85 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
86 
87 namespace Foam
88 {
89 
90 // Forward declaration of classes
91 class primitiveMesh;
92 class cell;
93 class cellShape;
94 class cellModel;
95 
96 /*---------------------------------------------------------------------------*\
97  Class cellMatcher Declaration
98 \*---------------------------------------------------------------------------*/
99 
101 {
102 protected:
103 
104  // Static functions
105 
106  //- Given start and end of edge generate unique key
107  inline static label edgeKey
108  (
109  const label numVert,
110  const label v0,
111  const label v1
112  );
113 
114  //- Step along face either in righthand or lefthand direction
115  inline static label nextVert(const label, const label, const bool);
116 
117  // Protected data
118 
119  // Map from mesh to local vertex numbering
121 
122  //- Faces using local vertex numbering
124 
125  //- Number of vertices per face in localFaces_
127 
128  //- Map from local to mesh vertex numbering
130 
131  //- Map from local to mesh face numbering
133 
134  //- Map from 'edge' to neighbouring faces
136 
137  //- pointFaceIndex[localVertI][localFaceI] is index in localFace
138  // where localVertI is.
140 
141  //- After matching: holds mesh vertices in cellmodel order
143 
144  //- After matching: holds mesh faces in cellmodel order
146 
147  //- CellModel name
149 
150  mutable const cellModel* cellModelPtr_;
151 
152 
153  // Protected Member Functions
154 
155  //- Calculates localFaces. Returns number of local vertices (or -1
156  // if more than vertPerCell).
157  label calcLocalFaces(const faceList& faces, const labelList& myFaces);
158 
159  //- Fill edge (start, end) to face number
160  void calcEdgeAddressing(const label numVert);
161 
162  //- Fill vertex/face to index in face data structure
163  void calcPointFaceIndex();
164 
165  //- Given start,end of edge lookup both faces sharing it and return
166  // face != localFaceI
167  label otherFace
168  (
169  const label numVert,
170  const label v0,
171  const label v1,
172  const label localFaceI
173  ) const;
174 
175 
176 private:
177 
178  // Private Member Functions
179 
180  //- Disallow default bitwise copy construct and assignment
181  cellMatcher(const cellMatcher&);
182  void operator=(const cellMatcher&);
183 
184 
185 public:
186 
187  // Static functions
188 
189  //- Create list with incrementing labels
190  static labelList makeIdentity(const label nElems);
191 
192 
193  // Constructors
194 
195  //- Construct given mesh and shape factors
197  (
198  const label vertPerCell,
199  const label facePerCell,
200  const label maxVertPerFace,
201  const word& cellModelName
202  );
203 
204 
205  // Destructor
206 
207  virtual ~cellMatcher()
208  {}
209 
210 
211  // Member Functions
212 
213  // Access
214 
215  inline const Map<label>& localPoint() const;
216  inline const faceList& localFaces() const;
217  inline const labelList& faceSize() const;
218  inline const labelList& pointMap() const;
219  inline const labelList& faceMap() const;
220  inline const labelList& edgeFaces() const;
221  inline const labelListList& pointFaceIndex() const;
222  inline const labelList& vertLabels() const;
223  inline const labelList& faceLabels() const;
224  inline const cellModel& model() const;
225 
226 
227  // Write
228 
229  void write(Ostream& os) const;
230 
231  // Cell shape dependent
232 
233  virtual label nVertPerCell() const = 0;
234 
235  virtual label nFacePerCell() const = 0;
236 
237  virtual label nMaxVertPerFace() const = 0;
238 
239  //- Hash value of all face sizes of this shape. Can be used for
240  // quick initial recognition.
241  virtual label faceHashValue() const = 0;
242 
243  //- Check whether number of face sizes match the shape.
244  virtual bool faceSizeMatch(const faceList&, const labelList&)
245  const = 0;
246 
247  //- Low level shape recognition. Return true if matches.
248  // Works in detection mode only (checkOnly=true) or in exact
249  // matching. Returns true and sets vertLabels_.
250  // Needs faces, faceOwner of all faces in 'mesh' and cell number
251  // and labels of faces for this cell.
252  // cellI only used in combination with faceOwner to detect owner
253  // status.
254  virtual bool matchShape
255  (
256  const bool checkOnly,
257  const faceList& faces,
258  const labelList& faceOwner,
259  const label cellI,
260  const labelList& myFaces
261  ) = 0;
262 
263  //- Exact match. Uses faceSizeMatch.
264  // Returns true if cell matches shape exactly.
265  virtual bool isA(const primitiveMesh& mesh, const label cellI) = 0;
266 
267  //- Exact match given all the faces forming a cell. No checks
268  // on whether faces match up and form a closed shape.
269  virtual bool isA(const faceList&) = 0;
270 
271  //- Like isA but also constructs a cellShape (if shape matches)
272  virtual bool matches
273  (
274  const primitiveMesh& mesh,
275  const label cellI,
276  cellShape& shape
277  ) = 0;
278 
279 };
280 
281 
282 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
283 
284 } // End namespace Foam
285 
286 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
287 
288 #include "cellMatcherI.H"
289 
290 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
291 
292 #endif
293 
294 // ************************ vim: set sw=4 sts=4 et: ************************ //