1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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/>.
25 Construct an extruded hex cell shape from four straight edges
27 \*---------------------------------------------------------------------------*/
29 #include "cellShapeRecognition.H"
30 #include "labelList.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 cellShape extrudedQuadCellShape
41 const label cellIndex,
42 const labelList& faceLabels,
43 const faceList& faces,
44 const labelList& owner,
45 const labelList& neighbour,
46 const label pointOffset,
47 faceList& frontAndBackFaces
50 static const cellModel* hexModelPtr_ = NULL;
54 hexModelPtr_ = cellModeller::lookup("hex");
57 const cellModel& hex = *hexModelPtr_;
60 if (faceLabels.size() != 4)
64 "extrudedQuadCellShape(const label cellIndex, "
65 "const labelList& faceLabels, const faceList& faces, "
66 "const labelList& owner, const labelList& neighbour, "
67 "const label pointOffset, faceList& frontAndBackFaces)"
68 ) << "Trying to create a quad with " << faceLabels.size() << " faces"
72 // make a list of outward-pointing faces
73 labelListList localFaces(4);
75 forAll(faceLabels, faceI)
77 const label curFaceLabel = faceLabels[faceI];
79 const face& curFace = faces[curFaceLabel];
81 if (curFace.size() != 2)
85 "extrudedQuadCellShape(const label cellIndex, "
86 "const labelList& faceLabels, const faceList& faces, "
87 "const labelList& owner, const labelList& neighbour, "
88 "const label pointOffset, faceList& frontAndBackFaces)"
89 ) << "face " << curFaceLabel
90 << "does not have 2 vertices. Number of vertices: " << curFace
94 if (owner[curFaceLabel] == cellIndex)
96 localFaces[faceI] = curFace;
98 else if (neighbour[curFaceLabel] == cellIndex)
100 // Reverse the face. Note: it is necessary to reverse by
101 // hand to preserve connectivity of a 2-D mesh.
103 localFaces[faceI].setSize(curFace.size());
105 forAllReverse(curFace, i)
107 localFaces[faceI][curFace.size() - i - 1] =
115 "extrudedQuadCellShape(const label cellIndex, "
116 "const labelList& faceLabels, const faceList& faces, "
117 "const labelList& owner, const labelList& neighbour, "
118 "const label pointOffset, faceList& frontAndBackFaces)"
119 ) << "face " << curFaceLabel
120 << " does not belong to cell " << cellIndex
121 << ". Face owner: " << owner[curFaceLabel] << " neighbour: "
122 << neighbour[curFaceLabel]
123 << abort(FatalError);
127 // Create a label list for the model
128 // This is done by finding two edges that do not share any vertices.
129 // Knowing the opposite pair of edges (with normals poining outward
130 // is enough to make a cell
133 localFaces[0][0] != localFaces[1][1]
134 && localFaces[0][1] != localFaces[1][0]
137 // Set front and back plane faces
138 labelList missingPlaneFace(4);
141 missingPlaneFace[0] = localFaces[0][0];
142 missingPlaneFace[1] = localFaces[1][1];
143 missingPlaneFace[2] = localFaces[1][0];
144 missingPlaneFace[3] = localFaces[0][1];
146 frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
149 missingPlaneFace[0] = localFaces[0][0] + pointOffset;
150 missingPlaneFace[1] = localFaces[0][1] + pointOffset;
151 missingPlaneFace[2] = localFaces[1][0] + pointOffset;
152 missingPlaneFace[3] = localFaces[1][1] + pointOffset;
154 frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
157 labelList cellShapeLabels(8);
159 cellShapeLabels[0] = localFaces[0][0];
160 cellShapeLabels[1] = localFaces[0][1];
161 cellShapeLabels[2] = localFaces[1][0];
162 cellShapeLabels[3] = localFaces[1][1];
164 cellShapeLabels[4] = localFaces[0][0] + pointOffset;
165 cellShapeLabels[5] = localFaces[0][1] + pointOffset;
166 cellShapeLabels[6] = localFaces[1][0] + pointOffset;
167 cellShapeLabels[7] = localFaces[1][1] + pointOffset;
170 return cellShape(hex, cellShapeLabels);
174 localFaces[0][0] != localFaces[2][1]
175 && localFaces[0][1] != localFaces[2][0]
178 // Set front and back plane faces
179 labelList missingPlaneFace(4);
182 missingPlaneFace[0] = localFaces[0][0];
183 missingPlaneFace[1] = localFaces[2][1];
184 missingPlaneFace[2] = localFaces[2][0];
185 missingPlaneFace[3] = localFaces[0][1];
187 frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
190 missingPlaneFace[0] = localFaces[0][0] + pointOffset;
191 missingPlaneFace[1] = localFaces[0][1] + pointOffset;
192 missingPlaneFace[2] = localFaces[2][0] + pointOffset;
193 missingPlaneFace[3] = localFaces[2][1] + pointOffset;
195 frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
198 labelList cellShapeLabels(8);
200 cellShapeLabels[0] = localFaces[0][0];
201 cellShapeLabels[1] = localFaces[0][1];
202 cellShapeLabels[2] = localFaces[2][0];
203 cellShapeLabels[3] = localFaces[2][1];
205 cellShapeLabels[4] = localFaces[0][0] + pointOffset;
206 cellShapeLabels[5] = localFaces[0][1] + pointOffset;
207 cellShapeLabels[6] = localFaces[2][0] + pointOffset;
208 cellShapeLabels[7] = localFaces[2][1] + pointOffset;
211 return cellShape(hex, cellShapeLabels);
215 localFaces[0][0] != localFaces[3][1]
216 && localFaces[0][1] != localFaces[3][0]
219 // Set front and back plane faces
220 labelList missingPlaneFace(4);
223 missingPlaneFace[0] = localFaces[0][0];
224 missingPlaneFace[1] = localFaces[3][1];
225 missingPlaneFace[2] = localFaces[3][0];
226 missingPlaneFace[3] = localFaces[0][1];
228 frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
231 missingPlaneFace[0] = localFaces[0][0] + pointOffset;
232 missingPlaneFace[1] = localFaces[0][1] + pointOffset;
233 missingPlaneFace[2] = localFaces[3][0] + pointOffset;
234 missingPlaneFace[3] = localFaces[3][1] + pointOffset;
236 frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
239 labelList cellShapeLabels(8);
241 cellShapeLabels[0] = localFaces[0][0];
242 cellShapeLabels[1] = localFaces[0][1];
243 cellShapeLabels[2] = localFaces[3][0];
244 cellShapeLabels[3] = localFaces[3][1];
246 cellShapeLabels[4] = localFaces[0][0] + pointOffset;
247 cellShapeLabels[5] = localFaces[0][1] + pointOffset;
248 cellShapeLabels[6] = localFaces[3][0] + pointOffset;
249 cellShapeLabels[7] = localFaces[3][1] + pointOffset;
252 return cellShape(hex, cellShapeLabels);
258 "extrudedQuadCellShape(const label cellIndex, "
259 "const labelList& faceLabels, const faceList& faces, "
260 "const labelList& owner, const labelList& neighbour, "
261 "const label pointOffset, faceList& frontAndBackFaces)"
262 ) << "Problem with edge matching. Edges: " << localFaces
263 << abort(FatalError);
266 // Return added to keep compiler happy
267 return cellShape(hex, labelList(0));
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
273 } // End namespace Foam
275 // ************************************************************************* //