tetWedgeMatcher.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 "tetWedgeMatcher.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  "tetWedge" // same as cellModel::modelNames[cellModel::TETWEDGE]
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 tetWedge for sure now. No other shape has two tri, two quad
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  // Try first triangular face. Rotate in all directions.
96  // Walk path to other triangular face.
97  //
98 
99  label face0I = -1;
100  forAll(faceSize_, facei)
101  {
102  if (faceSize_[facei] == 3)
103  {
104  face0I = facei;
105  break;
106  }
107  }
108 
109  const face& face0 = localFaces_[face0I];
110 
111  // Try all rotations of this face
112  for (label face0vert0 = 0; face0vert0 < faceSize_[face0I]; face0vert0++)
113  {
114  //
115  // Try to follow prespecified path on faces of cell,
116  // starting at face0vert0
117  //
118 
119  vertLabels_[0] = pointMap_[face0[face0vert0]];
120  faceLabels_[0] = faceMap_[face0I];
121 
122  // Walk face 0 from vertex 0 to 1
123  label face0vert1 =
124  nextVert
125  (
126  face0vert0,
127  faceSize_[face0I],
128  !(owner[faceMap_[face0I]] == celli)
129  );
130  vertLabels_[1] = pointMap_[face0[face0vert1]];
131 
132  // Jump edge from face0 to face1 (the other triangular face)
133  label face1I =
134  otherFace
135  (
136  numVert,
137  face0[face0vert0],
138  face0[face0vert1],
139  face0I
140  );
141 
142  if (faceSize_[face1I] != 3)
143  {
144  continue;
145  }
146  faceLabels_[1] = faceMap_[face1I];
147 
148 
149  // Now correctly oriented tet-wedge for sure.
150 
151  // Walk face 0 from vertex 1 to 2
152  label face0vert2 =
153  nextVert
154  (
155  face0vert1,
156  faceSize_[face0I],
157  !(owner[faceMap_[face0I]] == celli)
158  );
159  vertLabels_[2] = pointMap_[face0[face0vert2]];
160 
161  // Jump edge from face0 to face3
162  label face3I =
163  otherFace
164  (
165  numVert,
166  face0[face0vert1],
167  face0[face0vert2],
168  face0I
169  );
170  faceLabels_[3] = faceMap_[face3I];
171 
172  // Jump edge from face0 to face2
173  label face2I =
174  otherFace
175  (
176  numVert,
177  face0[face0vert2],
178  face0[face0vert0],
179  face0I
180  );
181  faceLabels_[2] = faceMap_[face2I];
182 
183  // Get index of vertex 2 in face3
184  label face3vert2 = pointFaceIndex_[face0[face0vert2]][face3I];
185 
186  // Walk face 3 from vertex 2 to 4
187  label face3vert4 =
188  nextVert
189  (
190  face3vert2,
191  faceSize_[face3I],
192  (owner[faceMap_[face3I]] == celli)
193  );
194 
195  const face& face3 = localFaces_[face3I];
196 
197  vertLabels_[4] = pointMap_[face3[face3vert4]];
198 
199  // Walk face 3 from vertex 4 to 3
200  label face3vert3 =
201  nextVert
202  (
203  face3vert4,
204  faceSize_[face3I],
205  (owner[faceMap_[face3I]] == celli)
206  );
207  vertLabels_[3] = pointMap_[face3[face3vert3]];
208 
209  return true;
210  }
211 
212  // Tried all triangular faces, in all rotations but no match found
213  return false;
214 }
215 
216 
218 {
219  return 2*3 + 2*4;
220 }
221 
222 
224 (
225  const faceList& faces,
226  const labelList& myFaces
227 ) const
228 {
229  if (myFaces.size() != 4)
230  {
231  return false;
232  }
233 
234  label nTris = 0;
235  label nQuads = 0;
236 
237  for (const label facei : myFaces)
238  {
239  const label size = faces[facei].size();
240 
241  if (size == 3)
242  {
243  ++nTris;
244  }
245  else if (size == 4)
246  {
247  ++nQuads;
248  }
249  else
250  {
251  return false;
252  }
253  }
254 
255  return (nTris == 2 && nQuads == 2);
256 }
257 
258 
260 {
261  return matchShape
262  (
263  true,
264  mesh.faces(),
265  mesh.faceOwner(),
266  celli,
267  mesh.cells()[celli]
268  );
269 }
270 
271 
273 {
274  // Do as if mesh with one cell only
275  return matchShape
276  (
277  true,
278  faces, // all faces in mesh
279  labelList(faces.size(), Zero), // cell 0 is owner of all faces
280  0, // cell label
281  identity(faces.size()) // faces of cell 0
282  );
283 }
284 
285 
287 (
288  const primitiveMesh& mesh,
289  const label celli,
290  cellShape& shape
291 )
292 {
293  if
294  (
295  matchShape
296  (
297  false,
298  mesh.faces(),
299  mesh.faceOwner(),
300  celli,
301  mesh.cells()[celli]
302  )
303  )
304  {
305  shape = cellShape(model(), vertLabels());
306 
307  return true;
308  }
309 
310  return false;
311 }
312 
313 
314 // ************************************************************************* //
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::tetWedgeMatcher::~tetWedgeMatcher
~tetWedgeMatcher()
Destructor.
Definition: tetWedgeMatcher.C:50
tetWedgeMatcher.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::tetWedgeMatcher::tetWedgeMatcher
tetWedgeMatcher()
Construct null.
Definition: tetWedgeMatcher.C:36
Foam::tetWedgeMatcher::matches
virtual bool matches(const primitiveMesh &mesh, const label celli, cellShape &shape)
Like isA but also constructs a cellShape (if shape matches)
Definition: tetWedgeMatcher.C:287
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::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::tetWedgeMatcher::faceSizeMatch
virtual bool faceSizeMatch(const faceList &, const labelList &) const
Check whether number of face sizes match the shape.
Definition: tetWedgeMatcher.C:224
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::tetWedgeMatcher::isA
virtual bool isA(const primitiveMesh &mesh, const label celli)
Exact match. Uses faceSizeMatch.
Definition: tetWedgeMatcher.C:259
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::tetWedgeMatcher::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: tetWedgeMatcher.C:57
Foam::tetWedgeMatcher::faceHashValue
virtual label faceHashValue() const
Hash value of all face sizes of this shape. Can be used for.
Definition: tetWedgeMatcher.C:217
Foam::primitiveMesh
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:78