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

DimensionedFieldReuseFunctions.H

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 \*---------------------------------------------------------------------------*/
00025 
00026 #ifndef DimensionedFieldReuseFunctions_H
00027 #define DimensionedFieldReuseFunctions_H
00028 
00029 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033 
00034 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00035 
00036 template<class TypeR, class Type1, class GeoMesh>
00037 class reuseTmpDimensionedField
00038 {
00039 public:
00040 
00041     static tmp<DimensionedField<TypeR, GeoMesh> > New
00042     (
00043         const tmp<DimensionedField<Type1, GeoMesh> >& tdf1,
00044         const word& name,
00045         const dimensionSet& dimensions
00046     )
00047     {
00048         const DimensionedField<Type1, GeoMesh>& df1 = tdf1();
00049 
00050         return tmp<DimensionedField<TypeR, GeoMesh> >
00051         (
00052             new DimensionedField<TypeR, GeoMesh>
00053             (
00054                 IOobject
00055                 (
00056                     name,
00057                     df1.instance(),
00058                     df1.db()
00059                 ),
00060                 df1.mesh(),
00061                 dimensions
00062             )
00063         );
00064     }
00065 
00066     static void clear(const tmp<DimensionedField<Type1, GeoMesh> >& tdf1)
00067     {
00068         tdf1.clear();
00069     }
00070 };
00071 
00072 
00073 template<class TypeR, class GeoMesh>
00074 class reuseTmpDimensionedField<TypeR, TypeR, GeoMesh>
00075 {
00076 public:
00077 
00078     static tmp<DimensionedField<TypeR, GeoMesh> > New
00079     (
00080         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf1,
00081         const word& name,
00082         const dimensionSet& dimensions
00083     )
00084     {
00085         DimensionedField<TypeR, GeoMesh>& df1 =
00086             const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf1());
00087 
00088         if (tdf1.isTmp())
00089         {
00090             df1.rename(name);
00091             df1.dimensions().reset(dimensions);
00092             return tdf1;
00093         }
00094         else
00095         {
00096             return tmp<DimensionedField<TypeR, GeoMesh> >
00097             (
00098                 new DimensionedField<TypeR, GeoMesh>
00099                 (
00100                     IOobject
00101                     (
00102                         name,
00103                         df1.instance(),
00104                         df1.db()
00105                     ),
00106                     df1.mesh(),
00107                     dimensions
00108                 )
00109             );
00110         }
00111     }
00112 
00113     static void clear(const tmp<DimensionedField<TypeR, GeoMesh> >& tdf1)
00114     {
00115         if (tdf1.isTmp())
00116         {
00117             tdf1.ptr();
00118         }
00119     }
00120 };
00121 
00122 
00123 template<class TypeR, class Type1, class Type12, class Type2, class GeoMesh>
00124 class reuseTmpTmpDimensionedField
00125 {
00126 public:
00127 
00128     static tmp<DimensionedField<TypeR, GeoMesh> > New
00129     (
00130         const tmp<DimensionedField<Type1, GeoMesh> >& tdf1,
00131         const tmp<DimensionedField<Type2, GeoMesh> >& tdf2,
00132         const word& name,
00133         const dimensionSet& dimensions
00134     )
00135     {
00136         const DimensionedField<Type1, GeoMesh>& df1 = tdf1();
00137 
00138         return tmp<DimensionedField<TypeR, GeoMesh> >
00139         (
00140             new DimensionedField<TypeR, GeoMesh>
00141             (
00142                 IOobject
00143                 (
00144                     name,
00145                     df1.instance(),
00146                     df1.db()
00147                 ),
00148                 df1.mesh(),
00149                 dimensions
00150             )
00151         );
00152     }
00153 
00154     static void clear
00155     (
00156         const tmp<DimensionedField<Type1, GeoMesh> >& tdf1,
00157         const tmp<DimensionedField<Type2, GeoMesh> >& tdf2
00158     )
00159     {
00160         tdf1.clear();
00161         tdf2.clear();
00162     }
00163 };
00164 
00165 
00166 template<class TypeR, class Type1, class Type12, class GeoMesh>
00167 class reuseTmpTmpDimensionedField<TypeR, Type1, Type12, TypeR, GeoMesh>
00168 {
00169 public:
00170 
00171     static tmp<DimensionedField<TypeR, GeoMesh> > New
00172     (
00173         const tmp<DimensionedField<Type1, GeoMesh> >& tdf1,
00174         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf2,
00175         const word& name,
00176         const dimensionSet& dimensions
00177     )
00178     {
00179         const DimensionedField<Type1, GeoMesh>& df1 = tdf1();
00180         DimensionedField<TypeR, GeoMesh>& df2 =
00181             const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf2());
00182 
00183         if (tdf2.isTmp())
00184         {
00185             df2.rename(name);
00186             df2.dimensions().reset(dimensions);
00187             return tdf2;
00188         }
00189         else
00190         {
00191             return tmp<DimensionedField<TypeR, GeoMesh> >
00192             (
00193                 new DimensionedField<TypeR, GeoMesh>
00194                 (
00195                     IOobject
00196                     (
00197                         name,
00198                         df1.instance(),
00199                         df1.db()
00200                     ),
00201                     df1.mesh(),
00202                     dimensions
00203                 )
00204             );
00205         }
00206     }
00207 
00208     static void clear
00209     (
00210         const tmp<DimensionedField<Type1, GeoMesh> >& tdf1,
00211         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf2
00212     )
00213     {
00214         tdf1.clear();
00215         if (tdf2.isTmp())
00216         {
00217             tdf2.ptr();
00218         }
00219     }
00220 };
00221 
00222 
00223 template<class TypeR, class Type2, class GeoMesh>
00224 class reuseTmpTmpDimensionedField<TypeR, TypeR, TypeR, Type2, GeoMesh>
00225 {
00226 public:
00227 
00228     static tmp<DimensionedField<TypeR, GeoMesh> > New
00229     (
00230         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf1,
00231         const tmp<DimensionedField<Type2, GeoMesh> >& tdf2,
00232         const word& name,
00233         const dimensionSet& dimensions
00234     )
00235     {
00236         DimensionedField<TypeR, GeoMesh>& df1 =
00237             const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf1());
00238 
00239         if (tdf1.isTmp())
00240         {
00241             df1.rename(name);
00242             df1.dimensions().reset(dimensions);
00243             return tdf1;
00244         }
00245         else
00246         {
00247             return tmp<DimensionedField<TypeR, GeoMesh> >
00248             (
00249                 new DimensionedField<TypeR, GeoMesh>
00250                 (
00251                     IOobject
00252                     (
00253                         name,
00254                         df1.instance(),
00255                         df1.db()
00256                     ),
00257                     df1.mesh(),
00258                     dimensions
00259                 )
00260             );
00261         }
00262     }
00263 
00264     static void clear
00265     (
00266         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf1,
00267         const tmp<DimensionedField<Type2, GeoMesh> >& tdf2
00268     )
00269     {
00270         if (tdf1.isTmp())
00271         {
00272             tdf1.ptr();
00273         }
00274         tdf2.clear();
00275     }
00276 };
00277 
00278 
00279 template<class TypeR, class GeoMesh>
00280 class reuseTmpTmpDimensionedField<TypeR, TypeR, TypeR, TypeR, GeoMesh>
00281 {
00282 public:
00283 
00284     static tmp<DimensionedField<TypeR, GeoMesh> > New
00285     (
00286         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf1,
00287         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf2,
00288         const word& name,
00289         const dimensionSet& dimensions
00290     )
00291     {
00292         DimensionedField<TypeR, GeoMesh>& df1 =
00293             const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf1());
00294         DimensionedField<TypeR, GeoMesh>& df2 =
00295             const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf2());
00296 
00297         if (tdf1.isTmp())
00298         {
00299             df1.rename(name);
00300             df1.dimensions().reset(dimensions);
00301             return tdf1;
00302         }
00303         else if (tdf2.isTmp())
00304         {
00305             df2.rename(name);
00306             df2.dimensions().reset(dimensions);
00307             return tdf2;
00308         }
00309         else
00310         {
00311             return tmp<DimensionedField<TypeR, GeoMesh> >
00312             (
00313                 new DimensionedField<TypeR, GeoMesh>
00314                 (
00315                     IOobject
00316                     (
00317                         name,
00318                         df1.instance(),
00319                         df1.db()
00320                     ),
00321                     df1.mesh(),
00322                     dimensions
00323                 )
00324             );
00325         }
00326     }
00327 
00328     static void clear
00329     (
00330         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf1,
00331         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf2
00332     )
00333     {
00334         if (tdf1.isTmp())
00335         {
00336             tdf1.ptr();
00337             tdf2.clear();
00338         }
00339         else if (tdf2.isTmp())
00340         {
00341             tdf1.clear();
00342             tdf2.ptr();
00343         }
00344     }
00345 };
00346 
00347 
00348 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00349 
00350 } // End namespace Foam
00351 
00352 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00353 
00354 #endif
00355 
00356 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines