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

CFCCellToCellStencil.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 "CFCCellToCellStencil.H"
00028 #include "syncTools.H"
00029 #include "SortableList.H"
00030 #include "emptyPolyPatch.H"
00031 
00032 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00033 
00034 // Calculates per face the neighbour data (= cell or boundary face)
00035 void Foam::CFCCellToCellStencil::calcFaceBoundaryData
00036 (
00037     labelList& 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 cell on the other side
00054             forAll(pp, i)
00055             {
00056                 label bFaceI = faceI-mesh().nInternalFaces(); 
00057                 neiGlobal[bFaceI] = globalNumbering().toGlobal(own[faceI]);
00058                 faceI++;
00059             }
00060         }
00061         else if (isA<emptyPolyPatch>(pp))
00062         {
00063             forAll(pp, i)
00064             {
00065                 label bFaceI = faceI-mesh().nInternalFaces(); 
00066                 neiGlobal[bFaceI] = -1;
00067                 faceI++;
00068             }
00069         }
00070         else
00071         {
00072             // For noncoupled faces get the boundary face.
00073             forAll(pp, i)
00074             {
00075                 label bFaceI = faceI-mesh().nInternalFaces(); 
00076                 neiGlobal[bFaceI] =
00077                     globalNumbering().toGlobal(mesh().nCells()+bFaceI);
00078                 faceI++;
00079             }
00080         }
00081     }
00082     syncTools::swapBoundaryFaceList(mesh(), neiGlobal, false);
00083 }
00084 
00085 
00086 // Calculates per cell the neighbour data (= cell or boundary in global
00087 // numbering). First element is always cell itself!
00088 void Foam::CFCCellToCellStencil::calcCellStencil(labelListList& globalCellCells)
00089  const
00090 {
00091     const label nBnd = mesh().nFaces()-mesh().nInternalFaces();
00092     const labelList& own = mesh().faceOwner();
00093     const labelList& nei = mesh().faceNeighbour();
00094 
00095 
00096     // Calculate coupled neighbour (in global numbering)
00097     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00098 
00099     labelList neiGlobal(nBnd);
00100     calcFaceBoundaryData(neiGlobal);
00101 
00102 
00103     // Determine cellCells in global numbering
00104     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00105 
00106     globalCellCells.setSize(mesh().nCells());
00107     forAll(globalCellCells, cellI)
00108     {
00109         const cell& cFaces = mesh().cells()[cellI];
00110 
00111         labelList& cCells = globalCellCells[cellI];
00112 
00113         cCells.setSize(cFaces.size()+1);
00114 
00115         label nNbr = 0;
00116 
00117         // Myself
00118         cCells[nNbr++] = globalNumbering().toGlobal(cellI);
00119 
00120         // Collect neighbouring cells/faces
00121         forAll(cFaces, i)
00122         {
00123             label faceI = cFaces[i];
00124 
00125             if (mesh().isInternalFace(faceI))
00126             {
00127                 label nbrCellI = own[faceI];
00128                 if (nbrCellI == cellI)
00129                 {
00130                     nbrCellI = nei[faceI];
00131                 }
00132                 cCells[nNbr++] = globalNumbering().toGlobal(nbrCellI);
00133             }
00134             else
00135             {
00136                 label nbrCellI = neiGlobal[faceI-mesh().nInternalFaces()];
00137                 if (nbrCellI != -1)
00138                 {
00139                     cCells[nNbr++] = nbrCellI;
00140                 }
00141             }
00142         }
00143         cCells.setSize(nNbr);
00144     }
00145 }
00146 
00147 
00148 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00149 
00150 Foam::CFCCellToCellStencil::CFCCellToCellStencil(const polyMesh& mesh)
00151 :
00152     cellToCellStencil(mesh)
00153 {
00154     // Calculate per cell the (face) connected cells (in global numbering)
00155     calcCellStencil(*this);
00156 }
00157 
00158 
00159 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd