OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

extrudedQuadCellShape.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026     Construct an extruded hex cell shape from four straight edges
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "cellShapeRecognition.H"
00031 #include "labelList.H"
00032 
00033 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00034 
00035 namespace Foam
00036 {
00037 
00038 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00039 
00040 cellShape extrudedQuadCellShape
00041 (
00042     const label cellIndex,
00043     const labelList& faceLabels,
00044     const faceList& faces,
00045     const labelList& owner,
00046     const labelList& neighbour,
00047     const label pointOffset,
00048     faceList& frontAndBackFaces
00049 )
00050 {
00051     const static cellModel* hexModelPtr_ = NULL;
00052 
00053     if (!hexModelPtr_)
00054     {
00055         hexModelPtr_ = cellModeller::lookup("hex");
00056     }
00057 
00058     const cellModel& hex = *hexModelPtr_;
00059 
00060     // Checking
00061     if (faceLabels.size() != 4)
00062     {
00063         FatalErrorIn
00064         (
00065             "extrudedQuadCellShape(const label cellIndex, "
00066             "const labelList& faceLabels, const faceList& faces, "
00067             "const labelList& owner, const labelList& neighbour, "
00068             "const label pointOffset, faceList& frontAndBackFaces)"
00069         )   << "Trying to create a quad with " << faceLabels.size() << " faces"
00070             << abort(FatalError);
00071     }
00072 
00073     // make a list of outward-pointing faces
00074     labelListList localFaces(4);
00075 
00076     forAll (faceLabels, faceI)
00077     {
00078         const label curFaceLabel = faceLabels[faceI];
00079 
00080         const face& curFace = faces[curFaceLabel];
00081 
00082         if (curFace.size() != 2)
00083         {
00084             FatalErrorIn
00085             (
00086                 "extrudedQuadCellShape(const label cellIndex, "
00087                 "const labelList& faceLabels, const faceList& faces, "
00088                 "const labelList& owner, const labelList& neighbour, "
00089                 "const label pointOffset, faceList& frontAndBackFaces)"
00090             )   << "face " << curFaceLabel
00091                 << "does not have 2 vertices. Number of vertices: " << curFace
00092                 << abort(FatalError);
00093         }
00094 
00095         if (owner[curFaceLabel] == cellIndex)
00096         {
00097             localFaces[faceI] = curFace;
00098         }
00099         else if (neighbour[curFaceLabel] == cellIndex)
00100         {
00101             // Reverse the face.  Note: it is necessary to reverse by
00102             // hand to preserve connectivity of a 2-D mesh.
00103             // 
00104             localFaces[faceI].setSize(curFace.size());
00105 
00106             forAllReverse(curFace, i)
00107             {
00108                 localFaces[faceI][curFace.size() - i - 1] =
00109                     curFace[i];
00110             }
00111         }
00112         else
00113         {
00114             FatalErrorIn
00115             (
00116                 "extrudedQuadCellShape(const label cellIndex, "
00117                 "const labelList& faceLabels, const faceList& faces, "
00118                 "const labelList& owner, const labelList& neighbour, "
00119                 "const label pointOffset, faceList& frontAndBackFaces)"
00120             )   << "face " << curFaceLabel
00121                 << " does not belong to cell " << cellIndex
00122                 << ". Face owner: " << owner[curFaceLabel] << " neighbour: "
00123                 << neighbour[curFaceLabel]
00124                 << abort(FatalError);
00125         }
00126     }
00127 
00128     // Create a label list for the model
00129     // This is done by finding two edges that do not share any vertices.
00130     // Knowing the opposite pair of edges (with normals poining outward
00131     // is enough to make a cell
00132     if
00133     (
00134         localFaces[0][0] != localFaces[1][1]
00135      && localFaces[0][1] != localFaces[1][0]
00136     )
00137     {
00138         // Set front and back plane faces
00139         labelList missingPlaneFace(4);
00140 
00141         // front plane
00142         missingPlaneFace[0] = localFaces[0][0];
00143         missingPlaneFace[1] = localFaces[1][1];
00144         missingPlaneFace[2] = localFaces[1][0];
00145         missingPlaneFace[3] = localFaces[0][1];
00146 
00147         frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
00148 
00149         // back plane
00150         missingPlaneFace[0] = localFaces[0][0] + pointOffset;
00151         missingPlaneFace[1] = localFaces[0][1] + pointOffset;
00152         missingPlaneFace[2] = localFaces[1][0] + pointOffset;
00153         missingPlaneFace[3] = localFaces[1][1] + pointOffset;
00154 
00155         frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
00156 
00157         // make a cell
00158         labelList cellShapeLabels(8);
00159 
00160         cellShapeLabels[0] = localFaces[0][0];
00161         cellShapeLabels[1] = localFaces[0][1];
00162         cellShapeLabels[2] = localFaces[1][0];
00163         cellShapeLabels[3] = localFaces[1][1];
00164 
00165         cellShapeLabels[4] = localFaces[0][0] + pointOffset;
00166         cellShapeLabels[5] = localFaces[0][1] + pointOffset;
00167         cellShapeLabels[6] = localFaces[1][0] + pointOffset;
00168         cellShapeLabels[7] = localFaces[1][1] + pointOffset;
00169 
00170 
00171         return cellShape(hex, cellShapeLabels);
00172     }
00173     else if
00174     (
00175         localFaces[0][0] != localFaces[2][1]
00176      && localFaces[0][1] != localFaces[2][0]
00177     )
00178     {
00179         // Set front and back plane faces
00180         labelList missingPlaneFace(4);
00181 
00182         // front plane
00183         missingPlaneFace[0] = localFaces[0][0];
00184         missingPlaneFace[1] = localFaces[2][1];
00185         missingPlaneFace[2] = localFaces[2][0];
00186         missingPlaneFace[3] = localFaces[0][1];
00187 
00188         frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
00189 
00190         // back plane
00191         missingPlaneFace[0] = localFaces[0][0] + pointOffset;
00192         missingPlaneFace[1] = localFaces[0][1] + pointOffset;
00193         missingPlaneFace[2] = localFaces[2][0] + pointOffset;
00194         missingPlaneFace[3] = localFaces[2][1] + pointOffset;
00195 
00196         frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
00197 
00198         // make a cell
00199         labelList cellShapeLabels(8);
00200 
00201         cellShapeLabels[0] = localFaces[0][0];
00202         cellShapeLabels[1] = localFaces[0][1];
00203         cellShapeLabels[2] = localFaces[2][0];
00204         cellShapeLabels[3] = localFaces[2][1];
00205 
00206         cellShapeLabels[4] = localFaces[0][0] + pointOffset;
00207         cellShapeLabels[5] = localFaces[0][1] + pointOffset;
00208         cellShapeLabels[6] = localFaces[2][0] + pointOffset;
00209         cellShapeLabels[7] = localFaces[2][1] + pointOffset;
00210 
00211 
00212         return cellShape(hex, cellShapeLabels);
00213     }
00214     else if
00215     (
00216         localFaces[0][0] != localFaces[3][1]
00217      && localFaces[0][1] != localFaces[3][0]
00218     )
00219     {
00220         // Set front and back plane faces
00221         labelList missingPlaneFace(4);
00222 
00223         // front plane
00224         missingPlaneFace[0] = localFaces[0][0];
00225         missingPlaneFace[1] = localFaces[3][1];
00226         missingPlaneFace[2] = localFaces[3][0];
00227         missingPlaneFace[3] = localFaces[0][1];
00228 
00229         frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
00230 
00231         // back plane
00232         missingPlaneFace[0] = localFaces[0][0] + pointOffset;
00233         missingPlaneFace[1] = localFaces[0][1] + pointOffset;
00234         missingPlaneFace[2] = localFaces[3][0] + pointOffset;
00235         missingPlaneFace[3] = localFaces[3][1] + pointOffset;
00236 
00237         frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
00238 
00239         // make a cell
00240         labelList cellShapeLabels(8);
00241 
00242         cellShapeLabels[0] = localFaces[0][0];
00243         cellShapeLabels[1] = localFaces[0][1];
00244         cellShapeLabels[2] = localFaces[3][0];
00245         cellShapeLabels[3] = localFaces[3][1];
00246 
00247         cellShapeLabels[4] = localFaces[0][0] + pointOffset;
00248         cellShapeLabels[5] = localFaces[0][1] + pointOffset;
00249         cellShapeLabels[6] = localFaces[3][0] + pointOffset;
00250         cellShapeLabels[7] = localFaces[3][1] + pointOffset;
00251 
00252 
00253         return cellShape(hex, cellShapeLabels);
00254     }
00255     else
00256     {
00257         FatalErrorIn
00258         (
00259             "extrudedQuadCellShape(const label cellIndex, "
00260             "const labelList& faceLabels, const faceList& faces, "
00261             "const labelList& owner, const labelList& neighbour, "
00262             "const label pointOffset, faceList& frontAndBackFaces)"
00263         )   << "Problem with edge matching. Edges: " << localFaces
00264             << abort(FatalError);
00265     }
00266 
00267     // Return added to keep compiler happy
00268     return cellShape(hex, labelList(0));
00269 }
00270 
00271 
00272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00273 
00274 } // End namespace Foam
00275 
00276 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd