FreeFOAM The Cross-Platform CFD Toolkit
nutRoughWallFunctionFvPatchScalarField.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 incompressible
37 {
38 namespace RASModels
39 {
40 
41 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
42 
44 (
45  const scalar KsPlus,
46  const scalar Cs
47 ) const
48 {
49  // Return fn based on non-dimensional roughness height
50 
51  if (KsPlus < 90.0)
52  {
53  return pow
54  (
55  (KsPlus - 2.25)/87.75 + Cs*KsPlus,
56  sin(0.4258*(log(KsPlus) - 0.811))
57  );
58  }
59  else
60  {
61  return (1.0 + Cs*KsPlus);
62  }
63 }
64 
65 
67 {
68  const label patchI = patch().index();
69 
70  const RASModel& rasModel = db().lookupObject<RASModel>("RASProperties");
71  const scalarField& y = rasModel.y()[patchI];
72  const tmp<volScalarField> tk = rasModel.k();
73  const volScalarField& k = tk();
74  const scalarField& nuw = rasModel.nu().boundaryField()[patchI];
75 
76  const scalar Cmu25 = pow(Cmu_, 0.25);
77 
78  tmp<scalarField> tnutw(new scalarField(*this));
79  scalarField& nutw = tnutw();
80 
81  forAll(nutw, faceI)
82  {
83  label faceCellI = patch().faceCells()[faceI];
84 
85  scalar uStar = Cmu25*sqrt(k[faceCellI]);
86  scalar yPlus = uStar*y[faceI]/nuw[faceI];
87  scalar KsPlus = uStar*Ks_[faceI]/nuw[faceI];
88 
89  scalar Edash = E_;
90 
91  if (KsPlus > 2.25)
92  {
93  Edash /= fnRough(KsPlus, Cs_[faceI]);
94  }
95 
96  if (yPlus > yPlusLam_)
97  {
98  scalar limitingNutw = max(nutw[faceI], nuw[faceI]);
99 
100  // To avoid oscillations limit the change in the wall viscosity
101  // which is particularly important if it temporarily becomes zero
102  nutw[faceI] =
103  max
104  (
105  min
106  (
107  nuw[faceI]
108  *(yPlus*kappa_/log(max(Edash*yPlus, 1+1e-4)) - 1),
109  2*limitingNutw
110  ), 0.5*limitingNutw
111  );
112  }
113 
114  if (debug)
115  {
116  Info<< "yPlus = " << yPlus
117  << ", KsPlus = " << KsPlus
118  << ", Edash = " << Edash
119  << ", nutw = " << nutw[faceI]
120  << endl;
121  }
122  }
123 
124  return tnutw;
125 }
126 
127 
128 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
129 
131 (
132  const fvPatch& p,
134 )
135 :
137  Ks_(p.size(), 0.0),
138  Cs_(p.size(), 0.0)
139 {}
140 
141 
143 (
145  const fvPatch& p,
147  const fvPatchFieldMapper& mapper
148 )
149 :
150  nutWallFunctionFvPatchScalarField(ptf, p, iF, mapper),
151  Ks_(ptf.Ks_, mapper),
152  Cs_(ptf.Cs_, mapper)
153 {}
154 
155 
157 (
158  const fvPatch& p,
160  const dictionary& dict
161 )
162 :
164  Ks_("Ks", dict, p.size()),
165  Cs_("Cs", dict, p.size())
166 {}
167 
168 
170 (
172 )
173 :
175  Ks_(rwfpsf.Ks_),
176  Cs_(rwfpsf.Cs_)
177 {}
178 
179 
181 (
184 )
185 :
187  Ks_(rwfpsf.Ks_),
188  Cs_(rwfpsf.Cs_)
189 {}
190 
191 
192 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
193 
195 (
196  const fvPatchFieldMapper& m
197 )
198 {
199  nutWallFunctionFvPatchScalarField::autoMap(m);
200  Ks_.autoMap(m);
201  Cs_.autoMap(m);
202 }
203 
204 
206 (
207  const fvPatchScalarField& ptf,
208  const labelList& addr
209 )
210 {
211  nutWallFunctionFvPatchScalarField::rmap(ptf, addr);
212 
214  refCast<const nutRoughWallFunctionFvPatchScalarField>(ptf);
215 
216  Ks_.rmap(nrwfpsf.Ks_, addr);
217  Cs_.rmap(nrwfpsf.Cs_, addr);
218 }
219 
220 
222 {
224  writeLocalEntries(os);
225  Cs_.writeEntry("Cs", os);
226  Ks_.writeEntry("Ks", os);
227  writeEntry("value", os);
228 }
229 
230 
231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
232 
234 
235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236 
237 } // End namespace RASModels
238 } // End namespace incompressible
239 } // End namespace Foam
240 
241 // ************************ vim: set sw=4 sts=4 et: ************************ //