initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / turbulenceModels / incompressible / LES / derivedFvPatchFields / wallFunctions / nuSgsWallFunctions / nuSgsWallFunction / nuSgsWallFunctionFvPatchScalarField.C
blob5555fd3086f0152f71b1d80287efffa937b47bf4
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 "nuSgsWallFunctionFvPatchScalarField.H"
28 #include "fvPatchFieldMapper.H"
29 #include "volFields.H"
30 #include "addToRunTimeSelectionTable.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 namespace Foam
36 namespace incompressible
38 namespace LESModels
41 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
43 nuSgsWallFunctionFvPatchScalarField::
44 nuSgsWallFunctionFvPatchScalarField
46     const fvPatch& p,
47     const DimensionedField<scalar, volMesh>& iF
50     fixedValueFvPatchScalarField(p, iF),
51     UName_("U"),
52     nuName_("nu"),
53     kappa_(0.41),
54     E_(9.8)
58 nuSgsWallFunctionFvPatchScalarField::
59 nuSgsWallFunctionFvPatchScalarField
61     const nuSgsWallFunctionFvPatchScalarField& 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     nuName_(ptf.nuName_),
70     kappa_(ptf.kappa_),
71     E_(ptf.E_)
75 nuSgsWallFunctionFvPatchScalarField::
76 nuSgsWallFunctionFvPatchScalarField
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     nuName_(dict.lookupOrDefault<word>("nu", "nu")),
86     kappa_(dict.lookupOrDefault<scalar>("kappa", 0.41)),
87     E_(dict.lookupOrDefault<scalar>("E", 9.8))
91 nuSgsWallFunctionFvPatchScalarField::
92 nuSgsWallFunctionFvPatchScalarField
94     const nuSgsWallFunctionFvPatchScalarField& nwfpsf
97     fixedValueFvPatchScalarField(nwfpsf),
98     UName_(nwfpsf.UName_),
99     nuName_(nwfpsf.nuName_),
100     kappa_(nwfpsf.kappa_),
101     E_(nwfpsf.E_)
105 nuSgsWallFunctionFvPatchScalarField::
106 nuSgsWallFunctionFvPatchScalarField
108     const nuSgsWallFunctionFvPatchScalarField& nwfpsf,
109     const DimensionedField<scalar, volMesh>& iF
112     fixedValueFvPatchScalarField(nwfpsf, iF),
113     UName_(nwfpsf.UName_),
114     nuName_(nwfpsf.nuName_),
115     kappa_(nwfpsf.kappa_),
116     E_(nwfpsf.E_)
120 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
122 void nuSgsWallFunctionFvPatchScalarField::evaluate
124     const Pstream::commsTypes
127     const scalarField& ry = patch().deltaCoeffs();
129     const fvPatchVectorField& U =
130         patch().lookupPatchField<volVectorField, vector>(UName_);
132     scalarField magUp = mag(U.patchInternalField() - U);
134     const scalarField& nuw =
135         patch().lookupPatchField<volScalarField, scalar>(nuName_);
136     scalarField& nuSgsw = *this;
139     scalarField magFaceGradU = mag(U.snGrad());
141     forAll(nuSgsw, facei)
142     {
143         scalar magUpara = magUp[facei];
145         scalar utau = sqrt((nuSgsw[facei] + nuw[facei])*magFaceGradU[facei]);
147         if (utau > VSMALL)
148         {
149             int iter = 0;
150             scalar err = GREAT;
152             do
153             {
154                 scalar kUu = min(kappa_*magUpara/utau, 50);
155                 scalar fkUu = exp(kUu) - 1 - kUu*(1 + 0.5*kUu);
157                 scalar f =
158                     - utau/(ry[facei]*nuw[facei])
159                     + magUpara/utau
160                     + 1/E_*(fkUu - 1.0/6.0*kUu*sqr(kUu));
162                 scalar df =
163                     - 1.0/(ry[facei]*nuw[facei])
164                     - magUpara/sqr(utau)
165                     - 1/E_*kUu*fkUu/utau;
167                 scalar utauNew = utau - f/df;
168                 err = mag((utau - utauNew)/utau);
169                 utau = utauNew;
171             } while (utau > VSMALL && err > 0.01 && ++iter < 10);
173             nuSgsw[facei] =
174                 max(sqr(max(utau, 0))/magFaceGradU[facei] - nuw[facei], 0.0);
175         }
176         else
177         {
178             nuSgsw[facei] = 0;
179         }
180     }
184 void nuSgsWallFunctionFvPatchScalarField::write(Ostream& os) const
186     fvPatchField<scalar>::write(os);
187     writeEntryIfDifferent<word>(os, "U", "U", UName_);
188     writeEntryIfDifferent<word>(os, "nu", "nu", nuName_);
189     os.writeKeyword("kappa") << kappa_ << token::END_STATEMENT << nl;
190     os.writeKeyword("E") << E_ << token::END_STATEMENT << nl;
191     writeEntry("value", os);
195 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
197 makePatchTypeField
199     fvPatchScalarField,
200     nuSgsWallFunctionFvPatchScalarField
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205 } // End namespace LESModels
206 } // End namespace incompressible
207 } // End namespace Foam
209 // ************************************************************************* //