1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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.optionFound("ybl"))
81 // If the boundary-layer thickness is provided use it
82 ybl.value() = args.optionRead<scalar>("ybl");
84 else if (args.optionFound("Cbl"))
86 // Calculate boundary layer thickness as Cbl * mean distance to wall
87 ybl.value() = gAverage(y) * args.optionRead<scalar>("Cbl");
91 FatalErrorIn(args.executable())
92 << "Neither option 'ybl' or 'Cbl' have been provided to calculate"
93 " the boundary-layer thickness"
97 Info<< "\nCreating boundary-layer for U of thickness "
98 << ybl.value() << " m" << nl << endl;
100 // Modify velocity by applying a 1/7th power law boundary-layer
101 // u/U0 = (y/ybl)^(1/7)
102 // assumes U0 is the same as the current cell velocity
104 scalar yblv = ybl.value();
107 if (y[celli] <= yblv)
109 U[celli] *= ::pow(y[celli]/yblv, (1.0/7.0));
113 Info<< "Writing U" << endl;
116 // Update/re-write phi
117 phi = fvc::interpolate(U) & mesh.Sf();
120 // Set turbulence constants
121 dimensionedScalar kappa("kappa", dimless, 0.41);
122 dimensionedScalar Cmu("Cmu", dimless, 0.09);
124 // Read and modify turbulence fields if present
126 IOobject epsilonHeader
142 IOobject nuTildaHeader
150 // First calculate nut
154 sqr(kappa*min(y, ybl))*::sqrt(2)*mag(dev(symm(fvc::grad(U))))
157 if (args.optionFound("writenut"))
159 Info<< "Writing nut" << endl;
164 // Read and modify turbulence fields if present
166 if (nuTildaHeader.headerOk())
168 Info<< "Reading field nuTilda\n" << endl;
169 volScalarField nuTilda(nuTildaHeader, mesh);
171 nuTilda.correctBoundaryConditions();
173 Info<< "Writing nuTilda\n" << endl;
177 if (kHeader.headerOk() && epsilonHeader.headerOk())
179 Info<< "Reading field k\n" << endl;
180 volScalarField k(kHeader, mesh);
182 Info<< "Reading field epsilon\n" << endl;
183 volScalarField epsilon(epsilonHeader, mesh);
185 scalar ck0 = ::pow(Cmu.value(), 0.25)*kappa.value();
186 k = sqr(nut/(ck0*min(y, ybl)));
187 k.correctBoundaryConditions();
189 scalar ce0 = ::pow(Cmu.value(), 0.75)/kappa.value();
190 epsilon = ce0*k*sqrt(k)/min(y, ybl);
191 epsilon.correctBoundaryConditions();
193 Info<< "Writing k\n" << endl;
196 Info<< "Writing epsilon\n" << endl;
200 Info<< nl << "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
201 << " ClockTime = " << runTime.elapsedClockTime() << " s"
204 Info<< "End\n" << endl;
210 // ************************************************************************* //