ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / OpenFOAM / fields / GeometricFields / GeometricField / GeometricFieldReuseFunctions.H
blob5861a2efddc46834e3f099ee84e588b14c71367e
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 GeometricFieldReuseFunctions_H
27 #define GeometricFieldReuseFunctions_H
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 namespace Foam
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 template
38     class TypeR,
39     class Type1,
40     template<class> class PatchField,
41     class GeoMesh
43 class reuseTmpGeometricField
45 public:
47     static tmp<GeometricField<TypeR, PatchField, GeoMesh> > New
48     (
49         const tmp<GeometricField<Type1, PatchField, GeoMesh> >& tdf1,
50         const word& name,
51         const dimensionSet& dimensions
52     )
53     {
54         const GeometricField<Type1, PatchField, GeoMesh>& df1 = tdf1();
56         return tmp<GeometricField<TypeR, PatchField, GeoMesh> >
57         (
58             new GeometricField<TypeR, PatchField, GeoMesh>
59             (
60                 IOobject
61                 (
62                     name,
63                     df1.instance(),
64                     df1.db()
65                 ),
66                 df1.mesh(),
67                 dimensions
68             )
69         );
70     }
72     static void clear
73     (
74         const tmp<GeometricField<Type1, PatchField, GeoMesh> >& tdf1
75     )
76     {
77         tdf1.clear();
78     }
82 template<class TypeR, template<class> class PatchField, class GeoMesh>
83 class reuseTmpGeometricField<TypeR, TypeR, PatchField, GeoMesh>
85 public:
87     static tmp<GeometricField<TypeR, PatchField, GeoMesh> > New
88     (
89         const tmp<GeometricField<TypeR, PatchField, GeoMesh> >& tdf1,
90         const word& name,
91         const dimensionSet& dimensions
92     )
93     {
94         GeometricField<TypeR, PatchField, GeoMesh>& df1 =
95             const_cast<GeometricField<TypeR, PatchField, GeoMesh>& >(tdf1());
97         if (tdf1.isTmp())
98         {
99             df1.rename(name);
100             df1.dimensions().reset(dimensions);
101             return tdf1;
102         }
103         else
104         {
105             return tmp<GeometricField<TypeR, PatchField, GeoMesh> >
106             (
107                 new GeometricField<TypeR, PatchField, GeoMesh>
108                 (
109                     IOobject
110                     (
111                         name,
112                         df1.instance(),
113                         df1.db()
114                     ),
115                     df1.mesh(),
116                     dimensions
117                 )
118             );
119         }
120     }
122     static void clear
123     (
124         const tmp<GeometricField<TypeR, PatchField, GeoMesh> >& tdf1
125     )
126     {
127         if (tdf1.isTmp())
128         {
129             tdf1.ptr();
130         }
131     }
135 template
137     class TypeR,
138     class Type1,
139     class Type12,
140     class Type2,
141     template<class> class PatchField,
142     class GeoMesh
144 class reuseTmpTmpGeometricField
146 public:
148     static tmp<GeometricField<TypeR, PatchField, GeoMesh> > New
149     (
150         const tmp<GeometricField<Type1, PatchField, GeoMesh> >& tdf1,
151         const tmp<GeometricField<Type2, PatchField, GeoMesh> >& tdf2,
152         const word& name,
153         const dimensionSet& dimensions
154     )
155     {
156         const GeometricField<Type1, PatchField, GeoMesh>& df1 = tdf1();
158         return tmp<GeometricField<TypeR, PatchField, GeoMesh> >
159         (
160             new GeometricField<TypeR, PatchField, GeoMesh>
161             (
162                 IOobject
163                 (
164                     name,
165                     df1.instance(),
166                     df1.db()
167                 ),
168                 df1.mesh(),
169                 dimensions
170             )
171         );
172     }
174     static void clear
175     (
176         const tmp<GeometricField<Type1, PatchField, GeoMesh> >& tdf1,
177         const tmp<GeometricField<Type2, PatchField, GeoMesh> >& tdf2
178     )
179     {
180         tdf1.clear();
181         tdf2.clear();
182     }
186 template
188     class TypeR,
189     class Type1,
190     class Type12,
191     template<class> class PatchField,
192     class GeoMesh
194 class reuseTmpTmpGeometricField
195     <TypeR, Type1, Type12, TypeR, PatchField, GeoMesh>
197 public:
199     static tmp<GeometricField<TypeR, PatchField, GeoMesh> > New
200     (
201         const tmp<GeometricField<Type1, PatchField, GeoMesh> >& tdf1,
202         const tmp<GeometricField<TypeR, PatchField, GeoMesh> >& tdf2,
203         const word& name,
204         const dimensionSet& dimensions
205     )
206     {
207         const GeometricField<Type1, PatchField, GeoMesh>& df1 = tdf1();
208         GeometricField<TypeR, PatchField, GeoMesh>& df2 =
209             const_cast<GeometricField<TypeR, PatchField, GeoMesh>& >(tdf2());
211         if (tdf2.isTmp())
212         {
213             df2.rename(name);
214             df2.dimensions().reset(dimensions);
215             return tdf2;
216         }
217         else
218         {
219             return tmp<GeometricField<TypeR, PatchField, GeoMesh> >
220             (
221                 new GeometricField<TypeR, PatchField, GeoMesh>
222                 (
223                     IOobject
224                     (
225                         name,
226                         df1.instance(),
227                         df1.db()
228                     ),
229                     df1.mesh(),
230                     dimensions
231                 )
232             );
233         }
234     }
236     static void clear
237     (
238         const tmp<GeometricField<Type1, PatchField, GeoMesh> >& tdf1,
239         const tmp<GeometricField<TypeR, PatchField, GeoMesh> >& tdf2
240     )
241     {
242         tdf1.clear();
243         if (tdf2.isTmp())
244         {
245             tdf2.ptr();
246         }
247     }
251 template
253     class TypeR,
254     class Type2,
255     template<class> class PatchField,
256     class GeoMesh
258 class reuseTmpTmpGeometricField<TypeR, TypeR, TypeR, Type2, PatchField, GeoMesh>
260 public:
262     static tmp<GeometricField<TypeR, PatchField, GeoMesh> > New
263     (
264         const tmp<GeometricField<TypeR, PatchField, GeoMesh> >& tdf1,
265         const tmp<GeometricField<Type2, PatchField, GeoMesh> >& tdf2,
266         const word& name,
267         const dimensionSet& dimensions
268     )
269     {
270         GeometricField<TypeR, PatchField, GeoMesh>& df1 =
271             const_cast<GeometricField<TypeR, PatchField, GeoMesh>& >(tdf1());
273         if (tdf1.isTmp())
274         {
275             df1.rename(name);
276             df1.dimensions().reset(dimensions);
277             return tdf1;
278         }
279         else
280         {
281             return tmp<GeometricField<TypeR, PatchField, GeoMesh> >
282             (
283                 new GeometricField<TypeR, PatchField, GeoMesh>
284                 (
285                     IOobject
286                     (
287                         name,
288                         df1.instance(),
289                         df1.db()
290                     ),
291                     df1.mesh(),
292                     dimensions
293                 )
294             );
295         }
296     }
298     static void clear
299     (
300         const tmp<GeometricField<TypeR, PatchField, GeoMesh> >& tdf1,
301         const tmp<GeometricField<Type2, PatchField, GeoMesh> >& tdf2
302     )
303     {
304         if (tdf1.isTmp())
305         {
306             tdf1.ptr();
307         }
308         tdf2.clear();
309     }
313 template<class TypeR, template<class> class PatchField, class GeoMesh>
314 class reuseTmpTmpGeometricField<TypeR, TypeR, TypeR, TypeR, PatchField, GeoMesh>
316 public:
318     static tmp<GeometricField<TypeR, PatchField, GeoMesh> > New
319     (
320         const tmp<GeometricField<TypeR, PatchField, GeoMesh> >& tdf1,
321         const tmp<GeometricField<TypeR, PatchField, GeoMesh> >& tdf2,
322         const word& name,
323         const dimensionSet& dimensions
324     )
325     {
326         GeometricField<TypeR, PatchField, GeoMesh>& df1 =
327             const_cast<GeometricField<TypeR, PatchField, GeoMesh>& >(tdf1());
328         GeometricField<TypeR, PatchField, GeoMesh>& df2 =
329             const_cast<GeometricField<TypeR, PatchField, GeoMesh>& >(tdf2());
331         if (tdf1.isTmp())
332         {
333             df1.rename(name);
334             df1.dimensions().reset(dimensions);
335             return tdf1;
336         }
337         else if (tdf2.isTmp())
338         {
339             df2.rename(name);
340             df2.dimensions().reset(dimensions);
341             return tdf2;
342         }
343         else
344         {
345             return tmp<GeometricField<TypeR, PatchField, GeoMesh> >
346             (
347                 new GeometricField<TypeR, PatchField, GeoMesh>
348                 (
349                     IOobject
350                     (
351                         name,
352                         df1.instance(),
353                         df1.db()
354                     ),
355                     df1.mesh(),
356                     dimensions
357                 )
358             );
359         }
360     }
362     static void clear
363     (
364         const tmp<GeometricField<TypeR, PatchField, GeoMesh> >& tdf1,
365         const tmp<GeometricField<TypeR, PatchField, GeoMesh> >& tdf2
366     )
367     {
368         if (tdf1.isTmp())
369         {
370             tdf1.ptr();
371             tdf2.clear();
372         }
373         else if (tdf2.isTmp())
374         {
375             tdf1.clear();
376             tdf2.ptr();
377         }
378     }
382 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
384 } // End namespace Foam
386 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
388 #endif
390 // ************************************************************************* //