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

readCells.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     Create intermediate mesh from Prostar files
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "starMesh.H"
00031 #include "IFstream.H"
00032 
00033 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00034 
00035 void starMesh::addRegularCell
00036 (
00037     const labelList& labels,
00038     const label nCreatedCells
00039 )
00040 {
00041     // Momory management
00042     static labelList labelsHex(8);
00043     static labelList labelsPrism(6);
00044     static labelList labelsPyramid(5);
00045     static labelList labelsTet(4);
00046     static labelList labelsTetWedge(5);
00047 
00048     label regularTypeFlag = -1;
00049 
00050     // grab the shape from the table
00051     const cellModel* curModelPtr = reinterpret_cast<cellModel*>(0);
00052 
00053     if      // Tetrahedron
00054     (
00055         labels[2] == labels[3]
00056      && labels[4] == labels[5]
00057      && labels[5] == labels[6]
00058      && labels[6] == labels[7]
00059     )
00060     {
00061         regularTypeFlag = 0;
00062         curModelPtr = tetPtr_;
00063     }
00064     else if // Square-based pyramid
00065     (
00066         labels[4] == labels[5]
00067      && labels[5] == labels[6]
00068      && labels[6] == labels[7]
00069     )
00070     {
00071         regularTypeFlag = 1;
00072         curModelPtr = pyrPtr_;
00073     }
00074     else if // Tet Wedge
00075     (
00076         labels[2] == labels[3]
00077      && labels[4] == labels[5]
00078      && labels[6] == labels[7]
00079     )
00080     {
00081         regularTypeFlag = 2;
00082         curModelPtr = tetWedgePtr_;
00083     }
00084     else if // Triangular prism
00085     (
00086         labels[2] == labels[3]
00087      && labels[6] == labels[7]
00088     )
00089     {
00090         regularTypeFlag = 3;
00091         curModelPtr = prismPtr_;
00092     }
00093     else if // Wedge
00094     (
00095         labels[4] == labels[7]
00096     )
00097     {
00098         regularTypeFlag = 4;
00099         curModelPtr = wedgePtr_;
00100     }
00101     else    // Hex
00102     {
00103         regularTypeFlag = 5;
00104         curModelPtr = hexPtr_;
00105     }
00106 
00107     labelList regularCellLabels(curModelPtr->nPoints(), -1);
00108     // get reference to the addressing list
00109     const label* addressing = regularAddressingTable[regularTypeFlag];
00110 
00111     forAll (regularCellLabels, labelI)
00112     {
00113         regularCellLabels[labelI] = labels[addressing[labelI]];
00114     }
00115 
00116     cellShapes_[nCreatedCells] = cellShape(*curModelPtr, regularCellLabels);
00117 }
00118 
00119 
00120 void starMesh::addSAMMcell
00121 (
00122     const labelList& labels,
00123     const label nCreatedCells
00124 )
00125 {
00126     // get type, reg and permutation flag
00127     label typeFlag = labels[21];
00128 //     label regularityFlag = labels[22];  // Not used. 
00129     label permutationFlag = labels[23];
00130 
00131     // grab the shape from the table
00132     label sammTypeFlag = -1;
00133     const cellModel* curModelPtr = reinterpret_cast<cellModel*>(0);
00134 
00135     switch (typeFlag)
00136     {
00137         case 1:
00138         {
00139             sammTypeFlag = 1;
00140             curModelPtr = sammTrim1Ptr_;
00141             break;
00142         }
00143 
00144         case 2:
00145         {
00146             sammTypeFlag = 2;
00147             curModelPtr = sammTrim2Ptr_;
00148             break;
00149         }
00150 
00151         case 7:
00152         {
00153             if (labels[0] != -1)
00154             {
00155                 sammTypeFlag = 3;
00156                 curModelPtr = sammTrim3Ptr_;
00157             }
00158             else
00159             {
00160                 sammTypeFlag = 5;
00161                 curModelPtr = sammTrim5Ptr_;
00162             }
00163 
00164             break;
00165         }
00166 
00167         case 8:
00168         {
00169             sammTypeFlag = 4;
00170             curModelPtr = sammTrim4Ptr_;
00171             break;
00172         }
00173 
00174         case 85:
00175         {
00176             sammTypeFlag = 8;
00177             curModelPtr = sammTrim8Ptr_;
00178             break;
00179         }
00180 
00181         default:
00182         {
00183             FatalErrorIn
00184             (
00185                 "starMesh::addSAMMcell"
00186                 "(const labelList& labels, const label nCreatedCells)"
00187             )   << "SAMM type " << sammTypeFlag << " is invalid"
00188                 << abort(FatalError);
00189         }
00190     }
00191 
00192     // make a list of labels
00193     labelList sammCellLabels(curModelPtr->nPoints(), -1);
00194     // get reference to the addressing list
00195     const label* addressing = sammAddressingTable[sammTypeFlag];
00196 
00197     forAll (sammCellLabels, labelI)
00198     {
00199         sammCellLabels[labelI] = labels[addressing[labelI]];
00200     }
00201 
00202     cellShapes_[nCreatedCells] = cellShape(*curModelPtr, sammCellLabels);
00203 
00204     // set permutation flag for cell
00205     starCellPermutation_[nCreatedCells] = permutationFlag;
00206 }
00207 
00208 
00209 void starMesh::readCells()
00210 {
00211     label nCells = 0;
00212     label maxLabel = -1;
00213 
00214     fileName cellsFileName(casePrefix_ + ".cel");
00215 
00216     {
00217         IFstream cellsFile(cellsFileName);
00218 
00219         if (cellsFile.good())
00220         {
00221             label lineLabel, pointLabel, regionLabel, typeFlag;
00222 
00223             maxLabel = -1;
00224             while (!(cellsFile >> lineLabel).eof())
00225             {
00226                 maxLabel = max(maxLabel, lineLabel);
00227                 for (int i=0; i<8; i++)
00228                 {
00229                     cellsFile >> pointLabel;
00230                 }
00231 
00232                 cellsFile >> regionLabel;
00233                 cellsFile >> typeFlag;
00234 
00235                 // lines with typeFlag of zero are continuation lines.
00236                 if (typeFlag != 0)
00237                 {
00238                     nCells++;
00239                 }
00240 
00241                 // backward compatibility: number of trailing rubbish in
00242                 // STAR is unknown. 
00243                 // Fixed to cope with missing \n on last line.
00244                 readToNl(cellsFile);
00245             }
00246         }
00247         else
00248         {
00249             FatalErrorIn("starMesh::readCells()")
00250                 << "Cannot read file " << cellsFileName
00251                 << abort(FatalError);
00252         }
00253     }
00254 
00255     Info<< "Number of cells = " << nCells << endl << endl;
00256 
00257     cellShapes_.setSize(nCells);
00258     starCellID_.setSize(nCells);
00259     starCellPermutation_.setSize(nCells);
00260 
00261     // reset permutation to invalid value
00262     forAll (starCellPermutation_, i)
00263     {
00264         starCellPermutation_[i] = -1;
00265     }
00266 
00267     starCellLabelLookup_.setSize(maxLabel+1);
00268     
00269     // reset point labels to invalid value
00270     forAll (starCellLabelLookup_, i)
00271     {
00272         starCellLabelLookup_[i] = -1;
00273     }
00274 
00275     if (nCells > 0)
00276     {
00277         IFstream cellsFile(cellsFileName);
00278 
00279         labelList labels(24, -1);
00280         label lineLabel, starLabel, regionLabel, typeFlag;
00281 
00282         for (label cellI = 0; cellI < nCells; cellI++)
00283         {
00284             label nLabels = 0;
00285 
00286             label addOnToCell = 0;
00287 
00288             // reset the labels to -1. Debugging. 
00289             forAll (labels, i)
00290             {
00291                 labels[i] = -1;
00292             }
00293 
00294             do
00295             {
00296                 if ((cellsFile >> lineLabel).eof())
00297                 {
00298                     FatalErrorIn("starMesh::readCells()")
00299                         << "Reached end of cells file before "
00300                         << "all cells are read in."
00301                         << abort(FatalError);
00302                 }
00303 
00304                 nLabels += 8;
00305 
00306                 for (int i=nLabels-8; i<nLabels; i++)
00307                 {
00308                     cellsFile >> starLabel;
00309 
00310                     if (i < 21)
00311                     {
00312                         if (starLabel != 0)
00313                         {
00314                             // Convert Star vertex number to point label
00315                             labels[i] = starPointLabelLookup_[starLabel];
00316 
00317                             if (labels[i] < 0)
00318                             {
00319                                 Info<< "Cells not consistent with vertex file. "
00320                                     << "Star vertex number " << starLabel
00321                                     << " does not exist\n";
00322                             }
00323                         }
00324                         else
00325                         {
00326                             labels[i] = -1;
00327                         }
00328                     }
00329                     else
00330                     {
00331                         labels[i] = starLabel;
00332                     }
00333                 }
00334 
00335                 cellsFile >> regionLabel;
00336                 cellsFile >> typeFlag;
00337 
00338                 // check for continuation line
00339                 if (typeFlag == -1)
00340                 {
00341                     addOnToCell = 2;
00342                 }
00343 
00344                 // backward compatibility: number of trailing rubbish in
00345                 // STAR is unknown. 
00346                 readToNl(cellsFile);
00347 
00348                 addOnToCell--;
00349 
00350             } while (addOnToCell >= 0);
00351 
00352             // Record STAR cell number (used for debugging)
00353             starCellID_[cellI] = lineLabel;
00354 
00355             // insert STAR lookup addressing
00356             starCellLabelLookup_[lineLabel] = cellI;
00357 
00358             if (nLabels == 8)
00359             {
00360                 addRegularCell(labels, cellI);
00361             }
00362             else
00363             {
00364                 addSAMMcell(labels, cellI);
00365             }
00366 
00367             // check cell labels
00368             const labelList& curShapeLabels = cellShapes_[cellI];
00369 
00370             forAll (curShapeLabels, i)
00371             {
00372                 if (curShapeLabels[i] < 0)
00373                 {
00374                     FatalErrorIn("starMesh::readCells()")
00375                         << "Invalid vertex found in cell " << cellI
00376                         << ". STAR cell no: " << lineLabel 
00377                         << " labels: " << curShapeLabels
00378                         << abort(FatalError);
00379                 }
00380             }
00381         }
00382     }
00383     else
00384     {
00385         FatalErrorIn("starMesh::readCells()")
00386             << "No cells in file " << cellsFileName
00387             << abort(FatalError);
00388     }
00389 }
00390 
00391 
00392 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd