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