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

FECCellToFaceStencil.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 \*---------------------------------------------------------------------------*/
00026 
00027 #include "FECCellToFaceStencil.H"
00028 #include "syncTools.H"
00029 #include "emptyPolyPatch.H"
00030 //#include "meshTools.H"
00031 //#include "OFstream.H"
00032 //#include "Time.H"
00033 
00034 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00035 
00036 // Calculates per edge the neighbour data (= edgeCells)
00037 void Foam::FECCellToFaceStencil::calcEdgeBoundaryData
00038 (
00039     const boolList& isValidBFace,
00040     const labelList& boundaryEdges,
00041     EdgeMap<labelList>& neiGlobal
00042 ) const
00043 {
00044     neiGlobal.resize(2*boundaryEdges.size());
00045 
00046     labelHashSet edgeGlobals;
00047 
00048     forAll(boundaryEdges, i)
00049     {
00050         label edgeI = boundaryEdges[i];
00051 
00052         neiGlobal.insert
00053         (
00054             mesh().edges()[edgeI],
00055             calcFaceCells
00056             (
00057                 isValidBFace,
00058                 mesh().edgeFaces(edgeI),
00059                 edgeGlobals
00060             )
00061         );
00062     }
00063 
00064     syncTools::syncEdgeMap
00065     (
00066         mesh(),
00067         neiGlobal,
00068         unionEqOp(),
00069         false           // apply separation
00070     );
00071 }
00072 
00073 
00074 // Calculates per face the edge connected data (= cell or boundary in global
00075 // numbering).
00076 void Foam::FECCellToFaceStencil::calcFaceStencil
00077 (
00078     labelListList& faceStencil
00079 ) const
00080 {
00081     const polyBoundaryMesh& patches = mesh().boundaryMesh();
00082     const label nBnd = mesh().nFaces()-mesh().nInternalFaces();
00083     const labelList& own = mesh().faceOwner();
00084     const labelList& nei = mesh().faceNeighbour();
00085 
00086 
00087 
00088     // Determine neighbouring global cell
00089     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00090 
00091     labelList neiGlobalCell(nBnd);
00092     forAll(patches, patchI)
00093     {
00094         const polyPatch& pp = patches[patchI];
00095 
00096         if (pp.coupled())
00097         {
00098             label faceI = pp.start();
00099 
00100             forAll(pp, i)
00101             {
00102                 neiGlobalCell[faceI-mesh().nInternalFaces()] =
00103                     globalNumbering().toGlobal(own[faceI]);
00104                 faceI++;
00105             }
00106         }
00107     }
00108     syncTools::swapBoundaryFaceList(mesh(), neiGlobalCell, false);
00109 
00110 
00111 
00112     // Determine on coupled edges the edge cells on the other side
00113     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00114 
00115     // Calculate edges on coupled patches
00116     labelList boundaryEdges
00117     (
00118         allCoupledFacesPatch()().meshEdges
00119         (
00120             mesh().edges(),
00121             mesh().pointEdges()
00122         )
00123     );
00124 
00125     // Mark boundary faces to be included in stencil (i.e. not coupled or empty)
00126     boolList isValidBFace;
00127     validBoundaryFaces(isValidBFace);
00128 
00129     // Swap edgeCells for coupled edges. Note: use EdgeMap for now since we've
00130     // got syncTools::syncEdgeMap for those. Should be replaced with Map and
00131     // syncTools functionality to handle those.
00132     EdgeMap<labelList> neiGlobal;
00133     calcEdgeBoundaryData
00134     (
00135         isValidBFace,
00136         boundaryEdges,
00137         neiGlobal
00138     );
00139 
00140 
00141 
00142     // Construct stencil in global numbering
00143     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00144 
00145     faceStencil.setSize(mesh().nFaces());
00146 
00147     // Do coupled edges first
00148 
00149     forAll(boundaryEdges, i)
00150     {
00151         label edgeI = boundaryEdges[i];
00152 
00153         const labelList& eGlobals = neiGlobal[mesh().edges()[edgeI]];
00154 
00155         // Distribute to all edgeFaces
00156         const labelList& eFaces = mesh().edgeFaces(edgeI);
00157 
00158         forAll(eFaces, j)
00159         {
00160             label faceI = eFaces[j];
00161 
00162             // Insert eGlobals into faceStencil.
00163             merge(-1, -1, eGlobals, faceStencil[faceI]);
00164         }
00165     }
00166     neiGlobal.clear();
00167 
00168 
00169     // Do remaining edges by looping over all faces
00170 
00171     // Work arrays
00172     DynamicList<label> fEdgesSet;
00173     DynamicList<label> eFacesSet;
00174     labelHashSet faceStencilSet;
00175 
00176     for (label faceI = 0; faceI < mesh().nInternalFaces(); faceI++)
00177     {
00178         label globalOwn = globalNumbering().toGlobal(own[faceI]);
00179         label globalNei = globalNumbering().toGlobal(nei[faceI]);
00180 
00181         // Convert any existing faceStencil (from coupled edges) into
00182         // set and operate on this.
00183 
00184         faceStencilSet.clear();
00185 
00186         // Insert all but global owner and neighbour
00187         forAll(faceStencil[faceI], i)
00188         {
00189             label globalI = faceStencil[faceI][i];
00190             if (globalI != globalOwn && globalI != globalNei)
00191             {
00192                 faceStencilSet.insert(globalI);
00193             }
00194         }
00195         faceStencil[faceI].clear();
00196 
00197         // Collect all edge connected (internal) cells
00198         const labelList& fEdges = mesh().faceEdges(faceI, fEdgesSet);
00199 
00200         forAll(fEdges, i)
00201         {
00202             label edgeI = fEdges[i];
00203 
00204             insertFaceCells
00205             (
00206                 globalOwn,
00207                 globalNei,
00208                 isValidBFace,
00209                 mesh().edgeFaces(edgeI, eFacesSet),
00210                 faceStencilSet
00211             );
00212         }
00213 
00214         // Extract, guarantee owner first, neighbour second.
00215         faceStencil[faceI].setSize(faceStencilSet.size()+2);
00216         label n = 0;
00217         faceStencil[faceI][n++] = globalOwn;
00218         faceStencil[faceI][n++] = globalNei;
00219         forAllConstIter(labelHashSet, faceStencilSet, iter)
00220         {
00221             if (iter.key() == globalOwn || iter.key() == globalNei)
00222             {
00223                 FatalErrorIn("FECCellToFaceStencil::calcFaceStencil(..)")
00224                     << "problem:" << faceStencilSet
00225                     << abort(FatalError);
00226             }
00227             faceStencil[faceI][n++] = iter.key();
00228         }
00229     }
00230     forAll(patches, patchI)
00231     {
00232         const polyPatch& pp = patches[patchI];
00233         label faceI = pp.start();
00234 
00235         if (pp.coupled())
00236         {
00237             forAll(pp, i)
00238             {
00239                 label globalOwn = globalNumbering().toGlobal(own[faceI]);
00240                 label globalNei = neiGlobalCell[faceI-mesh().nInternalFaces()];
00241 
00242                 // Convert any existing faceStencil (from coupled edges) into
00243                 // set and operate on this.
00244 
00245                 faceStencilSet.clear();
00246 
00247                 // Insert all but global owner and neighbour
00248                 forAll(faceStencil[faceI], i)
00249                 {
00250                     label globalI = faceStencil[faceI][i];
00251                     if (globalI != globalOwn && globalI != globalNei)
00252                     {
00253                         faceStencilSet.insert(globalI);
00254                     }
00255                 }
00256                 faceStencil[faceI].clear();
00257 
00258                 // Collect all edge connected (internal) cells
00259                 const labelList& fEdges = mesh().faceEdges(faceI, fEdgesSet);
00260 
00261                 forAll(fEdges, i)
00262                 {
00263                     label edgeI = fEdges[i];
00264 
00265                     insertFaceCells
00266                     (
00267                         globalOwn,
00268                         globalNei,
00269                         isValidBFace,
00270                         mesh().edgeFaces(edgeI, eFacesSet),
00271                         faceStencilSet
00272                     );
00273                 }
00274 
00275                 // Extract, guarantee owner first, neighbour second.
00276                 faceStencil[faceI].setSize(faceStencilSet.size()+2);
00277                 label n = 0;
00278                 faceStencil[faceI][n++] = globalOwn;
00279                 faceStencil[faceI][n++] = globalNei;
00280                 forAllConstIter(labelHashSet, faceStencilSet, iter)
00281                 {
00282                     if (iter.key() == globalOwn || iter.key() == globalNei)
00283                     {
00284                         FatalErrorIn
00285                         (
00286                             "FECCellToFaceStencil::calcFaceStencil(..)"
00287                         )   << "problem:" << faceStencilSet
00288                             << abort(FatalError);
00289                     }
00290                     faceStencil[faceI][n++] = iter.key();
00291                 }
00292 
00293                 if (n != faceStencil[faceI].size())
00294                 {
00295                     FatalErrorIn("problem") << "n:" << n
00296                         << " size:" << faceStencil[faceI].size()
00297                         << abort(FatalError);
00298                 }
00299 
00300                 faceI++;
00301             }
00302         }
00303         else if (!isA<emptyPolyPatch>(pp))
00304         {
00305             forAll(pp, i)
00306             {
00307                 label globalOwn = globalNumbering().toGlobal(own[faceI]);
00308 
00309                 // Convert any existing faceStencil (from coupled edges) into
00310                 // set and operate on this.
00311 
00312                 faceStencilSet.clear();
00313 
00314                 // Insert all but global owner and neighbour
00315                 forAll(faceStencil[faceI], i)
00316                 {
00317                     label globalI = faceStencil[faceI][i];
00318                     if (globalI != globalOwn)
00319                     {
00320                         faceStencilSet.insert(globalI);
00321                     }
00322                 }
00323                 faceStencil[faceI].clear();
00324 
00325                 // Collect all edge connected (internal) cells
00326                 const labelList& fEdges = mesh().faceEdges(faceI, fEdgesSet);
00327 
00328                 forAll(fEdges, i)
00329                 {
00330                     label edgeI = fEdges[i];
00331 
00332                     insertFaceCells
00333                     (
00334                         globalOwn,
00335                         -1,
00336                         isValidBFace,
00337                         mesh().edgeFaces(edgeI, eFacesSet),
00338                         faceStencilSet
00339                     );
00340                 }
00341 
00342                 // Extract, guarantee owner first, neighbour second.
00343                 faceStencil[faceI].setSize(faceStencilSet.size()+1);
00344                 label n = 0;
00345                 faceStencil[faceI][n++] = globalOwn;
00346                 forAllConstIter(labelHashSet, faceStencilSet, iter)
00347                 {
00348                     if (iter.key() == globalOwn)
00349                     {
00350                         FatalErrorIn
00351                         (
00352                             "FECCellToFaceStencil::calcFaceStencil(..)"
00353                         )   << "problem:" << faceStencilSet
00354                             << abort(FatalError);
00355                     }
00356                     faceStencil[faceI][n++] = iter.key();
00357                 }
00358 
00359                 faceI++;
00360             }
00361         }
00362     }
00363 
00364 
00365     for (label faceI = 0; faceI < mesh().nInternalFaces(); faceI++)
00366     {
00367         label globalOwn = globalNumbering().toGlobal(own[faceI]);
00368         if (faceStencil[faceI][0] != globalOwn)
00369         {
00370             FatalErrorIn("FECCellToFaceStencil::calcFaceStencil(..)")
00371                 << "problem:" << faceStencil[faceI]
00372                 << " globalOwn:" << globalOwn
00373                 << abort(FatalError);
00374         }
00375         label globalNei = globalNumbering().toGlobal(nei[faceI]);
00376         if (faceStencil[faceI][1] != globalNei)
00377         {
00378             FatalErrorIn("FECCellToFaceStencil::calcFaceStencil(..)")
00379                 << "problem:" << faceStencil[faceI]
00380                 << " globalNei:" << globalNei
00381                 << abort(FatalError);
00382         }
00383     }
00384 
00385 
00386     forAll(patches, patchI)
00387     {
00388         const polyPatch& pp = patches[patchI];
00389 
00390         if (pp.coupled())
00391         {
00392             forAll(pp, i)
00393             {
00394                 label faceI = pp.start()+i;
00395 
00396                 label globalOwn = globalNumbering().toGlobal(own[faceI]);
00397                 if (faceStencil[faceI][0] != globalOwn)
00398                 {
00399                     FatalErrorIn("FECCellToFaceStencil::calcFaceStencil(..)")
00400                         << "problem:" << faceStencil[faceI]
00401                         << " globalOwn:" << globalOwn
00402                         << abort(FatalError);
00403                 }
00404                 label globalNei = neiGlobalCell[faceI-mesh().nInternalFaces()];
00405                 if (faceStencil[faceI][1] != globalNei)
00406                 {
00407                     FatalErrorIn("FECCellToFaceStencil::calcFaceStencil(..)")
00408                         << "problem:" << faceStencil[faceI]
00409                         << " globalNei:" << globalNei
00410                         << abort(FatalError);
00411                 }
00412             }
00413         }
00414         else if (!isA<emptyPolyPatch>(pp))
00415         {
00416             forAll(pp, i)
00417             {
00418                 label faceI = pp.start()+i;
00419 
00420                 label globalOwn = globalNumbering().toGlobal(own[faceI]);
00421                 if (faceStencil[faceI][0] != globalOwn)
00422                 {
00423                     FatalErrorIn("FECCellToFaceStencil::calcFaceStencil(..)")
00424                         << "problem:" << faceStencil[faceI]
00425                         << " globalOwn:" << globalOwn
00426                         << abort(FatalError);
00427                 }
00428             }
00429         }
00430     }
00431 }
00432 
00433 
00434 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00435 
00436 Foam::FECCellToFaceStencil::FECCellToFaceStencil(const polyMesh& mesh)
00437 :
00438     cellToFaceStencil(mesh)
00439 {
00440     // Calculate per face the (edge) connected cells (in global numbering)
00441     labelListList faceStencil;
00442     calcFaceStencil(faceStencil);
00443 
00444     // Transfer to *this
00445     transfer(faceStencil);
00446 }
00447 
00448 
00449 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd