BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / turbulenceModels / compressible / LES / derivedFvPatchFields / wallFunctions / muSgsWallFunctions / muSgsUSpaldingWallFunction / muSgsUSpaldingWallFunctionFvPatchScalarField.C
blobe6de9e18132526e8d3f5871a3fdb8d7ae91e3ab2
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "muSgsUSpaldingWallFunctionFvPatchScalarField.H"
27 #include "LESModel.H"
28 #include "fvPatchFieldMapper.H"
29 #include "volFields.H"
30 #include "addToRunTimeSelectionTable.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 namespace Foam
36 namespace compressible
38 namespace LESModels
41 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
43 muSgsUSpaldingWallFunctionFvPatchScalarField::
44 muSgsUSpaldingWallFunctionFvPatchScalarField
46     const fvPatch& p,
47     const DimensionedField<scalar, volMesh>& iF
50     fixedValueFvPatchScalarField(p, iF),
51     UName_("U"),
52     rhoName_("rho"),
53     muName_("mu"),
54     kappa_(0.41),
55     E_(9.8)
59 muSgsUSpaldingWallFunctionFvPatchScalarField::
60 muSgsUSpaldingWallFunctionFvPatchScalarField
62     const muSgsUSpaldingWallFunctionFvPatchScalarField& ptf,
63     const fvPatch& p,
64     const DimensionedField<scalar, volMesh>& iF,
65     const fvPatchFieldMapper& mapper
68     fixedValueFvPatchScalarField(ptf, p, iF, mapper),
69     UName_(ptf.UName_),
70     rhoName_(ptf.rhoName_),
71     muName_(ptf.muName_),
72     kappa_(ptf.kappa_),
73     E_(ptf.E_)
77 muSgsUSpaldingWallFunctionFvPatchScalarField::
78 muSgsUSpaldingWallFunctionFvPatchScalarField
80     const fvPatch& p,
81     const DimensionedField<scalar, volMesh>& iF,
82     const dictionary& dict
85     fixedValueFvPatchScalarField(p, iF, dict),
86     UName_(dict.lookupOrDefault<word>("U", "U")),
87     rhoName_(dict.lookupOrDefault<word>("rho", "rho")),
88     muName_(dict.lookupOrDefault<word>("mu", "mu")),
89     kappa_(dict.lookupOrDefault<scalar>("kappa", 0.41)),
90     E_(dict.lookupOrDefault<scalar>("E", 9.8))
94 muSgsUSpaldingWallFunctionFvPatchScalarField::
95 muSgsUSpaldingWallFunctionFvPatchScalarField
97     const muSgsUSpaldingWallFunctionFvPatchScalarField& mwfpsf
100     fixedValueFvPatchScalarField(mwfpsf),
101     UName_(mwfpsf.UName_),
102     rhoName_(mwfpsf.rhoName_),
103     muName_(mwfpsf.muName_),
104     kappa_(mwfpsf.kappa_),
105     E_(mwfpsf.E_)
109 muSgsUSpaldingWallFunctionFvPatchScalarField::
110 muSgsUSpaldingWallFunctionFvPatchScalarField
112     const muSgsUSpaldingWallFunctionFvPatchScalarField& mwfpsf,
113     const DimensionedField<scalar, volMesh>& iF
116     fixedValueFvPatchScalarField(mwfpsf, iF),
117     UName_(mwfpsf.UName_),
118     rhoName_(mwfpsf.rhoName_),
119     muName_(mwfpsf.muName_),
120     kappa_(mwfpsf.kappa_),
121     E_(mwfpsf.E_)
125 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
127 void muSgsUSpaldingWallFunctionFvPatchScalarField::evaluate
129     const Pstream::commsTypes
132     const scalarField& ry = patch().deltaCoeffs();
134     const fvPatchVectorField& U =
135         patch().lookupPatchField<volVectorField, vector>(UName_);
137     const scalarField magUp(mag(U.patchInternalField() - U));
139     const scalarField& muw =
140         patch().lookupPatchField<volScalarField, scalar>(muName_);
142     const scalarField& rhow =
143         patch().lookupPatchField<volScalarField, scalar>(rhoName_);
145     scalarField& muSgsw = *this;
147     const scalarField magFaceGradU(mag(U.snGrad()));
149     forAll(muSgsw, facei)
150     {
151         scalar magUpara = magUp[facei];
153         scalar utau =
154             sqrt((muSgsw[facei] + muw[facei])*magFaceGradU[facei]/rhow[facei]);
156         if (utau > 0)
157         {
158             int iter = 0;
159             scalar err = GREAT;
161             do
162             {
163                 scalar kUu = kappa_*magUpara/utau;
164                 scalar fkUu = exp(kUu) - 1 - kUu*(1 + 0.5*kUu);
166                 scalar f =
167                     - utau/(ry[facei]*muw[facei]/rhow[facei])
168                     + magUpara/utau
169                     + 1/E_*(fkUu - 1.0/6.0*kUu*sqr(kUu));
171                 scalar df =
172                     - 1.0/(ry[facei]*muw[facei]/rhow[facei])
173                     - magUpara/sqr(utau)
174                     - 1/E_*kUu*fkUu/utau;
176                 scalar utauNew = utau - f/df;
177                 err = mag((utau - utauNew)/utau);
178                 utau = utauNew;
180             } while (utau > VSMALL && err > 0.01 && ++iter < 10);
182             muSgsw[facei] =
183                 max
184                 (
185                     rhow[facei]*sqr(utau)/magFaceGradU[facei] - muw[facei],
186                     0.0
187                 );
188         }
189         else
190         {
191             muSgsw[facei] = 0;
192         }
193     }
197 void muSgsUSpaldingWallFunctionFvPatchScalarField::write(Ostream& os) const
199     fvPatchField<scalar>::write(os);
200     writeEntryIfDifferent<word>(os, "U", "U", UName_);
201     writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
202     writeEntryIfDifferent<word>(os, "mu", "mu", muName_);
203     os.writeKeyword("kappa") << kappa_ << token::END_STATEMENT << nl;
204     os.writeKeyword("E") << E_ << token::END_STATEMENT << nl;
205     writeEntry("value", os);
209 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
211 makePatchTypeField
213     fvPatchScalarField,
214     muSgsUSpaldingWallFunctionFvPatchScalarField
217 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
219 } // End namespace LESModels
220 } // End namespace compressible
221 } // End namespace Foam
223 // ************************************************************************* //