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