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) 2011-2016 OpenFOAM Foundation
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 necessary try other rotations of this face
59  (only necessary for wedge, tet-wedge)
60  - if necessary try other faces which most unique face shape
61  (never necessary 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 "labelList.H"
81 #include "faceList.H"
82 #include "boolList.H"
83 #include "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 
100 class cellMatcher
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
148  const word cellModelName_;
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
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  // Constructors
188 
189  //- Construct given mesh and shape factors
191  (
192  const label vertPerCell,
193  const label facePerCell,
194  const label maxVertPerFace,
195  const word& cellModelName
196  );
197 
198 
199  //- Destructor
200  virtual ~cellMatcher()
201  {}
202 
203 
204  // Member Functions
205 
206  // Access
207 
208  inline const Map<label>& localPoint() const;
209  inline const faceList& localFaces() const;
210  inline const labelList& faceSize() const;
211  inline const labelList& pointMap() const;
212  inline const labelList& faceMap() const;
213  inline const labelList& edgeFaces() const;
214  inline const labelListList& pointFaceIndex() const;
215  inline const labelList& vertLabels() const;
216  inline const labelList& faceLabels() const;
217  inline const cellModel& model() const;
218 
219 
220  // Write
221 
222  void write(Ostream& os) const;
223 
224  // Cell shape dependent
225 
226  virtual label nVertPerCell() const = 0;
227 
228  virtual label nFacePerCell() const = 0;
229 
230  virtual label nMaxVertPerFace() const = 0;
231 
232  //- Hash value of all face sizes of this shape. Can be used for
233  // quick initial recognition.
234  virtual label faceHashValue() const = 0;
235 
236  //- Check whether number of face sizes match the shape.
237  virtual bool faceSizeMatch(const faceList&, const labelList&)
238  const = 0;
239 
240  //- Low level shape recognition. Return true if matches.
241  // Works in detection mode only (checkOnly=true) or in exact
242  // matching. Returns true and sets vertLabels_.
243  // Needs faces, faceOwner of all faces in 'mesh' and cell number
244  // and labels of faces for this cell.
245  // celli only used in combination with faceOwner to detect owner
246  // status.
247  virtual bool matchShape
248  (
249  const bool checkOnly,
250  const faceList& faces,
251  const labelList& faceOwner,
252  const label celli,
253  const labelList& myFaces
254  ) = 0;
255 
256  //- Exact match. Uses faceSizeMatch.
257  // Returns true if cell matches shape exactly.
258  virtual bool isA(const primitiveMesh& mesh, const label celli) = 0;
259 
260  //- Exact match given all the faces forming a cell. No checks
261  // on whether faces match up and form a closed shape.
262  virtual bool isA(const faceList&) = 0;
263 
264  //- Like isA but also constructs a cellShape (if shape matches)
265  virtual bool matches
266  (
267  const primitiveMesh& mesh,
268  const label celli,
269  cellShape& shape
270  ) = 0;
271 
272 };
273 
274 
275 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
276 
277 } // End namespace Foam
278 
279 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
280 
281 #include "cellMatcherI.H"
282 
283 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
284 
285 #endif
286 
287 // ************************************************************************* //
const Map< label > & localPoint() const
Definition: cellMatcherI.H:32
const labelList & vertLabels() const
Definition: cellMatcherI.H:74
const labelList & faceSize() const
Definition: cellMatcherI.H:44
virtual bool faceSizeMatch(const faceList &, const labelList &) const =0
Check whether number of face sizes match the shape.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
const faceList & localFaces() const
Definition: cellMatcherI.H:38
Base class for cellshape matchers (hexMatch, prismMatch, etc.). These are classes which given a mesh ...
Definition: cellMatcher.H:99
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:74
labelList faceMap_
Map from local to mesh face numbering.
Definition: cellMatcher.H:131
An analytical geometric cellShape.
Definition: cellShape.H:69
virtual bool matchShape(const bool checkOnly, const faceList &faces, const labelList &faceOwner, const label celli, const labelList &myFaces)=0
Low level shape recognition. Return true if matches.
void calcEdgeAddressing(const label numVert)
Fill edge (start, end) to face number.
Definition: cellMatcher.C:138
const labelList & faceLabels() const
Definition: cellMatcherI.H:80
labelList vertLabels_
After matching: holds mesh vertices in cellmodel order.
Definition: cellMatcher.H:141
labelListList pointFaceIndex_
pointFaceIndex[localVertI][localFacei] is index in localFace
Definition: cellMatcher.H:138
virtual bool isA(const primitiveMesh &mesh, const label celli)=0
Exact match. Uses faceSizeMatch.
virtual label nVertPerCell() const =0
labelList edgeFaces_
Map from &#39;edge&#39; to neighbouring faces.
Definition: cellMatcher.H:134
dynamicFvMesh & mesh
virtual bool matches(const primitiveMesh &mesh, const label celli, cellShape &shape)=0
Like isA but also constructs a cellShape (if shape matches)
const cellModel * cellModelPtr_
Definition: cellMatcher.H:149
void calcPointFaceIndex()
Fill vertex/face to index in face data structure.
Definition: cellMatcher.C:187
A class for handling words, derived from string.
Definition: word.H:59
label calcLocalFaces(const faceList &faces, const labelList &myFaces)
Calculates localFaces. Returns number of local vertices (or -1.
Definition: cellMatcher.C:74
labelList faceSize_
Number of vertices per face in localFaces_.
Definition: cellMatcher.H:125
virtual label faceHashValue() const =0
Hash value of all face sizes of this shape. Can be used for.
virtual ~cellMatcher()
Destructor.
Definition: cellMatcher.H:199
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
labelList faceLabels_
After matching: holds mesh faces in cellmodel order.
Definition: cellMatcher.H:144
const labelList & faceMap() const
Definition: cellMatcherI.H:56
Map< label > localPoint_
Definition: cellMatcher.H:119
const cellModel & model() const
Definition: cellMatcherI.H:86
faceList localFaces_
Faces using local vertex numbering.
Definition: cellMatcher.H:122
labelList pointMap_
Map from local to mesh vertex numbering.
Definition: cellMatcher.H:128
label otherFace(const label numVert, const label v0, const label v1, const label localFacei) const
Given start,end of edge lookup both faces sharing it and return.
Definition: cellMatcher.C:216
const word cellModelName_
CellModel name.
Definition: cellMatcher.H:147
virtual label nFacePerCell() const =0
virtual label nMaxVertPerFace() const =0
Maps a geometry to a set of cell primitives, which enables geometric cell data to be calculated witho...
Definition: cellModel.H:64
void write(Ostream &os) const
Definition: cellMatcher.C:247
static label edgeKey(const label numVert, const label v0, const label v1)
Given start and end of edge generate unique key.
Definition: cellMatcherI.H:100
const labelList & pointMap() const
Definition: cellMatcherI.H:50
const labelList & edgeFaces() const
Definition: cellMatcherI.H:62
static label nextVert(const label, const label, const bool)
Step along face either in righthand or lefthand direction.
Definition: cellMatcherI.H:112
const labelListList & pointFaceIndex() const
Definition: cellMatcherI.H:68
Namespace for OpenFOAM.