FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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