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

inversePointDistanceDiffusivity.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 "inversePointDistanceDiffusivity.H"
00027 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00028 #include <OpenFOAM/HashSet.H>
00029 #include <meshTools/pointEdgePoint.H>
00030 #include <meshTools/PointEdgeWave.H>
00031 
00032 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00033 
00034 namespace Foam
00035 {
00036     defineTypeNameAndDebug(inversePointDistanceDiffusivity, 0);
00037 
00038     addToRunTimeSelectionTable
00039     (
00040         motionDiffusivity,
00041         inversePointDistanceDiffusivity,
00042         Istream
00043     );
00044 }
00045 
00046 
00047 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00048 
00049 Foam::inversePointDistanceDiffusivity::inversePointDistanceDiffusivity
00050 (
00051     const fvMotionSolver& mSolver,
00052     Istream& mdData
00053 )
00054 :
00055     uniformDiffusivity(mSolver, mdData),
00056     patchNames_(mdData)
00057 {
00058     correct();
00059 }
00060 
00061 
00062 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00063 
00064 Foam::inversePointDistanceDiffusivity::~inversePointDistanceDiffusivity()
00065 {}
00066 
00067 
00068 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00069 
00070 void Foam::inversePointDistanceDiffusivity::correct()
00071 {
00072     const polyMesh& mesh = mSolver().mesh();
00073     const polyBoundaryMesh& bdry = mesh.boundaryMesh();
00074 
00075     labelHashSet patchSet(bdry.size());
00076 
00077     label nPatchEdges = 0;
00078 
00079     forAll (patchNames_, i)
00080     {
00081         label pID = bdry.findPatchID(patchNames_[i]);
00082 
00083         if (pID > -1)
00084         {
00085             patchSet.insert(pID);
00086             nPatchEdges += bdry[pID].nEdges();
00087         }
00088     }
00089 
00090     // Distance to wall on points and edges.
00091     List<pointEdgePoint> pointWallDist(mesh.nPoints());
00092     List<pointEdgePoint> edgeWallDist(mesh.nEdges());
00093 
00094     {
00095         // Seeds
00096         List<pointEdgePoint> seedInfo(nPatchEdges);
00097         labelList seedPoints(nPatchEdges);
00098 
00099         nPatchEdges = 0;
00100 
00101         forAllConstIter(labelHashSet, patchSet, iter)
00102         {
00103             const polyPatch& patch = bdry[iter.key()];
00104 
00105             const labelList& meshPoints = patch.meshPoints();
00106 
00107             forAll(meshPoints, i)
00108             {
00109                 label pointI = meshPoints[i];
00110 
00111                 if (!pointWallDist[pointI].valid())
00112                 {
00113                     // Not yet seeded
00114                     seedInfo[nPatchEdges] = pointEdgePoint
00115                     (
00116                         mesh.points()[pointI],
00117                         0.0
00118                     );
00119                     seedPoints[nPatchEdges] = pointI;
00120                     pointWallDist[pointI] = seedInfo[nPatchEdges];
00121 
00122                     nPatchEdges++;
00123                 }
00124             }
00125         }
00126         seedInfo.setSize(nPatchEdges);
00127         seedPoints.setSize(nPatchEdges);
00128 
00129         // Do calculations
00130         PointEdgeWave<pointEdgePoint> waveInfo
00131         (
00132             mesh,
00133             seedPoints,
00134             seedInfo,
00135 
00136             pointWallDist,
00137             edgeWallDist,
00138             mesh.globalData().nTotalPoints() // max iterations
00139         );
00140     }
00141 
00142 
00143     for (label faceI=0; faceI<mesh.nInternalFaces(); faceI++)
00144     {
00145         const face& f = mesh.faces()[faceI];
00146 
00147         scalar dist = 0;
00148 
00149         forAll(f, fp)
00150         {
00151             dist += sqrt(pointWallDist[f[fp]].distSqr());
00152         }
00153         dist /= f.size();
00154 
00155         faceDiffusivity_[faceI] = 1.0/dist;
00156     }
00157 
00158     forAll(faceDiffusivity_.boundaryField(), patchI)
00159     {
00160         fvsPatchScalarField& bfld = faceDiffusivity_.boundaryField()[patchI];
00161 
00162         if (patchSet.found(patchI))
00163         {
00164             const unallocLabelList& faceCells = bfld.patch().faceCells();
00165 
00166             forAll(bfld, i)
00167             {
00168                 const cell& ownFaces = mesh.cells()[faceCells[i]];
00169 
00170                 labelHashSet cPoints(4*ownFaces.size());
00171 
00172                 scalar dist = 0;
00173 
00174                 forAll(ownFaces, ownFaceI)
00175                 {
00176                     const face& f = mesh.faces()[ownFaces[ownFaceI]];
00177 
00178                     forAll(f, fp)
00179                     {
00180                         if (cPoints.insert(f[fp]))
00181                         {
00182                             dist += sqrt(pointWallDist[f[fp]].distSqr());
00183                         }
00184                     }
00185                 }
00186                 dist /= cPoints.size();
00187 
00188                 bfld[i] = 1.0/dist;
00189             }
00190         }
00191         else
00192         {
00193             label start = bfld.patch().patch().start();
00194 
00195             forAll(bfld, i)
00196             {
00197                 const face& f = mesh.faces()[start+i];
00198 
00199                 scalar dist = 0;
00200 
00201                 forAll(f, fp)
00202                 {
00203                     dist += sqrt(pointWallDist[f[fp]].distSqr());
00204                 }
00205                 dist /= f.size();
00206 
00207                 bfld[i] = 1.0/dist;
00208             }
00209         }
00210     }
00211 }
00212 
00213 
00214 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines