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

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