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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
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 
26 Description
27  Construct an extruded hex cell shape from four straight edges
28 
29 \*---------------------------------------------------------------------------*/
30 
31 #include "cellShapeRecognition.H"
32 #include "labelList.H"
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 cellShape extrudedQuadCellShape
42 (
43  const label cellIndex,
44  const labelList& faceLabels,
45  const faceList& faces,
46  const labelList& owner,
47  const labelList& neighbour,
48  const label pointOffset,
49  faceList& frontAndBackFaces
50 )
51 {
52  static const cellModel* hexModelPtr_ = nullptr;
53 
54  if (!hexModelPtr_)
55  {
56  hexModelPtr_ = cellModel::ptr(cellModel::HEX);
57  }
58 
59  const cellModel& hex = *hexModelPtr_;
60 
61  // Checking
62  if (faceLabels.size() != 4)
63  {
65  << "Trying to create a quad with " << faceLabels.size() << " faces"
66  << abort(FatalError);
67  }
68 
69  // make a list of outward-pointing faces
70  labelListList localFaces(4);
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  // This is done by finding two edges that do not share any vertices.
116  // Knowing the opposite pair of edges (with normals poining outward
117  // is enough to make a cell
118  if
119  (
120  localFaces[0][0] != localFaces[1][1]
121  && localFaces[0][1] != localFaces[1][0]
122  )
123  {
124  // Set front and back plane faces
125  labelList missingPlaneFace(4);
126 
127  // front plane
128  missingPlaneFace[0] = localFaces[0][0];
129  missingPlaneFace[1] = localFaces[1][1];
130  missingPlaneFace[2] = localFaces[1][0];
131  missingPlaneFace[3] = localFaces[0][1];
132 
133  frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
134 
135  // back plane
136  missingPlaneFace[0] = localFaces[0][0] + pointOffset;
137  missingPlaneFace[1] = localFaces[0][1] + pointOffset;
138  missingPlaneFace[2] = localFaces[1][0] + pointOffset;
139  missingPlaneFace[3] = localFaces[1][1] + pointOffset;
140 
141  frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
142 
143  // make a cell
144  labelList cellShapeLabels(8);
145 
146  cellShapeLabels[0] = localFaces[0][0];
147  cellShapeLabels[1] = localFaces[0][1];
148  cellShapeLabels[2] = localFaces[1][0];
149  cellShapeLabels[3] = localFaces[1][1];
150 
151  cellShapeLabels[4] = localFaces[0][0] + pointOffset;
152  cellShapeLabels[5] = localFaces[0][1] + pointOffset;
153  cellShapeLabels[6] = localFaces[1][0] + pointOffset;
154  cellShapeLabels[7] = localFaces[1][1] + pointOffset;
155 
156 
157  return cellShape(hex, cellShapeLabels);
158  }
159  else if
160  (
161  localFaces[0][0] != localFaces[2][1]
162  && localFaces[0][1] != localFaces[2][0]
163  )
164  {
165  // Set front and back plane faces
166  labelList missingPlaneFace(4);
167 
168  // front plane
169  missingPlaneFace[0] = localFaces[0][0];
170  missingPlaneFace[1] = localFaces[2][1];
171  missingPlaneFace[2] = localFaces[2][0];
172  missingPlaneFace[3] = localFaces[0][1];
173 
174  frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
175 
176  // back plane
177  missingPlaneFace[0] = localFaces[0][0] + pointOffset;
178  missingPlaneFace[1] = localFaces[0][1] + pointOffset;
179  missingPlaneFace[2] = localFaces[2][0] + pointOffset;
180  missingPlaneFace[3] = localFaces[2][1] + pointOffset;
181 
182  frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
183 
184  // make a cell
185  labelList cellShapeLabels(8);
186 
187  cellShapeLabels[0] = localFaces[0][0];
188  cellShapeLabels[1] = localFaces[0][1];
189  cellShapeLabels[2] = localFaces[2][0];
190  cellShapeLabels[3] = localFaces[2][1];
191 
192  cellShapeLabels[4] = localFaces[0][0] + pointOffset;
193  cellShapeLabels[5] = localFaces[0][1] + pointOffset;
194  cellShapeLabels[6] = localFaces[2][0] + pointOffset;
195  cellShapeLabels[7] = localFaces[2][1] + pointOffset;
196 
197 
198  return cellShape(hex, cellShapeLabels);
199  }
200  else if
201  (
202  localFaces[0][0] != localFaces[3][1]
203  && localFaces[0][1] != localFaces[3][0]
204  )
205  {
206  // Set front and back plane faces
207  labelList missingPlaneFace(4);
208 
209  // front plane
210  missingPlaneFace[0] = localFaces[0][0];
211  missingPlaneFace[1] = localFaces[3][1];
212  missingPlaneFace[2] = localFaces[3][0];
213  missingPlaneFace[3] = localFaces[0][1];
214 
215  frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
216 
217  // back plane
218  missingPlaneFace[0] = localFaces[0][0] + pointOffset;
219  missingPlaneFace[1] = localFaces[0][1] + pointOffset;
220  missingPlaneFace[2] = localFaces[3][0] + pointOffset;
221  missingPlaneFace[3] = localFaces[3][1] + pointOffset;
222 
223  frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
224 
225  // make a cell
226  labelList cellShapeLabels(8);
227 
228  cellShapeLabels[0] = localFaces[0][0];
229  cellShapeLabels[1] = localFaces[0][1];
230  cellShapeLabels[2] = localFaces[3][0];
231  cellShapeLabels[3] = localFaces[3][1];
232 
233  cellShapeLabels[4] = localFaces[0][0] + pointOffset;
234  cellShapeLabels[5] = localFaces[0][1] + pointOffset;
235  cellShapeLabels[6] = localFaces[3][0] + pointOffset;
236  cellShapeLabels[7] = localFaces[3][1] + pointOffset;
237 
238 
239  return cellShape(hex, cellShapeLabels);
240  }
241 
242 
244  << "Problem with edge matching. Edges: " << localFaces
245  << abort(FatalError);
246 
247  // Return added to keep compiler happy
248  return cellShape(hex, labelList());
249 }
250 
251 
252 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
253 
254 } // End namespace Foam
255 
256 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::cellModel::HEX
hex
Definition: cellModel.H:81
Foam::cellModel::ptr
static const cellModel * ptr(const modelType model)
Look up pointer to cellModel by enumeration, or nullptr on failure.
Definition: cellModels.C:120
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
labelList.H
Foam::FatalError
error FatalError
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::hex
IOstream & hex(IOstream &io)
Definition: IOstream.H:446
Foam::extrudedQuadCellShape
cellShape extrudedQuadCellShape(const label cellIndex, const labelList &faceLabels, const faceList &faces, const labelList &owner, const labelList &neighbour, const label pointOffset, faceList &frontAndBackFaces)
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::faceList
List< face > faceList
A List of faces.
Definition: faceListFwd.H:47
forAllReverse
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Definition: stdFoam.H:309
cellShapeRecognition.H