FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 Description
00025     Construct an extruded hex cell shape from four straight edges
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "cellShapeRecognition.H"
00030 #include <OpenFOAM/labelList.H>
00031 
00032 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00033 
00034 namespace Foam
00035 {
00036 
00037 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00038 
00039 cellShape extrudedQuadCellShape
00040 (
00041     const label cellIndex,
00042     const labelList& faceLabels,
00043     const faceList& faces,
00044     const labelList& owner,
00045     const labelList& neighbour,
00046     const label pointOffset,
00047     faceList& frontAndBackFaces
00048 )
00049 {
00050     const static cellModel* hexModelPtr_ = NULL;
00051 
00052     if (!hexModelPtr_)
00053     {
00054         hexModelPtr_ = cellModeller::lookup("hex");
00055     }
00056 
00057     const cellModel& hex = *hexModelPtr_;
00058 
00059     // Checking
00060     if (faceLabels.size() != 4)
00061     {
00062         FatalErrorIn
00063         (
00064             "extrudedQuadCellShape(const label cellIndex, "
00065             "const labelList& faceLabels, const faceList& faces, "
00066             "const labelList& owner, const labelList& neighbour, "
00067             "const label pointOffset, faceList& frontAndBackFaces)"
00068         )   << "Trying to create a quad with " << faceLabels.size() << " faces"
00069             << abort(FatalError);
00070     }
00071 
00072     // make a list of outward-pointing faces
00073     labelListList localFaces(4);
00074 
00075     forAll (faceLabels, faceI)
00076     {
00077         const label curFaceLabel = faceLabels[faceI];
00078 
00079         const face& curFace = faces[curFaceLabel];
00080 
00081         if (curFace.size() != 2)
00082         {
00083             FatalErrorIn
00084             (
00085                 "extrudedQuadCellShape(const label cellIndex, "
00086                 "const labelList& faceLabels, const faceList& faces, "
00087                 "const labelList& owner, const labelList& neighbour, "
00088                 "const label pointOffset, faceList& frontAndBackFaces)"
00089             )   << "face " << curFaceLabel
00090                 << "does not have 2 vertices. Number of vertices: " << curFace
00091                 << abort(FatalError);
00092         }
00093 
00094         if (owner[curFaceLabel] == cellIndex)
00095         {
00096             localFaces[faceI] = curFace;
00097         }
00098         else if (neighbour[curFaceLabel] == cellIndex)
00099         {
00100             // Reverse the face.  Note: it is necessary to reverse by
00101             // hand to preserve connectivity of a 2-D mesh.
00102             // 
00103             localFaces[faceI].setSize(curFace.size());
00104 
00105             forAllReverse(curFace, i)
00106             {
00107                 localFaces[faceI][curFace.size() - i - 1] =
00108                     curFace[i];
00109             }
00110         }
00111         else
00112         {
00113             FatalErrorIn
00114             (
00115                 "extrudedQuadCellShape(const label cellIndex, "
00116                 "const labelList& faceLabels, const faceList& faces, "
00117                 "const labelList& owner, const labelList& neighbour, "
00118                 "const label pointOffset, faceList& frontAndBackFaces)"
00119             )   << "face " << curFaceLabel
00120                 << " does not belong to cell " << cellIndex
00121                 << ". Face owner: " << owner[curFaceLabel] << " neighbour: "
00122                 << neighbour[curFaceLabel]
00123                 << abort(FatalError);
00124         }
00125     }
00126 
00127     // Create a label list for the model
00128     // This is done by finding two edges that do not share any vertices.
00129     // Knowing the opposite pair of edges (with normals poining outward
00130     // is enough to make a cell
00131     if
00132     (
00133         localFaces[0][0] != localFaces[1][1]
00134      && localFaces[0][1] != localFaces[1][0]
00135     )
00136     {
00137         // Set front and back plane faces
00138         labelList missingPlaneFace(4);
00139 
00140         // front plane
00141         missingPlaneFace[0] = localFaces[0][0];
00142         missingPlaneFace[1] = localFaces[1][1];
00143         missingPlaneFace[2] = localFaces[1][0];
00144         missingPlaneFace[3] = localFaces[0][1];
00145 
00146         frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
00147 
00148         // back plane
00149         missingPlaneFace[0] = localFaces[0][0] + pointOffset;
00150         missingPlaneFace[1] = localFaces[0][1] + pointOffset;
00151         missingPlaneFace[2] = localFaces[1][0] + pointOffset;
00152         missingPlaneFace[3] = localFaces[1][1] + pointOffset;
00153 
00154         frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
00155 
00156         // make a cell
00157         labelList cellShapeLabels(8);
00158 
00159         cellShapeLabels[0] = localFaces[0][0];
00160         cellShapeLabels[1] = localFaces[0][1];
00161         cellShapeLabels[2] = localFaces[1][0];
00162         cellShapeLabels[3] = localFaces[1][1];
00163 
00164         cellShapeLabels[4] = localFaces[0][0] + pointOffset;
00165         cellShapeLabels[5] = localFaces[0][1] + pointOffset;
00166         cellShapeLabels[6] = localFaces[1][0] + pointOffset;
00167         cellShapeLabels[7] = localFaces[1][1] + pointOffset;
00168 
00169 
00170         return cellShape(hex, cellShapeLabels);
00171     }
00172     else if
00173     (
00174         localFaces[0][0] != localFaces[2][1]
00175      && localFaces[0][1] != localFaces[2][0]
00176     )
00177     {
00178         // Set front and back plane faces
00179         labelList missingPlaneFace(4);
00180 
00181         // front plane
00182         missingPlaneFace[0] = localFaces[0][0];
00183         missingPlaneFace[1] = localFaces[2][1];
00184         missingPlaneFace[2] = localFaces[2][0];
00185         missingPlaneFace[3] = localFaces[0][1];
00186 
00187         frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
00188 
00189         // back plane
00190         missingPlaneFace[0] = localFaces[0][0] + pointOffset;
00191         missingPlaneFace[1] = localFaces[0][1] + pointOffset;
00192         missingPlaneFace[2] = localFaces[2][0] + pointOffset;
00193         missingPlaneFace[3] = localFaces[2][1] + pointOffset;
00194 
00195         frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
00196 
00197         // make a cell
00198         labelList cellShapeLabels(8);
00199 
00200         cellShapeLabels[0] = localFaces[0][0];
00201         cellShapeLabels[1] = localFaces[0][1];
00202         cellShapeLabels[2] = localFaces[2][0];
00203         cellShapeLabels[3] = localFaces[2][1];
00204 
00205         cellShapeLabels[4] = localFaces[0][0] + pointOffset;
00206         cellShapeLabels[5] = localFaces[0][1] + pointOffset;
00207         cellShapeLabels[6] = localFaces[2][0] + pointOffset;
00208         cellShapeLabels[7] = localFaces[2][1] + pointOffset;
00209 
00210 
00211         return cellShape(hex, cellShapeLabels);
00212     }
00213     else if
00214     (
00215         localFaces[0][0] != localFaces[3][1]
00216      && localFaces[0][1] != localFaces[3][0]
00217     )
00218     {
00219         // Set front and back plane faces
00220         labelList missingPlaneFace(4);
00221 
00222         // front plane
00223         missingPlaneFace[0] = localFaces[0][0];
00224         missingPlaneFace[1] = localFaces[3][1];
00225         missingPlaneFace[2] = localFaces[3][0];
00226         missingPlaneFace[3] = localFaces[0][1];
00227 
00228         frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
00229 
00230         // back plane
00231         missingPlaneFace[0] = localFaces[0][0] + pointOffset;
00232         missingPlaneFace[1] = localFaces[0][1] + pointOffset;
00233         missingPlaneFace[2] = localFaces[3][0] + pointOffset;
00234         missingPlaneFace[3] = localFaces[3][1] + pointOffset;
00235 
00236         frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
00237 
00238         // make a cell
00239         labelList cellShapeLabels(8);
00240 
00241         cellShapeLabels[0] = localFaces[0][0];
00242         cellShapeLabels[1] = localFaces[0][1];
00243         cellShapeLabels[2] = localFaces[3][0];
00244         cellShapeLabels[3] = localFaces[3][1];
00245 
00246         cellShapeLabels[4] = localFaces[0][0] + pointOffset;
00247         cellShapeLabels[5] = localFaces[0][1] + pointOffset;
00248         cellShapeLabels[6] = localFaces[3][0] + pointOffset;
00249         cellShapeLabels[7] = localFaces[3][1] + pointOffset;
00250 
00251 
00252         return cellShape(hex, cellShapeLabels);
00253     }
00254     else
00255     {
00256         FatalErrorIn
00257         (
00258             "extrudedQuadCellShape(const label cellIndex, "
00259             "const labelList& faceLabels, const faceList& faces, "
00260             "const labelList& owner, const labelList& neighbour, "
00261             "const label pointOffset, faceList& frontAndBackFaces)"
00262         )   << "Problem with edge matching. Edges: " << localFaces
00263             << abort(FatalError);
00264     }
00265 
00266     // Return added to keep compiler happy
00267     return cellShape(hex, labelList(0));
00268 }
00269 
00270 
00271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00272 
00273 } // End namespace Foam
00274 
00275 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines