fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / OpenFOAM / fields / DimensionedFields / DimensionedField / DimensionedFieldReuseFunctions.H
blob4aafdb7f8a46c0a4cb1331c733f81729a5b9419c
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #ifndef DimensionedFieldReuseFunctions_H
28 #define DimensionedFieldReuseFunctions_H
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 namespace Foam
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 template<class TypeR, class Type1, class GeoMesh>
38 class reuseTmpDimensionedField
40 public:
42     static tmp<DimensionedField<TypeR, GeoMesh> > New
43     (
44         const tmp<DimensionedField<Type1, GeoMesh> >& tdf1,
45         const word& name,
46         const dimensionSet& dimensions
47     )
48     {
49         const DimensionedField<Type1, GeoMesh>& df1 = tdf1();
51         return tmp<DimensionedField<TypeR, GeoMesh> >
52         (
53             new DimensionedField<TypeR, GeoMesh>
54             (
55                 IOobject
56                 (
57                     name,
58                     df1.instance(),
59                     df1.db()
60                 ),
61                 df1.mesh(),
62                 dimensions
63             )
64         );
65     }
67     static void clear(const tmp<DimensionedField<Type1, GeoMesh> >& tdf1)
68     {
69         tdf1.clear();
70     }
74 template<class TypeR, class GeoMesh>
75 class reuseTmpDimensionedField<TypeR, TypeR, GeoMesh>
77 public:
79     static tmp<DimensionedField<TypeR, GeoMesh> > New
80     (
81         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf1,
82         const word& name,
83         const dimensionSet& dimensions
84     )
85     {
86         DimensionedField<TypeR, GeoMesh>& df1 =
87             const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf1());
89         if (tdf1.isTmp())
90         {
91             df1.rename(name);
92             df1.dimensions().reset(dimensions);
93             return tdf1;
94         }
95         else
96         {
97             return tmp<DimensionedField<TypeR, GeoMesh> >
98             (
99                 new DimensionedField<TypeR, GeoMesh>
100                 (
101                     IOobject
102                     (
103                         name,
104                         df1.instance(),
105                         df1.db()
106                     ),
107                     df1.mesh(),
108                     dimensions
109                 )
110             );
111         }
112     }
114     static void clear(const tmp<DimensionedField<TypeR, GeoMesh> >& tdf1)
115     {
116         if (tdf1.isTmp())
117         {
118             tdf1.ptr();
119         }
120     }
124 template<class TypeR, class Type1, class Type12, class Type2, class GeoMesh>
125 class reuseTmpTmpDimensionedField
127 public:
129     static tmp<DimensionedField<TypeR, GeoMesh> > New
130     (
131         const tmp<DimensionedField<Type1, GeoMesh> >& tdf1,
132         const tmp<DimensionedField<Type2, GeoMesh> >& tdf2,
133         const word& name,
134         const dimensionSet& dimensions
135     )
136     {
137         const DimensionedField<Type1, GeoMesh>& df1 = tdf1();
139         return tmp<DimensionedField<TypeR, GeoMesh> >
140         (
141             new DimensionedField<TypeR, GeoMesh>
142             (
143                 IOobject
144                 (
145                     name,
146                     df1.instance(),
147                     df1.db()
148                 ),
149                 df1.mesh(),
150                 dimensions
151             )
152         );
153     }
155     static void clear
156     (
157         const tmp<DimensionedField<Type1, GeoMesh> >& tdf1,
158         const tmp<DimensionedField<Type2, GeoMesh> >& tdf2
159     )
160     {
161         tdf1.clear();
162         tdf2.clear();
163     }
167 template<class TypeR, class Type1, class Type12, class GeoMesh>
168 class reuseTmpTmpDimensionedField<TypeR, Type1, Type12, TypeR, GeoMesh>
170 public:
172     static tmp<DimensionedField<TypeR, GeoMesh> > New
173     (
174         const tmp<DimensionedField<Type1, GeoMesh> >& tdf1,
175         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf2,
176         const word& name,
177         const dimensionSet& dimensions
178     )
179     {
180         const DimensionedField<Type1, GeoMesh>& df1 = tdf1();
181         DimensionedField<TypeR, GeoMesh>& df2 =
182             const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf2());
184         if (tdf2.isTmp())
185         {
186             df2.rename(name);
187             df2.dimensions().reset(dimensions);
188             return tdf2;
189         }
190         else
191         {
192             return tmp<DimensionedField<TypeR, GeoMesh> >
193             (
194                 new DimensionedField<TypeR, GeoMesh>
195                 (
196                     IOobject
197                     (
198                         name,
199                         df1.instance(),
200                         df1.db()
201                     ),
202                     df1.mesh(),
203                     dimensions
204                 )
205             );
206         }
207     }
209     static void clear
210     (
211         const tmp<DimensionedField<Type1, GeoMesh> >& tdf1,
212         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf2
213     )
214     {
215         tdf1.clear();
216         if (tdf2.isTmp())
217         {
218             tdf2.ptr();
219         }
220     }
224 template<class TypeR, class Type2, class GeoMesh>
225 class reuseTmpTmpDimensionedField<TypeR, TypeR, TypeR, Type2, GeoMesh>
227 public:
229     static tmp<DimensionedField<TypeR, GeoMesh> > New
230     (
231         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf1,
232         const tmp<DimensionedField<Type2, GeoMesh> >& tdf2,
233         const word& name,
234         const dimensionSet& dimensions
235     )
236     {
237         DimensionedField<TypeR, GeoMesh>& df1 =
238             const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf1());
240         if (tdf1.isTmp())
241         {
242             df1.rename(name);
243             df1.dimensions().reset(dimensions);
244             return tdf1;
245         }
246         else
247         {
248             return tmp<DimensionedField<TypeR, GeoMesh> >
249             (
250                 new DimensionedField<TypeR, GeoMesh>
251                 (
252                     IOobject
253                     (
254                         name,
255                         df1.instance(),
256                         df1.db()
257                     ),
258                     df1.mesh(),
259                     dimensions
260                 )
261             );
262         }
263     }
265     static void clear
266     (
267         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf1,
268         const tmp<DimensionedField<Type2, GeoMesh> >& tdf2
269     )
270     {
271         if (tdf1.isTmp())
272         {
273             tdf1.ptr();
274         }
275         tdf2.clear();
276     }
280 template<class TypeR, class GeoMesh>
281 class reuseTmpTmpDimensionedField<TypeR, TypeR, TypeR, TypeR, GeoMesh>
283 public:
285     static tmp<DimensionedField<TypeR, GeoMesh> > New
286     (
287         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf1,
288         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf2,
289         const word& name,
290         const dimensionSet& dimensions
291     )
292     {
293         DimensionedField<TypeR, GeoMesh>& df1 =
294             const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf1());
295         DimensionedField<TypeR, GeoMesh>& df2 =
296             const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf2());
298         if (tdf1.isTmp())
299         {
300             df1.rename(name);
301             df1.dimensions().reset(dimensions);
302             return tdf1;
303         }
304         else if (tdf2.isTmp())
305         {
306             df2.rename(name);
307             df2.dimensions().reset(dimensions);
308             return tdf2;
309         }
310         else
311         {
312             return tmp<DimensionedField<TypeR, GeoMesh> >
313             (
314                 new DimensionedField<TypeR, GeoMesh>
315                 (
316                     IOobject
317                     (
318                         name,
319                         df1.instance(),
320                         df1.db()
321                     ),
322                     df1.mesh(),
323                     dimensions
324                 )
325             );
326         }
327     }
329     static void clear
330     (
331         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf1,
332         const tmp<DimensionedField<TypeR, GeoMesh> >& tdf2
333     )
334     {
335         if (tdf1.isTmp())
336         {
337             tdf1.ptr();
338             tdf2.clear();
339         }
340         else if (tdf2.isTmp())
341         {
342             tdf1.clear();
343             tdf2.ptr();
344         }
345     }
349 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
351 } // End namespace Foam
353 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
355 #endif
357 // ************************************************************************* //