DimensionedFieldReuseFunctions.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 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  (
57  name,
58  df1.mesh(),
59  dimensions
60  );
61  }
62 }
63 
64 
65 template<class TypeR, class Type1, class GeoMesh>
67 {
68 public:
69 
71  (
73  const word& name,
74  const dimensionSet& dimensions
75  )
76  {
77  const DimensionedField<Type1, GeoMesh>& df1 = tdf1();
78 
80  (
81  name,
82  df1.mesh(),
83  dimensions
84  );
85  }
86 };
87 
88 
89 template<class TypeR, class GeoMesh>
90 class reuseTmpDimensionedField<TypeR, TypeR, GeoMesh>
91 {
92 public:
93 
95  (
97  const word& name,
98  const dimensionSet& dimensions
99  )
100  {
102  const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf1());
103 
104  if (tdf1.isTmp())
105  {
106  df1.rename(name);
107  df1.dimensions().reset(dimensions);
108  return tdf1;
109  }
110  else
111  {
113  (
114  name,
115  df1.mesh(),
116  dimensions
117  );
118  }
119  }
120 };
121 
122 
123 template<class TypeR, class Type1, 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  (
140  name,
141  df1.mesh(),
142  dimensions
143  );
144  }
145 };
146 
147 
148 template<class TypeR, class Type1, class GeoMesh>
149 class reuseTmpTmpDimensionedField<TypeR, Type1, TypeR, GeoMesh>
150 {
151 public:
152 
154  (
157  const word& name,
158  const dimensionSet& dimensions
159  )
160  {
161  const DimensionedField<Type1, GeoMesh>& df1 = tdf1();
163  const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf2());
164 
165  if (tdf2.isTmp())
166  {
167  df2.rename(name);
168  df2.dimensions().reset(dimensions);
169  return tdf2;
170  }
171  else
172  {
174  (
175  name,
176  df1.mesh(),
177  dimensions
178  );
179  }
180  }
181 };
182 
183 
184 template<class TypeR, class Type2, class GeoMesh>
185 class reuseTmpTmpDimensionedField<TypeR, TypeR, Type2, GeoMesh>
186 {
187 public:
188 
190  (
193  const word& name,
194  const dimensionSet& dimensions
195  )
196  {
198  const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf1());
199 
200  if (tdf1.isTmp())
201  {
202  df1.rename(name);
203  df1.dimensions().reset(dimensions);
204  return tdf1;
205  }
206  else
207  {
209  (
210  name,
211  df1.mesh(),
212  dimensions
213  );
214  }
215  }
216 };
217 
218 
219 template<class TypeR, class GeoMesh>
220 class reuseTmpTmpDimensionedField<TypeR, TypeR, TypeR, GeoMesh>
221 {
222 public:
223 
225  (
228  const word& name,
229  const dimensionSet& dimensions
230  )
231  {
233  const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf1());
235  const_cast<DimensionedField<TypeR, GeoMesh>& >(tdf2());
236 
237  if (tdf1.isTmp())
238  {
239  df1.rename(name);
240  df1.dimensions().reset(dimensions);
241  return tdf1;
242  }
243  else if (tdf2.isTmp())
244  {
245  df2.rename(name);
246  df2.dimensions().reset(dimensions);
247  return tdf2;
248  }
249  else
250  {
252  (
253  name,
254  df1.mesh(),
255  dimensions
256  );
257  }
258  }
259 };
260 
261 
262 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
263 
264 } // End namespace Foam
265 
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
267 
268 #endif
269 
270 // ************************************************************************* //
static tmp< DimensionedField< Type, GeoMesh > > New(const word &name, const Mesh &mesh, const dimensionSet &)
Return a temporary field constructed from name, mesh.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
const dimensionSet & dimensions() const
Return dimensions.
Dimension set for the base types.
Definition: dimensionSet.H:120
A class for handling words, derived from string.
Definition: word.H:59
const Mesh & mesh() const
Return mesh.
virtual void rename(const word &newName)
Rename.
Definition: regIOobject.C:376
void reset(const dimensionSet &)
Definition: dimensionSet.C:108
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:53
Namespace for OpenFOAM.
static tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< Type1, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)