GeometricFieldReuseFunctions.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 GeometricFieldReuseFunctions_H
27 #define GeometricFieldReuseFunctions_H
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 template
37 <
38  class TypeR,
39  class Type1,
40  template<class> class PatchField,
41  class GeoMesh
42 >
44 {
45 public:
46 
48  (
50  const word& name,
51  const dimensionSet& dimensions
52  )
53  {
55 
57  (
59  (
60  IOobject
61  (
62  name,
63  df1.instance(),
64  df1.db()
65  ),
66  df1.mesh(),
67  dimensions
68  )
69  );
70  }
71 
72  static void clear
73  (
75  )
76  {
77  tdf1.clear();
78  }
79 };
80 
81 
82 template<class TypeR, template<class> class PatchField, class GeoMesh>
83 class reuseTmpGeometricField<TypeR, TypeR, PatchField, GeoMesh>
84 {
85 public:
86 
88  (
90  const word& name,
91  const dimensionSet& dimensions
92  )
93  {
95  const_cast<GeometricField<TypeR, PatchField, GeoMesh>& >(tdf1());
96 
97  if (tdf1.isTmp())
98  {
99  df1.rename(name);
100  df1.dimensions().reset(dimensions);
101  return tdf1;
102  }
103  else
104  {
106  (
108  (
109  IOobject
110  (
111  name,
112  df1.instance(),
113  df1.db()
114  ),
115  df1.mesh(),
116  dimensions
117  )
118  );
119  }
120  }
121 
122  static void clear
123  (
125  )
126  {
127  if (tdf1.isTmp())
128  {
129  tdf1.ptr();
130  }
131  }
132 };
133 
134 
135 template
136 <
137  class TypeR,
138  class Type1,
139  class Type12,
140  class Type2,
141  template<class> class PatchField,
142  class GeoMesh
143 >
145 {
146 public:
147 
149  (
152  const word& name,
153  const dimensionSet& dimensions
154  )
155  {
156  const GeometricField<Type1, PatchField, GeoMesh>& df1 = tdf1();
157 
159  (
161  (
162  IOobject
163  (
164  name,
165  df1.instance(),
166  df1.db()
167  ),
168  df1.mesh(),
169  dimensions
170  )
171  );
172  }
173 
174  static void clear
175  (
178  )
179  {
180  tdf1.clear();
181  tdf2.clear();
182  }
183 };
184 
185 
186 template
187 <
188  class TypeR,
189  class Type1,
190  class Type12,
191  template<class> class PatchField,
192  class GeoMesh
193 >
195  <TypeR, Type1, Type12, TypeR, PatchField, GeoMesh>
196 {
197 public:
198 
200  (
203  const word& name,
204  const dimensionSet& dimensions
205  )
206  {
207  const GeometricField<Type1, PatchField, GeoMesh>& df1 = tdf1();
209  const_cast<GeometricField<TypeR, PatchField, GeoMesh>& >(tdf2());
210 
211  if (tdf2.isTmp())
212  {
213  df2.rename(name);
214  df2.dimensions().reset(dimensions);
215  return tdf2;
216  }
217  else
218  {
220  (
222  (
223  IOobject
224  (
225  name,
226  df1.instance(),
227  df1.db()
228  ),
229  df1.mesh(),
230  dimensions
231  )
232  );
233  }
234  }
235 
236  static void clear
237  (
240  )
241  {
242  tdf1.clear();
243  if (tdf2.isTmp())
244  {
245  tdf2.ptr();
246  }
247  }
248 };
249 
250 
251 template
252 <
253  class TypeR,
254  class Type2,
255  template<class> class PatchField,
256  class GeoMesh
257 >
258 class reuseTmpTmpGeometricField<TypeR, TypeR, TypeR, Type2, PatchField, GeoMesh>
259 {
260 public:
261 
263  (
266  const word& name,
267  const dimensionSet& dimensions
268  )
269  {
271  const_cast<GeometricField<TypeR, PatchField, GeoMesh>& >(tdf1());
272 
273  if (tdf1.isTmp())
274  {
275  df1.rename(name);
276  df1.dimensions().reset(dimensions);
277  return tdf1;
278  }
279  else
280  {
282  (
284  (
285  IOobject
286  (
287  name,
288  df1.instance(),
289  df1.db()
290  ),
291  df1.mesh(),
292  dimensions
293  )
294  );
295  }
296  }
297 
298  static void clear
299  (
302  )
303  {
304  if (tdf1.isTmp())
305  {
306  tdf1.ptr();
307  }
308  tdf2.clear();
309  }
310 };
311 
312 
313 template<class TypeR, template<class> class PatchField, class GeoMesh>
314 class reuseTmpTmpGeometricField<TypeR, TypeR, TypeR, TypeR, PatchField, GeoMesh>
315 {
316 public:
317 
319  (
322  const word& name,
323  const dimensionSet& dimensions
324  )
325  {
327  const_cast<GeometricField<TypeR, PatchField, GeoMesh>& >(tdf1());
329  const_cast<GeometricField<TypeR, PatchField, GeoMesh>& >(tdf2());
330 
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  {
346  (
348  (
349  IOobject
350  (
351  name,
352  df1.instance(),
353  df1.db()
354  ),
355  df1.mesh(),
356  dimensions
357  )
358  );
359  }
360  }
361 
362  static void clear
363  (
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  }
379 };
380 
381 
382 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
383 
384 } // End namespace Foam
385 
386 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
387 
388 #endif
389 
390 // ************************************************************************* //
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
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::reuseTmpTmpGeometricField::New
static tmp< GeometricField< TypeR, PatchField, GeoMesh > > New(const tmp< GeometricField< Type1, PatchField, GeoMesh > > &tdf1, const tmp< GeometricField< Type2, PatchField, GeoMesh > > &tdf2, const word &name, const dimensionSet &dimensions)
Definition: GeometricFieldReuseFunctions.H:149
Foam::reuseTmpGeometricField
Definition: GeometricFieldReuseFunctions.H:43
Foam::reuseTmpGeometricField::clear
static void clear(const tmp< GeometricField< Type1, PatchField, GeoMesh > > &tdf1)
Definition: GeometricFieldReuseFunctions.H:73
Foam::GeoMesh
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:46
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::reuseTmpGeometricField::New
static tmp< GeometricField< TypeR, PatchField, GeoMesh > > New(const tmp< GeometricField< Type1, PatchField, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Definition: GeometricFieldReuseFunctions.H:48
Foam::reuseTmpTmpGeometricField
Definition: GeometricFieldReuseFunctions.H:144
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::reuseTmpTmpGeometricField::clear
static void clear(const tmp< GeometricField< Type1, PatchField, GeoMesh > > &tdf1, const tmp< GeometricField< Type2, PatchField, GeoMesh > > &tdf2)
Definition: GeometricFieldReuseFunctions.H:175
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47