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

extrudedTriangleCellShape.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 triangular prism cell shape from three straight edges
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "cellShapeRecognition.H"
00031 #include "labelList.H"
00032 #include "cellModeller.H"
00033 
00034 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00035 
00036 namespace Foam
00037 {
00038 
00039 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00040 
00041 cellShape extrudedTriangleCellShape
00042 (
00043     const label cellIndex,
00044     const labelList& faceLabels,
00045     const faceList& faces,
00046     const labelList& owner,
00047     const labelList& neighbour,
00048     const label pointOffset,
00049     faceList& frontAndBackFaces
00050 )
00051 {
00052     const static cellModel* prismModelPtr_ = NULL;
00053 
00054     if (!prismModelPtr_)
00055     {
00056         prismModelPtr_ = cellModeller::lookup("prism");
00057     }
00058 
00059     const cellModel& prism = *prismModelPtr_;
00060 
00061     // Checking
00062     if (faceLabels.size() != 3)
00063     {
00064         FatalErrorIn
00065         (
00066             "extrudedTriangleCellShape(const label cellIndex, "
00067             "const labelList& faceLabels, const faceList& faces, "
00068             "const labelList& owner, const labelList& neighbour, "
00069             "const label pointOffset, faceList& frontAndBackFaces)"
00070         )   << "Trying to create a triangle with " << faceLabels.size()
00071             << " faces"
00072             << abort(FatalError);
00073     }
00074 
00075     // make a list of outward-pointing faces
00076     labelListList localFaces(3);
00077 
00078     forAll (faceLabels, faceI)
00079     {
00080         const label curFaceLabel = faceLabels[faceI];
00081 
00082         const face& curFace = faces[curFaceLabel];
00083 
00084         if (curFace.size() != 2)
00085         {
00086             FatalErrorIn
00087             (
00088                 "extrudedTriangleCellShape(const label cellIndex, "
00089                 "const labelList& faceLabels, const faceList& faces, "
00090                 "const labelList& owner, const labelList& neighbour, "
00091                 "const label pointOffset, faceList& frontAndBackFaces)"
00092             )   << "face " << curFaceLabel
00093                 << "does not have 2 vertices. Number of vertices: " << curFace
00094                 << abort(FatalError);
00095         }
00096 
00097         if (owner[curFaceLabel] == cellIndex)
00098         {
00099             localFaces[faceI] = curFace;
00100         }
00101         else if (neighbour[curFaceLabel] == cellIndex)
00102         {
00103             // Reverse the face.  Note: it is necessary to reverse by
00104             // hand to preserve connectivity of a 2-D mesh.
00105             // 
00106             localFaces[faceI].setSize(curFace.size());
00107 
00108             forAllReverse(curFace, i)
00109             {
00110                 localFaces[faceI][curFace.size() - i - 1] =
00111                     curFace[i];
00112             }
00113         }
00114         else
00115         {
00116             FatalErrorIn
00117             (
00118                 "extrudedTriangleCellShape(const label cellIndex, "
00119                 "const labelList& faceLabels, const faceList& faces, "
00120                 "const labelList& owner, const labelList& neighbour, "
00121                 "const label pointOffset, faceList& frontAndBackFaces)"
00122             )   << "face " << curFaceLabel
00123                 << " does not belong to cell " << cellIndex
00124                 << ". Face owner: " << owner[curFaceLabel] << " neighbour: "
00125                 << neighbour[curFaceLabel]
00126                 << abort(FatalError);
00127         }
00128     }
00129 
00130     // Create a label list for the model
00131     if (localFaces[0][1] == localFaces[1][0])
00132     {
00133         // Set front and back plane faces
00134         labelList missingPlaneFace(3);
00135 
00136         // front plane
00137         missingPlaneFace[0] = localFaces[0][0];
00138         missingPlaneFace[1] = localFaces[1][1];
00139         missingPlaneFace[2] = localFaces[0][1];
00140 
00141         frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
00142 
00143         // back plane
00144         missingPlaneFace[0] = localFaces[0][0] + pointOffset;
00145         missingPlaneFace[1] = localFaces[0][1] + pointOffset;
00146         missingPlaneFace[2] = localFaces[1][1] + pointOffset;
00147 
00148         frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
00149 
00150         // make a cell
00151         labelList cellShapeLabels(6);
00152 
00153         cellShapeLabels[0] = localFaces[0][0];
00154         cellShapeLabels[1] = localFaces[0][1];
00155         cellShapeLabels[2] = localFaces[1][1];
00156 
00157         cellShapeLabels[3] = localFaces[0][0] + pointOffset;
00158         cellShapeLabels[4] = localFaces[0][1] + pointOffset;
00159         cellShapeLabels[5] = localFaces[1][1] + pointOffset;
00160 
00161         return cellShape(prism, cellShapeLabels);
00162     }
00163     else if (localFaces[0][1] == localFaces[2][0])
00164     {
00165         // Set front and back plane faces
00166         labelList missingPlaneFace(3);
00167 
00168         // front plane
00169         missingPlaneFace[0] = localFaces[0][0];
00170         missingPlaneFace[1] = localFaces[2][1];
00171         missingPlaneFace[2] = localFaces[0][1];
00172 
00173         frontAndBackFaces[2*cellIndex] = face(missingPlaneFace);
00174 
00175         // back plane
00176         missingPlaneFace[0] = localFaces[0][0] + pointOffset;
00177         missingPlaneFace[1] = localFaces[0][1] + pointOffset;
00178         missingPlaneFace[2] = localFaces[2][1] + pointOffset;
00179 
00180         frontAndBackFaces[2*cellIndex + 1] = face(missingPlaneFace);
00181 
00182         // make a cell
00183         labelList cellShapeLabels(6);
00184 
00185         cellShapeLabels[0] = localFaces[0][0];
00186         cellShapeLabels[1] = localFaces[0][1];
00187         cellShapeLabels[2] = localFaces[2][1];
00188 
00189         cellShapeLabels[3] = localFaces[0][0] + pointOffset;
00190         cellShapeLabels[4] = localFaces[0][1] + pointOffset;
00191         cellShapeLabels[5] = localFaces[2][1] + pointOffset;
00192 
00193         return cellShape(prism, cellShapeLabels);
00194     }
00195     else
00196     {
00197         FatalErrorIn
00198         (
00199             "extrudedTriangleCellShape(const label cellIndex, "
00200             "const labelList& faceLabels, const faceList& faces, "
00201             "const labelList& owner, const labelList& neighbour, "
00202             "const label pointOffset, faceList& frontAndBackFaces)"
00203         )   << "Problem with edge matching. Edges: " << localFaces
00204             << abort(FatalError);
00205     }
00206 
00207     // Return added to keep compiler happy
00208     return cellShape(prism, labelList(0));
00209 }
00210 
00211 
00212 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00213 
00214 } // End namespace Foam
00215 
00216 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd