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

starMesh.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 \*---------------------------------------------------------------------------*/
00025 
00026 #include "starMesh.H"
00027 #include <OpenFOAM/emptyPolyPatch.H>
00028 #include <OpenFOAM/demandDrivenData.H>
00029 #include <OpenFOAM/cellModeller.H>
00030 
00031 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00032 
00033 // Merge tolerances
00034 // Moni, tolerances:
00035 const scalar starMesh::smallMergeTol_ = 1e-3;
00036 const scalar starMesh::cpMergePointTol_ = 1e-4;
00037 
00038 // const scalar starMesh::smallMergeTol_ = 4e-4;
00039 // const scalar starMesh::cpMergePointTol_ = 1e-3;
00040 
00041 // Cell shape models
00042 const cellModel* starMesh::unknownPtr_ = cellModeller::lookup("unknown");
00043 const cellModel* starMesh::tetPtr_ = cellModeller::lookup("tet");
00044 const cellModel* starMesh::pyrPtr_ = cellModeller::lookup("pyr");
00045 const cellModel* starMesh::tetWedgePtr_ = cellModeller::lookup("tetWedge");
00046 const cellModel* starMesh::prismPtr_ = cellModeller::lookup("prism");
00047 const cellModel* starMesh::wedgePtr_ = cellModeller::lookup("wedge");
00048 const cellModel* starMesh::hexPtr_ = cellModeller::lookup("hex");
00049 
00050 const cellModel* starMesh::sammTrim1Ptr_ = cellModeller::lookup("sammTrim1");
00051 const cellModel* starMesh::sammTrim2Ptr_ = cellModeller::lookup("sammTrim2");
00052 const cellModel* starMesh::sammTrim3Ptr_ = cellModeller::lookup("sammTrim3");
00053 const cellModel* starMesh::sammTrim4Ptr_ = cellModeller::lookup("sammTrim4");
00054 const cellModel* starMesh::sammTrim5Ptr_ = cellModeller::lookup("sammTrim5");
00055 const cellModel* starMesh::sammTrim8Ptr_ = cellModeller::lookup("hexagonalPrism");
00056 
00057 // Regular cell point addressing
00058 // SAMM point addressing
00059 const label starMesh::regularAddressingTable[6][8] =
00060 {
00061     { 0,  1,  2,  4, -1, -1, -1, -1},    // tet
00062     { 0,  1,  2,  3,  4, -1, -1, -1},    // pyramid
00063     { 0,  1,  2,  4,  6, -1, -1, -1},    // tet wedge
00064     { 0,  1,  2,  4,  5,  6, -1, -1},    // prism
00065     { 7,  6,  5,  3,  2,  1,  0, -1},    // wedge
00066     { 0,  1,  2,  3,  4,  5,  6,  7}     // hex
00067 };
00068 
00069 
00070 // SAMM point addressing
00071 const label starMesh::sammAddressingTable[9][12] =
00072 {
00073     {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},    // samm0 - empty
00074     { 3,  2,  6,  7, 11,  9,  1,  5,  4, 12, -1, -1},    // samm1+
00075     {13,  5,  6,  2, 10, 12,  4,  7,  3, 11, -1, -1},    // samm2+
00076     { 2,  3,  0,  1, 10, 11, 12,  4,  8,  9, -1, -1},    // samm3+
00077     { 0,  1,  3,  4, 13,  8,  9, 10, 11, 12, -1, -1},    // samm4+
00078     {12,  7,  6,  5,  8, 11, 10,  9, -1, -1, -1, -1},    // samm5+
00079     {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},    // samm6 - empty
00080     {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},    // samm7 - empty
00081     {11,  3, 15, 12,  4,  8, 10,  2, 14, 13,  5,  9}     // samm8+
00082 };
00083 
00084 
00085 // lookup table giving FOAM face number when looked up with shape index
00086 // (first index) and STAR face number
00087 // - first column is always -1
00088 // - last column is -1 for all but hexagonal prism
00089 // WARNING: Possible bug for sammTrim2 
00090 // The lookup table for SAMM shapes is based on the rotation of the
00091 // shape. This would imply that the table below needs to be split between
00092 // the regular shapes (3-9), which are OK, and the SAMM shapes, for which
00093 // the face lookup needs to be done based on the rotation. Thus, for a samm
00094 // cell, firts find out the face index in the normal rotation using the cell
00095 // face permutation table and then use the index from the shape face lookup.
00096 // Additionally, have in mind that this silliness does not allow matches
00097 // on face 7 and 8 of the samm cell. 
00098 
00099 const label starMesh::sammFacePermutationTable[24][8] =
00100 {
00101   {-1, 1, 2, 3, 4, 5, 6, 7},    // permutation   0
00102   {-1, 3, 4, 5, 6, 1, 2, 7},    // permutation   1
00103   {-1, 5, 6, 1, 2, 3, 4, 7},    // permutation   2
00104   {-1, 1, 2, 5, 6, 4, 3, 7},    // permutation   3
00105   {-1, 3, 4, 1, 2, 6, 5, 7},    // permutation   4
00106   {-1, 5, 6, 3, 4, 2, 1, 7},    // permutation   5
00107   {-1, 1, 2, 4, 3, 6, 5, 7},    // permutation   6
00108   {-1, 3, 4, 6, 5, 2, 1, 7},    // permutation   7
00109   {-1, 5, 6, 2, 1, 4, 3, 7},    // permutation   8
00110   {-1, 1, 2, 6, 5, 3, 4, 7},    // permutation   9
00111   {-1, 3, 4, 2, 1, 5, 6, 7},    // permutation  10
00112   {-1, 5, 6, 4, 3, 1, 2, 7},    // permutation  11
00113   {-1, 2, 1, 5, 6, 3, 4, 7},    // permutation  12
00114   {-1, 4, 3, 1, 2, 5, 6, 7},    // permutation  13
00115   {-1, 6, 5, 3, 4, 1, 2, 7},    // permutation  14
00116   {-1, 2, 1, 3, 4, 6, 5, 7},    // permutation  15
00117   {-1, 4, 3, 5, 6, 2, 1, 7},    // permutation  16
00118   {-1, 6, 5, 1, 2, 4, 3, 7},    // permutation  17
00119   {-1, 2, 1, 6, 5, 4, 3, 7},    // permutation  18
00120   {-1, 4, 3, 2, 1, 6, 5, 7},    // permutation  19
00121   {-1, 6, 5, 4, 3, 2, 1, 7},    // permutation  20
00122   {-1, 2, 1, 4, 3, 5, 6, 7},    // permutation  21
00123   {-1, 4, 3, 6, 5, 1, 2, 7},    // permutation  22
00124   {-1, 6, 5, 2, 1, 3, 4, 7}     // permutation  23
00125 };
00126 
00127 const label starMesh::shapeFaceLookup[19][9] =
00128 {
00129     {-1, -1, -1, -1, -1, -1, -1, -1, -1},    // shape  0 - empty+
00130     {-1, -1, -1, -1, -1, -1, -1, -1, -1},    // shape  1 - empty+
00131     {-1, -1, -1, -1, -1, -1, -1, -1, -1},    // shape  2 - empty+
00132     {-1,  4,  5,  2,  3,  0,  1, -1, -1},    // shape  3 - hex+
00133     {-1,  1,  0,  5,  4,  2,  3, -1, -1},    // shape  4 - wedge+
00134     {-1,  0,  1,  4, -1,  2,  3, -1, -1},    // shape  5 - prism+
00135     {-1,  0, -1,  4,  2,  1,  3, -1, -1},    // shape  6 - pyr+
00136     {-1,  3, -1,  2, -1,  1,  0, -1, -1},    // shape  7 - tet+
00137     {-1, -1, -1, -1, -1, -1, -1, -1, -1},    // shape  8 - splitHex (empty)
00138     {-1,  0, -1,  1, -1,  2,  3, -1, -1},    // shape  9 - tetWedge+
00139     {-1, -1, -1, -1, -1, -1, -1, -1, -1},    // shape 10 - empty+
00140     {-1,  1,  0,  3,  2,  5,  4,  6, -1},    // shape 11 - sammTrim1
00141     {-1,  5,  4,  1,  0,  3,  2,  6, -1},    // shape 12 - sammTrim2
00142     {-1,  2,  3,  0,  1,  4,  5,  6, -1},    // shape 13 - sammTrim3
00143     {-1,  2,  3,  0,  1,  4,  5,  6, -1},    // shape 14 - sammTrim4
00144     {-1,  5,  2,  4,  3,  1,  0, -1, -1},    // shape 15 - sammTrim5
00145     {-1, -1, -1, -1, -1, -1, -1, -1, -1},    // shape 16 - empty
00146     {-1, -1, -1, -1, -1, -1, -1, -1, -1},    // shape 17 - empty
00147     {-1,  1,  0,  6,  7,  2,  3,  4,  5}     // shape 18 - sammTrim8
00148 };
00149 
00150 
00151 // The star to foam face order mapping tables are potentially incomplete
00152 // Currently available data is listed below.
00153 // 1) hex and degenerate hex: OK
00154 // samm trim 1:
00155 // star number: 1 2 3 4 5 6 7 8  In ROTATION 0
00156 // foam number: 5 4 1 0 3 2 6
00157 // confirmed:   1 0 3 2 5 4 6
00158 
00159 // samm trim 2:
00160 // star number: 1 2 3 4 5 6 7 8  In ROTATION 0
00161 // foam number: 5 4 1 0 3 2 6
00162 // confirmed:     4   0 3 2
00163 
00164 // samm trim 3:
00165 // star number: 1 2 3 4 5 6 7 8  In ROTATION 0
00166 // foam number: 2 3 0 1 4 5 6
00167 // confirmed:
00168 
00169 // samm trim 4:
00170 // star number: 1 2 3 4 5 6 7 8  In ROTATION 0
00171 // foam number: 2 3 0 1 4 5 6
00172 // confirmed:
00173 
00174 // samm trim 5:
00175 // star number: 1 2 3 4 5 6 7 8  In ROTATION 0
00176 // foam number: 2 4 3 1 0 5
00177 // confirmed:   5 2 4 3 1 0
00178 
00179 // samm trim 8:
00180 // star number: 1 2 3 4 5 6 7 8  In ROTATION 0
00181 // foam number: 2 5 4 7 1 0 3 6
00182 // confirmed:   1 0 6 
00183 
00184 
00185 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00186 
00187 // Make polyhedral mesh data (packing)
00188 void starMesh::createPolyMeshData()
00189 {
00190     Info << "Creating a polyMesh" << endl;
00191 
00192     createPolyCells();
00193 
00194     Info<< "\nNumber of internal faces: "
00195         << nInternalFaces_ << endl;
00196 
00197     createPolyBoundary();
00198 }
00199 
00200 
00201 // Clear extra storage before creation of the mesh to remove
00202 // a memory peak
00203 void starMesh::clearExtraStorage()
00204 {
00205     Info << "Clearing extra storage" << endl;
00206 
00207     starPointLabelLookup_.setSize(0);
00208     starPointID_.setSize(0);
00209     starCellID_.setSize(0);
00210     starCellLabelLookup_.setSize(0);
00211     starCellPermutation_.setSize(0);
00212     cellFaces_.setSize(0);
00213     boundaryCellIDs_.setSize(0);
00214     boundaryCellFaceIDs_.setSize(0);
00215     couples_.clear();
00216 
00217     deleteDemandDrivenData(pointCellsPtr_);
00218 }
00219 
00220 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00221 
00222 // Construct from components
00223 starMesh::starMesh
00224 (
00225     const fileName& prefix,
00226     const Time& rt,
00227     const scalar scaleFactor
00228 )
00229 :
00230     casePrefix_(prefix),
00231     runTime_(rt),
00232     points_(0),
00233     cellShapes_(0),
00234     boundary_(0),
00235     patchTypes_(0),
00236     defaultFacesName_("defaultFaces"),
00237     defaultFacesType_(emptyPolyPatch::typeName),
00238     patchNames_(0),
00239     patchPhysicalTypes_(0),
00240     starPointLabelLookup_(0),
00241     starPointID_(0),
00242     starCellID_(0),
00243     starCellLabelLookup_(0),
00244     starCellPermutation_(0),
00245     cellFaces_(0),
00246     boundaryCellIDs_(0),
00247     boundaryCellFaceIDs_(0),
00248     meshFaces_(0),
00249     cellPolys_(0),
00250     nInternalFaces_(0),
00251     polyBoundaryPatchStartIndices_(0),
00252     pointCellsPtr_(NULL),
00253     couples_(0),
00254     isShapeMesh_(true)
00255 {
00256     readPoints(scaleFactor);
00257 
00258     readCells();
00259 
00260     readBoundary();
00261 
00262     fixCollapsedEdges();
00263 
00264     readCouples();
00265 
00266     if (couples_.size())
00267     {
00268         createCoupleMatches();
00269     }
00270 
00271     markBoundaryFaces();
00272 
00273     mergeCoupleFacePoints();
00274 
00275     purgeCellShapes();
00276 
00277     collectBoundaryFaces();
00278 }
00279 
00280 
00281 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00282 
00283 starMesh::~starMesh()
00284 {
00285     deleteDemandDrivenData(pointCellsPtr_);
00286 }
00287 
00288 
00289 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00290 
00291 
00292 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines