initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / fvMotionSolver / motionDiffusivity / inverseFaceDistance / inverseFaceDistanceDiffusivity.C
blobdbfad5848cb50a792d6867706895d5d3494a1da2
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "inverseFaceDistanceDiffusivity.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "HashSet.H"
30 #include "wallPoint.H"
31 #include "MeshWave.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 namespace Foam
37     defineTypeNameAndDebug(inverseFaceDistanceDiffusivity, 0);
39     addToRunTimeSelectionTable
40     (
41         motionDiffusivity,
42         inverseFaceDistanceDiffusivity,
43         Istream
44     );
48 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
50 Foam::inverseFaceDistanceDiffusivity::inverseFaceDistanceDiffusivity
52     const fvMotionSolver& mSolver,
53     Istream& mdData
56     uniformDiffusivity(mSolver, mdData),
57     patchNames_(mdData)
59     correct();
63 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
65 Foam::inverseFaceDistanceDiffusivity::~inverseFaceDistanceDiffusivity()
69 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
71 void Foam::inverseFaceDistanceDiffusivity::correct()
73     const polyMesh& mesh = mSolver().mesh();
74     const polyBoundaryMesh& bdry = mesh.boundaryMesh();
76     labelHashSet patchSet(bdry.size());
78     label nPatchFaces = 0;
80     forAll (patchNames_, i)
81     {
82         label pID = bdry.findPatchID(patchNames_[i]);
84         if (pID > -1)
85         {
86             patchSet.insert(pID);
87             nPatchFaces += bdry[pID].size();
88         }
89     }
91     List<wallPoint> faceDist(nPatchFaces);
92     labelList changedFaces(nPatchFaces);
94     nPatchFaces = 0;
96     forAllConstIter(labelHashSet, patchSet, iter)
97     {
98         const polyPatch& patch = bdry[iter.key()];
100         const vectorField::subField fc = patch.faceCentres();
102         forAll(fc, patchFaceI)
103         {
104             changedFaces[nPatchFaces] = patch.start() + patchFaceI;
106             faceDist[nPatchFaces] = wallPoint(fc[patchFaceI], 0);
108             nPatchFaces++;
109         }
110     }
111     faceDist.setSize(nPatchFaces);
112     changedFaces.setSize(nPatchFaces);
114     MeshWave<wallPoint> waveInfo
115     (
116         mesh,
117         changedFaces,
118         faceDist,
119         mesh.globalData().nTotalCells() // max iterations
120     );
122     const List<wallPoint>& faceInfo = waveInfo.allFaceInfo();
123     const List<wallPoint>& cellInfo = waveInfo.allCellInfo();
125     for (label faceI=0; faceI<mesh.nInternalFaces(); faceI++)
126     {
127         scalar dist = faceInfo[faceI].distSqr();
129         faceDiffusivity_[faceI] = 1.0/sqrt(dist);
130     }
132     forAll(faceDiffusivity_.boundaryField(), patchI)
133     {
134         fvsPatchScalarField& bfld = faceDiffusivity_.boundaryField()[patchI];
136         const unallocLabelList& faceCells = bfld.patch().faceCells();
138         if (patchSet.found(patchI))
139         {
140             forAll(bfld, i)
141             {
142                 scalar dist = cellInfo[faceCells[i]].distSqr();
143                 bfld[i] = 1.0/sqrt(dist);
144             }
145         }
146         else
147         {
148             label start = bfld.patch().patch().start();
150             forAll(bfld, i)
151             {
152                 scalar dist = faceInfo[start+i].distSqr();
153                 bfld[i] = 1.0/sqrt(dist);
154             }
155         }
156     }
160 // ************************************************************************* //