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 cellPolys
00027     - use pointCells when searching for connectivity
00028     - initialize the cell connectivity with '-1'
00029     - find both cell faces corresponding to the baffles and mark them
00030       to prevent a connection
00031     - standard connectivity checks
00032 
00033     - added baffle support
00034 
00035 \*---------------------------------------------------------------------------*/
00036 
00037 #include "meshReader.H"
00038 
00039 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00040 
00041 void Foam::meshReader::createPolyCells()
00042 {
00043     // loop through all cell faces and create connectivity. This will produce
00044     // a global face list and will describe all cells as lists of face labels
00045 
00046     const faceListList& cFaces = cellFaces();
00047 
00048     // count the maximum number of faces and set the size of the cellPolys_
00049     cellPolys_.setSize(cFaces.size());
00050 
00051     label maxFaces = 0;
00052 
00053     forAll(cellPolys_, cellI)
00054     {
00055         cellPolys_[cellI].setSize(cFaces[cellI].size(), -1);
00056 
00057         maxFaces += cFaces[cellI].size();
00058     }
00059 
00060     Info<< "Maximum possible number of faces in mesh: " << maxFaces << endl;
00061 
00062     meshFaces_.setSize(maxFaces);
00063 
00064     // set reference to point-cell addressing
00065     const labelListList& ptCells = pointCells();
00066 
00067     // size the baffle lists and initialize to -1
00068     baffleIds_.setSize(baffleFaces_.size());
00069     forAll(baffleIds_, baffleI)
00070     {
00071         baffleIds_[baffleI].setSize(2);
00072     }
00073 
00074     // block off baffles first
00075     //
00076     // To prevent internal faces, we'll mark the cell faces
00077     // with negative cell ids (offset by nCells).
00078     // eg,
00079     //    cellI = -(nCells + baffleI)
00080     //
00081     // To distinguish these from the normal '-1' marker, we require
00082     //    cellI = -(nCells + baffleI) < -1
00083     //
00084     // This condition is met provided that nCells > 1.
00085     // ie., baffles require at least 2 volume cells
00086 
00087     label baffleOffset = cFaces.size();
00088     forAll(baffleFaces_, baffleI)
00089     {
00090         label cellI = -(baffleOffset + baffleI);
00091         const face& curFace = baffleFaces_[baffleI];
00092 
00093         // get the list of labels
00094         const labelList& curPoints = curFace;
00095 
00096         // a baffle is a single face - only need to match one face
00097         // get the list of cells sharing this point
00098         const labelList& curNeighbours = ptCells[curPoints[0]];
00099 
00100         label nNeighbours = 0;
00101 
00102         // For all neighbours
00103         forAll(curNeighbours, neiI)
00104         {
00105             label curNei = curNeighbours[neiI];
00106 
00107             // get the list of search faces
00108             const faceList& searchFaces = cFaces[curNei];
00109 
00110             forAll(searchFaces, neiFaceI)
00111             {
00112                 int cmp = face::compare(curFace, searchFaces[neiFaceI]);
00113 
00114                 if (cmp)
00115                 {
00116                     // maintain baffle orientation
00117                     // side0: baffle normal same as attached face
00118                     // side1: baffle normal opposite from attached face
00119                     //
00120                     label side = 0;
00121                     if (cmp < 0)
00122                     {
00123                         side = 1;
00124                     }
00125 
00126 #ifdef DEBUG_FACE_ORDERING
00127                     Info<< "cmp " << cmp << " matched " << curFace
00128                         << " with " << searchFaces[neiFaceI]
00129                         << endl;
00130 
00131 
00132                     Info<< "match " << baffleI
00133                         << " (" << origCellId_[baffleOffset+baffleI] << ")"
00134                         << " side " << side
00135                         << " against cell " << curNei
00136                         << " face " << neiFaceI
00137                         << " curFace " << curFace[1]
00138                         << " neiFace " << searchFaces[neiFaceI][1]
00139                         << endl;
00140 #endif
00141 
00142                     if (baffleIds_[baffleI][side].unused())
00143                     {
00144                         baffleIds_[baffleI][side] = cellFaceIdentifier
00145                         (
00146                             curNei,
00147                             neiFaceI
00148                         );
00149 
00150                         nNeighbours++;
00151                     }
00152                     else
00153                     {
00154                         Info<< "multiple matches for side " << side
00155                             << " of baffle " << baffleI
00156                             << " (original cell "
00157                             << origCellId_[baffleOffset+baffleI] << ")"
00158                             << endl;
00159                     }
00160                     break;
00161                 }
00162             }
00163             if (nNeighbours >= 2) break;
00164         }
00165 
00166         if (nNeighbours == 2)
00167         {
00168             for (label side = 0; side < nNeighbours; ++side)
00169             {
00170                 label neiCell = baffleIds_[baffleI][side].cell;
00171                 label neiFace = baffleIds_[baffleI][side].face;
00172 
00173                 if (baffleIds_[baffleI][side].used())
00174                 {
00175                     cellPolys_[neiCell][neiFace] = cellI;
00176                 }
00177             }
00178         }
00179         else
00180         {
00181             Info<< "drop baffle " << baffleI
00182                 << " (original cell "
00183                 << origCellId_[baffleOffset+baffleI] << ")"
00184                 << " with " << nNeighbours << " neighbours" << endl;
00185 
00186             baffleFaces_[baffleI].clear();
00187             baffleIds_[baffleI].clear();
00188         }
00189     }
00190 
00191 #ifdef DEBUG_CELLPOLY
00192     Info<< "cellPolys_" << cellPolys_ << endl;
00193     Info<< "baffleFaces_" << baffleFaces_ << endl;
00194     Info<< "baffleIds_"   << baffleIds_ << endl;
00195 #endif
00196 
00197     bool found = false;
00198 
00199     nInternalFaces_ = 0;
00200 
00201     forAll(cFaces, cellI)
00202     {
00203         // Note:
00204         // Insertion cannot be done in one go as the faces need to be
00205         // added into the list in the increasing order of neighbour
00206         // cells.  Therefore, all neighbours will be detected first
00207         // and then added in the correct order.
00208 
00209         const faceList& curFaces = cFaces[cellI];
00210 
00211         // Record the neighbour cell
00212         labelList neiCells(curFaces.size(), -1);
00213 
00214         // Record the face of neighbour cell
00215         labelList faceOfNeiCell(curFaces.size(), -1);
00216 
00217         label nNeighbours = 0;
00218 
00219         // For all faces ...
00220         forAll(curFaces, faceI)
00221         {
00222             // Skip already matched faces or those tagged by baffles
00223             if (cellPolys_[cellI][faceI] != -1) continue;
00224 
00225             found = false;
00226 
00227             const face& curFace = curFaces[faceI];
00228 
00229             // get the list of labels
00230             const labelList& curPoints = curFace;
00231 
00232             // For all points
00233             forAll(curPoints, pointI)
00234             {
00235                 // get the list of cells sharing this point
00236                 const labelList& curNeighbours = ptCells[curPoints[pointI]];
00237 
00238                 // For all neighbours
00239                 forAll(curNeighbours, neiI)
00240                 {
00241                     label curNei = curNeighbours[neiI];
00242 
00243                     // reject neighbours with the lower label. This should
00244                     // also reject current cell.
00245                     if (curNei > cellI)
00246                     {
00247                         // get the list of search faces
00248                         const faceList& searchFaces = cFaces[curNei];
00249 
00250                         forAll(searchFaces, neiFaceI)
00251                         {
00252                             if (searchFaces[neiFaceI] == curFace)
00253                             {
00254                                 // Record the neighbour cell and face
00255                                 neiCells[faceI] = curNei;
00256                                 faceOfNeiCell[faceI] = neiFaceI;
00257                                 nNeighbours++;
00258 #ifdef DEBUG_FACE_ORDERING
00259                                 Info<< " cell " << cellI
00260                                     << " face " << faceI
00261                                     << " point " << pointI
00262                                     << " nei " << curNei
00263                                     << " neiFace " << neiFaceI
00264                                     << endl;
00265 #endif
00266                                 found = true;
00267                                 break;
00268                             }
00269                         }
00270                         if (found) break;
00271                     }
00272                     if (found) break;
00273                 }
00274                 if (found) break;
00275             } // End of current points
00276         } // End of current faces
00277 
00278         // Add the faces in the increasing order of neighbours
00279         for (label neiSearch = 0; neiSearch < nNeighbours; neiSearch++)
00280         {
00281             // Find the lowest neighbour which is still valid
00282             label nextNei = -1;
00283             label minNei = cellPolys_.size();
00284 
00285             forAll(neiCells, ncI)
00286             {
00287                 if (neiCells[ncI] > -1 && neiCells[ncI] < minNei)
00288                 {
00289                     nextNei = ncI;
00290                     minNei = neiCells[ncI];
00291                 }
00292             }
00293 
00294             if (nextNei > -1)
00295             {
00296                 // Add the face to the list of faces
00297                 meshFaces_[nInternalFaces_] = curFaces[nextNei];
00298 
00299                 // Mark for owner
00300                 cellPolys_[cellI][nextNei] = nInternalFaces_;
00301 
00302                 // Mark for neighbour
00303                 cellPolys_[neiCells[nextNei]][faceOfNeiCell[nextNei]] =
00304                     nInternalFaces_;
00305 
00306                 // Stop the neighbour from being used again
00307                 neiCells[nextNei] = -1;
00308 
00309                 // Increment number of faces counter
00310                 nInternalFaces_++;
00311             }
00312             else
00313             {
00314               FatalErrorIn("meshReader::createPolyCells()")
00315                   << "Error in internal face insertion"
00316                   << abort(FatalError);
00317             }
00318         }
00319     }
00320 
00321 #ifdef DEBUG_CELLPOLY
00322     Info<< "cellPolys = " << cellPolys_ << endl;
00323 #endif
00324 
00325     // don't reset the size of internal faces, because more faces will be
00326     // added in createPolyBoundary()
00327 }
00328 
00329 
00330 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd