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

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