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

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