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

FieldReuseFunctions.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 FieldReuseFunctions_H
00027 #define FieldReuseFunctions_H
00028 
00029 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033 
00034 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00035 
00036 template<class TypeR, class Type1>
00037 class reuseTmp
00038 {
00039 public:
00040 
00041     static tmp<Field<TypeR> > New(const tmp<Field<Type1> >& tf1)
00042     {
00043         return tmp<Field<TypeR> >(new Field<TypeR>(tf1().size()));
00044     }
00045 
00046     static void clear(const tmp<Field<Type1> >& tf1)
00047     {
00048         tf1.clear();
00049     }
00050 };
00051 
00052 
00053 template<class TypeR>
00054 class reuseTmp<TypeR, TypeR>
00055 {
00056 public:
00057 
00058     static tmp<Field<TypeR> > New(const tmp<Field<TypeR> >& tf1)
00059     {
00060         if (tf1.isTmp())
00061         {
00062             return tf1;
00063         }
00064         else
00065         {
00066             return tmp<Field<TypeR> >(new Field<TypeR>(tf1().size()));
00067         }
00068     }
00069 
00070     static void clear(const tmp<Field<TypeR> >& tf1)
00071     {
00072         if (tf1.isTmp())
00073         {
00074             tf1.ptr();
00075         }
00076     }
00077 };
00078 
00079 
00080 template<class TypeR, class Type1, class Type12, class Type2>
00081 class reuseTmpTmp
00082 {
00083 public:
00084 
00085     static tmp<Field<TypeR> > New
00086     (
00087         const tmp<Field<Type1> >& tf1,
00088         const tmp<Field<Type2> >& tf2
00089     )
00090     {
00091         return tmp<Field<TypeR> >(new Field<TypeR>(tf1().size()));
00092     }
00093 
00094     static void clear
00095     (
00096         const tmp<Field<Type1> >& tf1,
00097         const tmp<Field<Type2> >& tf2
00098     )
00099     {
00100         tf1.clear();
00101         tf2.clear();
00102     }
00103 };
00104 
00105 
00106 template<class TypeR, class Type1, class Type12>
00107 class reuseTmpTmp<TypeR, Type1, Type12, TypeR>
00108 {
00109 public:
00110 
00111     static tmp<Field<TypeR> > New
00112     (
00113         const tmp<Field<Type1> >& tf1,
00114         const tmp<Field<TypeR> >& tf2
00115     )
00116     {
00117         if (tf2.isTmp())
00118         {
00119             return tf2;
00120         }
00121         else
00122         {
00123             return tmp<Field<TypeR> >(new Field<TypeR>(tf1().size()));
00124         }
00125     }
00126 
00127     static void clear
00128     (
00129         const tmp<Field<Type1> >& tf1,
00130         const tmp<Field<TypeR> >& tf2
00131     )
00132     {
00133         tf1.clear();
00134         if (tf2.isTmp())
00135         {
00136             tf2.ptr();
00137         }
00138     }
00139 };
00140 
00141 
00142 template<class TypeR, class Type2>
00143 class reuseTmpTmp<TypeR, TypeR, TypeR, Type2>
00144 {
00145 public:
00146 
00147     static tmp<Field<TypeR> > New
00148     (
00149         const tmp<Field<TypeR> >& tf1,
00150         const tmp<Field<Type2> >& tf2
00151     )
00152     {
00153         if (tf1.isTmp())
00154         {
00155             return tf1;
00156         }
00157         else
00158         {
00159             return tmp<Field<TypeR> >(new Field<TypeR>(tf1().size()));
00160         }
00161     }
00162 
00163     static void clear
00164     (
00165         const tmp<Field<TypeR> >& tf1,
00166         const tmp<Field<Type2> >& tf2
00167     )
00168     {
00169         if (tf1.isTmp())
00170         {
00171             tf1.ptr();
00172         }
00173         tf2.clear();
00174     }
00175 };
00176 
00177 
00178 template<class TypeR>
00179 class reuseTmpTmp<TypeR, TypeR, TypeR, TypeR>
00180 {
00181 public:
00182 
00183     static tmp<Field<TypeR> > New
00184     (
00185         const tmp<Field<TypeR> >& tf1,
00186         const tmp<Field<TypeR> >& tf2
00187     )
00188     {
00189         if (tf1.isTmp())
00190         {
00191             return tf1;
00192         }
00193         else if (tf2.isTmp())
00194         {
00195             return tf2;
00196         }
00197         else
00198         {
00199             return tmp<Field<TypeR> >(new Field<TypeR>(tf1().size()));
00200         }
00201     }
00202 
00203     static void clear
00204     (
00205         const tmp<Field<TypeR> >& tf1,
00206         const tmp<Field<TypeR> >& tf2
00207     )
00208     {
00209         if (tf1.isTmp())
00210         {
00211             tf1.ptr();
00212             tf2.clear();
00213         }
00214         else if (tf2.isTmp())
00215         {
00216             tf1.clear();
00217             tf2.ptr();
00218         }
00219     }
00220 };
00221 
00222 
00223 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00224 
00225 } // End namespace Foam
00226 
00227 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00228 
00229 #endif
00230 
00231 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines