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 | Copyright (C) 2011 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 Description
25  Construct an extruded triangular prism cell shape from three straight edges
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "cellShapeRecognition.H"
30 #include "labelList.H"
31 #include "cellModeller.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
41 (
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
49 )
50 {
51  static const cellModel* prismModelPtr_ = NULL;
52 
53  if (!prismModelPtr_)
54  {
55  prismModelPtr_ = cellModeller::lookup("prism");
56  }
57 
58  const cellModel& prism = *prismModelPtr_;
59 
60  // Checking
61  if (faceLabels.size() != 3)
62  {
64  (
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()
70  << " faces"
71  << abort(FatalError);
72  }
73 
74  // make a list of outward-pointing faces
75  labelListList localFaces(3);
76 
77  forAll(faceLabels, faceI)
78  {
79  const label curFaceLabel = faceLabels[faceI];
80 
81  const face& curFace = faces[curFaceLabel];
82 
83  if (curFace.size() != 2)
84  {
86  (
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
93  << abort(FatalError);
94  }
95 
96  if (owner[curFaceLabel] == cellIndex)
97  {
98  localFaces[faceI] = curFace;
99  }
100  else if (neighbour[curFaceLabel] == cellIndex)
101  {
102  // Reverse the face. Note: it is necessary to reverse by
103  // hand to preserve connectivity of a 2-D mesh.
104  //
105  localFaces[faceI].setSize(curFace.size());
106 
107  forAllReverse(curFace, i)
108  {
109  localFaces[faceI][curFace.size() - i - 1] =
110  curFace[i];
111  }
112  }
113  else
114  {
116  (
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);
126  }
127  }
128 
129  // Create a label list for the model
130  if (localFaces[0][1] == localFaces[1][0])
131  {
132  // Set front and back plane faces
133  labelList missingPlaneFace(3);
134 
135  // front plane
136  missingPlaneFace[0] = localFaces[0][0];
137  missingPlaneFace[1] = localFaces[1][1];
138  missingPlaneFace[2] = localFaces[0][1];
139 
140  frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
141 
142  // back plane
143  missingPlaneFace[0] = localFaces[0][0] + pointOffset;
144  missingPlaneFace[1] = localFaces[0][1] + pointOffset;
145  missingPlaneFace[2] = localFaces[1][1] + pointOffset;
146 
147  frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
148 
149  // make a cell
150  labelList cellShapeLabels(6);
151 
152  cellShapeLabels[0] = localFaces[0][0];
153  cellShapeLabels[1] = localFaces[0][1];
154  cellShapeLabels[2] = localFaces[1][1];
155 
156  cellShapeLabels[3] = localFaces[0][0] + pointOffset;
157  cellShapeLabels[4] = localFaces[0][1] + pointOffset;
158  cellShapeLabels[5] = localFaces[1][1] + pointOffset;
159 
160  return cellShape(prism, cellShapeLabels);
161  }
162  else if (localFaces[0][1] == localFaces[2][0])
163  {
164  // Set front and back plane faces
165  labelList missingPlaneFace(3);
166 
167  // front plane
168  missingPlaneFace[0] = localFaces[0][0];
169  missingPlaneFace[1] = localFaces[2][1];
170  missingPlaneFace[2] = localFaces[0][1];
171 
172  frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
173 
174  // back plane
175  missingPlaneFace[0] = localFaces[0][0] + pointOffset;
176  missingPlaneFace[1] = localFaces[0][1] + pointOffset;
177  missingPlaneFace[2] = localFaces[2][1] + pointOffset;
178 
179  frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
180 
181  // make a cell
182  labelList cellShapeLabels(6);
183 
184  cellShapeLabels[0] = localFaces[0][0];
185  cellShapeLabels[1] = localFaces[0][1];
186  cellShapeLabels[2] = localFaces[2][1];
187 
188  cellShapeLabels[3] = localFaces[0][0] + pointOffset;
189  cellShapeLabels[4] = localFaces[0][1] + pointOffset;
190  cellShapeLabels[5] = localFaces[2][1] + pointOffset;
191 
192  return cellShape(prism, cellShapeLabels);
193  }
194  else
195  {
197  (
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);
204  }
205 
206  // Return added to keep compiler happy
207  return cellShape(prism, labelList(0));
208 }
209 
210 
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 
213 } // End namespace Foam
214 
215 // ************************************************************************* //
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
List< face > faceList
Definition: faceListFwd.H:43
cellShape extrudedTriangleCellShape(const label cellIndex, const labelList &faceLabels, const faceList &faces, const labelList &owner, const labelList &neighbour, const label pointOffset, faceList &frontAndBackFaces)
Namespace for OpenFOAM.
#define forAll(list, i)
Definition: UList.H:421
errorManip< error > abort(error &err)
Definition: errorManip.H:131
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
#define forAllReverse(list, i)
Definition: UList.H:424
error FatalError
List< label > labelList
A List of labels.
Definition: labelList.H:56
static const cellModel * lookup(const word &)
Look up a model by name and return a pointer to the model or NULL.
Definition: cellModeller.C:91
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57