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-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::cellMatcher
29
30Description
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
74SourceFiles
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
88namespace Foam
89{
90
91// Forward Declarations
92class cell;
93class cellShape;
94class primitiveMesh;
95
96/*---------------------------------------------------------------------------*\
97 Class cellMatcher Declaration
98\*---------------------------------------------------------------------------*/
100class cellMatcher
101{
102protected:
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
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
183public:
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
224 virtual label nVertPerCell() const = 0;
226 virtual label nFacePerCell() const = 0;
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// ************************************************************************* //
A HashTable to objects of type <T> with a label key.
Definition: Map.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Base class for cellshape matchers (hexMatch, prismMatch, etc.). These are classes which given a mesh ...
Definition: cellMatcher.H:100
const faceList & localFaces() const
Definition: cellMatcherI.H:36
const cellModel & model() const
Definition: cellMatcherI.H:84
virtual label nFacePerCell() const =0
labelListList pointFaceIndex_
pointFaceIndex[localVertI][localFacei] is index in localFace
Definition: cellMatcher.H:139
labelList faceMap_
Map from local to mesh face numbering.
Definition: cellMatcher.H:132
const word cellModelName_
CellModel name.
Definition: cellMatcher.H:148
labelList edgeFaces_
Map from 'edge' to neighbouring faces.
Definition: cellMatcher.H:135
const labelList & faceMap() const
Definition: cellMatcherI.H:54
virtual bool matches(const primitiveMesh &mesh, const label celli, cellShape &shape)=0
Like isA but also constructs a cellShape (if shape matches)
const labelList & faceLabels() const
Definition: cellMatcherI.H:78
label calcLocalFaces(const faceList &faces, const labelList &myFaces)
Calculates localFaces. Returns number of local vertices (or -1.
Definition: cellMatcher.C:74
Map< label > localPoint_
Definition: cellMatcher.H:120
labelList pointMap_
Map from local to mesh vertex numbering.
Definition: cellMatcher.H:129
labelList faceLabels_
After matching: holds mesh faces in cellmodel order.
Definition: cellMatcher.H:145
static label nextVert(const label, const label, const bool)
Step along face either in righthand or lefthand direction.
Definition: cellMatcherI.H:109
virtual ~cellMatcher()=default
Destructor.
const cellModel * cellModelPtr_
Definition: cellMatcher.H:150
virtual label faceHashValue() const =0
Hash value of all face sizes of this shape. Can be used for.
virtual label nMaxVertPerFace() const =0
cellMatcher & operator=(const cellMatcher &)=delete
No copy assignment.
virtual label nVertPerCell() const =0
const Map< label > & localPoint() const
Definition: cellMatcherI.H:30
virtual bool isA(const primitiveMesh &mesh, const label celli)=0
Exact match. Uses faceSizeMatch.
labelList vertLabels_
After matching: holds mesh vertices in cellmodel order.
Definition: cellMatcher.H:142
const labelList & pointMap() const
Definition: cellMatcherI.H:48
const labelList & vertLabels() const
Definition: cellMatcherI.H:72
labelList faceSize_
Number of vertices per face in localFaces_.
Definition: cellMatcher.H:126
const labelList & faceSize() const
Definition: cellMatcherI.H:42
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.
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
const labelListList & pointFaceIndex() const
Definition: cellMatcherI.H:66
virtual bool faceSizeMatch(const faceList &, const labelList &) const =0
Check whether number of face sizes match the shape.
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
void calcEdgeAddressing(const label numVert)
Fill edge (start, end) to face number.
Definition: cellMatcher.C:137
const labelList & edgeFaces() const
Definition: cellMatcherI.H:60
faceList localFaces_
Faces using local vertex numbering.
Definition: cellMatcher.H:123
cellMatcher(const cellMatcher &)=delete
No copy construct.
void calcPointFaceIndex()
Fill vertex/face to index in face data structure.
Definition: cellMatcher.C:186
Maps a geometry to a set of cell primitives.
Definition: cellModel.H:73
An analytical geometric cellShape.
Definition: cellShape.H:72
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:79
A class for handling words, derived from Foam::string.
Definition: word.H:68
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
runTime write()