extrudedTriangleCellShape.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Description
27 Construct an extruded triangular prism cell shape from three straight edges
28
29\*---------------------------------------------------------------------------*/
30
32#include "labelList.H"
33#include "cellModel.H"
34
35// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36
37namespace Foam
38{
39
40// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41
43(
44 const label cellIndex,
45 const labelList& faceLabels,
46 const faceList& faces,
47 const labelList& owner,
48 const labelList& neighbour,
49 const label pointOffset,
50 faceList& frontAndBackFaces
51)
52{
53 static const cellModel* prismModelPtr_ = nullptr;
54
55 if (!prismModelPtr_)
56 {
57 prismModelPtr_ = cellModel::ptr(cellModel::PRISM);
58 }
59
60 const cellModel& prism = *prismModelPtr_;
61
62 // Checking
63 if (faceLabels.size() != 3)
64 {
66 << "Trying to create a triangle with " << faceLabels.size()
67 << " faces"
68 << abort(FatalError);
69 }
70
71 // make a list of outward-pointing faces
72 labelListList localFaces(3);
73
74 forAll(faceLabels, facei)
75 {
76 const label curFaceLabel = faceLabels[facei];
77
78 const face& curFace = faces[curFaceLabel];
79
80 if (curFace.size() != 2)
81 {
83 << "face " << curFaceLabel
84 << "does not have 2 vertices. Number of vertices: " << curFace
85 << abort(FatalError);
86 }
87
88 if (owner[curFaceLabel] == cellIndex)
89 {
90 localFaces[facei] = curFace;
91 }
92 else if (neighbour[curFaceLabel] == cellIndex)
93 {
94 // Reverse the face. Note: it is necessary to reverse by
95 // hand to preserve connectivity of a 2-D mesh.
96 //
97 localFaces[facei].setSize(curFace.size());
98
99 forAllReverse(curFace, i)
100 {
101 localFaces[facei][curFace.size() - i - 1] =
102 curFace[i];
103 }
104 }
105 else
106 {
108 << "face " << curFaceLabel
109 << " does not belong to cell " << cellIndex
110 << ". Face owner: " << owner[curFaceLabel] << " neighbour: "
111 << neighbour[curFaceLabel]
112 << abort(FatalError);
113 }
114 }
115
116 // Create a label list for the model
117 if (localFaces[0][1] == localFaces[1][0])
118 {
119 // Set front and back plane faces
120 labelList missingPlaneFace(3);
121
122 // front plane
123 missingPlaneFace[0] = localFaces[0][0];
124 missingPlaneFace[1] = localFaces[1][1];
125 missingPlaneFace[2] = localFaces[0][1];
126
127 frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
128
129 // back plane
130 missingPlaneFace[0] = localFaces[0][0] + pointOffset;
131 missingPlaneFace[1] = localFaces[0][1] + pointOffset;
132 missingPlaneFace[2] = localFaces[1][1] + pointOffset;
133
134 frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
135
136 // make a cell
137 labelList cellShapeLabels(6);
138
139 cellShapeLabels[0] = localFaces[0][0];
140 cellShapeLabels[1] = localFaces[0][1];
141 cellShapeLabels[2] = localFaces[1][1];
142
143 cellShapeLabels[3] = localFaces[0][0] + pointOffset;
144 cellShapeLabels[4] = localFaces[0][1] + pointOffset;
145 cellShapeLabels[5] = localFaces[1][1] + pointOffset;
146
147 return cellShape(prism, cellShapeLabels);
148 }
149 else if (localFaces[0][1] == localFaces[2][0])
150 {
151 // Set front and back plane faces
152 labelList missingPlaneFace(3);
153
154 // front plane
155 missingPlaneFace[0] = localFaces[0][0];
156 missingPlaneFace[1] = localFaces[2][1];
157 missingPlaneFace[2] = localFaces[0][1];
158
159 frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
160
161 // back plane
162 missingPlaneFace[0] = localFaces[0][0] + pointOffset;
163 missingPlaneFace[1] = localFaces[0][1] + pointOffset;
164 missingPlaneFace[2] = localFaces[2][1] + pointOffset;
165
166 frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
167
168 // make a cell
169 labelList cellShapeLabels(6);
170
171 cellShapeLabels[0] = localFaces[0][0];
172 cellShapeLabels[1] = localFaces[0][1];
173 cellShapeLabels[2] = localFaces[2][1];
174
175 cellShapeLabels[3] = localFaces[0][0] + pointOffset;
176 cellShapeLabels[4] = localFaces[0][1] + pointOffset;
177 cellShapeLabels[5] = localFaces[2][1] + pointOffset;
178
179 return cellShape(prism, cellShapeLabels);
180 }
181
182
184 << "Problem with edge matching. Edges: " << localFaces
185 << abort(FatalError);
186
187 // Return added to keep compiler happy
188 return cellShape(prism, labelList());
189}
190
191
192// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
193
194} // End namespace Foam
195
196// ************************************************************************* //
@ PRISM
prism
Definition: cellModel.H:83
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: List.H:66
cellShape extrudedTriangleCellShape(const label cellIndex, const labelList &faceLabels, const faceList &faces, const labelList &owner, const labelList &neighbour, const label pointOffset, faceList &frontAndBackFaces)
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
List< face > faceList
A List of faces.
Definition: faceListFwd.H:47
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Definition: stdFoam.H:346