initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / turbulenceModels / compressible / LES / derivedFvPatchFields / wallFunctions / muSgsWallFunctions / muSgsWallFunction / muSgsWallFunctionFvPatchScalarField.C
blobc31ac8815c2be76875a58e8296eb0be2eb9c0e42
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 "muSgsWallFunctionFvPatchScalarField.H"
28 #include "LESModel.H"
29 #include "fvPatchFieldMapper.H"
30 #include "volFields.H"
31 #include "addToRunTimeSelectionTable.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 namespace Foam
37 namespace compressible
39 namespace LESModels
42 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
44 muSgsWallFunctionFvPatchScalarField::muSgsWallFunctionFvPatchScalarField
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 muSgsWallFunctionFvPatchScalarField::muSgsWallFunctionFvPatchScalarField
61     const muSgsWallFunctionFvPatchScalarField& ptf,
62     const fvPatch& p,
63     const DimensionedField<scalar, volMesh>& iF,
64     const fvPatchFieldMapper& mapper
67     fixedValueFvPatchScalarField(ptf, p, iF, mapper),
68     UName_(ptf.UName_),
69     rhoName_(ptf.rhoName_),
70     muName_(ptf.muName_),
71     kappa_(ptf.kappa_),
72     E_(ptf.E_)
76 muSgsWallFunctionFvPatchScalarField::muSgsWallFunctionFvPatchScalarField
78     const fvPatch& p,
79     const DimensionedField<scalar, volMesh>& iF,
80     const dictionary& dict
83     fixedValueFvPatchScalarField(p, iF, dict),
84     UName_(dict.lookupOrDefault<word>("U", "U")),
85     rhoName_(dict.lookupOrDefault<word>("rho", "rho")),
86     muName_(dict.lookupOrDefault<word>("mu", "mu")),
87     kappa_(dict.lookupOrDefault<scalar>("kappa", 0.41)),
88     E_(dict.lookupOrDefault<scalar>("E", 9.8))
92 muSgsWallFunctionFvPatchScalarField::muSgsWallFunctionFvPatchScalarField
94     const muSgsWallFunctionFvPatchScalarField& mwfpsf
97     fixedValueFvPatchScalarField(mwfpsf),
98     UName_(mwfpsf.UName_),
99     rhoName_(mwfpsf.rhoName_),
100     muName_(mwfpsf.muName_),
101     kappa_(mwfpsf.kappa_),
102     E_(mwfpsf.E_)
106 muSgsWallFunctionFvPatchScalarField::muSgsWallFunctionFvPatchScalarField
108     const muSgsWallFunctionFvPatchScalarField& mwfpsf,
109     const DimensionedField<scalar, volMesh>& iF
112     fixedValueFvPatchScalarField(mwfpsf, iF),
113     UName_(mwfpsf.UName_),
114     rhoName_(mwfpsf.rhoName_),
115     muName_(mwfpsf.muName_),
116     kappa_(mwfpsf.kappa_),
117     E_(mwfpsf.E_)
121 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
123 void muSgsWallFunctionFvPatchScalarField::evaluate
125     const Pstream::commsTypes
128     const scalarField& ry = patch().deltaCoeffs();
130     const fvPatchVectorField& U =
131         patch().lookupPatchField<volVectorField, vector>(UName_);
133     scalarField magUp = mag(U.patchInternalField() - U);
135     const scalarField& muw =
136         patch().lookupPatchField<volScalarField, scalar>(muName_);
138     const scalarField& rhow =
139         patch().lookupPatchField<volScalarField, scalar>(rhoName_);
141     scalarField& muSgsw = *this;
143     scalarField magFaceGradU = mag(U.snGrad());
145     forAll(muSgsw, facei)
146     {
147         scalar magUpara = magUp[facei];
149         scalar utau =
150             sqrt((muSgsw[facei] + muw[facei])*magFaceGradU[facei]/rhow[facei]);
152         if (utau > 0)
153         {
154             int iter = 0;
155             scalar err = GREAT;
157             do
158             {
159                 scalar kUu = kappa_*magUpara/utau;
160                 scalar fkUu = exp(kUu) - 1 - kUu*(1 + 0.5*kUu);
162                 scalar f =
163                     - utau/(ry[facei]*muw[facei]/rhow[facei])
164                     + magUpara/utau
165                     + 1/E_*(fkUu - 1.0/6.0*kUu*sqr(kUu));
167                 scalar df =
168                     - 1.0/(ry[facei]*muw[facei]/rhow[facei])
169                     - magUpara/sqr(utau)
170                     - 1/E_*kUu*fkUu/utau;
172                 scalar utauNew = utau - f/df;
173                 err = mag((utau - utauNew)/utau);
174                 utau = utauNew;
176             } while (utau > VSMALL && err > 0.01 && ++iter < 10);
178             muSgsw[facei] =
179                 max
180                 (
181                     rhow[facei]*sqr(utau)/magFaceGradU[facei] - muw[facei],
182                     0.0
183                 );
184         }
185         else
186         {
187             muSgsw[facei] = 0;
188         }
189     }
193 void muSgsWallFunctionFvPatchScalarField::write(Ostream& os) const
195     fvPatchField<scalar>::write(os);
196     writeEntryIfDifferent<word>(os, "U", "U", UName_);
197     writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
198     writeEntryIfDifferent<word>(os, "mu", "mu", muName_);
199     os.writeKeyword("kappa") << kappa_ << token::END_STATEMENT << nl;
200     os.writeKeyword("E") << E_ << token::END_STATEMENT << nl;
201     writeEntry("value", os);
205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207 makePatchTypeField
209     fvPatchScalarField,
210     muSgsWallFunctionFvPatchScalarField
213 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
215 } // End namespace LESModels
216 } // End namespace compressible
217 } // End namespace Foam
219 // ************************************************************************* //