extrudedQuadCellShape.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 hex cell shape from four straight edges
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "cellShapeRecognition.H"
30 #include "labelList.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
39 cellShape extrudedQuadCellShape
40 (
41  const label cellIndex,
42  const labelList& faceLabels,
43  const faceList& faces,
44  const labelList& owner,
45  const labelList& neighbour,
46  const label pointOffset,
47  faceList& frontAndBackFaces
48 )
49 {
50  static const cellModel* hexModelPtr_ = NULL;
51 
52  if (!hexModelPtr_)
53  {
54  hexModelPtr_ = cellModeller::lookup("hex");
55  }
56 
57  const cellModel& hex = *hexModelPtr_;
58 
59  // Checking
60  if (faceLabels.size() != 4)
61  {
63  (
64  "extrudedQuadCellShape(const label cellIndex, "
65  "const labelList& faceLabels, const faceList& faces, "
66  "const labelList& owner, const labelList& neighbour, "
67  "const label pointOffset, faceList& frontAndBackFaces)"
68  ) << "Trying to create a quad with " << faceLabels.size() << " faces"
69  << abort(FatalError);
70  }
71 
72  // make a list of outward-pointing faces
73  labelListList localFaces(4);
74 
75  forAll(faceLabels, faceI)
76  {
77  const label curFaceLabel = faceLabels[faceI];
78 
79  const face& curFace = faces[curFaceLabel];
80 
81  if (curFace.size() != 2)
82  {
84  (
85  "extrudedQuadCellShape(const label cellIndex, "
86  "const labelList& faceLabels, const faceList& faces, "
87  "const labelList& owner, const labelList& neighbour, "
88  "const label pointOffset, faceList& frontAndBackFaces)"
89  ) << "face " << curFaceLabel
90  << "does not have 2 vertices. Number of vertices: " << curFace
91  << abort(FatalError);
92  }
93 
94  if (owner[curFaceLabel] == cellIndex)
95  {
96  localFaces[faceI] = curFace;
97  }
98  else if (neighbour[curFaceLabel] == cellIndex)
99  {
100  // Reverse the face. Note: it is necessary to reverse by
101  // hand to preserve connectivity of a 2-D mesh.
102  //
103  localFaces[faceI].setSize(curFace.size());
104 
105  forAllReverse(curFace, i)
106  {
107  localFaces[faceI][curFace.size() - i - 1] =
108  curFace[i];
109  }
110  }
111  else
112  {
114  (
115  "extrudedQuadCellShape(const label cellIndex, "
116  "const labelList& faceLabels, const faceList& faces, "
117  "const labelList& owner, const labelList& neighbour, "
118  "const label pointOffset, faceList& frontAndBackFaces)"
119  ) << "face " << curFaceLabel
120  << " does not belong to cell " << cellIndex
121  << ". Face owner: " << owner[curFaceLabel] << " neighbour: "
122  << neighbour[curFaceLabel]
123  << abort(FatalError);
124  }
125  }
126 
127  // Create a label list for the model
128  // This is done by finding two edges that do not share any vertices.
129  // Knowing the opposite pair of edges (with normals poining outward
130  // is enough to make a cell
131  if
132  (
133  localFaces[0][0] != localFaces[1][1]
134  && localFaces[0][1] != localFaces[1][0]
135  )
136  {
137  // Set front and back plane faces
138  labelList missingPlaneFace(4);
139 
140  // front plane
141  missingPlaneFace[0] = localFaces[0][0];
142  missingPlaneFace[1] = localFaces[1][1];
143  missingPlaneFace[2] = localFaces[1][0];
144  missingPlaneFace[3] = localFaces[0][1];
145 
146  frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
147 
148  // back plane
149  missingPlaneFace[0] = localFaces[0][0] + pointOffset;
150  missingPlaneFace[1] = localFaces[0][1] + pointOffset;
151  missingPlaneFace[2] = localFaces[1][0] + pointOffset;
152  missingPlaneFace[3] = localFaces[1][1] + pointOffset;
153 
154  frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
155 
156  // make a cell
157  labelList cellShapeLabels(8);
158 
159  cellShapeLabels[0] = localFaces[0][0];
160  cellShapeLabels[1] = localFaces[0][1];
161  cellShapeLabels[2] = localFaces[1][0];
162  cellShapeLabels[3] = localFaces[1][1];
163 
164  cellShapeLabels[4] = localFaces[0][0] + pointOffset;
165  cellShapeLabels[5] = localFaces[0][1] + pointOffset;
166  cellShapeLabels[6] = localFaces[1][0] + pointOffset;
167  cellShapeLabels[7] = localFaces[1][1] + pointOffset;
168 
169 
170  return cellShape(hex, cellShapeLabels);
171  }
172  else if
173  (
174  localFaces[0][0] != localFaces[2][1]
175  && localFaces[0][1] != localFaces[2][0]
176  )
177  {
178  // Set front and back plane faces
179  labelList missingPlaneFace(4);
180 
181  // front plane
182  missingPlaneFace[0] = localFaces[0][0];
183  missingPlaneFace[1] = localFaces[2][1];
184  missingPlaneFace[2] = localFaces[2][0];
185  missingPlaneFace[3] = localFaces[0][1];
186 
187  frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
188 
189  // back plane
190  missingPlaneFace[0] = localFaces[0][0] + pointOffset;
191  missingPlaneFace[1] = localFaces[0][1] + pointOffset;
192  missingPlaneFace[2] = localFaces[2][0] + pointOffset;
193  missingPlaneFace[3] = localFaces[2][1] + pointOffset;
194 
195  frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
196 
197  // make a cell
198  labelList cellShapeLabels(8);
199 
200  cellShapeLabels[0] = localFaces[0][0];
201  cellShapeLabels[1] = localFaces[0][1];
202  cellShapeLabels[2] = localFaces[2][0];
203  cellShapeLabels[3] = localFaces[2][1];
204 
205  cellShapeLabels[4] = localFaces[0][0] + pointOffset;
206  cellShapeLabels[5] = localFaces[0][1] + pointOffset;
207  cellShapeLabels[6] = localFaces[2][0] + pointOffset;
208  cellShapeLabels[7] = localFaces[2][1] + pointOffset;
209 
210 
211  return cellShape(hex, cellShapeLabels);
212  }
213  else if
214  (
215  localFaces[0][0] != localFaces[3][1]
216  && localFaces[0][1] != localFaces[3][0]
217  )
218  {
219  // Set front and back plane faces
220  labelList missingPlaneFace(4);
221 
222  // front plane
223  missingPlaneFace[0] = localFaces[0][0];
224  missingPlaneFace[1] = localFaces[3][1];
225  missingPlaneFace[2] = localFaces[3][0];
226  missingPlaneFace[3] = localFaces[0][1];
227 
228  frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
229 
230  // back plane
231  missingPlaneFace[0] = localFaces[0][0] + pointOffset;
232  missingPlaneFace[1] = localFaces[0][1] + pointOffset;
233  missingPlaneFace[2] = localFaces[3][0] + pointOffset;
234  missingPlaneFace[3] = localFaces[3][1] + pointOffset;
235 
236  frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
237 
238  // make a cell
239  labelList cellShapeLabels(8);
240 
241  cellShapeLabels[0] = localFaces[0][0];
242  cellShapeLabels[1] = localFaces[0][1];
243  cellShapeLabels[2] = localFaces[3][0];
244  cellShapeLabels[3] = localFaces[3][1];
245 
246  cellShapeLabels[4] = localFaces[0][0] + pointOffset;
247  cellShapeLabels[5] = localFaces[0][1] + pointOffset;
248  cellShapeLabels[6] = localFaces[3][0] + pointOffset;
249  cellShapeLabels[7] = localFaces[3][1] + pointOffset;
250 
251 
252  return cellShape(hex, cellShapeLabels);
253  }
254  else
255  {
257  (
258  "extrudedQuadCellShape(const label cellIndex, "
259  "const labelList& faceLabels, const faceList& faces, "
260  "const labelList& owner, const labelList& neighbour, "
261  "const label pointOffset, faceList& frontAndBackFaces)"
262  ) << "Problem with edge matching. Edges: " << localFaces
263  << abort(FatalError);
264  }
265 
266  // Return added to keep compiler happy
267  return cellShape(hex, labelList(0));
268 }
269 
270 
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 
273 } // End namespace Foam
274 
275 // ************************************************************************* //
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
Namespace for OpenFOAM.
#define forAll(list, i)
Definition: UList.H:421
errorManip< error > abort(error &err)
Definition: errorManip.H:131
cellShape extrudedQuadCellShape(const label cellIndex, const labelList &faceLabels, const faceList &faces, const labelList &owner, const labelList &neighbour, const label pointOffset, faceList &frontAndBackFaces)
#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