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

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