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-2016 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  << "Trying to create a triangle with " << faceLabels.size()
65  << " faces"
66  << abort(FatalError);
67  }
68 
69  // make a list of outward-pointing faces
70  labelListList localFaces(3);
71 
72  forAll(faceLabels, facei)
73  {
74  const label curFaceLabel = faceLabels[facei];
75 
76  const face& curFace = faces[curFaceLabel];
77 
78  if (curFace.size() != 2)
79  {
81  << "face " << curFaceLabel
82  << "does not have 2 vertices. Number of vertices: " << curFace
83  << abort(FatalError);
84  }
85 
86  if (owner[curFaceLabel] == cellIndex)
87  {
88  localFaces[facei] = curFace;
89  }
90  else if (neighbour[curFaceLabel] == cellIndex)
91  {
92  // Reverse the face. Note: it is necessary to reverse by
93  // hand to preserve connectivity of a 2-D mesh.
94  //
95  localFaces[facei].setSize(curFace.size());
96 
97  forAllReverse(curFace, i)
98  {
99  localFaces[facei][curFace.size() - i - 1] =
100  curFace[i];
101  }
102  }
103  else
104  {
106  << "face " << curFaceLabel
107  << " does not belong to cell " << cellIndex
108  << ". Face owner: " << owner[curFaceLabel] << " neighbour: "
109  << neighbour[curFaceLabel]
110  << abort(FatalError);
111  }
112  }
113 
114  // Create a label list for the model
115  if (localFaces[0][1] == localFaces[1][0])
116  {
117  // Set front and back plane faces
118  labelList missingPlaneFace(3);
119 
120  // front plane
121  missingPlaneFace[0] = localFaces[0][0];
122  missingPlaneFace[1] = localFaces[1][1];
123  missingPlaneFace[2] = localFaces[0][1];
124 
125  frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
126 
127  // back plane
128  missingPlaneFace[0] = localFaces[0][0] + pointOffset;
129  missingPlaneFace[1] = localFaces[0][1] + pointOffset;
130  missingPlaneFace[2] = localFaces[1][1] + pointOffset;
131 
132  frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
133 
134  // make a cell
135  labelList cellShapeLabels(6);
136 
137  cellShapeLabels[0] = localFaces[0][0];
138  cellShapeLabels[1] = localFaces[0][1];
139  cellShapeLabels[2] = localFaces[1][1];
140 
141  cellShapeLabels[3] = localFaces[0][0] + pointOffset;
142  cellShapeLabels[4] = localFaces[0][1] + pointOffset;
143  cellShapeLabels[5] = localFaces[1][1] + pointOffset;
144 
145  return cellShape(prism, cellShapeLabels);
146  }
147  else if (localFaces[0][1] == localFaces[2][0])
148  {
149  // Set front and back plane faces
150  labelList missingPlaneFace(3);
151 
152  // front plane
153  missingPlaneFace[0] = localFaces[0][0];
154  missingPlaneFace[1] = localFaces[2][1];
155  missingPlaneFace[2] = localFaces[0][1];
156 
157  frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
158 
159  // back plane
160  missingPlaneFace[0] = localFaces[0][0] + pointOffset;
161  missingPlaneFace[1] = localFaces[0][1] + pointOffset;
162  missingPlaneFace[2] = localFaces[2][1] + pointOffset;
163 
164  frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
165 
166  // make a cell
167  labelList cellShapeLabels(6);
168 
169  cellShapeLabels[0] = localFaces[0][0];
170  cellShapeLabels[1] = localFaces[0][1];
171  cellShapeLabels[2] = localFaces[2][1];
172 
173  cellShapeLabels[3] = localFaces[0][0] + pointOffset;
174  cellShapeLabels[4] = localFaces[0][1] + pointOffset;
175  cellShapeLabels[5] = localFaces[2][1] + pointOffset;
176 
177  return cellShape(prism, cellShapeLabels);
178  }
179  else
180  {
182  << "Problem with edge matching. Edges: " << localFaces
183  << abort(FatalError);
184  }
185 
186  // Return added to keep compiler happy
187  return cellShape(prism, labelList(0));
188 }
189 
190 
191 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
192 
193 } // End namespace Foam
194 
195 // ************************************************************************* //
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
static const cellModel * lookup(const word &)
Look up a model by name and return a pointer to the model or NULL.
Definition: cellModeller.C:88
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
List< face > faceList
Definition: faceListFwd.H:43
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Definition: UList.H:440
List< label > labelList
A List of labels.
Definition: labelList.H:56
errorManip< error > abort(error &err)
Definition: errorManip.H:131
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.