DimensionedFieldReuseFunctions.H
Go to the documentation of this file.
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.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #ifndef DimensionedFieldReuseFunctions_H
27 #define DimensionedFieldReuseFunctions_H
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 template<class TypeR, class Type1, class GeoMesh>
38 {
39 public:
40 
42  (
44  const word& name,
45  const dimensionSet& dimensions
46  )
47  {
48  const DimensionedField<Type1, GeoMesh>& df1 = tdf1();
49 
51  (
53  (
54  IOobject
55  (
56  name,
57  df1.instance(),
58  df1.db()
59  ),
60  df1.mesh(),
61  dimensions
62  )
63  );
64  }
65 
66  static void clear(const tmp<DimensionedField<Type1, GeoMesh> >& tdf1)
67  {
68  tdf1.clear();
69  }
70 };
71 
72 
73 template<class TypeR, class GeoMesh>
74 class reuseTmpDimensionedField<TypeR, TypeR, GeoMesh>
75 {
76 public:
77 
79  (
81  const word& name,
82  const dimensionSet& dimensions
83  )
84  {
86  const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf1());
87 
88  if (tdf1.isTmp())
89  {
90  df1.rename(name);
91  df1.dimensions().reset(dimensions);
92  return tdf1;
93  }
94  else
95  {
97  (
99  (
100  IOobject
101  (
102  name,
103  df1.instance(),
104  df1.db()
105  ),
106  df1.mesh(),
107  dimensions
108  )
109  );
110  }
111  }
112 
113  static void clear(const tmp<DimensionedField<TypeR, GeoMesh> >& tdf1)
114  {
115  if (tdf1.isTmp())
116  {
117  tdf1.ptr();
118  }
119  }
120 };
121 
122 
123 template<class TypeR, class Type1, class Type12, class Type2, class GeoMesh>
125 {
126 public:
127 
129  (
132  const word& name,
133  const dimensionSet& dimensions
134  )
135  {
136  const DimensionedField<Type1, GeoMesh>& df1 = tdf1();
137 
139  (
141  (
142  IOobject
143  (
144  name,
145  df1.instance(),
146  df1.db()
147  ),
148  df1.mesh(),
149  dimensions
150  )
151  );
152  }
153 
154  static void clear
155  (
158  )
159  {
160  tdf1.clear();
161  tdf2.clear();
162  }
163 };
164 
165 
166 template<class TypeR, class Type1, class Type12, class GeoMesh>
167 class reuseTmpTmpDimensionedField<TypeR, Type1, Type12, TypeR, GeoMesh>
168 {
169 public:
170 
172  (
175  const word& name,
176  const dimensionSet& dimensions
177  )
178  {
179  const DimensionedField<Type1, GeoMesh>& df1 = tdf1();
181  const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf2());
182 
183  if (tdf2.isTmp())
184  {
185  df2.rename(name);
186  df2.dimensions().reset(dimensions);
187  return tdf2;
188  }
189  else
190  {
192  (
194  (
195  IOobject
196  (
197  name,
198  df1.instance(),
199  df1.db()
200  ),
201  df1.mesh(),
202  dimensions
203  )
204  );
205  }
206  }
207 
208  static void clear
209  (
212  )
213  {
214  tdf1.clear();
215  if (tdf2.isTmp())
216  {
217  tdf2.ptr();
218  }
219  }
220 };
221 
222 
223 template<class TypeR, class Type2, class GeoMesh>
224 class reuseTmpTmpDimensionedField<TypeR, TypeR, TypeR, Type2, GeoMesh>
225 {
226 public:
227 
229  (
232  const word& name,
233  const dimensionSet& dimensions
234  )
235  {
237  const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf1());
238 
239  if (tdf1.isTmp())
240  {
241  df1.rename(name);
242  df1.dimensions().reset(dimensions);
243  return tdf1;
244  }
245  else
246  {
248  (
250  (
251  IOobject
252  (
253  name,
254  df1.instance(),
255  df1.db()
256  ),
257  df1.mesh(),
258  dimensions
259  )
260  );
261  }
262  }
263 
264  static void clear
265  (
268  )
269  {
270  if (tdf1.isTmp())
271  {
272  tdf1.ptr();
273  }
274  tdf2.clear();
275  }
276 };
277 
278 
279 template<class TypeR, class GeoMesh>
280 class reuseTmpTmpDimensionedField<TypeR, TypeR, TypeR, TypeR, GeoMesh>
281 {
282 public:
283 
285  (
288  const word& name,
289  const dimensionSet& dimensions
290  )
291  {
293  const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf1());
295  const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf2());
296 
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  {
312  (
314  (
315  IOobject
316  (
317  name,
318  df1.instance(),
319  df1.db()
320  ),
321  df1.mesh(),
322  dimensions
323  )
324  );
325  }
326  }
327 
328  static void clear
329  (
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  }
345 };
346 
347 
348 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
349 
350 } // End namespace Foam
351 
352 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
353 
354 #endif
355 
356 // ************************************************************************* //
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::dimensionSet::reset
void reset(const dimensionSet &)
Definition: dimensionSet.C:108
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::dimensionSet
Dimension set for the base types.
Definition: dimensionSet.H:116
Foam::DimensionedField::mesh
const Mesh & mesh() const
Return mesh.
Definition: DimensionedFieldI.H:38
Foam::reuseTmpDimensionedField
Definition: DimensionedFieldReuseFunctions.H:37
Foam::reuseTmpDimensionedField< TypeR, TypeR, GeoMesh >::clear
static void clear(const tmp< DimensionedField< TypeR, GeoMesh > > &tdf1)
Definition: DimensionedFieldReuseFunctions.H:113
Foam::GeoMesh
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:46
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::DimensionedField::dimensions
const dimensionSet & dimensions() const
Return dimensions.
Definition: DimensionedFieldI.H:46
Foam::reuseTmpTmpDimensionedField
Definition: DimensionedFieldReuseFunctions.H:124
Foam::reuseTmpTmpDimensionedField::clear
static void clear(const tmp< DimensionedField< Type1, GeoMesh > > &tdf1, const tmp< DimensionedField< Type2, GeoMesh > > &tdf2)
Definition: DimensionedFieldReuseFunctions.H:155
Foam::reuseTmpDimensionedField::clear
static void clear(const tmp< DimensionedField< Type1, GeoMesh > > &tdf1)
Definition: DimensionedFieldReuseFunctions.H:66
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::reuseTmpTmpDimensionedField::New
static tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< Type1, GeoMesh > > &tdf1, const tmp< DimensionedField< Type2, GeoMesh > > &tdf2, const word &name, const dimensionSet &dimensions)
Definition: DimensionedFieldReuseFunctions.H:129
Foam::reuseTmpDimensionedField::New
static tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< Type1, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Definition: DimensionedFieldReuseFunctions.H:42
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:51