initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / utilities / mesh / conversion / fluentMeshToFoam / extrudedTriangleCellShape.C
blob401ea6225c10a83ebf6e6e23a1336cb613e547e3
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 Description
26     Construct an extruded triangular prism cell shape from three straight edges
28 \*---------------------------------------------------------------------------*/
30 #include "cellShapeRecognition.H"
31 #include "labelList.H"
32 #include "cellModeller.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 namespace Foam
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 cellShape extrudedTriangleCellShape
43     const label cellIndex,
44     const labelList& faceLabels,
45     const faceList& faces,
46     const labelList& owner,
47     const labelList& neighbour,
48     const label pointOffset,
49     faceList& frontAndBackFaces
52     const static cellModel* prismModelPtr_ = NULL;
54     if (!prismModelPtr_)
55     {
56         prismModelPtr_ = cellModeller::lookup("prism");
57     }
59     const cellModel& prism = *prismModelPtr_;
61     // Checking
62     if (faceLabels.size() != 3)
63     {
64         FatalErrorIn
65         (
66             "extrudedTriangleCellShape(const label cellIndex, "
67             "const labelList& faceLabels, const faceList& faces, "
68             "const labelList& owner, const labelList& neighbour, "
69             "const label pointOffset, faceList& frontAndBackFaces)"
70         )   << "Trying to create a triangle with " << faceLabels.size()
71             << " faces"
72             << abort(FatalError);
73     }
75     // make a list of outward-pointing faces
76     labelListList localFaces(3);
78     forAll (faceLabels, faceI)
79     {
80         const label curFaceLabel = faceLabels[faceI];
82         const face& curFace = faces[curFaceLabel];
84         if (curFace.size() != 2)
85         {
86             FatalErrorIn
87             (
88                 "extrudedTriangleCellShape(const label cellIndex, "
89                 "const labelList& faceLabels, const faceList& faces, "
90                 "const labelList& owner, const labelList& neighbour, "
91                 "const label pointOffset, faceList& frontAndBackFaces)"
92             )   << "face " << curFaceLabel
93                 << "does not have 2 vertices. Number of vertices: " << curFace
94                 << abort(FatalError);
95         }
97         if (owner[curFaceLabel] == cellIndex)
98         {
99             localFaces[faceI] = curFace;
100         }
101         else if (neighbour[curFaceLabel] == cellIndex)
102         {
103             // Reverse the face.  Note: it is necessary to reverse by
104             // hand to preserve connectivity of a 2-D mesh.
105             // 
106             localFaces[faceI].setSize(curFace.size());
108             forAllReverse(curFace, i)
109             {
110                 localFaces[faceI][curFace.size() - i - 1] =
111                     curFace[i];
112             }
113         }
114         else
115         {
116             FatalErrorIn
117             (
118                 "extrudedTriangleCellShape(const label cellIndex, "
119                 "const labelList& faceLabels, const faceList& faces, "
120                 "const labelList& owner, const labelList& neighbour, "
121                 "const label pointOffset, faceList& frontAndBackFaces)"
122             )   << "face " << curFaceLabel
123                 << " does not belong to cell " << cellIndex
124                 << ". Face owner: " << owner[curFaceLabel] << " neighbour: "
125                 << neighbour[curFaceLabel]
126                 << abort(FatalError);
127         }
128     }
130     // Create a label list for the model
131     if (localFaces[0][1] == localFaces[1][0])
132     {
133         // Set front and back plane faces
134         labelList missingPlaneFace(3);
136         // front plane
137         missingPlaneFace[0] = localFaces[0][0];
138         missingPlaneFace[1] = localFaces[1][1];
139         missingPlaneFace[2] = localFaces[0][1];
141         frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
143         // back plane
144         missingPlaneFace[0] = localFaces[0][0] + pointOffset;
145         missingPlaneFace[1] = localFaces[0][1] + pointOffset;
146         missingPlaneFace[2] = localFaces[1][1] + pointOffset;
148         frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
150         // make a cell
151         labelList cellShapeLabels(6);
153         cellShapeLabels[0] = localFaces[0][0];
154         cellShapeLabels[1] = localFaces[0][1];
155         cellShapeLabels[2] = localFaces[1][1];
157         cellShapeLabels[3] = localFaces[0][0] + pointOffset;
158         cellShapeLabels[4] = localFaces[0][1] + pointOffset;
159         cellShapeLabels[5] = localFaces[1][1] + pointOffset;
161         return cellShape(prism, cellShapeLabels);
162     }
163     else if (localFaces[0][1] == localFaces[2][0])
164     {
165         // Set front and back plane faces
166         labelList missingPlaneFace(3);
168         // front plane
169         missingPlaneFace[0] = localFaces[0][0];
170         missingPlaneFace[1] = localFaces[2][1];
171         missingPlaneFace[2] = localFaces[0][1];
173         frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
175         // back plane
176         missingPlaneFace[0] = localFaces[0][0] + pointOffset;
177         missingPlaneFace[1] = localFaces[0][1] + pointOffset;
178         missingPlaneFace[2] = localFaces[2][1] + pointOffset;
180         frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
182         // make a cell
183         labelList cellShapeLabels(6);
185         cellShapeLabels[0] = localFaces[0][0];
186         cellShapeLabels[1] = localFaces[0][1];
187         cellShapeLabels[2] = localFaces[2][1];
189         cellShapeLabels[3] = localFaces[0][0] + pointOffset;
190         cellShapeLabels[4] = localFaces[0][1] + pointOffset;
191         cellShapeLabels[5] = localFaces[2][1] + pointOffset;
193         return cellShape(prism, cellShapeLabels);
194     }
195     else
196     {
197         FatalErrorIn
198         (
199             "extrudedTriangleCellShape(const label cellIndex, "
200             "const labelList& faceLabels, const faceList& faces, "
201             "const labelList& owner, const labelList& neighbour, "
202             "const label pointOffset, faceList& frontAndBackFaces)"
203         )   << "Problem with edge matching. Edges: " << localFaces
204             << abort(FatalError);
205     }
207     // Return added to keep compiler happy
208     return cellShape(prism, labelList(0));
212 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
214 } // End namespace Foam
216 // ************************************************************************* //