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 triangular prism cell shape from three straight edges
27 \*---------------------------------------------------------------------------*/
29 #include "cellShapeRecognition.H"
30 #include "labelList.H"
31 #include "cellModeller.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 cellShape extrudedTriangleCellShape
42 const label cellIndex,
43 const labelList& faceLabels,
44 const faceList& faces,
45 const labelList& owner,
46 const labelList& neighbour,
47 const label pointOffset,
48 faceList& frontAndBackFaces
51 static const cellModel* prismModelPtr_ = NULL;
55 prismModelPtr_ = cellModeller::lookup("prism");
58 const cellModel& prism = *prismModelPtr_;
61 if (faceLabels.size() != 3)
65 "extrudedTriangleCellShape(const label cellIndex, "
66 "const labelList& faceLabels, const faceList& faces, "
67 "const labelList& owner, const labelList& neighbour, "
68 "const label pointOffset, faceList& frontAndBackFaces)"
69 ) << "Trying to create a triangle with " << faceLabels.size()
74 // make a list of outward-pointing faces
75 labelListList localFaces(3);
77 forAll(faceLabels, faceI)
79 const label curFaceLabel = faceLabels[faceI];
81 const face& curFace = faces[curFaceLabel];
83 if (curFace.size() != 2)
87 "extrudedTriangleCellShape(const label cellIndex, "
88 "const labelList& faceLabels, const faceList& faces, "
89 "const labelList& owner, const labelList& neighbour, "
90 "const label pointOffset, faceList& frontAndBackFaces)"
91 ) << "face " << curFaceLabel
92 << "does not have 2 vertices. Number of vertices: " << curFace
96 if (owner[curFaceLabel] == cellIndex)
98 localFaces[faceI] = curFace;
100 else if (neighbour[curFaceLabel] == cellIndex)
102 // Reverse the face. Note: it is necessary to reverse by
103 // hand to preserve connectivity of a 2-D mesh.
105 localFaces[faceI].setSize(curFace.size());
107 forAllReverse(curFace, i)
109 localFaces[faceI][curFace.size() - i - 1] =
117 "extrudedTriangleCellShape(const label cellIndex, "
118 "const labelList& faceLabels, const faceList& faces, "
119 "const labelList& owner, const labelList& neighbour, "
120 "const label pointOffset, faceList& frontAndBackFaces)"
121 ) << "face " << curFaceLabel
122 << " does not belong to cell " << cellIndex
123 << ". Face owner: " << owner[curFaceLabel] << " neighbour: "
124 << neighbour[curFaceLabel]
125 << abort(FatalError);
129 // Create a label list for the model
130 if (localFaces[0][1] == localFaces[1][0])
132 // Set front and back plane faces
133 labelList missingPlaneFace(3);
136 missingPlaneFace[0] = localFaces[0][0];
137 missingPlaneFace[1] = localFaces[1][1];
138 missingPlaneFace[2] = localFaces[0][1];
140 frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
143 missingPlaneFace[0] = localFaces[0][0] + pointOffset;
144 missingPlaneFace[1] = localFaces[0][1] + pointOffset;
145 missingPlaneFace[2] = localFaces[1][1] + pointOffset;
147 frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
150 labelList cellShapeLabels(6);
152 cellShapeLabels[0] = localFaces[0][0];
153 cellShapeLabels[1] = localFaces[0][1];
154 cellShapeLabels[2] = localFaces[1][1];
156 cellShapeLabels[3] = localFaces[0][0] + pointOffset;
157 cellShapeLabels[4] = localFaces[0][1] + pointOffset;
158 cellShapeLabels[5] = localFaces[1][1] + pointOffset;
160 return cellShape(prism, cellShapeLabels);
162 else if (localFaces[0][1] == localFaces[2][0])
164 // Set front and back plane faces
165 labelList missingPlaneFace(3);
168 missingPlaneFace[0] = localFaces[0][0];
169 missingPlaneFace[1] = localFaces[2][1];
170 missingPlaneFace[2] = localFaces[0][1];
172 frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
175 missingPlaneFace[0] = localFaces[0][0] + pointOffset;
176 missingPlaneFace[1] = localFaces[0][1] + pointOffset;
177 missingPlaneFace[2] = localFaces[2][1] + pointOffset;
179 frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
182 labelList cellShapeLabels(6);
184 cellShapeLabels[0] = localFaces[0][0];
185 cellShapeLabels[1] = localFaces[0][1];
186 cellShapeLabels[2] = localFaces[2][1];
188 cellShapeLabels[3] = localFaces[0][0] + pointOffset;
189 cellShapeLabels[4] = localFaces[0][1] + pointOffset;
190 cellShapeLabels[5] = localFaces[2][1] + pointOffset;
192 return cellShape(prism, cellShapeLabels);
198 "extrudedTriangleCellShape(const label cellIndex, "
199 "const labelList& faceLabels, const faceList& faces, "
200 "const labelList& owner, const labelList& neighbour, "
201 "const label pointOffset, faceList& frontAndBackFaces)"
202 ) << "Problem with edge matching. Edges: " << localFaces
203 << abort(FatalError);
206 // Return added to keep compiler happy
207 return cellShape(prism, labelList(0));
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
213 } // End namespace Foam
215 // ************************************************************************* //