1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
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 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
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
29 Apply a simplified boundary-layer model to the velocity and
30 turbulence fields based on the 1/7th power-law.
32 The uniform boundary-layer thickness is either provided via the -ybl option
33 or calculated as the average of the distance to the wall scaled with
34 the thickness coefficient supplied via the option -Cbl. If both options
35 are provided -ybl is used.
37 \*---------------------------------------------------------------------------*/
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 int main(int argc, char *argv[])
46 argList::validOptions.insert("ybl", "scalar");
47 argList::validOptions.insert("Cbl", "scalar");
48 argList::validOptions.insert("writenut", "");
50 # include "setRootCase.H"
52 # include "createTime.H"
53 # include "createMesh.H"
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 Info<< "Reading field U\n" << endl;
71 # include "createPhi.H"
73 Info<< "Calculating wall distance field" << endl;
74 volScalarField y = wallDist(mesh).y();
76 // Set the mean boundary-layer thickness
77 dimensionedScalar ybl("ybl", dimLength, 0);
79 if (args.options().found("ybl"))
81 // If the boundary-layer thickness is provided use it
82 ybl.value() = readScalar(IStringStream(args.options()["ybl"])());
84 else if (args.options().found("Cbl"))
86 // Calculate boundary layer thickness as Cbl * mean distance to wall
88 gAverage(y)*readScalar(IStringStream(args.options()["Cbl"])());
92 FatalErrorIn(args.executable())
93 << "Neither option 'ybl' or 'Cbl' have been provided to calculate"
94 " the boundary-layer thickness"
98 Info<< "\nCreating boundary-layer for U of thickness "
99 << ybl.value() << " m" << nl << endl;
101 // Modify velocity by applying a 1/7th power law boundary-layer
102 // u/U0 = (y/ybl)^(1/7)
103 // assumes U0 is the same as the current cell velocity
105 scalar yblv = ybl.value();
108 if (y[celli] <= yblv)
110 U[celli] *= ::pow(y[celli]/yblv, (1.0/7.0));
114 Info<< "Writing U" << endl;
117 // Update/re-write phi
118 phi = fvc::interpolate(U) & mesh.Sf();
121 // Set turbulence constants
122 dimensionedScalar kappa("kappa", dimless, 0.4187);
123 dimensionedScalar Cmu("Cmu", dimless, 0.09);
125 // Read and modify turbulence fields if present
127 IOobject epsilonHeader
143 IOobject nuTildaHeader
151 // First calculate nut
155 sqr(kappa*min(y, ybl))*::sqrt(2)*mag(dev(symm(fvc::grad(U))))
158 if (args.options().found("writenut"))
160 Info<< "Writing nut" << endl;
165 // Read and modify turbulence fields if present
167 if (nuTildaHeader.headerOk())
169 Info<< "Reading field nuTilda\n" << endl;
170 volScalarField nuTilda(nuTildaHeader, mesh);
172 nuTilda.correctBoundaryConditions();
174 Info<< "Writing nuTilda\n" << endl;
178 if (kHeader.headerOk() && epsilonHeader.headerOk())
180 Info<< "Reading field k\n" << endl;
181 volScalarField k(kHeader, mesh);
183 Info<< "Reading field epsilon\n" << endl;
184 volScalarField epsilon(epsilonHeader, mesh);
186 scalar ck0 = ::pow(Cmu.value(), 0.25)*kappa.value();
187 k = sqr(nut/(ck0*min(y, ybl)));
188 k.correctBoundaryConditions();
190 scalar ce0 = ::pow(Cmu.value(), 0.75)/kappa.value();
191 epsilon = ce0*k*sqrt(k)/min(y, ybl);
192 epsilon.correctBoundaryConditions();
194 Info<< "Writing k\n" << endl;
197 Info<< "Writing epsilon\n" << endl;
201 Info<< nl << "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
202 << " ClockTime = " << runTime.elapsedClockTime() << " s"
205 Info<< "End\n" << endl;
211 // ************************************************************************* //