All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tetMatcher.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 "tetMatcher.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::tetMatcher::vertPerCell = 4;
36 const Foam::label Foam::tetMatcher::facePerCell = 4;
37 const Foam::label Foam::tetMatcher::maxVertPerFace = 3;
38 
39 
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 
43 :
45  (
46  vertPerCell,
47  facePerCell,
48  maxVertPerFace,
49  "tet"
50  )
51 {}
52 
53 
54 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
55 
57 {}
58 
59 
60 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
61 
62 
64 (
65  const bool checkOnly,
66  const faceList& faces,
67  const labelList& owner,
68  const label celli,
69  const labelList& myFaces
70 )
71 {
72  if (!faceSizeMatch(faces, myFaces))
73  {
74  return false;
75  }
76 
77  // Tet for sure now
78  if (checkOnly)
79  {
80  return true;
81  }
82 
83  // Calculate localFaces_ and mapping pointMap_, faceMap_
84  label numVert = calcLocalFaces(faces, myFaces);
85 
86  if (numVert != vertPerCell)
87  {
88  return false;
89  }
90 
91  // Set up 'edge' to face mapping.
92  calcEdgeAddressing(numVert);
93 
94  // Set up point on face to index-in-face mapping
96 
97  // Storage for maps -vertex to mesh and -face to mesh
98  vertLabels_.setSize(vertPerCell);
99  faceLabels_.setSize(facePerCell);
100 
101  //
102  // Try bottom face (face 3)
103  //
104 
105  label face3I = 0;
106  const face& face3 = localFaces_[face3I];
107  label face3vert0 = 0;
108 
109  //
110  // Try to follow prespecified path on faces of cell,
111  // starting at face3vert0
112  //
113 
114  vertLabels_[0] = pointMap_[face3[face3vert0]];
115  faceLabels_[3] = faceMap_[face3I];
116 
117  // Walk face 3 from vertex 0 to 1
118  label face3vert1 =
119  nextVert
120  (
121  face3vert0,
122  faceSize_[face3I],
123  !(owner[faceMap_[face3I]] == celli)
124  );
125  vertLabels_[1] = pointMap_[face3[face3vert1]];
126 
127  // Walk face 3 from vertex 1 to 2
128  label face3vert2 =
129  nextVert
130  (
131  face3vert1,
132  faceSize_[face3I],
133  !(owner[faceMap_[face3I]] == celli)
134  );
135  vertLabels_[2] = pointMap_[face3[face3vert2]];
136 
137  // Jump edge from face3 to face2
138  label face2I =
139  otherFace
140  (
141  numVert,
142  face3[face3vert0],
143  face3[face3vert1],
144  face3I
145  );
146  faceLabels_[2] = faceMap_[face2I];
147 
148  // Jump edge from face3 to face0
149  label face0I =
150  otherFace
151  (
152  numVert,
153  face3[face3vert1],
154  face3[face3vert2],
155  face3I
156  );
157  faceLabels_[0] = faceMap_[face0I];
158 
159  // Jump edge from face3 to face1
160  label face1I =
161  otherFace
162  (
163  numVert,
164  face3[face3vert2],
165  face3[face3vert0],
166  face3I
167  );
168  faceLabels_[1] = faceMap_[face1I];
169  const face& face1 = localFaces_[face1I];
170 
171  // Get index of vert0 in face 1
172  label face1vert0 = pointFaceIndex_[face3[face3vert0]][face1I];
173 
174  // Walk face 1 from vertex 0 to 3
175  label face1vert3 =
176  nextVert
177  (
178  face1vert0,
179  faceSize_[face1I],
180  (owner[faceMap_[face1I]] == celli)
181  );
182  vertLabels_[3] = pointMap_[face1[face1vert3]];
183 
184  return true;
185 }
186 
187 
189 {
190  return 4*3;
191 }
192 
193 
195 (
196  const faceList& faces,
197  const labelList& myFaces
198 ) const
199 {
200  if (myFaces.size() != 4)
201  {
202  return false;
203  }
204 
205  forAll(myFaces, myFacei)
206  {
207  label size = faces[myFaces[myFacei]].size();
208 
209  if (size != 3)
210  {
211  return false;
212  }
213  }
214  return true;
215 }
216 
217 
218 bool Foam::tetMatcher::isA(const primitiveMesh& mesh, const label celli)
219 {
220  return matchShape
221  (
222  true,
223  mesh.faces(),
224  mesh.faceOwner(),
225  celli,
226  mesh.cells()[celli]
227  );
228 }
229 
230 
231 bool Foam::tetMatcher::isA(const faceList& faces)
232 {
233  // Do as if mesh with one cell only
234  return matchShape
235  (
236  true,
237  faces, // all faces in mesh
238  labelList(faces.size(), 0), // cell 0 is owner of all faces
239  0, // cell label
240  identity(faces.size()) // faces of cell 0
241  );
242 }
243 
244 
246 (
247  const primitiveMesh& mesh,
248  const label celli,
249  cellShape& shape
250 )
251 {
252  if
253  (
254  matchShape
255  (
256  false,
257  mesh.faces(),
258  mesh.faceOwner(),
259  celli,
260  mesh.cells()[celli]
261  )
262  )
263  {
264  shape = cellShape(model(), vertLabels());
265 
266  return true;
267  }
268  else
269  {
270  return false;
271  }
272 }
273 
274 
275 // ************************************************************************* //
const labelList & vertLabels() const
Definition: cellMatcherI.H:74
virtual bool matches(const primitiveMesh &mesh, const label celli, cellShape &shape)
Like isA but also constructs a cellShape (if shape matches)
Definition: tetMatcher.C:246
#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
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: tetMatcher.C:64
Base class for cellshape matchers (hexMatch, prismMatch, etc.). These are classes which given a mesh ...
Definition: cellMatcher.H:99
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
~tetMatcher()
Destructor.
Definition: tetMatcher.C:56
virtual bool faceSizeMatch(const faceList &, const labelList &) const
Check whether number of face sizes match the shape.
Definition: tetMatcher.C:195
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
Definition: ListOps.C:104
const cellList & cells() const
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
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
virtual label faceHashValue() const
Hash value of all face sizes of this shape. Can be used for.
Definition: tetMatcher.C:188
List< label > labelList
A List of labels.
Definition: labelList.H:56
tetMatcher()
Construct null.
Definition: tetMatcher.C:42
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
virtual bool isA(const primitiveMesh &mesh, const label celli)
Exact match. Uses faceSizeMatch.
Definition: tetMatcher.C:218
void setSize(const label)
Reset size of List.
Definition: List.C:281
virtual const faceList & faces() const =0
Return faces.
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