hexMatcher.C
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-2018 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 \*---------------------------------------------------------------------------*/
25 
26 #include "hexMatcher.H"
27 #include "primitiveMesh.H"
28 #include "ListOps.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 const Foam::label Foam::hexMatcher::vertPerCell = 8;
33 const Foam::label Foam::hexMatcher::facePerCell = 6;
34 const Foam::label Foam::hexMatcher::maxVertPerFace = 4;
35 
36 
37 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 
40 :
42  (
43  vertPerCell,
44  facePerCell,
45  maxVertPerFace,
46  "hex"
47  )
48 {}
49 
50 
51 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
52 
54 {}
55 
56 
57 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
58 
60 (
61  const bool checkOnly,
62  const faceList& faces,
63  const labelList& owner,
64  const label celli,
65  const labelList& myFaces
66 )
67 {
68  if (!faceSizeMatch(faces, myFaces))
69  {
70  return false;
71  }
72 
73  // Is hex for sure since all faces are quads
74 
75  if (checkOnly)
76  {
77  return true;
78  }
79 
80  // Calculate localFaces_ and mapping pointMap_, faceMap_
81  label numVert = calcLocalFaces(faces, myFaces);
82 
83  if (numVert != vertPerCell)
84  {
85  return false;
86  }
87 
88  // Set up 'edge' to face mapping.
89  calcEdgeAddressing(numVert);
90 
91  // Set up point on face to index-in-face mapping
93 
94  // Storage for maps -vertex to mesh and -face to mesh
95  vertLabels_.setSize(vertPerCell);
96  faceLabels_.setSize(facePerCell);
97 
98  //
99  // Try bottom face (face 4).
100  // Only need to try one orientation of this face since hex is
101  // rotation symmetric
102  //
103 
104  label face4I = 0;
105 
106  const face& face4 = localFaces_[face4I];
107  label face4vert0 = 0;
108 
109  vertLabels_[0] = pointMap_[face4[face4vert0]];
110  faceLabels_[4] = faceMap_[face4I];
111 
112  // Walk face 4 from vertex 0 to 1
113  label face4vert1 =
114  nextVert
115  (
116  face4vert0,
117  faceSize_[face4I],
118  !(owner[faceMap_[face4I]] == celli)
119  );
120  vertLabels_[1] = pointMap_[face4[face4vert1]];
121 
122  // Walk face 4 from vertex 1 to 2
123  label face4vert2 =
124  nextVert
125  (
126  face4vert1,
127  faceSize_[face4I],
128  !(owner[faceMap_[face4I]] == celli)
129  );
130  vertLabels_[2] = pointMap_[face4[face4vert2]];
131 
132  // Walk face 4 from vertex 2 to 3
133  label face4vert3 =
134  nextVert
135  (
136  face4vert2,
137  faceSize_[face4I],
138  !(owner[faceMap_[face4I]] == celli)
139  );
140  vertLabels_[3] = pointMap_[face4[face4vert3]];
141 
142  // Jump edge from face4 to face0
143  label face0I =
144  otherFace
145  (
146  numVert,
147  face4[face4vert3],
148  face4[face4vert0],
149  face4I
150  );
151  faceLabels_[0] = faceMap_[face0I];
152  const face& face0 = localFaces_[face0I];
153 
154  label face0vert0 = pointFaceIndex_[face4[face4vert0]][face0I];
155 
156  // Walk face 0 from vertex 0 to 4
157  label face0vert4 =
158  nextVert
159  (
160  face0vert0,
161  faceSize_[face0I],
162  (owner[faceMap_[face0I]] == celli)
163  );
164  vertLabels_[4] = pointMap_[face0[face0vert4]];
165 
166  // Walk face 0 from vertex 4 to 7
167  label face0vert7 =
168  nextVert
169  (
170  face0vert4,
171  faceSize_[face0I],
172  (owner[faceMap_[face0I]] == celli)
173  );
174  vertLabels_[7] = pointMap_[face0[face0vert7]];
175 
176  // Jump edge from face0 to face5
177  label face5I =
178  otherFace
179  (
180  numVert,
181  face0[face0vert4],
182  face0[face0vert7],
183  face0I
184  );
185  const face& face5 = localFaces_[face5I];
186  faceLabels_[5] = faceMap_[face5I];
187 
188  label face5vert4 = pointFaceIndex_[face0[face0vert4]][face5I];
189 
190  // Walk face 5 from vertex 4 to 5
191  label face5vert5 =
192  nextVert
193  (
194  face5vert4,
195  faceSize_[face5I],
196  (owner[faceMap_[face5I]] == celli)
197  );
198  vertLabels_[5] = pointMap_[face5[face5vert5]];
199 
200  // Walk face 5 from vertex 5 to 6
201  label face5vert6 =
202  nextVert
203  (
204  face5vert5,
205  faceSize_[face5I],
206  (owner[faceMap_[face5I]] == celli)
207  );
208  vertLabels_[6] = pointMap_[face5[face5vert6]];
209 
210  // Jump edge from face4 to face2
211  label face2I =
212  otherFace
213  (
214  numVert,
215  face4[face4vert0],
216  face4[face4vert1],
217  face4I
218  );
219  faceLabels_[2] = faceMap_[face2I];
220 
221  // Jump edge from face4 to face1
222  label face1I =
223  otherFace
224  (
225  numVert,
226  face4[face4vert1],
227  face4[face4vert2],
228  face4I
229  );
230  faceLabels_[1] = faceMap_[face1I];
231 
232  // Jump edge from face4 to face3
233  label face3I =
234  otherFace
235  (
236  numVert,
237  face4[face4vert2],
238  face4[face4vert3],
239  face4I
240  );
241  faceLabels_[3] = faceMap_[face3I];
242 
243  return true;
244 }
245 
246 
248 {
249  return facePerCell*vertPerCell;
250 }
251 
252 
254 (
255  const faceList& faces,
256  const labelList& myFaces
257 ) const
258 {
259  if (myFaces.size() != facePerCell)
260  {
261  return false;
262  }
263 
264  forAll(myFaces, myFacei)
265  {
266  label size = faces[myFaces[myFacei]].size();
267 
268  if (size != 4)
269  {
270  return false;
271  }
272  }
273 
274  return true;
275 }
276 
277 
278 bool Foam::hexMatcher::isA(const primitiveMesh& mesh, const label celli)
279 {
280  return matchShape
281  (
282  true,
283  mesh.faces(),
284  mesh.faceOwner(),
285  celli,
286  mesh.cells()[celli]
287  );
288 }
289 
290 
291 bool Foam::hexMatcher::isA(const faceList& faces)
292 {
293  // Do as if mesh with one cell only
294  return matchShape
295  (
296  true,
297  faces, // all faces in mesh
298  labelList(faces.size(), 0), // cell 0 is owner of all faces
299  0, // cell label
300  identity(faces.size()) // faces of cell 0
301  );
302 }
303 
304 
306 (
307  const primitiveMesh& mesh,
308  const label celli,
309  cellShape& shape
310 )
311 {
312  if
313  (
314  matchShape
315  (
316  false,
317  mesh.faces(),
318  mesh.faceOwner(),
319  celli,
320  mesh.cells()[celli]
321  )
322  )
323  {
324  shape = cellShape(model(), vertLabels());
325 
326  return true;
327  }
328  else
329  {
330  return false;
331  }
332 }
333 
334 
335 // ************************************************************************* //
virtual bool matches(const primitiveMesh &mesh, const label celli, cellShape &shape)
Like isA but also constructs a cellShape (if shape matches)
Definition: hexMatcher.C:306
const labelList & vertLabels() const
Definition: cellMatcherI.H:74
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
Base class for cellshape matchers (hexMatch, prismMatch, etc.). These are classes which given a mesh ...
Definition: cellMatcher.H:99
virtual label faceHashValue() const
Hash value of all face sizes of this shape. Can be used for.
Definition: hexMatcher.C:247
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
Definition: ListOps.C:104
const cellList & cells() const
void calcEdgeAddressing(const label numVert)
Fill edge (start, end) to face number.
Definition: cellMatcher.C:138
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
Various functions to operate on Lists.
~hexMatcher()
Destructor.
Definition: hexMatcher.C:53
void calcPointFaceIndex()
Fill vertex/face to index in face data structure.
Definition: cellMatcher.C:187
virtual bool isA(const primitiveMesh &mesh, const label celli)
Exact match. Uses faceSizeMatch.
Definition: hexMatcher.C:278
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
List< label > labelList
A List of labels.
Definition: labelList.H:56
labelList faceLabels_
After matching: holds mesh faces in cellmodel order.
Definition: cellMatcher.H:145
virtual bool faceSizeMatch(const faceList &, const labelList &) const
Check whether number of face sizes match the shape.
Definition: hexMatcher.C:254
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
void setSize(const label)
Reset size of List.
Definition: List.C:281
virtual bool matchShape(const bool checkOnly, const faceList &faces, const labelList &faceOwner, const label celli, const labelList &myFaces)
Low level shape recognition. Return true if matches.
Definition: hexMatcher.C:60
hexMatcher()
Construct null.
Definition: hexMatcher.C:39
virtual const faceList & faces() const =0
Return faces.
virtual const labelList & faceOwner() const =0
Face face-owner addressing.
static label nextVert(const label, const label, const bool)
Step along face either in righthand or lefthand direction.
Definition: cellMatcherI.H:112