1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "wedgeMatcher.H"
27 #include "primitiveMesh.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 const Foam::label Foam::wedgeMatcher::vertPerCell = 7;
33 const Foam::label Foam::wedgeMatcher::facePerCell = 6;
34 const Foam::label Foam::wedgeMatcher::maxVertPerFace = 4;
37 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 Foam::wedgeMatcher::wedgeMatcher()
51 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
53 Foam::wedgeMatcher::~wedgeMatcher()
57 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
59 bool Foam::wedgeMatcher::matchShape
62 const faceList& faces,
63 const labelList& owner,
65 const labelList& myFaces
68 if (!faceSizeMatch(faces, myFaces))
73 // Calculate localFaces_ and mapping pointMap_, faceMap_
74 label numVert = calcLocalFaces(faces, myFaces);
76 if (numVert != vertPerCell)
81 // Set up 'edge' to face mapping.
82 calcEdgeAddressing(numVert);
84 // Set up point on face to index-in-face mapping
87 // Storage for maps -vertex to mesh and -face to mesh
88 vertLabels_.setSize(vertPerCell);
89 faceLabels_.setSize(facePerCell);
92 // Try first triangular face. Rotate in all directions.
93 // Walk path to other triangular face.
97 forAll(faceSize_, faceI)
99 if (faceSize_[faceI] == 3)
106 const face& face0 = localFaces_[face0I];
108 // Try all rotations of this face
109 for (label face0vert0 = 0; face0vert0 < faceSize_[face0I]; face0vert0++)
112 // Try to follow prespecified path on faces of cell,
113 // starting at face0vert0
116 vertLabels_[0] = pointMap_[face0[face0vert0]];
117 faceLabels_[0] = faceMap_[face0I];
118 //Info<< endl << "Wedge vertex 0: vertex " << face0[face0vert0]
119 // << " at position " << face0vert0 << " in face " << face0
122 // Walk face 0 from vertex 0 to 1
128 !(owner[faceMap_[face0I]] == cellI)
130 vertLabels_[1] = pointMap_[face0[face0vert1]];
131 //Info<< "Wedge vertex 1: vertex " << face0[face0vert1]
132 // << " at position " << face0vert1 << " in face " << face0
135 // Jump edge from face0 to face4
144 const face& face4 = localFaces_[face4I];
145 //Info<< "Stepped to wedge face 4 " << face4
146 // << " across edge " << face0[face0vert0] << " "
147 // << face0[face0vert1]
150 if (faceSize_[face4I] != 4)
152 //Info<< "Cannot be Wedge Face 4 since size="
153 // << faceSize_[face4I] << endl;
157 // Is wedge for sure now
163 faceLabels_[4] = faceMap_[face4I];
165 // Get index of vertex 0 in face4
166 label face4vert0 = pointFaceIndex_[face0[face0vert0]][face4I];
168 //Info<< "Wedge vertex 0 also: vertex " << face4[face4vert0]
169 // << " at position " << face4vert0 << " in face " << face4
172 // Walk face 4 from vertex 4 to 3
178 !(owner[faceMap_[face4I]] == cellI)
180 vertLabels_[3] = pointMap_[face4[face4vert3]];
181 //Info<< "Wedge vertex 3: vertex " << face4[face4vert3]
182 // << " at position " << face4vert3 << " in face " << face4
186 // Jump edge from face4 to face2
195 const face& face2 = localFaces_[face2I];
196 //Info<< "Stepped to wedge face 2 " << face2
197 // << " across edge " << face4[face4vert0] << " "
198 // << face4[face4vert3]
201 if (faceSize_[face2I] != 3)
203 //Info<< "Cannot be Wedge Face 2 since size="
204 // << faceSize_[face2I] << endl;
207 faceLabels_[2] = faceMap_[face2I];
209 // Is wedge for sure now
210 //Info<< "** WEDGE **" << endl;
214 // Walk to other faces and vertices and assign mapping.
218 label face2vert3 = pointFaceIndex_[face4[face4vert3]][face2I];
220 // Walk face 2 from vertex 3 to 6
226 (owner[faceMap_[face2I]] == cellI)
228 vertLabels_[6] = pointMap_[face2[face2vert6]];
230 // Jump edge from face2 to face1
239 faceLabels_[1] = faceMap_[face1I];
240 const face& face1 = localFaces_[face1I];
241 //Info<< "Stepped to wedge face 1 " << face1
242 // << " across edge " << face2[face2vert3] << " "
243 // << face2[face2vert6]
246 label face1vert6 = pointFaceIndex_[face2[face2vert6]][face1I];
248 // Walk face 1 from vertex 6 to 5
254 !(owner[faceMap_[face1I]] == cellI)
256 vertLabels_[5] = pointMap_[face1[face1vert5]];
258 // Walk face 1 from vertex 5 to 4
264 !(owner[faceMap_[face1I]] == cellI)
266 vertLabels_[4] = pointMap_[face1[face1vert4]];
268 // Walk face 0 from vertex 1 to 2
274 !(owner[faceMap_[face0I]] == cellI)
276 vertLabels_[2] = pointMap_[face0[face0vert2]];
277 //Info<< "Wedge vertex 2: vertex " << face0[face0vert2]
278 // << " at position " << face0vert2 << " in face " << face0
281 // Jump edge from face0 to face3
290 faceLabels_[3] = faceMap_[face3I];
291 //const face& face3 = localFaces_[face3I];
292 //Info<< "Stepped to wedge face 3 " << face3
293 // << " across edge " << face0[face0vert1] << " "
294 // << face0[face0vert2]
298 // Jump edge from face0 to face5
307 faceLabels_[5] = faceMap_[face5I];
308 //const face& face5 = localFaces_[face5I];
309 //Info<< "Stepped to wedge face 5 " << face5
310 // << " across edge " << face0[face0vert2] << " "
311 // << face0[face0vert0]
317 // Tried all triangular faces, in all rotations but no match found
322 Foam::label Foam::wedgeMatcher::faceHashValue() const
328 bool Foam::wedgeMatcher::faceSizeMatch
330 const faceList& faces,
331 const labelList& myFaces
334 if (myFaces.size() != 6)
342 forAll(myFaces, myFaceI)
344 label size = faces[myFaces[myFaceI]].size();
359 if ((nTris == 2) && (nQuads == 4))
370 bool Foam::wedgeMatcher::isA(const primitiveMesh& mesh, const label cellI)
383 bool Foam::wedgeMatcher::isA(const faceList& faces)
385 // Do as if mesh with one cell only
389 faces, // all faces in mesh
390 labelList(faces.size(), 0), // cell 0 is owner of all faces
392 identity(faces.size()) // faces of cell 0
397 bool Foam::wedgeMatcher::matches
399 const primitiveMesh& mesh,
416 shape = cellShape(model(), vertLabels());
427 // ************************************************************************* //