FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 Application
00025     applyBoundaryLayer
00026 
00027 Description
00028     Apply a simplified boundary-layer model to the velocity and
00029     turbulence fields based on the 1/7th power-law.
00030 
00031     The uniform boundary-layer thickness is either provided via the -ybl option
00032     or calculated as the average of the distance to the wall scaled with
00033     the thickness coefficient supplied via the option -Cbl.  If both options
00034     are provided -ybl is used.
00035 
00036 Usage
00037 
00038     - applyBoundaryLayer [OPTIONS]
00039 
00040     @param -case <dir>\n
00041     Case directory.
00042 
00043     @param -parallel \n
00044     Run in parallel.
00045 
00046     @param -help \n
00047     Display help message.
00048 
00049     @param -doc \n
00050     Display Doxygen API documentation page for this application.
00051 
00052     @param -srcDoc \n
00053     Display Doxygen source documentation page for this application.
00054 
00055     @param -writenut \n
00056     Output turbulent viscosity.
00057 
00058     @param -Cbl <scalar>\n
00059     Coefficient for scaling of the average distance from the wall.
00060 
00061     @param -ybl <scalar>\n
00062     Specify the uniform boundary layer thickness.
00063 
00064 \*---------------------------------------------------------------------------*/
00065 
00066 #include <finiteVolume/fvCFD.H>
00067 #include <finiteVolume/wallDist.H>
00068 
00069 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00070 
00071 int main(int argc, char *argv[])
00072 {
00073     argList::validOptions.insert("ybl", "scalar");
00074     argList::validOptions.insert("Cbl", "scalar");
00075     argList::validOptions.insert("writenut", "");
00076 
00077 #   include <OpenFOAM/setRootCase.H>
00078 
00079 #   include <OpenFOAM/createTime.H>
00080 #   include <OpenFOAM/createMesh.H>
00081 
00082 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00083 
00084     Info<< "Reading field U\n" << endl;
00085     volVectorField U
00086     (
00087         IOobject
00088         (
00089             "U",
00090             runTime.timeName(),
00091             mesh,
00092             IOobject::MUST_READ,
00093             IOobject::NO_WRITE
00094         ),
00095         mesh
00096     );
00097 
00098 #   include <finiteVolume/createPhi.H>
00099 
00100     Info<< "Calculating wall distance field" << endl;
00101     volScalarField y = wallDist(mesh).y();
00102 
00103     // Set the mean boundary-layer thickness
00104     dimensionedScalar ybl("ybl", dimLength, 0);
00105 
00106     if (args.optionFound("ybl"))
00107     {
00108         // If the boundary-layer thickness is provided use it
00109         ybl.value() = args.optionRead<scalar>("ybl");
00110     }
00111     else if (args.optionFound("Cbl"))
00112     {
00113         // Calculate boundary layer thickness as Cbl * mean distance to wall
00114         ybl.value() = gAverage(y) * args.optionRead<scalar>("Cbl");
00115     }
00116     else
00117     {
00118         FatalErrorIn(args.executable())
00119             << "Neither option 'ybl' or 'Cbl' have been provided to calculate"
00120                " the boundary-layer thickness"
00121             << exit(FatalError);
00122     }
00123 
00124     Info<< "\nCreating boundary-layer for U of thickness "
00125         << ybl.value() << " m" << nl << endl;
00126 
00127     // Modify velocity by applying a 1/7th power law boundary-layer
00128     // u/U0 = (y/ybl)^(1/7)
00129     // assumes U0 is the same as the current cell velocity
00130 
00131     scalar yblv = ybl.value();
00132     forAll(U, celli)
00133     {
00134         if (y[celli] <= yblv)
00135         {
00136             U[celli] *= ::pow(y[celli]/yblv, (1.0/7.0));
00137         }
00138     }
00139 
00140     Info<< "Writing U" << endl;
00141     U.write();
00142 
00143     // Update/re-write phi
00144     phi = fvc::interpolate(U) & mesh.Sf();
00145     phi.write();
00146 
00147     // Set turbulence constants
00148     dimensionedScalar kappa("kappa", dimless, 0.41);
00149     dimensionedScalar Cmu("Cmu", dimless, 0.09);
00150 
00151     // Read and modify turbulence fields if present
00152 
00153     IOobject epsilonHeader
00154     (
00155         "epsilon",
00156         runTime.timeName(),
00157         mesh,
00158         IOobject::MUST_READ
00159     );
00160 
00161     IOobject kHeader
00162     (
00163         "k",
00164         runTime.timeName(),
00165         mesh,
00166         IOobject::MUST_READ
00167     );
00168 
00169     IOobject nuTildaHeader
00170     (
00171         "nuTilda",
00172         runTime.timeName(),
00173         mesh,
00174         IOobject::MUST_READ
00175     );
00176 
00177     // First calculate nut
00178     volScalarField nut
00179     (
00180         "nut",
00181         sqr(kappa*min(y, ybl))*::sqrt(2)*mag(dev(symm(fvc::grad(U))))
00182     );
00183 
00184     if (args.optionFound("writenut"))
00185     {
00186         Info<< "Writing nut" << endl;
00187         nut.write();
00188     }
00189 
00190 
00191     // Read and modify turbulence fields if present
00192 
00193     if (nuTildaHeader.headerOk())
00194     {
00195         Info<< "Reading field nuTilda\n" << endl;
00196         volScalarField nuTilda(nuTildaHeader, mesh);
00197         nuTilda = nut;
00198         nuTilda.correctBoundaryConditions();
00199 
00200         Info<< "Writing nuTilda\n" << endl;
00201         nuTilda.write();
00202     }
00203 
00204     if (kHeader.headerOk() && epsilonHeader.headerOk())
00205     {
00206         Info<< "Reading field k\n" << endl;
00207         volScalarField k(kHeader, mesh);
00208 
00209         Info<< "Reading field epsilon\n" << endl;
00210         volScalarField epsilon(epsilonHeader, mesh);
00211 
00212         scalar ck0 = ::pow(Cmu.value(), 0.25)*kappa.value();
00213         k = sqr(nut/(ck0*min(y, ybl)));
00214         k.correctBoundaryConditions();
00215 
00216         scalar ce0 = ::pow(Cmu.value(), 0.75)/kappa.value();
00217         epsilon = ce0*k*sqrt(k)/min(y, ybl);
00218         epsilon.correctBoundaryConditions();
00219 
00220         Info<< "Writing k\n" << endl;
00221         k.write();
00222 
00223         Info<< "Writing epsilon\n" << endl;
00224         epsilon.write();
00225     }
00226 
00227     Info<< nl << "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
00228         << "  ClockTime = " << runTime.elapsedClockTime() << " s"
00229         << nl << endl;
00230 
00231     Info<< "End\n" << endl;
00232 
00233     return 0;
00234 }
00235 
00236 
00237 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines