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-2016 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 GeoMesh>
37 tmp<DimensionedField<TypeR, GeoMesh>> New
38 (
40  const word& name,
41  const dimensionSet& dimensions
42 )
43 {
45  const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf1());
46 
47  if (tdf1.isTmp())
48  {
49  df1.rename(name);
50  df1.dimensions().reset(dimensions);
51  return tdf1;
52  }
53  else
54  {
56  (
58  (
59  IOobject
60  (
61  name,
62  df1.instance(),
63  df1.db()
64  ),
65  df1.mesh(),
66  dimensions
67  )
68  );
69  }
70 }
71 
72 
73 template<class TypeR, class Type1, class GeoMesh>
75 {
76 public:
77 
79  (
81  const word& name,
82  const dimensionSet& dimensions
83  )
84  {
85  const DimensionedField<Type1, GeoMesh>& df1 = tdf1();
86 
88  (
90  (
91  IOobject
92  (
93  name,
94  df1.instance(),
95  df1.db()
96  ),
97  df1.mesh(),
98  dimensions
99  )
100  );
101  }
102 };
103 
104 
105 template<class TypeR, class GeoMesh>
106 class reuseTmpDimensionedField<TypeR, TypeR, GeoMesh>
107 {
108 public:
109 
111  (
113  const word& name,
114  const dimensionSet& dimensions
115  )
116  {
118  const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf1());
119 
120  if (tdf1.isTmp())
121  {
122  df1.rename(name);
123  df1.dimensions().reset(dimensions);
124  return tdf1;
125  }
126  else
127  {
129  (
131  (
132  IOobject
133  (
134  name,
135  df1.instance(),
136  df1.db()
137  ),
138  df1.mesh(),
139  dimensions
140  )
141  );
142  }
143  }
144 };
145 
146 
147 template<class TypeR, class Type1, class Type12, class Type2, class GeoMesh>
149 {
150 public:
151 
153  (
156  const word& name,
157  const dimensionSet& dimensions
158  )
159  {
160  const DimensionedField<Type1, GeoMesh>& df1 = tdf1();
161 
163  (
165  (
166  IOobject
167  (
168  name,
169  df1.instance(),
170  df1.db()
171  ),
172  df1.mesh(),
173  dimensions
174  )
175  );
176  }
177 };
178 
179 
180 template<class TypeR, class Type1, class Type12, class GeoMesh>
181 class reuseTmpTmpDimensionedField<TypeR, Type1, Type12, TypeR, GeoMesh>
182 {
183 public:
184 
186  (
189  const word& name,
190  const dimensionSet& dimensions
191  )
192  {
193  const DimensionedField<Type1, GeoMesh>& df1 = tdf1();
195  const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf2());
196 
197  if (tdf2.isTmp())
198  {
199  df2.rename(name);
200  df2.dimensions().reset(dimensions);
201  return tdf2;
202  }
203  else
204  {
206  (
208  (
209  IOobject
210  (
211  name,
212  df1.instance(),
213  df1.db()
214  ),
215  df1.mesh(),
216  dimensions
217  )
218  );
219  }
220  }
221 };
222 
223 
224 template<class TypeR, class Type2, class GeoMesh>
225 class reuseTmpTmpDimensionedField<TypeR, TypeR, TypeR, Type2, GeoMesh>
226 {
227 public:
228 
230  (
233  const word& name,
234  const dimensionSet& dimensions
235  )
236  {
238  const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf1());
239 
240  if (tdf1.isTmp())
241  {
242  df1.rename(name);
243  df1.dimensions().reset(dimensions);
244  return tdf1;
245  }
246  else
247  {
249  (
251  (
252  IOobject
253  (
254  name,
255  df1.instance(),
256  df1.db()
257  ),
258  df1.mesh(),
259  dimensions
260  )
261  );
262  }
263  }
264 };
265 
266 
267 template<class TypeR, class GeoMesh>
268 class reuseTmpTmpDimensionedField<TypeR, TypeR, TypeR, TypeR, GeoMesh>
269 {
270 public:
271 
273  (
276  const word& name,
277  const dimensionSet& dimensions
278  )
279  {
281  const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf1());
283  const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf2());
284 
285  if (tdf1.isTmp())
286  {
287  df1.rename(name);
288  df1.dimensions().reset(dimensions);
289  return tdf1;
290  }
291  else if (tdf2.isTmp())
292  {
293  df2.rename(name);
294  df2.dimensions().reset(dimensions);
295  return tdf2;
296  }
297  else
298  {
300  (
302  (
303  IOobject
304  (
305  name,
306  df1.instance(),
307  df1.db()
308  ),
309  df1.mesh(),
310  dimensions
311  )
312  );
313  }
314  }
315 };
316 
317 
318 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
319 
320 } // End namespace Foam
321 
322 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
323 
324 #endif
325 
326 // ************************************************************************* //
const objectRegistry & db() const
Return the local objectRegistry.
Definition: IOobject.C:221
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Dimension set for the base types.
Definition: dimensionSet.H:118
A class for handling words, derived from string.
Definition: word.H:59
const dimensionSet & dimensions() const
Return dimensions.
virtual void rename(const word &newName)
Rename.
Definition: regIOobject.C:408
void reset(const dimensionSet &)
Definition: dimensionSet.C:108
const Mesh & mesh() const
Return mesh.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:46
A class for managing temporary objects.
Definition: PtrList.H:54
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
const fileName & instance() const
Definition: IOobject.H:337
Namespace for OpenFOAM.
static tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< Type1, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)