hexMatcher.C
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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "hexMatcher.H"
29 #include "primitiveMesh.H"
30 #include "ListOps.H"
31 
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
35 :
37  (
38  vertPerCell,
39  facePerCell,
40  maxVertPerFace,
41  "hex" // same as cellModel::modelNames[cellModel::HEX]
42  )
43 {}
44 
45 
46 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
47 
49 {}
50 
51 
52 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
53 
55 (
56  const bool checkOnly,
57  const faceList& faces,
58  const labelList& owner,
59  const label celli,
60  const labelList& myFaces
61 )
62 {
63  if (!faceSizeMatch(faces, myFaces))
64  {
65  return false;
66  }
67 
68  // Is hex for sure since all faces are quads
69 
70  if (checkOnly)
71  {
72  return true;
73  }
74 
75  // Calculate localFaces_ and mapping pointMap_, faceMap_
76  label numVert = calcLocalFaces(faces, myFaces);
77 
78  if (numVert != vertPerCell)
79  {
80  return false;
81  }
82 
83  // Set up 'edge' to face mapping.
84  calcEdgeAddressing(numVert);
85 
86  // Set up point on face to index-in-face mapping
87  calcPointFaceIndex();
88 
89  // Storage for maps -vertex to mesh and -face to mesh
90  vertLabels_.setSize(vertPerCell);
91  faceLabels_.setSize(facePerCell);
92 
93  //
94  // Try bottom face (face 4).
95  // Only need to try one orientation of this face since hex is
96  // rotation symmetric
97  //
98 
99  label face4I = 0;
100 
101  const face& face4 = localFaces_[face4I];
102  label face4vert0 = 0;
103 
104  vertLabels_[0] = pointMap_[face4[face4vert0]];
105  faceLabels_[4] = faceMap_[face4I];
106 
107  // Walk face 4 from vertex 0 to 1
108  label face4vert1 =
109  nextVert
110  (
111  face4vert0,
112  faceSize_[face4I],
113  !(owner[faceMap_[face4I]] == celli)
114  );
115  vertLabels_[1] = pointMap_[face4[face4vert1]];
116 
117  // Walk face 4 from vertex 1 to 2
118  label face4vert2 =
119  nextVert
120  (
121  face4vert1,
122  faceSize_[face4I],
123  !(owner[faceMap_[face4I]] == celli)
124  );
125  vertLabels_[2] = pointMap_[face4[face4vert2]];
126 
127  // Walk face 4 from vertex 2 to 3
128  label face4vert3 =
129  nextVert
130  (
131  face4vert2,
132  faceSize_[face4I],
133  !(owner[faceMap_[face4I]] == celli)
134  );
135  vertLabels_[3] = pointMap_[face4[face4vert3]];
136 
137  // Jump edge from face4 to face0
138  label face0I =
139  otherFace
140  (
141  numVert,
142  face4[face4vert3],
143  face4[face4vert0],
144  face4I
145  );
146  faceLabels_[0] = faceMap_[face0I];
147  const face& face0 = localFaces_[face0I];
148 
149  label face0vert0 = pointFaceIndex_[face4[face4vert0]][face0I];
150 
151  // Walk face 0 from vertex 0 to 4
152  label face0vert4 =
153  nextVert
154  (
155  face0vert0,
156  faceSize_[face0I],
157  (owner[faceMap_[face0I]] == celli)
158  );
159  vertLabels_[4] = pointMap_[face0[face0vert4]];
160 
161  // Walk face 0 from vertex 4 to 7
162  label face0vert7 =
163  nextVert
164  (
165  face0vert4,
166  faceSize_[face0I],
167  (owner[faceMap_[face0I]] == celli)
168  );
169  vertLabels_[7] = pointMap_[face0[face0vert7]];
170 
171  // Jump edge from face0 to face5
172  label face5I =
173  otherFace
174  (
175  numVert,
176  face0[face0vert4],
177  face0[face0vert7],
178  face0I
179  );
180  const face& face5 = localFaces_[face5I];
181  faceLabels_[5] = faceMap_[face5I];
182 
183  label face5vert4 = pointFaceIndex_[face0[face0vert4]][face5I];
184 
185  // Walk face 5 from vertex 4 to 5
186  label face5vert5 =
187  nextVert
188  (
189  face5vert4,
190  faceSize_[face5I],
191  (owner[faceMap_[face5I]] == celli)
192  );
193  vertLabels_[5] = pointMap_[face5[face5vert5]];
194 
195  // Walk face 5 from vertex 5 to 6
196  label face5vert6 =
197  nextVert
198  (
199  face5vert5,
200  faceSize_[face5I],
201  (owner[faceMap_[face5I]] == celli)
202  );
203  vertLabels_[6] = pointMap_[face5[face5vert6]];
204 
205  // Jump edge from face4 to face2
206  label face2I =
207  otherFace
208  (
209  numVert,
210  face4[face4vert0],
211  face4[face4vert1],
212  face4I
213  );
214  faceLabels_[2] = faceMap_[face2I];
215 
216  // Jump edge from face4 to face1
217  label face1I =
218  otherFace
219  (
220  numVert,
221  face4[face4vert1],
222  face4[face4vert2],
223  face4I
224  );
225  faceLabels_[1] = faceMap_[face1I];
226 
227  // Jump edge from face4 to face3
228  label face3I =
229  otherFace
230  (
231  numVert,
232  face4[face4vert2],
233  face4[face4vert3],
234  face4I
235  );
236  faceLabels_[3] = faceMap_[face3I];
237 
238  return true;
239 }
240 
241 
243 {
244  return facePerCell*vertPerCell;
245 }
246 
247 
249 (
250  const faceList& faces,
251  const labelList& myFaces
252 ) const
253 {
254  if (myFaces.size() != facePerCell)
255  {
256  return false;
257  }
258 
259  for (const label facei : myFaces)
260  {
261  const label size = faces[facei].size();
262 
263  if (size != 4)
264  {
265  return false;
266  }
267  }
268 
269  return true;
270 }
271 
272 
274 {
275  return matchShape
276  (
277  true,
278  mesh.faces(),
279  mesh.faceOwner(),
280  celli,
281  mesh.cells()[celli]
282  );
283 }
284 
285 
286 bool Foam::hexMatcher::isA(const faceList& faces)
287 {
288  // Do as if mesh with one cell only
289  return matchShape
290  (
291  true,
292  faces, // all faces in mesh
293  labelList(faces.size(), Zero), // cell 0 is owner of all faces
294  0, // cell label
295  identity(faces.size()) // faces of cell 0
296  );
297 }
298 
299 
301 (
302  const primitiveMesh& mesh,
303  const label celli,
304  cellShape& shape
305 )
306 {
307  if
308  (
309  matchShape
310  (
311  false,
312  mesh.faces(),
313  mesh.faceOwner(),
314  celli,
315  mesh.cells()[celli]
316  )
317  )
318  {
319  shape = cellShape(model(), vertLabels());
320 
321  return true;
322  }
323 
324  return false;
325 }
326 
327 
328 // ************************************************************************* //
Foam::hexMatcher::~hexMatcher
~hexMatcher()
Destructor.
Definition: hexMatcher.C:48
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:74
Foam::hexMatcher::faceSizeMatch
virtual bool faceSizeMatch(const faceList &, const labelList &) const
Check whether number of face sizes match the shape.
Definition: hexMatcher.C:249
Foam::meshTools::otherFace
label otherFace(const primitiveMesh &mesh, const label celli, const label facei, const label edgeI)
Return face on cell using edgeI but not facei. Throws error.
Definition: meshTools.C:555
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
hexMatcher.H
Foam::primitiveMesh::cells
const cellList & cells() const
Definition: primitiveMeshCells.C:138
primitiveMesh.H
Foam::hexMatcher::matchShape
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:55
Foam::cellMatcher
Base class for cellshape matchers (hexMatch, prismMatch, etc.). These are classes which given a mesh ...
Definition: cellMatcher.H:101
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
Foam::polyMesh::faceOwner
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1076
Foam::hexMatcher::isA
virtual bool isA(const primitiveMesh &mesh, const label celli)
Exact match. Uses faceSizeMatch.
Definition: hexMatcher.C:273
Foam::hexMatcher::matches
virtual bool matches(const primitiveMesh &mesh, const label celli, cellShape &shape)
Like isA but also constructs a cellShape (if shape matches)
Definition: hexMatcher.C:301
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::cellShape
An analytical geometric cellShape.
Definition: cellShape.H:71
Foam::hexMatcher::faceHashValue
virtual label faceHashValue() const
Hash value of all face sizes of this shape. Can be used for.
Definition: hexMatcher.C:242
Foam::polyMesh::faces
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1063
Foam::List< face >
Foam::identity
labelList identity(const label len, label start=0)
Create identity map of the given length with (map[i] == i)
Definition: labelList.C:38
Foam::hexMatcher::hexMatcher
hexMatcher()
Construct null.
Definition: hexMatcher.C:34
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:74
ListOps.H
Various functions to operate on Lists.
Foam::primitiveMesh
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:78