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

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