initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / meshes / meshShapes / cellMatcher / hexMatcher.C
blobaa4b8ab357579858366e40831cd164cccf25e694
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "hexMatcher.H"
28 #include "primitiveMesh.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 const Foam::label Foam::hexMatcher::vertPerCell = 8;
33 const Foam::label Foam::hexMatcher::facePerCell = 6;
34 const Foam::label Foam::hexMatcher::maxVertPerFace = 4;
37 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
39 // Construct null
40 Foam::hexMatcher::hexMatcher()
42     cellMatcher
43     (
44         vertPerCell,
45         facePerCell,
46         maxVertPerFace,
47         "hex"
48     )
52 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
54 Foam::hexMatcher::~hexMatcher()
58 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
60 bool Foam::hexMatcher::matchShape
62     const bool checkOnly,
63     const faceList& faces,
64     const labelList& owner,
65     const label cellI,
66     const labelList& myFaces
69     if (!faceSizeMatch(faces, myFaces))
70     {
71         return false;
72     }
74     // Is hex for sure since all faces are quads
76     if (checkOnly)
77     {
78         return true;
79     }
81     // Calculate localFaces_ and mapping pointMap_, faceMap_
82     label numVert = calcLocalFaces(faces, myFaces);
84     if (numVert != vertPerCell)
85     {
86         return false;
87     }
89     // Set up 'edge' to face mapping.
90     calcEdgeAddressing(numVert);
92     // Set up point on face to index-in-face mapping
93     calcPointFaceIndex();
95     // Storage for maps -vertex to mesh and -face to mesh
96     vertLabels_.setSize(vertPerCell);
97     faceLabels_.setSize(facePerCell);
99     //
100     // Try bottom face (face 4). 
101     // Only need to try one orientation of this face since hex is
102     // rotation symmetric
103     //
105     label face4I = 0;
107     const face& face4 = localFaces_[face4I];
108     label face4vert0 = 0;
110     vertLabels_[0] = pointMap_[face4[face4vert0]];
111     faceLabels_[4] = faceMap_[face4I];
113     // Walk face 4 from vertex 0 to 1
114     label face4vert1 =
115         nextVert
116         (
117             face4vert0,
118             faceSize_[face4I],
119             !(owner[faceMap_[face4I]] == cellI)
120         );
121     vertLabels_[1] = pointMap_[face4[face4vert1]];
123     // Walk face 4 from vertex 1 to 2
124     label face4vert2 =
125         nextVert
126         (
127             face4vert1,
128             faceSize_[face4I],
129             !(owner[faceMap_[face4I]] == cellI)
130         );
131     vertLabels_[2] = pointMap_[face4[face4vert2]];
133     // Walk face 4 from vertex 2 to 3
134     label face4vert3 =
135         nextVert
136         (
137             face4vert2,
138             faceSize_[face4I],
139             !(owner[faceMap_[face4I]] == cellI)
140         );
141     vertLabels_[3] = pointMap_[face4[face4vert3]];
143     // Jump edge from face4 to face0
144     label face0I =
145         otherFace
146         (
147             numVert,
148             face4[face4vert3],
149             face4[face4vert0],
150             face4I
151         );
152     faceLabels_[0] = faceMap_[face0I];
153     const face& face0 = localFaces_[face0I];
155     label face0vert0 = pointFaceIndex_[face4[face4vert0]][face0I];
157     // Walk face 0 from vertex 0 to 4
158     label face0vert4 =
159         nextVert
160         (
161             face0vert0,
162             faceSize_[face0I],
163             (owner[faceMap_[face0I]] == cellI)
164         );
165     vertLabels_[4] = pointMap_[face0[face0vert4]];
167     // Walk face 0 from vertex 4 to 7
168     label face0vert7 =
169         nextVert
170         (
171             face0vert4,
172             faceSize_[face0I],
173             (owner[faceMap_[face0I]] == cellI)
174         );
175     vertLabels_[7] = pointMap_[face0[face0vert7]];
177     // Jump edge from face0 to face5
178     label face5I =
179         otherFace
180         (
181             numVert,
182             face0[face0vert4],
183             face0[face0vert7],
184             face0I
185         );
186     const face& face5 = localFaces_[face5I];
187     faceLabels_[5] = faceMap_[face5I];
189     label face5vert4 = pointFaceIndex_[face0[face0vert4]][face5I];
191     // Walk face 5 from vertex 4 to 5
192     label face5vert5 =
193         nextVert
194         (
195             face5vert4,
196             faceSize_[face5I],
197             (owner[faceMap_[face5I]] == cellI)
198         );
199     vertLabels_[5] = pointMap_[face5[face5vert5]];
201     // Walk face 5 from vertex 5 to 6
202     label face5vert6 =
203         nextVert
204         (
205             face5vert5,
206             faceSize_[face5I],
207             (owner[faceMap_[face5I]] == cellI)
208         );
209     vertLabels_[6] = pointMap_[face5[face5vert6]];
211     // Jump edge from face4 to face2
212     label face2I =
213         otherFace
214         (
215             numVert,
216             face4[face4vert0],
217             face4[face4vert1],
218             face4I
219         );
220     faceLabels_[2] = faceMap_[face2I];
222     // Jump edge from face4 to face1
223     label face1I =
224         otherFace
225         (
226             numVert,
227             face4[face4vert1],
228             face4[face4vert2],
229             face4I
230         );
231     faceLabels_[1] = faceMap_[face1I];
233     // Jump edge from face4 to face3
234     label face3I =
235         otherFace
236         (
237             numVert,
238             face4[face4vert2],
239             face4[face4vert3],
240             face4I
241         );
242     faceLabels_[3] = faceMap_[face3I];
244     return true;
248 Foam::label Foam::hexMatcher::faceHashValue() const
250     return facePerCell*vertPerCell;
254 bool Foam::hexMatcher::faceSizeMatch
256     const faceList& faces,
257     const labelList& myFaces
258 ) const
260     if (myFaces.size() != facePerCell)
261     {
262         return false;
263     }
265     forAll(myFaces, myFaceI)
266     {
267         label size = faces[myFaces[myFaceI]].size();
269         if (size != 4)
270         {
271             return false;
272         }
273     }
275     return true;
279 bool Foam::hexMatcher::isA(const primitiveMesh& mesh, const label cellI)
281     return matchShape
282     (
283         true,
284         mesh.faces(),
285         mesh.faceOwner(),
286         cellI,
287         mesh.cells()[cellI]
288     );
292 bool Foam::hexMatcher::isA(const faceList& faces)
294     // Do as if mesh with one cell only
295     return matchShape
296     (
297         true,
298         faces,                      // all faces in mesh
299         labelList(faces.size(), 0), // cell 0 is owner of all faces
300         0,                          // cell label
301         makeIdentity(faces.size())  // faces of cell 0
302     );
306 bool Foam::hexMatcher::matches
308     const primitiveMesh& mesh,
309     const label cellI,
310     cellShape& shape
313     if
314     (
315         matchShape
316         (
317             false,
318             mesh.faces(),
319             mesh.faceOwner(),
320             cellI,
321             mesh.cells()[cellI]
322         )
323     )
324     {
325         shape = cellShape(model(), vertLabels());
327         return true;
328     }
329     else
330     {
331         return false;
332     }
336 // ************************************************************************* //