pyrMatcher.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 "pyrMatcher.H"
29 #include "cellMatcher.H"
30 #include "primitiveMesh.H"
31 #include "cellModel.H"
32 #include "ListOps.H"
33 
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35 
37 :
39  (
40  vertPerCell,
41  facePerCell,
42  maxVertPerFace,
43  "pyr" // same as cellModel::modelNames[cellModel::PYR]
44  )
45 {}
46 
47 
48 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
49 
51 {}
52 
53 
54 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
55 
57 (
58  const bool checkOnly,
59  const faceList& faces,
60  const labelList& owner,
61  const label celli,
62  const labelList& myFaces
63 )
64 {
65  if (!faceSizeMatch(faces, myFaces))
66  {
67  return false;
68  }
69 
70  // Is pyr for sure since no other shape with 1 quad, 4 triangles
71  if (checkOnly)
72  {
73  return true;
74  }
75 
76  // Calculate localFaces_ and mapping pointMap_, faceMap_
77  label numVert = calcLocalFaces(faces, myFaces);
78 
79  if (numVert != vertPerCell)
80  {
81  return false;
82  }
83 
84  // Set up 'edge' to face mapping.
85  calcEdgeAddressing(numVert);
86 
87  // Set up point on face to index-in-face mapping
88  calcPointFaceIndex();
89 
90  // Storage for maps -vertex to mesh and -face to mesh
91  vertLabels_.setSize(vertPerCell);
92  faceLabels_.setSize(facePerCell);
93 
94  //
95  // Start from quad face (face0)
96  //
97 
98  label face0I = -1;
99  forAll(faceSize_, facei)
100  {
101  if (faceSize_[facei] == 4)
102  {
103  face0I = facei;
104  break;
105  }
106  }
107  const face& face0 = localFaces_[face0I];
108  label face0vert0 = 0;
109 
110 
111  //
112  // Try to follow prespecified path on faces of cell,
113  // starting at face0vert0
114  //
115 
116  vertLabels_[0] = pointMap_[face0[face0vert0]];
117  faceLabels_[0] = faceMap_[face0I];
118 
119  // Walk face 0 from vertex 0 to 1
120  label face0vert1 =
121  nextVert
122  (
123  face0vert0,
124  faceSize_[face0I],
125  !(owner[faceMap_[face0I]] == celli)
126  );
127  vertLabels_[1] = pointMap_[face0[face0vert1]];
128 
129  // Walk face 0 from vertex 1 to 2
130  label face0vert2 =
131  nextVert
132  (
133  face0vert1,
134  faceSize_[face0I],
135  !(owner[faceMap_[face0I]] == celli)
136  );
137  vertLabels_[2] = pointMap_[face0[face0vert2]];
138 
139  // Walk face 0 from vertex 2 to 3
140  label face0vert3 =
141  nextVert
142  (
143  face0vert2,
144  faceSize_[face0I],
145  !(owner[faceMap_[face0I]] == celli)
146  );
147  vertLabels_[3] = pointMap_[face0[face0vert3]];
148 
149  // Jump edge from face0 to face1
150  label face1I =
151  otherFace
152  (
153  numVert,
154  face0[face0vert3],
155  face0[face0vert0],
156  face0I
157  );
158  faceLabels_[1] = faceMap_[face1I];
159 
160  // Jump edge from face0 to face2
161  label face2I =
162  otherFace
163  (
164  numVert,
165  face0[face0vert2],
166  face0[face0vert3],
167  face0I
168  );
169  faceLabels_[2] = faceMap_[face2I];
170 
171  // Jump edge from face0 to face3
172  label face3I =
173  otherFace
174  (
175  numVert,
176  face0[face0vert1],
177  face0[face0vert2],
178  face0I
179  );
180  faceLabels_[3] = faceMap_[face3I];
181 
182  // Jump edge from face0 to face4
183  label face4I =
184  otherFace
185  (
186  numVert,
187  face0[face0vert0],
188  face0[face0vert1],
189  face0I
190  );
191  faceLabels_[4] = faceMap_[face4I];
192 
193  const face& face4 = localFaces_[face4I];
194 
195  // Get index of vert0 in face 4
196  label face4vert0 = pointFaceIndex_[face0[face0vert0]][face4I];
197 
198  // Walk face 4 from vertex 0 to 4
199  label face4vert4 =
200  nextVert
201  (
202  face4vert0,
203  faceSize_[face4I],
204  !(owner[faceMap_[face4I]] == celli)
205  );
206  vertLabels_[4] = pointMap_[face4[face4vert4]];
207 
208  return true;
209 }
210 
211 
213 {
214  return 4*3+4;
215 }
216 
217 
219 (
220  const faceList& faces,
221  const labelList& myFaces
222 ) const
223 {
224  if (myFaces.size() != 5)
225  {
226  return false;
227  }
228 
229  label nTris = 0;
230  label nQuads = 0;
231 
232  for (const label facei : myFaces)
233  {
234  const label size = faces[facei].size();
235 
236  if (size == 3)
237  {
238  ++nTris;
239  }
240  else if (size == 4)
241  {
242  ++nQuads;
243  }
244  else
245  {
246  return false;
247  }
248  }
249 
250  return (nTris == 4 && nQuads == 1);
251 }
252 
253 
255 {
256  return matchShape
257  (
258  true,
259  mesh.faces(),
260  mesh.faceOwner(),
261  celli,
262  mesh.cells()[celli]
263  );
264 }
265 
266 
267 bool Foam::pyrMatcher::isA(const faceList& faces)
268 {
269  // Do as if mesh with one cell only
270  return matchShape
271  (
272  true,
273  faces, // all faces in mesh
274  labelList(faces.size(), Zero), // cell 0 is owner of all faces
275  0, // cell label
276  identity(faces.size()) // faces of cell 0
277  );
278 }
279 
280 
282 (
283  const primitiveMesh& mesh,
284  const label celli,
285  cellShape& shape
286 )
287 {
288  if
289  (
290  matchShape
291  (
292  false,
293  mesh.faces(),
294  mesh.faceOwner(),
295  celli,
296  mesh.cells()[celli]
297  )
298  )
299  {
300  shape = cellShape(model(), vertLabels());
301 
302  return true;
303  }
304 
305  return false;
306 }
307 
308 
309 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:74
Foam::pyrMatcher::faceHashValue
virtual label faceHashValue() const
Hash value of all face sizes of this shape. Can be used for.
Definition: pyrMatcher.C:212
Foam::pyrMatcher::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: pyrMatcher.C:57
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
Foam::pyrMatcher::isA
virtual bool isA(const primitiveMesh &mesh, const label celli)
Exact match. Uses faceSizeMatch.
Definition: pyrMatcher.C:254
Foam::primitiveMesh::cells
const cellList & cells() const
Definition: primitiveMeshCells.C:138
primitiveMesh.H
Foam::cellMatcher
Base class for cellshape matchers (hexMatch, prismMatch, etc.). These are classes which given a mesh ...
Definition: cellMatcher.H:101
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::pyrMatcher::matches
virtual bool matches(const primitiveMesh &mesh, const label celli, cellShape &shape)
Like isA but also constructs a cellShape (if shape matches)
Definition: pyrMatcher.C:282
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
cellModel.H
Foam::pyrMatcher::faceSizeMatch
virtual bool faceSizeMatch(const faceList &, const labelList &) const
Check whether number of face sizes match the shape.
Definition: pyrMatcher.C:219
Foam::polyMesh::faceOwner
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1076
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::pyrMatcher::~pyrMatcher
~pyrMatcher()
Destructor.
Definition: pyrMatcher.C:50
Foam::cellShape
An analytical geometric cellShape.
Definition: cellShape.H:71
Foam::polyMesh::faces
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1063
Foam::List< face >
cellMatcher.H
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::pyrMatcher::pyrMatcher
pyrMatcher()
Construct null.
Definition: pyrMatcher.C:36
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.
pyrMatcher.H
Foam::primitiveMesh
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:78