FreeFOAM The Cross-Platform CFD Toolkit
inverseFaceDistanceDiffusivity.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
28 #include <OpenFOAM/HashSet.H>
29 #include <meshTools/wallPoint.H>
30 #include <OpenFOAM/MeshWave.H>
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(inverseFaceDistanceDiffusivity, 0);
37 
39  (
40  motionDiffusivity,
41  inverseFaceDistanceDiffusivity,
42  Istream
43  );
44 }
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
49 Foam::inverseFaceDistanceDiffusivity::inverseFaceDistanceDiffusivity
50 (
51  const fvMotionSolver& mSolver,
52  Istream& mdData
53 )
54 :
55  uniformDiffusivity(mSolver, mdData),
56  patchNames_(mdData)
57 {
58  correct();
59 }
60 
61 
62 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
63 
65 {}
66 
67 
68 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
69 
71 {
72  const polyMesh& mesh = mSolver().mesh();
73  const polyBoundaryMesh& bdry = mesh.boundaryMesh();
74 
75  labelHashSet patchSet(bdry.size());
76 
77  label nPatchFaces = 0;
78 
79  forAll (patchNames_, i)
80  {
81  label pID = bdry.findPatchID(patchNames_[i]);
82 
83  if (pID > -1)
84  {
85  patchSet.insert(pID);
86  nPatchFaces += bdry[pID].size();
87  }
88  }
89 
90  List<wallPoint> faceDist(nPatchFaces);
91  labelList changedFaces(nPatchFaces);
92 
93  nPatchFaces = 0;
94 
95  forAllConstIter(labelHashSet, patchSet, iter)
96  {
97  const polyPatch& patch = bdry[iter.key()];
98 
99  const vectorField::subField fc = patch.faceCentres();
100 
101  forAll(fc, patchFaceI)
102  {
103  changedFaces[nPatchFaces] = patch.start() + patchFaceI;
104 
105  faceDist[nPatchFaces] = wallPoint(fc[patchFaceI], 0);
106 
107  nPatchFaces++;
108  }
109  }
110  faceDist.setSize(nPatchFaces);
111  changedFaces.setSize(nPatchFaces);
112 
113  MeshWave<wallPoint> waveInfo
114  (
115  mesh,
116  changedFaces,
117  faceDist,
118  mesh.globalData().nTotalCells() // max iterations
119  );
120 
121  const List<wallPoint>& faceInfo = waveInfo.allFaceInfo();
122  const List<wallPoint>& cellInfo = waveInfo.allCellInfo();
123 
124  for (label faceI=0; faceI<mesh.nInternalFaces(); faceI++)
125  {
126  scalar dist = faceInfo[faceI].distSqr();
127 
128  faceDiffusivity_[faceI] = 1.0/sqrt(dist);
129  }
130 
131  forAll(faceDiffusivity_.boundaryField(), patchI)
132  {
133  fvsPatchScalarField& bfld = faceDiffusivity_.boundaryField()[patchI];
134 
135  const unallocLabelList& faceCells = bfld.patch().faceCells();
136 
137  if (patchSet.found(patchI))
138  {
139  forAll(bfld, i)
140  {
141  scalar dist = cellInfo[faceCells[i]].distSqr();
142  bfld[i] = 1.0/sqrt(dist);
143  }
144  }
145  else
146  {
147  label start = bfld.patch().patch().start();
148 
149  forAll(bfld, i)
150  {
151  scalar dist = faceInfo[start+i].distSqr();
152  bfld[i] = 1.0/sqrt(dist);
153  }
154  }
155  }
156 }
157 
158 
159 // ************************ vim: set sw=4 sts=4 et: ************************ //