FreeFOAM The Cross-Platform CFD Toolkit
mutRoughWallFunctionFvPatchScalarField.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) 2008-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 
29 #include <finiteVolume/volFields.H>
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace compressible
37 {
38 namespace RASModels
39 {
40 
41 
42 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
43 
44 scalar mutRoughWallFunctionFvPatchScalarField::fnRough
45 (
46  const scalar KsPlus,
47  const scalar Cs
48 ) const
49 {
50  // Return fn based on non-dimensional roughness height
51 
52  if (KsPlus < 90.0)
53  {
54  return pow
55  (
56  (KsPlus - 2.25)/87.75 + Cs*KsPlus,
57  sin(0.4258*(log(KsPlus) - 0.811))
58  );
59  }
60  else
61  {
62  return (1.0 + Cs*KsPlus);
63  }
64 }
65 
66 
67 tmp<scalarField> mutRoughWallFunctionFvPatchScalarField::calcMut() const
68 {
69  const label patchI = patch().index();
70 
71  const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
72  const scalarField& y = rasModel.y()[patchI];
73  const scalarField& rhow = rasModel.rho().boundaryField()[patchI];
74  const tmp<volScalarField> tk = rasModel.k();
75  const volScalarField& k = tk();
76  const scalarField& muw = rasModel.mu().boundaryField()[patchI];
77 
78  const scalar Cmu25 = pow(Cmu_, 0.25);
79 
80  tmp<scalarField> tmutw(new scalarField(*this));
81  scalarField& mutw = tmutw();
82 
83  forAll(mutw, faceI)
84  {
85  label faceCellI = patch().faceCells()[faceI];
86 
87  scalar uStar = Cmu25*sqrt(k[faceCellI]);
88 
89  scalar yPlus = uStar*y[faceI]/(muw[faceI]/rhow[faceI]);
90 
91  scalar KsPlus = uStar*Ks_[faceI]/(muw[faceI]/rhow[faceI]);
92 
93  scalar Edash = E_;
94  scalar yPlusLamNew = yPlusLam_;
95  if (KsPlus > 2.25)
96  {
97  Edash /= fnRough(KsPlus, Cs_[faceI]);
98  yPlusLamNew = rasModel.yPlusLam(kappa_, Edash);
99  }
100 
101  if (debug)
102  {
103  Info<< "yPlus = " << yPlus
104  << ", KsPlus = " << KsPlus
105  << ", Edash = " << Edash
106  << ", yPlusLam = " << yPlusLam_
107  << endl;
108  }
109 
110  if (yPlus > yPlusLamNew)
111  {
112  mutw[faceI] =
113  muw[faceI]*(yPlus*kappa_/log(max(Edash*yPlus, 1+1e-4)) - 1);
114  }
115  }
116 
117  return tmutw;
118 }
119 
120 
121 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
122 
123 mutRoughWallFunctionFvPatchScalarField::mutRoughWallFunctionFvPatchScalarField
124 (
125  const fvPatch& p,
127 )
128 :
130  Ks_(p.size(), 0.0),
131  Cs_(p.size(), 0.0)
132 {}
133 
134 
135 mutRoughWallFunctionFvPatchScalarField::mutRoughWallFunctionFvPatchScalarField
136 (
138  const fvPatch& p,
140  const fvPatchFieldMapper& mapper
141 )
142 :
143  mutWallFunctionFvPatchScalarField(ptf, p, iF, mapper),
144  Ks_(ptf.Ks_, mapper),
145  Cs_(ptf.Cs_, mapper)
146 {}
147 
148 
149 mutRoughWallFunctionFvPatchScalarField::mutRoughWallFunctionFvPatchScalarField
150 (
151  const fvPatch& p,
153  const dictionary& dict
154 )
155 :
157  Ks_("Ks", dict, p.size()),
158  Cs_("Cs", dict, p.size())
159 {}
160 
161 
162 mutRoughWallFunctionFvPatchScalarField::mutRoughWallFunctionFvPatchScalarField
163 (
165 )
166 :
168  Ks_(rwfpsf.Ks_),
169  Cs_(rwfpsf.Cs_)
170 {}
171 
172 
173 mutRoughWallFunctionFvPatchScalarField::mutRoughWallFunctionFvPatchScalarField
174 (
177 )
178 :
180  Ks_(rwfpsf.Ks_),
181  Cs_(rwfpsf.Cs_)
182 {}
183 
184 
185 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
186 
187 void mutRoughWallFunctionFvPatchScalarField::autoMap
188 (
189  const fvPatchFieldMapper& m
190 )
191 {
192  mutWallFunctionFvPatchScalarField::autoMap(m);
193  Ks_.autoMap(m);
194  Cs_.autoMap(m);
195 }
196 
197 
198 void mutRoughWallFunctionFvPatchScalarField::rmap
199 (
200  const fvPatchScalarField& ptf,
201  const labelList& addr
202 )
203 {
204  mutWallFunctionFvPatchScalarField::rmap(ptf, addr);
205 
207  refCast<const mutRoughWallFunctionFvPatchScalarField>(ptf);
208 
209  Cs_.rmap(nrwfpsf.Cs_, addr);
210  Ks_.rmap(nrwfpsf.Ks_, addr);
211 }
212 
213 
214 void mutRoughWallFunctionFvPatchScalarField::write(Ostream& os) const
215 {
217  writeLocalEntries(os);
218  Cs_.writeEntry("Cs", os);
219  Ks_.writeEntry("Ks", os);
220  writeEntry("value", os);
221 }
222 
223 
224 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225 
227 
228 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
229 
230 } // End namespace RASModels
231 } // End namespace compressible
232 } // End namespace Foam
233 
234 // ************************ vim: set sw=4 sts=4 et: ************************ //