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

inverseFaceDistanceDiffusivity.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 "inverseFaceDistanceDiffusivity.H"
00028 #include "addToRunTimeSelectionTable.H"
00029 #include "HashSet.H"
00030 #include "wallPoint.H"
00031 #include "MeshWave.H"
00032 
00033 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00034 
00035 namespace Foam
00036 {
00037     defineTypeNameAndDebug(inverseFaceDistanceDiffusivity, 0);
00038 
00039     addToRunTimeSelectionTable
00040     (
00041         motionDiffusivity,
00042         inverseFaceDistanceDiffusivity,
00043         Istream
00044     );
00045 }
00046 
00047 
00048 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00049 
00050 Foam::inverseFaceDistanceDiffusivity::inverseFaceDistanceDiffusivity
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::inverseFaceDistanceDiffusivity::~inverseFaceDistanceDiffusivity()
00066 {}
00067 
00068 
00069 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00070 
00071 void Foam::inverseFaceDistanceDiffusivity::correct()
00072 {
00073     const polyMesh& mesh = mSolver().mesh();
00074     const polyBoundaryMesh& bdry = mesh.boundaryMesh();
00075 
00076     labelHashSet patchSet(bdry.size());
00077 
00078     label nPatchFaces = 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             nPatchFaces += bdry[pID].size();
00088         }
00089     }
00090 
00091     List<wallPoint> faceDist(nPatchFaces);
00092     labelList changedFaces(nPatchFaces);
00093 
00094     nPatchFaces = 0;
00095 
00096     forAllConstIter(labelHashSet, patchSet, iter)
00097     {
00098         const polyPatch& patch = bdry[iter.key()];
00099 
00100         const vectorField::subField fc = patch.faceCentres();
00101 
00102         forAll(fc, patchFaceI)
00103         {
00104             changedFaces[nPatchFaces] = patch.start() + patchFaceI;
00105 
00106             faceDist[nPatchFaces] = wallPoint(fc[patchFaceI], 0);
00107 
00108             nPatchFaces++;
00109         }
00110     }
00111     faceDist.setSize(nPatchFaces);
00112     changedFaces.setSize(nPatchFaces);
00113 
00114     MeshWave<wallPoint> waveInfo
00115     (
00116         mesh,
00117         changedFaces,
00118         faceDist,
00119         mesh.globalData().nTotalCells() // max iterations
00120     );
00121 
00122     const List<wallPoint>& faceInfo = waveInfo.allFaceInfo();
00123     const List<wallPoint>& cellInfo = waveInfo.allCellInfo();
00124 
00125     for (label faceI=0; faceI<mesh.nInternalFaces(); faceI++)
00126     {
00127         scalar dist = faceInfo[faceI].distSqr();
00128 
00129         faceDiffusivity_[faceI] = 1.0/sqrt(dist);
00130     }
00131 
00132     forAll(faceDiffusivity_.boundaryField(), patchI)
00133     {
00134         fvsPatchScalarField& bfld = faceDiffusivity_.boundaryField()[patchI];
00135 
00136         const unallocLabelList& faceCells = bfld.patch().faceCells();
00137 
00138         if (patchSet.found(patchI))
00139         {
00140             forAll(bfld, i)
00141             {
00142                 scalar dist = cellInfo[faceCells[i]].distSqr();
00143                 bfld[i] = 1.0/sqrt(dist);
00144             }
00145         }
00146         else
00147         {
00148             label start = bfld.patch().patch().start();
00149 
00150             forAll(bfld, i)
00151             {
00152                 scalar dist = faceInfo[start+i].distSqr();
00153                 bfld[i] = 1.0/sqrt(dist);
00154             }
00155         }
00156     }
00157 }
00158 
00159 
00160 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd