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

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