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