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