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

CFCFaceToCellStencil.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 "CFCFaceToCellStencil.H"
00028 #include "syncTools.H"
00029 #include "emptyPolyPatch.H"
00030 
00031 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00032 
00033 // Calculates per face the neighbour data (= faces of cell). Leaves out the
00034 // face itself since this is already in stencil.
00035 void Foam::CFCFaceToCellStencil::calcFaceBoundaryData
00036 (
00037     labelListList& neiGlobal
00038 ) const
00039 {
00040     const polyBoundaryMesh& patches = mesh().boundaryMesh();
00041     const label nBnd = mesh().nFaces()-mesh().nInternalFaces();
00042     const labelList& own = mesh().faceOwner();
00043 
00044     neiGlobal.setSize(nBnd);
00045 
00046     forAll(patches, patchI)
00047     {
00048         const polyPatch& pp = patches[patchI];
00049         label faceI = pp.start();
00050 
00051         if (pp.coupled())
00052         {
00053             // For coupled faces get the faces of the cell on the other side
00054             forAll(pp, i)
00055             {
00056                 const labelList& cFaces = mesh().cells()[own[faceI]];
00057 
00058                 labelList& globFaces = neiGlobal[faceI-mesh().nInternalFaces()];
00059                 globFaces.setSize(cFaces.size()-1);
00060                 label globI = 0;
00061 
00062                 forAll(cFaces, j)
00063                 {
00064                     if (cFaces[j] != faceI)
00065                     {
00066                         globFaces[globI++] = globalNumbering().toGlobal
00067                         (
00068                             cFaces[j]
00069                         );
00070                     }
00071                 }
00072                 faceI++;
00073             }
00074         }
00075         else if (isA<emptyPolyPatch>(pp))
00076         {
00077             // Do nothing.
00078         }
00079         else
00080         {
00081             // Do nothing since face itself already in stencil
00082         }
00083     }
00084     syncTools::swapBoundaryFaceList(mesh(), neiGlobal, false);
00085 }
00086 
00087 
00088 // Calculates per cell the neighbour data (= cell or boundary in global
00089 // numbering). First element is always cell itself!
00090 void Foam::CFCFaceToCellStencil::calcCellStencil(labelListList& globalCellFaces)
00091  const
00092 {
00093     const label nBnd = mesh().nFaces()-mesh().nInternalFaces();
00094     const labelList& own = mesh().faceOwner();
00095     const labelList& nei = mesh().faceNeighbour();
00096 
00097 
00098     // Calculate faces of coupled neighbour (in global numbering)
00099     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00100 
00101     labelListList neiGlobal(nBnd);
00102     calcFaceBoundaryData(neiGlobal);
00103 
00104 
00105 
00106     // Non-empty boundary faces
00107     boolList validBFace(mesh().nFaces()-mesh().nInternalFaces(), true);
00108 
00109     const polyBoundaryMesh& patches = mesh().boundaryMesh();
00110     forAll(patches, patchI)
00111     {
00112         const polyPatch& pp = patches[patchI];
00113 
00114         if (isA<emptyPolyPatch>(pp))
00115         {
00116             label bFaceI = pp.start()-mesh().nInternalFaces();
00117             forAll(pp, i)
00118             {
00119                 validBFace[bFaceI++] = false;
00120             }
00121         }
00122     }
00123 
00124 
00125     // Determine faces of cellCells in global numbering
00126     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00127 
00128     DynamicList<label> allGlobalFaces(100);
00129 
00130     globalCellFaces.setSize(mesh().nCells());
00131     forAll(globalCellFaces, cellI)
00132     {
00133         const cell& cFaces = mesh().cells()[cellI];
00134 
00135         allGlobalFaces.clear();
00136 
00137         // My faces first
00138         forAll(cFaces, i)
00139         {
00140             label faceI = cFaces[i];
00141 
00142             if
00143             (
00144                 mesh().isInternalFace(faceI)
00145              || validBFace[faceI-mesh().nInternalFaces()]
00146             )
00147             {
00148                 allGlobalFaces.append(globalNumbering().toGlobal(faceI));
00149             }
00150         }
00151 
00152         // faces of neighbouring cells second
00153         forAll(cFaces, i)
00154         {
00155             label faceI = cFaces[i];
00156 
00157             if (mesh().isInternalFace(faceI))
00158             {
00159                 label nbrCellI = own[faceI];
00160                 if (nbrCellI == cellI)
00161                 {
00162                     nbrCellI = nei[faceI];
00163                 }
00164                 const cell& nbrFaces = mesh().cells()[nbrCellI];
00165 
00166                 forAll(nbrFaces, j)
00167                 {
00168                     label nbrFaceI = nbrFaces[j];
00169 
00170                     if
00171                     (
00172                         mesh().isInternalFace(nbrFaceI)
00173                      || validBFace[nbrFaceI-mesh().nInternalFaces()]
00174                     )
00175                     {
00176                         label nbrGlobalI = globalNumbering().toGlobal(nbrFaceI);
00177 
00178                         // Check if already there. Note:should use hashset?
00179                         if (findIndex(allGlobalFaces, nbrGlobalI) == -1)
00180                         {
00181                             allGlobalFaces.append(nbrGlobalI);
00182                         }
00183                     }
00184                 }
00185             }
00186             else
00187             {
00188                 const labelList& nbrGlobalFaces =
00189                     neiGlobal[faceI-mesh().nInternalFaces()];
00190 
00191                 forAll(nbrGlobalFaces, j)
00192                 {
00193                     label nbrGlobalI = nbrGlobalFaces[j];
00194 
00195                     // Check if already there. Note:should use hashset?
00196                     if (findIndex(allGlobalFaces, nbrGlobalI) == -1)
00197                     {
00198                         allGlobalFaces.append(nbrGlobalI);
00199                     }
00200                 }
00201             }
00202         }
00203 
00204         globalCellFaces[cellI] = allGlobalFaces;
00205         //Pout<< "** cell:" << cellI
00206         //    << " at:" << mesh().cellCentres()[cellI]
00207         //    << endl;
00208         //const labelList& globalFaces = globalCellFaces[cellI];
00209         //forAll(globalFaces, i)
00210         //{
00211         //    label faceI = globalNumbering().toLocal(globalFaces[i]);
00212         //    Pout<< "    face:" << faceI
00213         //        << " at:" << mesh().faceCentres()[faceI]
00214         //        << endl;
00215         //}
00216     }
00217 }
00218 
00219 
00220 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00221 
00222 Foam::CFCFaceToCellStencil::CFCFaceToCellStencil(const polyMesh& mesh)
00223 :
00224     faceToCellStencil(mesh)
00225 {
00226     // Calculate per cell the (face) connected cells (in global numbering)
00227     calcCellStencil(*this);
00228 }
00229 
00230 
00231 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd