prismMatcher.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 "prismMatcher.H"
29 #include "primitiveMesh.H"
30 #include "ListOps.H"
31 
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
35 :
37  (
38  vertPerCell,
39  facePerCell,
40  maxVertPerFace,
41  "prism" // same as cellModel::modelNames[cellModel::PRISM]
42  )
43 {}
44 
45 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
46 
48 {}
49 
50 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
51 
53 (
54  const bool checkOnly,
55  const faceList& faces,
56  const labelList& owner,
57  const label celli,
58  const labelList& myFaces
59 )
60 {
61  if (!faceSizeMatch(faces, myFaces))
62  {
63  return false;
64  }
65 
66  // Calculate localFaces_ and mapping pointMap_, faceMap_
67  label numVert = calcLocalFaces(faces, myFaces);
68 
69  if (numVert != vertPerCell)
70  {
71  return false;
72  }
73 
74  // Set up 'edge' to face mapping.
75  calcEdgeAddressing(numVert);
76 
77  // Set up point on face to index-in-face mapping
78  calcPointFaceIndex();
79 
80  // Storage for maps -vertex to mesh and -face to mesh
81  vertLabels_.setSize(vertPerCell);
82  faceLabels_.setSize(facePerCell);
83 
84  //
85  // Try first triangular face.
86  // Only need to try one orientation of this face since prism is
87  // rotation symmetric
88  //
89 
90  label face0I = -1;
91  forAll(faceSize_, facei)
92  {
93  if (faceSize_[facei] == 3)
94  {
95  face0I = facei;
96  break;
97  }
98  }
99 
100  const face& face0 = localFaces_[face0I];
101  label face0vert0 = 0;
102 
103  //
104  // Try to follow prespecified path on faces of cell,
105  // starting at face0vert0
106  //
107 
108  vertLabels_[0] = pointMap_[face0[face0vert0]];
109  faceLabels_[0] = faceMap_[face0I];
110  //Info<< endl << "Prism vertex 0: vertex " << face0[face0vert0]
111  // << " at position " << face0vert0 << " in face " << face0
112  // << endl;
113 
114  // Walk face 0 from vertex 0 to 1
115  label face0vert1 =
116  nextVert
117  (
118  face0vert0,
119  faceSize_[face0I],
120  !(owner[faceMap_[face0I]] == celli)
121  );
122  vertLabels_[1] = pointMap_[face0[face0vert1]];
123  //Info<< "Prism vertex 1: vertex " << face0[face0vert1]
124  // << " at position " << face0vert1 << " in face " << face0
125  // << endl;
126 
127  // Jump edge from face0 to face4
128  label face4I =
129  otherFace
130  (
131  numVert,
132  face0[face0vert0],
133  face0[face0vert1],
134  face0I
135  );
136  const face& face4 = localFaces_[face4I];
137  //Info<< "Stepped to prism face 4 " << face4
138  // << " across edge " << face0[face0vert0] << " "
139  // << face0[face0vert1]
140  // << endl;
141 
142  if (faceSize_[face4I] != 4)
143  {
144  //Info<< "Cannot be Prism Face 4 since size="
145  // << faceSize_[face4I] << endl;
146  return false;
147  }
148  faceLabels_[4] = faceMap_[face4I];
149 
150  label face4vert1 = pointFaceIndex_[face0[face0vert1]][face4I];
151 
152  //Info<< "Prism vertex 1 also: vertex " << face4[face4vert1]
153  // << " at position " << face4vert1 << " in face " << face4
154  // << endl;
155 
156  // Walk face 4 from vertex 1 to 4
157  label face4vert4 =
158  nextVert
159  (
160  face4vert1,
161  faceSize_[face4I],
162  (owner[faceMap_[face4I]] == celli)
163  );
164  vertLabels_[4] = pointMap_[face4[face4vert4]];
165  //Info<< "Prism vertex 4: vertex " << face4[face4vert4]
166  // << " at position " << face4vert4 << " in face " << face4
167  // << endl;
168 
169  // Walk face 4 from vertex 1 to 3
170  label face4vert3 =
171  nextVert
172  (
173  face4vert4,
174  faceSize_[face4I],
175  (owner[faceMap_[face4I]] == celli)
176  );
177  vertLabels_[3] = pointMap_[face4[face4vert3]];
178  //Info<< "Prism vertex 3: vertex " << face4[face4vert3]
179  // << " at position " << face4vert3 << " in face " << face4
180  // << endl;
181 
182  // Jump edge from face4 to face1
183  label face1I =
184  otherFace
185  (
186  numVert,
187  face4[face4vert3],
188  face4[face4vert4],
189  face4I
190  );
191  //const face& face1 = localFaces_[face1I];
192  //Info<< "Stepped to prism face 1 " << face1
193  // << " across edge " << face4[face4vert3] << " "
194  // << face4[face4vert4]
195  // << endl;
196 
197  if (faceSize_[face1I] != 3)
198  {
199  //Info<< "Cannot be Prism Face 1 since size="
200  // << faceSize_[face1I] << endl;
201  return false;
202  }
203 
204  // Is prism for sure now
205  if (checkOnly)
206  {
207  return true;
208  }
209 
210  faceLabels_[1] = faceMap_[face1I];
211 
212 
213  //
214  // Walk to other faces and assign mapping.
215  //
216 
217 
218  // Walk face 0 from vertex 1 to 2
219  label face0vert2 =
220  nextVert
221  (
222  face0vert1,
223  faceSize_[face0I],
224  !(owner[faceMap_[face0I]] == celli)
225  );
226  vertLabels_[2] = pointMap_[face0[face0vert2]];
227  //Info<< "Prism vertex 2: vertex " << face0[face0vert2]
228  // << " at position " << face0vert2 << " in face " << face0
229  // << endl;
230 
231  // Jump edge from face0 to face3
232  label face3I =
233  otherFace
234  (
235  numVert,
236  face0[face0vert1],
237  face0[face0vert2],
238  face0I
239  );
240  faceLabels_[3] = faceMap_[face3I];
241  const face& face3 = localFaces_[face3I];
242  //Info<< "Stepped to prism face 3 " << face3
243  // << " across edge " << face0[face0vert1] << " "
244  // << face0[face0vert2]
245  // << endl;
246 
247  label face3vert2 = pointFaceIndex_[face0[face0vert2]][face3I];
248 
249  //Info<< "Prism vertex 2 also: vertex " << face3[face3vert2]
250  // << " at position " << face3vert2 << " in face " << face3
251  // << endl;
252 
253  label face3vert5 =
254  nextVert
255  (
256  face3vert2,
257  faceSize_[face3I],
258  (owner[faceMap_[face3I]] == celli)
259  );
260  vertLabels_[5] = pointMap_[face3[face3vert5]];
261  //Info<< "Prism vertex 5: vertex " << face3[face3vert5]
262  // << " at position " << face3vert5 << " in face " << face3
263  // << endl;
264 
265  // Jump edge from face0 to face2
266  label face2I =
267  otherFace
268  (
269  numVert,
270  face0[face0vert2],
271  face0[face0vert0],
272  face0I
273  );
274  faceLabels_[2] = faceMap_[face2I];
275  //const face& face2 = localFaces_[face2I];
276  //Info<< "Stepped to prism face 2 " << face2
277  // << " across edge " << face0[face0vert2] << " "
278  // << face0[face0vert0]
279  // << endl;
280 
281  //label face2vert2 = pointFaceIndex_[face0[face0vert2]][face2I];
282  //Info<< "Prism vertex 2 also: vertex " << face2[face2vert2]
283  // << " at position " << face2vert2 << " in face " << face2
284  // << endl;
285 
286  return true;
287 }
288 
289 
291 {
292  return 2*3 + 4*4;
293 }
294 
295 
297 (
298  const faceList& faces,
299  const labelList& myFaces
300 ) const
301 {
302  if (myFaces.size() != 5)
303  {
304  return false;
305  }
306 
307  label nTris = 0;
308  label nQuads = 0;
309 
310  for (const label facei : myFaces)
311  {
312  const label size = faces[facei].size();
313 
314  if (size == 3)
315  {
316  ++nTris;
317  }
318  else if (size == 4)
319  {
320  ++nQuads;
321  }
322  else
323  {
324  return false;
325  }
326  }
327 
328  return (nTris == 2 && nQuads == 3);
329 }
330 
331 
333 {
334  return matchShape
335  (
336  true,
337  mesh.faces(),
338  mesh.faceOwner(),
339  celli,
340  mesh.cells()[celli]
341  );
342 }
343 
344 
346 {
347  // Do as if mesh with one cell only
348  return matchShape
349  (
350  true,
351  faces, // all faces in mesh
352  labelList(faces.size(), Zero), // cell 0 is owner of all faces
353  0, // cell label
354  identity(faces.size()) // faces of cell 0
355  );
356 }
357 
358 
360 (
361  const primitiveMesh& mesh,
362  const label celli,
363  cellShape& shape
364 )
365 {
366  if
367  (
368  matchShape
369  (
370  false,
371  mesh.faces(),
372  mesh.faceOwner(),
373  celli,
374  mesh.cells()[celli]
375  )
376  )
377  {
378  shape = cellShape(model(), vertLabels());
379 
380  return true;
381  }
382 
383  return false;
384 }
385 
386 
387 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:74
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::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
prismMatcher.H
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::prismMatcher::isA
virtual bool isA(const primitiveMesh &mesh, const label celli)
Exact match. Uses faceSizeMatch.
Definition: prismMatcher.C:332
Foam::polyMesh::faceOwner
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1076
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::cellShape
An analytical geometric cellShape.
Definition: cellShape.H:71
Foam::prismMatcher::prismMatcher
prismMatcher()
Construct.
Definition: prismMatcher.C:34
Foam::polyMesh::faces
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1063
Foam::prismMatcher::~prismMatcher
~prismMatcher()
Destructor.
Definition: prismMatcher.C:47
Foam::prismMatcher::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: prismMatcher.C:53
Foam::List< face >
Foam::prismMatcher::matches
virtual bool matches(const primitiveMesh &mesh, const label celli, cellShape &shape)
Like isA but also constructs a cellShape (if shape matches)
Definition: prismMatcher.C:360
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::prismMatcher::faceSizeMatch
virtual bool faceSizeMatch(const faceList &, const labelList &) const
Check whether number of face sizes match the shape.
Definition: prismMatcher.C:297
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::prismMatcher::faceHashValue
virtual label faceHashValue() const
Hash value of all face sizes of this shape. Can be used for.
Definition: prismMatcher.C:290
Foam::primitiveMesh
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:78