All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cellMatcher.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 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 
118  // Protected data
119 
120  // Map from mesh to local vertex numbering
122 
123  //- Faces using local vertex numbering
125 
126  //- Number of vertices per face in localFaces_
128 
129  //- Map from local to mesh vertex numbering
131 
132  //- Map from local to mesh face numbering
134 
135  //- Map from 'edge' to neighbouring faces
137 
138  //- pointFaceIndex[localVertI][localFacei] is index in localFace
139  // where localVertI is.
141 
142  //- After matching: holds mesh vertices in cellmodel order
144 
145  //- After matching: holds mesh faces in cellmodel order
147 
148  //- CellModel name
149  const word cellModelName_;
151  mutable const cellModel* cellModelPtr_;
152 
153 
154  // Protected Member Functions
155 
156  //- Calculates localFaces. Returns number of local vertices (or -1
157  // if more than vertPerCell).
158  label calcLocalFaces(const faceList& faces, const labelList& myFaces);
159 
160  //- Fill edge (start, end) to face number
161  void calcEdgeAddressing(const label numVert);
162 
163  //- Fill vertex/face to index in face data structure
164  void calcPointFaceIndex();
165 
166  //- Given start,end of edge lookup both faces sharing it and return
167  // face != localFacei
169  (
170  const label numVert,
171  const label v0,
172  const label v1,
173  const label localFacei
174  ) const;
175 
176 
177 public:
178 
179  // Constructors
180 
181  //- Construct given mesh and shape factors
183  (
184  const label vertPerCell,
185  const label facePerCell,
186  const label maxVertPerFace,
187  const word& cellModelName
188  );
189 
190  //- Disallow default bitwise copy construction
191  cellMatcher(const cellMatcher&) = delete;
192 
193 
194  //- Destructor
195  virtual ~cellMatcher()
196  {}
197 
198 
199  // Member Functions
200 
201  // Access
202 
203  inline const Map<label>& localPoint() const;
204  inline const faceList& localFaces() const;
205  inline const labelList& faceSize() const;
206  inline const labelList& pointMap() const;
207  inline const labelList& faceMap() const;
208  inline const labelList& edgeFaces() const;
209  inline const labelListList& pointFaceIndex() const;
210  inline const labelList& vertLabels() const;
211  inline const labelList& faceLabels() const;
212  inline const cellModel& model() const;
213 
214 
215  // Write
216 
217  void write(Ostream& os) const;
218 
219  // Cell shape dependent
220 
221  virtual label nVertPerCell() const = 0;
222 
223  virtual label nFacePerCell() const = 0;
224 
225  virtual label nMaxVertPerFace() const = 0;
226 
227  //- Hash value of all face sizes of this shape. Can be used for
228  // quick initial recognition.
229  virtual label faceHashValue() const = 0;
230 
231  //- Check whether number of face sizes match the shape.
232  virtual bool faceSizeMatch(const faceList&, const labelList&)
233  const = 0;
234 
235  //- Low level shape recognition. Return true if matches.
236  // Works in detection mode only (checkOnly=true) or in exact
237  // matching. Returns true and sets vertLabels_.
238  // Needs faces, faceOwner of all faces in 'mesh' and cell number
239  // and labels of faces for this cell.
240  // celli only used in combination with faceOwner to detect owner
241  // status.
242  virtual bool matchShape
243  (
244  const bool checkOnly,
245  const faceList& faces,
246  const labelList& faceOwner,
247  const label celli,
248  const labelList& myFaces
249  ) = 0;
250 
251  //- Exact match. Uses faceSizeMatch.
252  // Returns true if cell matches shape exactly.
253  virtual bool isA(const primitiveMesh& mesh, const label celli) = 0;
254 
255  //- Exact match given all the faces forming a cell. No checks
256  // on whether faces match up and form a closed shape.
257  virtual bool isA(const faceList&) = 0;
258 
259  //- Like isA but also constructs a cellShape (if shape matches)
260  virtual bool matches
261  (
262  const primitiveMesh& mesh,
263  const label celli,
264  cellShape& shape
265  ) = 0;
266 
267 
268  // Member Operators
269 
270  void operator=(const cellMatcher&) = delete;
271 };
272 
273 
274 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
275 
276 } // End namespace Foam
277 
278 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
279 
280 #include "cellMatcherI.H"
281 
282 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
283 
284 #endif
285 
286 // ************************************************************************* //
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:132
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:142
labelListList pointFaceIndex_
pointFaceIndex[localVertI][localFacei] is index in localFace
Definition: cellMatcher.H:139
virtual bool isA(const primitiveMesh &mesh, const label celli)=0
Exact match. Uses faceSizeMatch.
cellMatcher(const label vertPerCell, const label facePerCell, const label maxVertPerFace, const word &cellModelName)
Construct given mesh and shape factors.
Definition: cellMatcher.C:38
virtual label nVertPerCell() const =0
labelList edgeFaces_
Map from &#39;edge&#39; to neighbouring faces.
Definition: cellMatcher.H:135
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:150
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:126
virtual label faceHashValue() const =0
Hash value of all face sizes of this shape. Can be used for.
virtual ~cellMatcher()
Destructor.
Definition: cellMatcher.H:194
void operator=(const cellMatcher &)=delete
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
labelList faceLabels_
After matching: holds mesh faces in cellmodel order.
Definition: cellMatcher.H:145
const labelList & faceMap() const
Definition: cellMatcherI.H:56
Map< label > localPoint_
Definition: cellMatcher.H:120
const cellModel & model() const
Definition: cellMatcherI.H:86
faceList localFaces_
Faces using local vertex numbering.
Definition: cellMatcher.H:123
labelList pointMap_
Map from local to mesh vertex numbering.
Definition: cellMatcher.H:129
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:148
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.