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

CECCellToCellStencil.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 "CECCellToCellStencil.H"
00028 #include "syncTools.H"
00029 
00030 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00031 
00032 // Calculates per edge the neighbour data (= edgeCells)
00033 void Foam::CECCellToCellStencil::calcEdgeBoundaryData
00034 (
00035     const boolList& isValidBFace,
00036     const labelList& boundaryEdges,
00037     EdgeMap<labelList>& neiGlobal
00038 ) const
00039 {
00040     neiGlobal.resize(2*boundaryEdges.size());
00041 
00042     labelHashSet edgeGlobals;
00043 
00044     forAll(boundaryEdges, i)
00045     {
00046         label edgeI = boundaryEdges[i];
00047 
00048         neiGlobal.insert
00049         (
00050             mesh().edges()[edgeI],
00051             calcFaceCells
00052             (
00053                 isValidBFace,
00054                 mesh().edgeFaces(edgeI),
00055                 edgeGlobals
00056             )
00057         );
00058     }
00059 
00060     syncTools::syncEdgeMap
00061     (
00062         mesh(),
00063         neiGlobal,
00064         unionEqOp(),
00065         false           // apply separation
00066     );
00067 }
00068 
00069 
00070 // Calculates per cell the neighbour data (= cell or boundary in global
00071 // numbering). First element is always cell itself!
00072 void Foam::CECCellToCellStencil::calcCellStencil
00073 (
00074     labelListList& globalCellCells
00075 ) const
00076 {
00077     // Calculate edges on coupled patches
00078     labelList boundaryEdges
00079     (
00080         allCoupledFacesPatch()().meshEdges
00081         (
00082             mesh().edges(),
00083             mesh().pointEdges()
00084         )
00085     );
00086 
00087     //{
00088     //    OFstream str(mesh().time().path()/"boundaryEdges.obj");
00089     //    Pout<< "DUmping boundary edges to " << str.name() << endl;
00090     //
00091     //    label vertI = 0;
00092     //    forAll(boundaryEdges, i)
00093     //    {
00094     //        label edgeI = boundaryEdges[i];
00095     //        const edge& e = mesh().edges()[edgeI];
00096     //        const point& p0 = mesh().points()[e[0]];
00097     //        const point& p1 = mesh().points()[e[1]];
00098     //
00099     //        Pout<< "boundary edge " << edgeI << " between " << p0 << p1
00100     //            << endl;
00101     //
00102     //        meshTools::writeOBJ(str, p0);
00103     //        vertI++;
00104     //        meshTools::writeOBJ(str, p1);
00105     //        vertI++;
00106     //        str << "l " << vertI-1 << ' ' << vertI << nl;
00107     //    }
00108     //}
00109 
00110 
00111     // Mark boundary faces to be included in stencil (i.e. not coupled or empty)
00112     boolList isValidBFace;
00113     validBoundaryFaces(isValidBFace);
00114 
00115 
00116     // Swap edgeCells for coupled edges. Note: use EdgeMap for now since we've
00117     // got syncTools::syncEdgeMap for those. Should be replaced with Map and
00118     // syncTools functionality to handle those.
00119     EdgeMap<labelList> neiGlobal;
00120     calcEdgeBoundaryData
00121     (
00122         isValidBFace,
00123         boundaryEdges,
00124         neiGlobal
00125     );
00126 
00127     globalCellCells.setSize(mesh().nCells());
00128 
00129     // Do coupled edges first
00130 
00131     forAll(boundaryEdges, i)
00132     {
00133         label edgeI = boundaryEdges[i];
00134 
00135         const labelList& eGlobals = neiGlobal[mesh().edges()[edgeI]];
00136 
00137         // Distribute to all edgeCells
00138         const labelList& eCells = mesh().edgeCells(edgeI);
00139 
00140         forAll(eCells, j)
00141         {
00142             label cellI = eCells[j];
00143 
00144             // Insert pGlobals into globalCellCells
00145             merge
00146             (
00147                 globalNumbering().toGlobal(cellI),
00148                 eGlobals,
00149                 globalCellCells[cellI]
00150             );
00151         }
00152     }
00153     neiGlobal.clear();
00154 
00155     // Do remaining edges cells
00156     labelHashSet edgeGlobals;
00157 
00158     for (label edgeI = 0; edgeI < mesh().nEdges(); edgeI++)
00159     {
00160         labelList eGlobals
00161         (
00162             calcFaceCells
00163             (
00164                 isValidBFace,
00165                 mesh().edgeFaces(edgeI),
00166                 edgeGlobals
00167             )
00168         );
00169 
00170         const labelList& eCells = mesh().edgeCells(edgeI);
00171 
00172         forAll(eCells, j)
00173         {
00174             label cellI = eCells[j];
00175 
00176             merge
00177             (
00178                 globalNumbering().toGlobal(cellI),
00179                 eGlobals,
00180                 globalCellCells[cellI]
00181             );
00182         }
00183     }
00184 }
00185 
00186 
00187 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00188 
00189 Foam::CECCellToCellStencil::CECCellToCellStencil(const polyMesh& mesh)
00190 :
00191     cellToCellStencil(mesh)
00192 {
00193     // Calculate per cell the (edge) connected cells (in global numbering)
00194     calcCellStencil(*this);
00195 }
00196 
00197 
00198 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd