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 "cellModel.H"
84 #include "Map.H"
85 
86 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
87 
88 namespace Foam
89 {
90 
91 // Forward Declarations
92 class cell;
93 class cellShape;
94 class primitiveMesh;
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_;
150 
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
168  label otherFace
169  (
170  const label numVert,
171  const label v0,
172  const label v1,
173  const label localFacei
174  ) const;
175 
176  //- No copy construct
177  cellMatcher(const cellMatcher&) = delete;
178 
179  //- No copy assignment
180  cellMatcher& operator=(const cellMatcher&) = delete;
181 
182 
183 public:
184 
185  // Constructors
186 
187  //- Construct for shape factors
189  (
190  const label vertPerCell,
191  const label facePerCell,
192  const label maxVertPerFace,
193  const word& cellModelName
194  );
195 
196 
197  //- Destructor
198  virtual ~cellMatcher() = default;
199 
200 
201  // Member Functions
202 
203  // Access
204 
205  inline const Map<label>& localPoint() const;
206  inline const faceList& localFaces() const;
207  inline const labelList& faceSize() const;
208  inline const labelList& pointMap() const;
209  inline const labelList& faceMap() const;
210  inline const labelList& edgeFaces() const;
211  inline const labelListList& pointFaceIndex() const;
212  inline const labelList& vertLabels() const;
213  inline const labelList& faceLabels() const;
214  inline const cellModel& model() const;
215 
216 
217  // Write
218 
219  void write(Ostream& os) const;
220 
221 
222  // Cell shape dependent
223 
224  virtual label nVertPerCell() const = 0;
225 
226  virtual label nFacePerCell() const = 0;
227 
228  virtual label nMaxVertPerFace() const = 0;
229 
230  //- Hash value of all face sizes of this shape. Can be used for
231  // quick initial recognition.
232  virtual label faceHashValue() const = 0;
233 
234  //- Check whether number of face sizes match the shape.
235  virtual bool faceSizeMatch(const faceList&, const labelList&)
236  const = 0;
237 
238  //- Low level shape recognition. Return true if matches.
239  // Works in detection mode only (checkOnly=true) or in exact
240  // matching. Returns true and sets vertLabels_.
241  // Needs faces, faceOwner of all faces in 'mesh' and cell number
242  // and labels of faces for this cell.
243  // celli only used in combination with faceOwner to detect owner
244  // status.
245  virtual bool matchShape
246  (
247  const bool checkOnly,
248  const faceList& faces,
249  const labelList& faceOwner,
250  const label celli,
251  const labelList& myFaces
252  ) = 0;
253 
254  //- Exact match. Uses faceSizeMatch.
255  // Returns true if cell matches shape exactly.
256  virtual bool isA(const primitiveMesh& mesh, const label celli) = 0;
257 
258  //- Exact match given all the faces forming a cell. No checks
259  // on whether faces match up and form a closed shape.
260  virtual bool isA(const faceList&) = 0;
261 
262  //- Like isA but also constructs a cellShape (if shape matches)
263  virtual bool matches
264  (
265  const primitiveMesh& mesh,
266  const label celli,
267  cellShape& shape
268  ) = 0;
269 };
270 
271 
272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
273 
274 } // End namespace Foam
275 
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
277 
278 #include "cellMatcherI.H"
279 
280 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
281 
282 #endif
283 
284 // ************************************************************************* //
Foam::cellMatcher::cellMatcher
cellMatcher(const cellMatcher &)=delete
No copy construct.
Foam::cellMatcher::cellModelName_
const word cellModelName_
CellModel name.
Definition: cellMatcher.H:148
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:139
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::cellMatcher::write
void write(Ostream &os) const
Definition: cellMatcher.C:242
Foam::cellMatcher::localFaces
const faceList & localFaces() const
Definition: cellMatcherI.H:36
Foam::cellMatcher::localFaces_
faceList localFaces_
Faces using local vertex numbering.
Definition: cellMatcher.H:123
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::operator=
cellMatcher & operator=(const cellMatcher &)=delete
No copy assignment.
Foam::cellMatcher::localPoint
const Map< label > & localPoint() const
Definition: cellMatcherI.H:30
Foam::cellMatcher
Base class for cellshape matchers (hexMatch, prismMatch, etc.). These are classes which given a mesh ...
Definition: cellMatcher.H:99
Foam::cellMatcher::nMaxVertPerFace
virtual label nMaxVertPerFace() const =0
Foam::cellMatcher::vertLabels
const labelList & vertLabels() const
Definition: cellMatcherI.H:72
Foam::cellMatcher::faceLabels_
labelList faceLabels_
After matching: holds mesh faces in cellmodel order.
Definition: cellMatcher.H:145
Foam::cellMatcher::pointMap_
labelList pointMap_
Map from local to mesh vertex numbering.
Definition: cellMatcher.H:129
Foam::cellMatcher::edgeFaces_
labelList edgeFaces_
Map from 'edge' to neighbouring faces.
Definition: cellMatcher.H:135
Foam::cellMatcher::faceMap
const labelList & faceMap() const
Definition: cellMatcherI.H:54
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:109
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:66
cellModel.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.
os
OBJstream os(runTime.globalPath()/outputName)
Foam::cellMatcher::edgeFaces
const labelList & edgeFaces() const
Definition: cellMatcherI.H:60
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::cellShape
An analytical geometric cellShape.
Definition: cellShape.H:69
Foam::cellMatcher::faceSize
const labelList & faceSize() const
Definition: cellMatcherI.H:42
Foam::cellMatcher::vertLabels_
labelList vertLabels_
After matching: holds mesh vertices in cellmodel order.
Definition: cellMatcher.H:142
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:97
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::cellMatcher::faceMap_
labelList faceMap_
Map from local to mesh face numbering.
Definition: cellMatcher.H:132
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:48
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:126
Foam::cellMatcher::faceLabels
const labelList & faceLabels() const
Definition: cellMatcherI.H:78
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:84
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:120
Foam::cellMatcher::~cellMatcher
virtual ~cellMatcher()=default
Destructor.
Foam::cellMatcher::cellModelPtr_
const cellModel * cellModelPtr_
Definition: cellMatcher.H:150
Foam::primitiveMesh
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:78