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

backwardsCompatibilityWallFunctionsTemplates.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) 2008-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 \*---------------------------------------------------------------------------*/
00026 
00027 #include "backwardsCompatibilityWallFunctions.H"
00028 #include "Time.H"
00029 #include "OSspecific.H"
00030 
00031 #include "wallPolyPatch.H"
00032 
00033 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00034 
00035 namespace Foam
00036 {
00037 namespace incompressible
00038 {
00039 
00040 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00041 
00042 template<class Type, class PatchType>
00043 tmp<GeometricField<Type, fvPatchField, volMesh> >
00044 autoCreateWallFunctionField
00045 (
00046     const word& fieldName,
00047     const fvMesh& mesh
00048 )
00049 {
00050     IOobject nutHeader
00051     (
00052         "nut",
00053         mesh.time().timeName(),
00054         mesh,
00055         IOobject::MUST_READ
00056     );
00057 
00058     typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
00059 
00060     if (nutHeader.headerOk())
00061     {
00062         return tmp<fieldType>
00063         (
00064             new fieldType
00065             (
00066                 IOobject
00067                 (
00068                     fieldName,
00069                     mesh.time().timeName(),
00070                     mesh,
00071                     IOobject::MUST_READ,
00072                     IOobject::NO_WRITE,
00073                     false
00074                 ),
00075                 mesh
00076             )
00077         );
00078     }
00079     else
00080     {
00081         Info<< "--> Upgrading " << fieldName
00082             << " to employ run-time selectable wall functions" << endl;
00083 
00084         // Read existing field
00085         IOobject ioObj
00086         (
00087             fieldName,
00088             mesh.time().timeName(),
00089             mesh,
00090             IOobject::MUST_READ,
00091             IOobject::NO_WRITE,
00092             false
00093         );
00094 
00095         tmp<fieldType> fieldOrig
00096         (
00097             new fieldType
00098             (
00099                 ioObj,
00100                 mesh
00101             )
00102         );
00103 
00104         // rename file
00105         Info<< "    Backup original " << fieldName << " to "
00106             << fieldName << ".old" << endl;
00107         mvBak(ioObj.objectPath(), "old");
00108 
00109 
00110         PtrList<fvPatchField<Type> > newPatchFields(mesh.boundary().size());
00111 
00112         forAll(newPatchFields, patchI)
00113         {
00114             if (isType<wallPolyPatch>(mesh.boundaryMesh()[patchI]))
00115             {
00116                 newPatchFields.set
00117                 (
00118                     patchI,
00119                     new PatchType
00120                     (
00121                         mesh.boundary()[patchI],
00122                         fieldOrig().dimensionedInternalField()
00123                     )
00124                 );
00125                 newPatchFields[patchI] == fieldOrig().boundaryField()[patchI];
00126             }
00127             else
00128             {
00129                 newPatchFields.set
00130                 (
00131                     patchI,
00132                     fieldOrig().boundaryField()[patchI].clone()
00133                 );
00134             }
00135         }
00136 
00137         tmp<fieldType> fieldNew
00138         (
00139             new fieldType
00140             (
00141                 IOobject
00142                 (
00143                     fieldName,
00144                     mesh.time().timeName(),
00145                     mesh,
00146                     IOobject::NO_READ,
00147                     IOobject::NO_WRITE,
00148                     false
00149                 ),
00150                 mesh,
00151                 fieldOrig().dimensions(),
00152                 fieldOrig().internalField(),
00153                 newPatchFields
00154             )
00155         );
00156 
00157         Info<< "    Writing updated " << fieldName << endl;
00158         fieldNew().write();
00159 
00160         return fieldNew;
00161     }
00162 }
00163 
00164 
00165 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00166 
00167 } // End namespace incompressible
00168 } // End namespace Foam
00169 
00170 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd