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

applyWallFunctionBoundaryConditions.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-2007 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     applyWallFunctionBounaryConditions
00027 
00028 Description
00029     Updates OpenFOAM RAS cases to use the new (v1.6) wall function framework
00030 
00031     Attempts to determine whether case is compressible or incompressible, or
00032     can be supplied with -compressible command line argument
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #include "argList.H"
00037 #include "fvMesh.H"
00038 #include "Time.H"
00039 #include "volFields.H"
00040 #include "surfaceFields.H"
00041 
00042 #include "wallPolyPatch.H"
00043 
00044 #include "incompressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.H"
00045 #include "incompressible/RAS/derivedFvPatchFields/wallFunctions/kqRWallFunctions/kqRWallFunction/kqRWallFunctionFvPatchField.H"
00046 #include "incompressible/RAS/derivedFvPatchFields/wallFunctions/nutWallFunctions/nutWallFunction/nutWallFunctionFvPatchScalarField.H"
00047 #include "incompressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.H"
00048 
00049 #include "compressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.H"
00050 #include "compressible/RAS/derivedFvPatchFields/wallFunctions/kqRWallFunctions/kqRWallFunction/kqRWallFunctionFvPatchField.H"
00051 #include "compressible/RAS/derivedFvPatchFields/wallFunctions/mutWallFunctions/mutWallFunction/mutWallFunctionFvPatchScalarField.H"
00052 #include "compressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.H"
00053 
00054 using namespace Foam;
00055 
00056 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00057 
00058 bool caseIsCompressible(const fvMesh& mesh)
00059 {
00060     // Attempt flux field
00061     IOobject phiHeader
00062     (
00063         "phi",
00064         mesh.time().timeName(),
00065         mesh,
00066         IOobject::MUST_READ,
00067         IOobject::NO_WRITE
00068     );
00069 
00070     if (phiHeader.headerOk())
00071     {
00072         surfaceScalarField phi(phiHeader, mesh);
00073         if (phi.dimensions() == dimDensity*dimVelocity*dimArea)
00074         {
00075             return true;
00076         }
00077     }
00078 
00079     // Attempt density field
00080     IOobject rhoHeader
00081     (
00082         "rho",
00083         mesh.time().timeName(),
00084         mesh,
00085         IOobject::MUST_READ,
00086         IOobject::NO_WRITE
00087     );
00088 
00089     if (rhoHeader.headerOk())
00090     {
00091         volScalarField rho(rhoHeader, mesh);
00092         if (rho.dimensions() == dimDensity)
00093         {
00094             return true;
00095         }
00096     }
00097 
00098     // Attempt pressure field
00099     IOobject pHeader
00100     (
00101         "p",
00102         mesh.time().timeName(),
00103         mesh,
00104         IOobject::MUST_READ,
00105         IOobject::NO_WRITE
00106     );
00107 
00108     if (pHeader.headerOk())
00109     {
00110         volScalarField p(pHeader, mesh);
00111         if (p.dimensions() == dimMass/sqr(dimTime)/dimLength)
00112         {
00113             return true;
00114         }
00115     }
00116 
00117     // If none of the above are true, assume that the case is incompressible
00118     return false;
00119 }
00120 
00121 
00122 void createVolScalarField
00123 (
00124     const fvMesh& mesh,
00125     const word& fieldName,
00126     const dimensionSet& dims
00127 )
00128 {
00129     IOobject fieldHeader
00130     (
00131         fieldName,
00132         mesh.time().timeName(),
00133         mesh,
00134         IOobject::MUST_READ,
00135         IOobject::NO_WRITE
00136     );
00137 
00138     if (!fieldHeader.headerOk())
00139     {
00140         Info<< "Creating field " << fieldName << nl << endl;
00141 
00142         volScalarField field
00143         (
00144             IOobject
00145             (
00146                 fieldName,
00147                 mesh.time().timeName(),
00148                 mesh,
00149                 IOobject::NO_READ,
00150                 IOobject::NO_WRITE
00151             ),
00152             mesh,
00153             dimensionedScalar("zero", dims, 0.0)
00154         );
00155 
00156         field.write();
00157     }
00158 }
00159 
00160 
00161 void replaceBoundaryType
00162 (
00163     const fvMesh& mesh,
00164     const word& fieldName,
00165     const word& boundaryType,
00166     const string& boundaryValue
00167 )
00168 {
00169     IOobject header
00170     (
00171         fieldName,
00172         mesh.time().timeName(),
00173         mesh,
00174         IOobject::MUST_READ,
00175         IOobject::NO_WRITE
00176     );
00177 
00178     if (!header.headerOk())
00179     {
00180         return;
00181     }
00182 
00183     Info<< "Updating boundary types for field " << header.name() << endl;
00184 
00185     const word oldTypeName = IOdictionary::typeName;
00186     const_cast<word&>(IOdictionary::typeName) = word::null;
00187 
00188     IOdictionary dict(header);
00189 
00190     const_cast<word&>(IOdictionary::typeName) = oldTypeName;
00191     const_cast<word&>(dict.type()) = dict.headerClassName();
00192 
00193     // Make a backup of the old field
00194     word backupName(dict.name() + ".old");
00195     Info<< "    copying " << dict.name() << " to "
00196         << backupName << endl;
00197     IOdictionary dictOld = dict;
00198     dictOld.rename(backupName);
00199     dictOld.regIOobject::write();
00200 
00201     // Loop through boundary patches and update
00202     const polyBoundaryMesh& bMesh = mesh.boundaryMesh();
00203     dictionary& boundaryDict = dict.subDict("boundaryField");
00204     forAll(bMesh, patchI)
00205     {
00206         if (isType<wallPolyPatch>(bMesh[patchI]))
00207         {
00208             word patchName = bMesh[patchI].name();
00209             dictionary& oldPatch = boundaryDict.subDict(patchName);
00210 
00211             dictionary newPatch(dictionary::null);
00212             newPatch.add("type", boundaryType);
00213             newPatch.add("value", ("uniform " + boundaryValue).c_str());
00214 
00215             oldPatch = newPatch;
00216         }
00217     }
00218 
00219     Info<< "    writing updated " << dict.name() << nl << endl;
00220     dict.regIOobject::write();
00221 }
00222 
00223 
00224 void updateCompressibleCase(const fvMesh& mesh)
00225 {
00226     Info<< "Case treated as compressible" << nl << endl;
00227     createVolScalarField
00228     (
00229         mesh,
00230         "mut",
00231         dimArea/dimTime*dimDensity
00232     );
00233     replaceBoundaryType
00234     (
00235         mesh,
00236         "mut",
00237         compressible::RASModels::mutWallFunctionFvPatchScalarField::typeName,
00238         "0"
00239     );
00240     replaceBoundaryType
00241     (
00242         mesh,
00243         "epsilon",
00244         compressible::RASModels::epsilonWallFunctionFvPatchScalarField::
00245             typeName,
00246         "0"
00247     );
00248     replaceBoundaryType
00249     (
00250         mesh,
00251         "omega",
00252         compressible::RASModels::omegaWallFunctionFvPatchScalarField::typeName,
00253         "0"
00254     );
00255     replaceBoundaryType
00256     (
00257         mesh,
00258         "k",
00259         compressible::RASModels::kqRWallFunctionFvPatchField<scalar>::typeName,
00260         "0"
00261     );
00262     replaceBoundaryType
00263     (
00264         mesh,
00265         "q",
00266         compressible::RASModels::kqRWallFunctionFvPatchField<scalar>::typeName,
00267         "0"
00268     );
00269     replaceBoundaryType
00270     (
00271         mesh,
00272         "R",
00273         compressible::RASModels::kqRWallFunctionFvPatchField<symmTensor>::
00274             typeName,
00275         "(0 0 0 0 0 0)"
00276     );
00277 }
00278 
00279 
00280 void updateIncompressibleCase(const fvMesh& mesh)
00281 {
00282     Info<< "Case treated as incompressible" << nl << endl;
00283     createVolScalarField(mesh, "nut", dimArea/dimTime);
00284 
00285     replaceBoundaryType
00286     (
00287         mesh,
00288         "nut",
00289         incompressible::RASModels::nutWallFunctionFvPatchScalarField::typeName,
00290         "0"
00291     );
00292     replaceBoundaryType
00293     (
00294         mesh,
00295         "epsilon",
00296         incompressible::RASModels::epsilonWallFunctionFvPatchScalarField::
00297             typeName,
00298         "0"
00299     );
00300     replaceBoundaryType
00301     (
00302         mesh,
00303         "omega",
00304         incompressible::RASModels::omegaWallFunctionFvPatchScalarField::
00305             typeName,
00306         "0"
00307     );
00308     replaceBoundaryType
00309     (
00310         mesh,
00311         "k",
00312         incompressible::RASModels::kqRWallFunctionFvPatchField<scalar>::
00313             typeName,
00314         "0"
00315     );
00316     replaceBoundaryType
00317     (
00318         mesh,
00319         "q",
00320         incompressible::RASModels::kqRWallFunctionFvPatchField<scalar>::
00321             typeName,
00322         "0"
00323     );
00324     replaceBoundaryType
00325     (
00326         mesh,
00327         "R",
00328         incompressible::RASModels::kqRWallFunctionFvPatchField<symmTensor>::
00329             typeName,
00330         "(0 0 0 0 0 0)"
00331     );
00332 }
00333 
00334 
00335 int main(int argc, char *argv[])
00336 {
00337     #include "addTimeOptions.H"
00338     argList::validOptions.insert("compressible", "");
00339 
00340     #include "setRootCase.H"
00341     #include "createTime.H"
00342     #include "createMesh.H"
00343 
00344     bool compressible = args.optionFound("compressible");
00345 
00346     Info<< "Updating turbulence fields to operate using new run time "
00347         << "selectable" << nl << "wall functions"
00348         << nl << endl;
00349 
00350     if (compressible || caseIsCompressible(mesh))
00351     {
00352         updateCompressibleCase(mesh);
00353     }
00354     else
00355     {
00356         updateIncompressibleCase(mesh);
00357     }
00358 
00359     Info<< "End\n" << endl;
00360 
00361     return 0;
00362 }
00363 
00364 
00365 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd