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-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 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  << "Trying to create a quad with " << faceLabels.size() << " faces"
64  << abort(FatalError);
65  }
66 
67  // make a list of outward-pointing faces
68  labelListList localFaces(4);
69 
70  forAll(faceLabels, facei)
71  {
72  const label curFaceLabel = faceLabels[facei];
73 
74  const face& curFace = faces[curFaceLabel];
75 
76  if (curFace.size() != 2)
77  {
79  << "face " << curFaceLabel
80  << "does not have 2 vertices. Number of vertices: " << curFace
81  << abort(FatalError);
82  }
83 
84  if (owner[curFaceLabel] == cellIndex)
85  {
86  localFaces[facei] = curFace;
87  }
88  else if (neighbour[curFaceLabel] == cellIndex)
89  {
90  // Reverse the face. Note: it is necessary to reverse by
91  // hand to preserve connectivity of a 2-D mesh.
92  //
93  localFaces[facei].setSize(curFace.size());
94 
95  forAllReverse(curFace, i)
96  {
97  localFaces[facei][curFace.size() - i - 1] =
98  curFace[i];
99  }
100  }
101  else
102  {
104  << "face " << curFaceLabel
105  << " does not belong to cell " << cellIndex
106  << ". Face owner: " << owner[curFaceLabel] << " neighbour: "
107  << neighbour[curFaceLabel]
108  << abort(FatalError);
109  }
110  }
111 
112  // Create a label list for the model
113  // This is done by finding two edges that do not share any vertices.
114  // Knowing the opposite pair of edges (with normals poining outward
115  // is enough to make a cell
116  if
117  (
118  localFaces[0][0] != localFaces[1][1]
119  && localFaces[0][1] != localFaces[1][0]
120  )
121  {
122  // Set front and back plane faces
123  labelList missingPlaneFace(4);
124 
125  // front plane
126  missingPlaneFace[0] = localFaces[0][0];
127  missingPlaneFace[1] = localFaces[1][1];
128  missingPlaneFace[2] = localFaces[1][0];
129  missingPlaneFace[3] = localFaces[0][1];
130 
131  frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
132 
133  // back plane
134  missingPlaneFace[0] = localFaces[0][0] + pointOffset;
135  missingPlaneFace[1] = localFaces[0][1] + pointOffset;
136  missingPlaneFace[2] = localFaces[1][0] + pointOffset;
137  missingPlaneFace[3] = localFaces[1][1] + pointOffset;
138 
139  frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
140 
141  // make a cell
142  labelList cellShapeLabels(8);
143 
144  cellShapeLabels[0] = localFaces[0][0];
145  cellShapeLabels[1] = localFaces[0][1];
146  cellShapeLabels[2] = localFaces[1][0];
147  cellShapeLabels[3] = localFaces[1][1];
148 
149  cellShapeLabels[4] = localFaces[0][0] + pointOffset;
150  cellShapeLabels[5] = localFaces[0][1] + pointOffset;
151  cellShapeLabels[6] = localFaces[1][0] + pointOffset;
152  cellShapeLabels[7] = localFaces[1][1] + pointOffset;
153 
154 
155  return cellShape(hex, cellShapeLabels);
156  }
157  else if
158  (
159  localFaces[0][0] != localFaces[2][1]
160  && localFaces[0][1] != localFaces[2][0]
161  )
162  {
163  // Set front and back plane faces
164  labelList missingPlaneFace(4);
165 
166  // front plane
167  missingPlaneFace[0] = localFaces[0][0];
168  missingPlaneFace[1] = localFaces[2][1];
169  missingPlaneFace[2] = localFaces[2][0];
170  missingPlaneFace[3] = 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][0] + pointOffset;
178  missingPlaneFace[3] = localFaces[2][1] + pointOffset;
179 
180  frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
181 
182  // make a cell
183  labelList cellShapeLabels(8);
184 
185  cellShapeLabels[0] = localFaces[0][0];
186  cellShapeLabels[1] = localFaces[0][1];
187  cellShapeLabels[2] = localFaces[2][0];
188  cellShapeLabels[3] = localFaces[2][1];
189 
190  cellShapeLabels[4] = localFaces[0][0] + pointOffset;
191  cellShapeLabels[5] = localFaces[0][1] + pointOffset;
192  cellShapeLabels[6] = localFaces[2][0] + pointOffset;
193  cellShapeLabels[7] = localFaces[2][1] + pointOffset;
194 
195 
196  return cellShape(hex, cellShapeLabels);
197  }
198  else if
199  (
200  localFaces[0][0] != localFaces[3][1]
201  && localFaces[0][1] != localFaces[3][0]
202  )
203  {
204  // Set front and back plane faces
205  labelList missingPlaneFace(4);
206 
207  // front plane
208  missingPlaneFace[0] = localFaces[0][0];
209  missingPlaneFace[1] = localFaces[3][1];
210  missingPlaneFace[2] = localFaces[3][0];
211  missingPlaneFace[3] = localFaces[0][1];
212 
213  frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
214 
215  // back plane
216  missingPlaneFace[0] = localFaces[0][0] + pointOffset;
217  missingPlaneFace[1] = localFaces[0][1] + pointOffset;
218  missingPlaneFace[2] = localFaces[3][0] + pointOffset;
219  missingPlaneFace[3] = localFaces[3][1] + pointOffset;
220 
221  frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
222 
223  // make a cell
224  labelList cellShapeLabels(8);
225 
226  cellShapeLabels[0] = localFaces[0][0];
227  cellShapeLabels[1] = localFaces[0][1];
228  cellShapeLabels[2] = localFaces[3][0];
229  cellShapeLabels[3] = localFaces[3][1];
230 
231  cellShapeLabels[4] = localFaces[0][0] + pointOffset;
232  cellShapeLabels[5] = localFaces[0][1] + pointOffset;
233  cellShapeLabels[6] = localFaces[3][0] + pointOffset;
234  cellShapeLabels[7] = localFaces[3][1] + pointOffset;
235 
236 
237  return cellShape(hex, cellShapeLabels);
238  }
239  else
240  {
242  << "Problem with edge matching. Edges: " << localFaces
243  << abort(FatalError);
244  }
245 
246  // Return added to keep compiler happy
247  return cellShape(hex, labelList(0));
248 }
249 
250 
251 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
252 
253 } // End namespace Foam
254 
255 // ************************************************************************* //
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 extrudedQuadCellShape(const label cellIndex, const labelList &faceLabels, const faceList &faces, const labelList &owner, const labelList &neighbour, const label pointOffset, faceList &frontAndBackFaces)
Namespace for OpenFOAM.