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-2023 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 #include "DimensionedField.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 
38 template<class TypeR, class GeoMesh>
40 (
42  const word& name,
44 )
45 {
47  const_cast<DimensionedField<TypeR, GeoMesh, Field>&>(tdf1());
48 
49  if (tdf1.isTmp())
50  {
51  df1.rename(name);
53  return tdf1;
54  }
55  else
56  {
58  (
59  name,
60  df1.mesh(),
62  );
63  }
64 }
65 
66 
67 template
68 <
69  class TypeR,
70  class Type1,
71  class GeoMesh,
72  template<class> class PrimitiveField
73 >
75 {
76 public:
77 
79  (
81  const word& name,
83  )
84  {
86 
88  (
89  name,
90  df1.mesh(),
92  );
93  }
94 };
95 
96 
97 template<class TypeR, class GeoMesh>
98 class reuseTmpDimensionedField<TypeR, TypeR, GeoMesh, Field>
99 {
100 public:
101 
103  (
105  const word& name,
106  const dimensionSet& dimensions
107  )
108  {
110  const_cast<DimensionedField<TypeR, GeoMesh, Field>&>(tdf1());
111 
112  if (tdf1.isTmp())
113  {
114  df1.rename(name);
115  df1.dimensions().reset(dimensions);
116  return tdf1;
117  }
118  else
119  {
121  (
122  name,
123  df1.mesh(),
124  dimensions
125  );
126  }
127  }
128 };
129 
130 
131 template
132 <
133  class TypeR,
134  class Type1,
135  class Type2,
136  class GeoMesh,
137  template<class> class PrimitiveField1,
138  template<class> class PrimitiveField2
139 >
141 {
142 public:
143 
145  (
148  const word& name,
149  const dimensionSet& dimensions
150  )
151  {
153 
155  (
156  name,
157  df1.mesh(),
158  dimensions
159  );
160  }
161 };
162 
163 
164 template
165 <
166  class TypeR,
167  class Type1,
168  class GeoMesh,
169  template<class> class PrimitiveField1
170 >
172 <TypeR, Type1, TypeR, GeoMesh, PrimitiveField1, Field>
173 {
174 public:
175 
177  (
180  const word& name,
181  const dimensionSet& dimensions
182  )
183  {
185  const_cast<DimensionedField<TypeR, GeoMesh, Field>&>(tdf2());
186 
187  if (tdf2.isTmp())
188  {
189  df2.rename(name);
190  df2.dimensions().reset(dimensions);
191  return tdf2;
192  }
193  else
194  {
196  (
197  name,
198  df2.mesh(),
199  dimensions
200  );
201  }
202  }
203 };
204 
205 
206 template
207 <
208  class TypeR,
209  class Type2,
210  class GeoMesh,
211  template<class> class PrimitiveField2
212 >
214 <TypeR, TypeR, Type2, GeoMesh, Field, PrimitiveField2>
215 {
216 public:
217 
219  (
222  const word& name,
223  const dimensionSet& dimensions
224  )
225  {
227  const_cast<DimensionedField<TypeR, GeoMesh, Field>&>(tdf1());
228 
229  if (tdf1.isTmp())
230  {
231  df1.rename(name);
232  df1.dimensions().reset(dimensions);
233  return tdf1;
234  }
235  else
236  {
238  (
239  name,
240  df1.mesh(),
241  dimensions
242  );
243  }
244  }
245 };
246 
247 
248 template<class TypeR, class GeoMesh>
249 class reuseTmpTmpDimensionedField<TypeR, TypeR, TypeR, GeoMesh, Field, Field>
250 {
251 public:
252 
254  (
257  const word& name,
258  const dimensionSet& dimensions
259  )
260  {
262  const_cast<DimensionedField<TypeR, GeoMesh, Field>&>(tdf1());
264  const_cast<DimensionedField<TypeR, GeoMesh, Field>&>(tdf2());
265 
266  if (tdf1.isTmp())
267  {
268  df1.rename(name);
269  df1.dimensions().reset(dimensions);
270  return tdf1;
271  }
272  else if (tdf2.isTmp())
273  {
274  df2.rename(name);
275  df2.dimensions().reset(dimensions);
276  return tdf2;
277  }
278  else
279  {
281  (
282  name,
283  df1.mesh(),
284  dimensions
285  );
286  }
287  }
288 };
289 
290 
291 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
292 
293 } // End namespace Foam
294 
295 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
296 
297 #endif
298 
299 // ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const dimensionSet & dimensions() const
Return dimensions.
const Mesh & mesh() const
Return mesh.
static tmp< DimensionedField< Type, GeoMesh, PrimitiveField > > New(const word &name, const Mesh &mesh, const dimensionSet &, const PrimitiveField< Type > &)
Return a temporary field constructed from name, mesh,.
Pre-declare SubField and related Field type.
Definition: Field.H:83
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:47
Dimension set for the base types.
Definition: dimensionSet.H:125
void reset(const dimensionSet &)
Definition: dimensionSet.C:126
virtual void rename(const word &newName)
Rename.
Definition: regIOobject.C:417
static tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
static tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< Type1, GeoMesh, PrimitiveField >> &tdf1, const word &name, const dimensionSet &dimensions)
static tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< Type1, GeoMesh, PrimitiveField1 >> &tdf1, const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf2, const word &name, const dimensionSet &dimensions)
static tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const tmp< DimensionedField< Type2, GeoMesh, PrimitiveField2 >> &tdf2, const word &name, const dimensionSet &dimensions)
static tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf2, const word &name, const dimensionSet &dimensions)
static tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< Type1, GeoMesh, PrimitiveField1 >> &tdf1, const tmp< DimensionedField< Type2, GeoMesh, PrimitiveField2 >> &tdf2, const word &name, const dimensionSet &dimensions)
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
const HashTable< dimensionSet > & dimensions()
Get the table of dimension sets.
Definition: dimensionSets.C:96
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)