1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
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
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 "SpaldingsLaw.H"
27 #include "addToRunTimeSelectionTable.H"
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 namespace tabulatedWallFunctions
35 defineTypeNameAndDebug(SpaldingsLaw, 0);
36 addToRunTimeSelectionTable
38 tabulatedWallFunction,
45 const Foam::label Foam::tabulatedWallFunctions::SpaldingsLaw::maxIters_ = 1000;
48 Foam::tabulatedWallFunctions::SpaldingsLaw::tolerance_ = 1e-4;
51 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
53 void Foam::tabulatedWallFunctions::SpaldingsLaw::invertFunction()
55 // Initialise u+ and R
60 forAll(invertedTable_, i)
62 if (invertedTable_.log10())
64 Re = pow(10, (i*invertedTable_.dx() + invertedTable_.x0()));
68 Re = i*invertedTable_.dx() + invertedTable_.x0();
71 // Use latest available u+ estimate
74 uPlus = invertedTable_[i-1];
77 // Newton iterations to determine u+
82 scalar kUPlus = min(kappa_*uPlus, 50);
86 *(exp(kUPlus) - pow3(kUPlus)/6 - 0.5*sqr(kUPlus) - kUPlus - 1);
88 scalar f = - Re + A/E_;
93 + exp(kUPlus)*(kUPlus + 1)
100 scalar uPlusNew = uPlus - f/(df + ROOTVSMALL);
101 error = mag((uPlus - uPlusNew)/uPlusNew);
103 } while (error > tolerance_ && ++iter < maxIters_);
105 if (iter == maxIters_)
107 WarningIn("SpaldingsLaw::invertFunction()")
108 << "Newton iterations not converged:" << nl
109 << " iters = " << iter << ", error = " << error << endl;
112 // Set new values - constrain u+ >= 0
113 invertedTable_[i] = max(0, uPlus);
118 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
120 Foam::tabulatedWallFunctions::SpaldingsLaw::SpaldingsLaw
122 const dictionary& dict,
126 tabulatedWallFunction(dict, mesh, typeName),
127 kappa_(readScalar(coeffDict_.lookup("kappa"))),
128 E_(readScalar(coeffDict_.lookup("E")))
139 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
141 Foam::tabulatedWallFunctions::SpaldingsLaw::~SpaldingsLaw()
145 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
147 Foam::scalar Foam::tabulatedWallFunctions::SpaldingsLaw::yPlus
152 scalar kUPlus = min(kappa_*uPlus, 50);
156 + 1/E_*(exp(kUPlus) - pow3(kUPlus)/6 - 0.5*sqr(kUPlus) - kUPlus - 1);
160 Foam::scalar Foam::tabulatedWallFunctions::SpaldingsLaw::Re
165 return uPlus*yPlus(uPlus);
169 void Foam::tabulatedWallFunctions::SpaldingsLaw::writeData(Ostream& os) const
171 if (invertedTable_.log10())
173 os << "log10(Re), y+, u+:" << endl;
174 forAll(invertedTable_, i)
176 scalar uPlus = invertedTable_[i];
177 scalar Re = ::log10(this->Re(uPlus));
178 scalar yPlus = this->yPlus(uPlus);
179 os << Re << ", " << yPlus << ", " << uPlus << endl;
184 os << "Re, y+, u+:" << endl;
185 forAll(invertedTable_, i)
187 scalar uPlus = invertedTable_[i];
188 scalar Re = this->Re(uPlus);
189 scalar yPlus = this->yPlus(uPlus);
190 os << Re << ", " << yPlus << ", " << uPlus << endl;
196 // ************************************************************************* //