OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

applyBoundaryLayer.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Application
00026     applyBoundaryLayer
00027 
00028 Description
00029     Apply a simplified boundary-layer model to the velocity and
00030     turbulence fields based on the 1/7th power-law.
00031 
00032     The uniform boundary-layer thickness is either provided via the -ybl option
00033     or calculated as the average of the distance to the wall scaled with
00034     the thickness coefficient supplied via the option -Cbl.  If both options
00035     are provided -ybl is used.
00036 
00037 \*---------------------------------------------------------------------------*/
00038 
00039 #include "fvCFD.H"
00040 #include "wallDist.H"
00041 
00042 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00043 
00044 int main(int argc, char *argv[])
00045 {
00046     argList::validOptions.insert("ybl", "scalar");
00047     argList::validOptions.insert("Cbl", "scalar");
00048     argList::validOptions.insert("writenut", "");
00049 
00050 #   include "setRootCase.H"
00051 
00052 #   include "createTime.H"
00053 #   include "createMesh.H"
00054 
00055 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00056 
00057     Info<< "Reading field U\n" << endl;
00058     volVectorField U
00059     (
00060         IOobject
00061         (
00062             "U",
00063             runTime.timeName(),
00064             mesh,
00065             IOobject::MUST_READ,
00066             IOobject::NO_WRITE
00067         ),
00068         mesh
00069     );
00070 
00071 #   include "createPhi.H"
00072 
00073     Info<< "Calculating wall distance field" << endl;
00074     volScalarField y = wallDist(mesh).y();
00075 
00076     // Set the mean boundary-layer thickness
00077     dimensionedScalar ybl("ybl", dimLength, 0);
00078 
00079     if (args.optionFound("ybl"))
00080     {
00081         // If the boundary-layer thickness is provided use it
00082         ybl.value() = args.optionRead<scalar>("ybl");
00083     }
00084     else if (args.optionFound("Cbl"))
00085     {
00086         // Calculate boundary layer thickness as Cbl * mean distance to wall
00087         ybl.value() = gAverage(y) * args.optionRead<scalar>("Cbl");
00088     }
00089     else
00090     {
00091         FatalErrorIn(args.executable())
00092             << "Neither option 'ybl' or 'Cbl' have been provided to calculate"
00093                " the boundary-layer thickness"
00094             << exit(FatalError);
00095     }
00096 
00097     Info<< "\nCreating boundary-layer for U of thickness "
00098         << ybl.value() << " m" << nl << endl;
00099 
00100     // Modify velocity by applying a 1/7th power law boundary-layer
00101     // u/U0 = (y/ybl)^(1/7)
00102     // assumes U0 is the same as the current cell velocity
00103 
00104     scalar yblv = ybl.value();
00105     forAll(U, celli)
00106     {
00107         if (y[celli] <= yblv)
00108         {
00109             U[celli] *= ::pow(y[celli]/yblv, (1.0/7.0));
00110         }
00111     }
00112 
00113     Info<< "Writing U" << endl;
00114     U.write();
00115 
00116     // Update/re-write phi
00117     phi = fvc::interpolate(U) & mesh.Sf();
00118     phi.write();
00119 
00120     // Set turbulence constants
00121     dimensionedScalar kappa("kappa", dimless, 0.4187);
00122     dimensionedScalar Cmu("Cmu", dimless, 0.09);
00123 
00124     // Read and modify turbulence fields if present
00125 
00126     IOobject epsilonHeader
00127     (
00128         "epsilon",
00129         runTime.timeName(),
00130         mesh,
00131         IOobject::MUST_READ
00132     );
00133 
00134     IOobject kHeader
00135     (
00136         "k",
00137         runTime.timeName(),
00138         mesh,
00139         IOobject::MUST_READ
00140     );
00141 
00142     IOobject nuTildaHeader
00143     (
00144         "nuTilda",
00145         runTime.timeName(),
00146         mesh,
00147         IOobject::MUST_READ
00148     );
00149 
00150     // First calculate nut
00151     volScalarField nut
00152     (
00153         "nut",
00154         sqr(kappa*min(y, ybl))*::sqrt(2)*mag(dev(symm(fvc::grad(U))))
00155     );
00156 
00157     if (args.optionFound("writenut"))
00158     {
00159         Info<< "Writing nut" << endl;
00160         nut.write();
00161     }
00162 
00163 
00164     // Read and modify turbulence fields if present
00165 
00166     if (nuTildaHeader.headerOk())
00167     {
00168         Info<< "Reading field nuTilda\n" << endl;
00169         volScalarField nuTilda(nuTildaHeader, mesh);
00170         nuTilda = nut;
00171         nuTilda.correctBoundaryConditions();
00172 
00173         Info<< "Writing nuTilda\n" << endl;
00174         nuTilda.write();
00175     }
00176 
00177     if (kHeader.headerOk() && epsilonHeader.headerOk())
00178     {
00179         Info<< "Reading field k\n" << endl;
00180         volScalarField k(kHeader, mesh);
00181 
00182         Info<< "Reading field epsilon\n" << endl;
00183         volScalarField epsilon(epsilonHeader, mesh);
00184 
00185         scalar ck0 = ::pow(Cmu.value(), 0.25)*kappa.value();
00186         k = sqr(nut/(ck0*min(y, ybl)));
00187         k.correctBoundaryConditions();
00188 
00189         scalar ce0 = ::pow(Cmu.value(), 0.75)/kappa.value();
00190         epsilon = ce0*k*sqrt(k)/min(y, ybl);
00191         epsilon.correctBoundaryConditions();
00192 
00193         Info<< "Writing k\n" << endl;
00194         k.write();
00195 
00196         Info<< "Writing epsilon\n" << endl;
00197         epsilon.write();
00198     }
00199 
00200     Info<< nl << "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
00201         << "  ClockTime = " << runTime.elapsedClockTime() << " s"
00202         << nl << endl;
00203 
00204     Info<< "End\n" << endl;
00205 
00206     return 0;
00207 }
00208 
00209 
00210 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd