initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / applications / utilities / preProcessing / applyBoundaryLayer / applyBoundaryLayer.C
blob06b9e6c884643fbbd7906349f6022ef45683bedd
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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 Application
26     applyBoundaryLayer
28 Description
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 \*---------------------------------------------------------------------------*/
39 #include "fvCFD.H"
40 #include "wallDist.H"
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;
58     volVectorField U
59     (
60         IOobject
61         (
62             "U",
63             runTime.timeName(),
64             mesh,
65             IOobject::MUST_READ,
66             IOobject::NO_WRITE
67         ),
68         mesh
69     );
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"))
80     {
81         // If the boundary-layer thickness is provided use it
82         ybl.value() = readScalar(IStringStream(args.options()["ybl"])());
83     }
84     else if (args.options().found("Cbl"))
85     {
86         // Calculate boundary layer thickness as Cbl * mean distance to wall
87         ybl.value() =
88             gAverage(y)*readScalar(IStringStream(args.options()["Cbl"])());
89     }
90     else
91     {
92         FatalErrorIn(args.executable())
93             << "Neither option 'ybl' or 'Cbl' have been provided to calculate"
94                " the boundary-layer thickness"
95             << exit(FatalError);
96     }
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();
106     forAll(U, celli)
107     {
108         if (y[celli] <= yblv)
109         {
110             U[celli] *= ::pow(y[celli]/yblv, (1.0/7.0));
111         }
112     }
114     Info<< "Writing U" << endl;
115     U.write();
117     // Update/re-write phi
118     phi = fvc::interpolate(U) & mesh.Sf();
119     phi.write();
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
128     (
129         "epsilon",
130         runTime.timeName(),
131         mesh,
132         IOobject::MUST_READ
133     );
135     IOobject kHeader
136     (
137         "k",
138         runTime.timeName(),
139         mesh,
140         IOobject::MUST_READ
141     );
143     IOobject nuTildaHeader
144     (
145         "nuTilda",
146         runTime.timeName(),
147         mesh,
148         IOobject::MUST_READ
149     );
151     // First calculate nut
152     volScalarField nut
153     (
154         "nut",
155         sqr(kappa*min(y, ybl))*::sqrt(2)*mag(dev(symm(fvc::grad(U))))
156     );
158     if (args.options().found("writenut"))
159     {
160         Info<< "Writing nut" << endl;
161         nut.write();
162     }
165     // Read and modify turbulence fields if present
167     if (nuTildaHeader.headerOk())
168     {
169         Info<< "Reading field nuTilda\n" << endl;
170         volScalarField nuTilda(nuTildaHeader, mesh);
171         nuTilda = nut;
172         nuTilda.correctBoundaryConditions();
174         Info<< "Writing nuTilda\n" << endl;
175         nuTilda.write();
176     }
178     if (kHeader.headerOk() && epsilonHeader.headerOk())
179     {
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;
195         k.write();
197         Info<< "Writing epsilon\n" << endl;
198         epsilon.write();
199     }
201     Info<< nl << "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
202         << "  ClockTime = " << runTime.elapsedClockTime() << " s"
203         << nl << endl;
205     Info<< "End\n" << endl;
207     return(0);
211 // ************************************************************************* //