ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / OpenFOAM / fields / DimensionedFields / DimensionedField / DimensionedFieldReuseFunctions.H
blob806745808f2451c37115f2edb2edb32cf9cb9497
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by
13     the Free Software Foundation, either version 3 of the License, or
14     (at your option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #ifndef DimensionedFieldReuseFunctions_H
27 #define DimensionedFieldReuseFunctions_H
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 namespace Foam
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 template<class TypeR, class Type1, class GeoMesh>
37 class reuseTmpDimensionedField
39 public:
41     static tmp<DimensionedField<TypeR, GeoMesh> > New
42     (
43         const tmp<DimensionedField<Type1, GeoMesh> >& tdf1,
44         const word& name,
45         const dimensionSet& dimensions
46     )
47     {
48         const DimensionedField<Type1, GeoMesh>& df1 = tdf1();
50         return tmp<DimensionedField<TypeR, GeoMesh> >
51         (
52             new DimensionedField<TypeR, GeoMesh>
53             (
54                 IOobject
55                 (
56                     name,
57                     df1.instance(),
58                     df1.db()
59                 ),
60                 df1.mesh(),
61                 dimensions
62             )
63         );
64     }
66     static void clear(const tmp<DimensionedField<Type1, GeoMesh> >& tdf1)
67     {
68         tdf1.clear();
69     }
73 template<class TypeR, class GeoMesh>
74 class reuseTmpDimensionedField<TypeR, TypeR, GeoMesh>
76 public:
78     static tmp<DimensionedField<TypeR, GeoMesh> > New
79     (
80         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf1,
81         const word& name,
82         const dimensionSet& dimensions
83     )
84     {
85         DimensionedField<TypeR, GeoMesh>& df1 =
86             const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf1());
88         if (tdf1.isTmp())
89         {
90             df1.rename(name);
91             df1.dimensions().reset(dimensions);
92             return tdf1;
93         }
94         else
95         {
96             return tmp<DimensionedField<TypeR, GeoMesh> >
97             (
98                 new DimensionedField<TypeR, GeoMesh>
99                 (
100                     IOobject
101                     (
102                         name,
103                         df1.instance(),
104                         df1.db()
105                     ),
106                     df1.mesh(),
107                     dimensions
108                 )
109             );
110         }
111     }
113     static void clear(const tmp<DimensionedField<TypeR, GeoMesh> >& tdf1)
114     {
115         if (tdf1.isTmp())
116         {
117             tdf1.ptr();
118         }
119     }
123 template<class TypeR, class Type1, class Type12, class Type2, class GeoMesh>
124 class reuseTmpTmpDimensionedField
126 public:
128     static tmp<DimensionedField<TypeR, GeoMesh> > New
129     (
130         const tmp<DimensionedField<Type1, GeoMesh> >& tdf1,
131         const tmp<DimensionedField<Type2, GeoMesh> >& tdf2,
132         const word& name,
133         const dimensionSet& dimensions
134     )
135     {
136         const DimensionedField<Type1, GeoMesh>& df1 = tdf1();
138         return tmp<DimensionedField<TypeR, GeoMesh> >
139         (
140             new DimensionedField<TypeR, GeoMesh>
141             (
142                 IOobject
143                 (
144                     name,
145                     df1.instance(),
146                     df1.db()
147                 ),
148                 df1.mesh(),
149                 dimensions
150             )
151         );
152     }
154     static void clear
155     (
156         const tmp<DimensionedField<Type1, GeoMesh> >& tdf1,
157         const tmp<DimensionedField<Type2, GeoMesh> >& tdf2
158     )
159     {
160         tdf1.clear();
161         tdf2.clear();
162     }
166 template<class TypeR, class Type1, class Type12, class GeoMesh>
167 class reuseTmpTmpDimensionedField<TypeR, Type1, Type12, TypeR, GeoMesh>
169 public:
171     static tmp<DimensionedField<TypeR, GeoMesh> > New
172     (
173         const tmp<DimensionedField<Type1, GeoMesh> >& tdf1,
174         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf2,
175         const word& name,
176         const dimensionSet& dimensions
177     )
178     {
179         const DimensionedField<Type1, GeoMesh>& df1 = tdf1();
180         DimensionedField<TypeR, GeoMesh>& df2 =
181             const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf2());
183         if (tdf2.isTmp())
184         {
185             df2.rename(name);
186             df2.dimensions().reset(dimensions);
187             return tdf2;
188         }
189         else
190         {
191             return tmp<DimensionedField<TypeR, GeoMesh> >
192             (
193                 new DimensionedField<TypeR, GeoMesh>
194                 (
195                     IOobject
196                     (
197                         name,
198                         df1.instance(),
199                         df1.db()
200                     ),
201                     df1.mesh(),
202                     dimensions
203                 )
204             );
205         }
206     }
208     static void clear
209     (
210         const tmp<DimensionedField<Type1, GeoMesh> >& tdf1,
211         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf2
212     )
213     {
214         tdf1.clear();
215         if (tdf2.isTmp())
216         {
217             tdf2.ptr();
218         }
219     }
223 template<class TypeR, class Type2, class GeoMesh>
224 class reuseTmpTmpDimensionedField<TypeR, TypeR, TypeR, Type2, GeoMesh>
226 public:
228     static tmp<DimensionedField<TypeR, GeoMesh> > New
229     (
230         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf1,
231         const tmp<DimensionedField<Type2, GeoMesh> >& tdf2,
232         const word& name,
233         const dimensionSet& dimensions
234     )
235     {
236         DimensionedField<TypeR, GeoMesh>& df1 =
237             const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf1());
239         if (tdf1.isTmp())
240         {
241             df1.rename(name);
242             df1.dimensions().reset(dimensions);
243             return tdf1;
244         }
245         else
246         {
247             return tmp<DimensionedField<TypeR, GeoMesh> >
248             (
249                 new DimensionedField<TypeR, GeoMesh>
250                 (
251                     IOobject
252                     (
253                         name,
254                         df1.instance(),
255                         df1.db()
256                     ),
257                     df1.mesh(),
258                     dimensions
259                 )
260             );
261         }
262     }
264     static void clear
265     (
266         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf1,
267         const tmp<DimensionedField<Type2, GeoMesh> >& tdf2
268     )
269     {
270         if (tdf1.isTmp())
271         {
272             tdf1.ptr();
273         }
274         tdf2.clear();
275     }
279 template<class TypeR, class GeoMesh>
280 class reuseTmpTmpDimensionedField<TypeR, TypeR, TypeR, TypeR, GeoMesh>
282 public:
284     static tmp<DimensionedField<TypeR, GeoMesh> > New
285     (
286         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf1,
287         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf2,
288         const word& name,
289         const dimensionSet& dimensions
290     )
291     {
292         DimensionedField<TypeR, GeoMesh>& df1 =
293             const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf1());
294         DimensionedField<TypeR, GeoMesh>& df2 =
295             const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf2());
297         if (tdf1.isTmp())
298         {
299             df1.rename(name);
300             df1.dimensions().reset(dimensions);
301             return tdf1;
302         }
303         else if (tdf2.isTmp())
304         {
305             df2.rename(name);
306             df2.dimensions().reset(dimensions);
307             return tdf2;
308         }
309         else
310         {
311             return tmp<DimensionedField<TypeR, GeoMesh> >
312             (
313                 new DimensionedField<TypeR, GeoMesh>
314                 (
315                     IOobject
316                     (
317                         name,
318                         df1.instance(),
319                         df1.db()
320                     ),
321                     df1.mesh(),
322                     dimensions
323                 )
324             );
325         }
326     }
328     static void clear
329     (
330         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf1,
331         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf2
332     )
333     {
334         if (tdf1.isTmp())
335         {
336             tdf1.ptr();
337             tdf2.clear();
338         }
339         else if (tdf2.isTmp())
340         {
341             tdf1.clear();
342             tdf2.ptr();
343         }
344     }
348 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
350 } // End namespace Foam
352 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
354 #endif
356 // ************************************************************************* //