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

createPolyCells.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 files from PROSTAR files
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "starMesh.H"
00031 
00032 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00033 
00034 void starMesh::createPolyCells()
00035 {
00036     // loop through all cell faces and create connectivity. This will produce
00037     // a global face list and will describe all cells as lists of face labels
00038 
00039     // count the maximum number of faces and set the size of the cellPolys_
00040     cellPolys_.setSize(cellShapes_.size());
00041 
00042     label maxFaces = 0;
00043 
00044     forAll (cellPolys_, cellI)
00045     {
00046         cell& curCell = cellPolys_[cellI];
00047 
00048         curCell.setSize(cellFaces_[cellI].size());
00049 
00050         forAll (curCell, fI)
00051         {
00052             curCell[fI] = -1;
00053         }
00054 
00055         maxFaces += cellFaces_[cellI].size();
00056     }
00057 
00058     Info << "Maximum possible number of faces in mesh: " << maxFaces << endl;
00059 
00060     meshFaces_.setSize(maxFaces);
00061 
00062     // set reference to point-cell addressing
00063     const labelListList& PointCells = pointCells();
00064 
00065     bool found = false;
00066 
00067     nInternalFaces_ = 0;
00068 
00069     forAll(cellFaces_, cellI)
00070     {
00071         // Note:
00072         // Insertion cannot be done in one go as the faces need to be
00073         // added into the list in the increasing order of neighbour
00074         // cells.  Therefore, all neighbours will be detected first
00075         // and then added in the correct order.  
00076 
00077         const faceList& curFaces = cellFaces_[cellI];
00078 
00079         // Record the neighbour cell
00080         labelList neiCells(curFaces.size(), -1);
00081 
00082         // Record the face of neighbour cell
00083         labelList faceOfNeiCell(curFaces.size(), -1);
00084 
00085         label nNeighbours = 0;
00086 
00087         // For all faces ...
00088         forAll(curFaces, faceI)
00089         {
00090             // Skip faces that have already been matched
00091             if (cellPolys_[cellI][faceI] >= 0) continue;
00092 
00093             found = false;
00094 
00095             const face& curFace = curFaces[faceI];
00096 
00097             // get the list of labels
00098             const labelList& curPoints = curFace;
00099 
00100             // For all points
00101             forAll(curPoints, pointI)
00102             {
00103                 // get the list of cells sharing this point
00104                 const labelList& curNeighbours = PointCells[curPoints[pointI]];
00105 
00106                 // For all neighbours
00107                 forAll(curNeighbours, neiI)
00108                 {
00109                     label curNei = curNeighbours[neiI];
00110 
00111                     // reject neighbours with the lower label. This should
00112                     // also reject current cell. 
00113                     if (curNei > cellI)
00114                     {
00115                         // get the list of search faces
00116                         const faceList& searchFaces = cellFaces_[curNei];
00117 
00118                         forAll(searchFaces, neiFaceI)
00119                         {
00120                             if (searchFaces[neiFaceI] == curFace)
00121                             {
00122                                 // match!!
00123                                 found = true;
00124 
00125                                 // Record the neighbour cell and face
00126                                 neiCells[faceI] = curNei;
00127                                 faceOfNeiCell[faceI] = neiFaceI;
00128                                 nNeighbours++;
00129 
00130                                 break;
00131                             }
00132                         }
00133                         if (found) break;
00134                     }
00135                     if (found) break;
00136                 }
00137                 if (found) break;
00138             } // End of current points
00139         } // End of current faces
00140 
00141         // Add the faces in the increasing order of neighbours
00142         for (label neiSearch = 0; neiSearch < nNeighbours; neiSearch++)
00143         {
00144             // Find the lowest neighbour which is still valid
00145             label nextNei = -1;
00146             label minNei = cellPolys_.size();
00147 
00148             forAll (neiCells, ncI)
00149             {
00150                 if (neiCells[ncI] > -1 && neiCells[ncI] < minNei)
00151                 {
00152                     nextNei = ncI;
00153                     minNei = neiCells[ncI];
00154                 }
00155             }
00156 
00157             if (nextNei > -1)
00158             {
00159                 // Add the face to the list of faces
00160                 meshFaces_[nInternalFaces_] = curFaces[nextNei];
00161 
00162                 // Mark for owner
00163                 cellPolys_[cellI][nextNei] = nInternalFaces_;
00164 
00165                 // Mark for neighbour
00166                 cellPolys_[neiCells[nextNei]][faceOfNeiCell[nextNei]] =
00167                     nInternalFaces_;
00168 
00169                 // Stop the neighbour from being used again
00170                 neiCells[nextNei] = -1;
00171 
00172                 // Increment number of faces counter
00173                 nInternalFaces_++;
00174             }
00175             else
00176             {
00177               FatalErrorIn("void starMesh::createPolyCells()")
00178                   << "Error in internal face insertion"
00179                   << abort(FatalError);
00180             }
00181         }
00182     }
00183 
00184     // I won't reset the size of internal faces, because more faces will be
00185     // added in createPolyBoundary()
00186 }
00187 
00188 
00189 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd