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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2018-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #ifndef Foam_DimensionedFieldReuseFunctions_H
30 #define Foam_DimensionedFieldReuseFunctions_H
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 // One-parameter versions
39 
40 template<class TypeR, class Type1, class GeoMesh>
42 {
43  //- Pass-through to New DimensionedField
45  (
47  const word& name,
48  const dimensionSet& dimensions
49  )
50  {
52  (
53  name,
54  f1.mesh(),
55  dimensions
56  );
57  }
58 
59  //- Dissimilar types: return new field
61  (
63  const word& name,
64  const dimensionSet& dimensions
65  )
66  {
67  const auto& f1 = tf1();
68 
70  (
71  name,
72  f1.mesh(),
73  dimensions
74  );
75  }
76 };
77 
78 
79 template<class TypeR, class GeoMesh>
80 struct reuseTmpDimensionedField<TypeR, TypeR, GeoMesh>
81 {
82  //- Allow optional copy assignment of the initial content
83  //- for identical input and output types
85  (
87  const word& name,
88  const dimensionSet& dimensions,
89  const bool initCopy = false
90  )
91  {
92  if (tf1.movable())
93  {
94  auto& f1 = tf1.constCast();
95 
96  f1.rename(name);
97  f1.dimensions().reset(dimensions);
98  return tf1;
99  }
100 
101  const auto& f1 = tf1();
102 
104  (
105  name,
106  f1.mesh(),
107  dimensions
108  );
109 
110  if (initCopy)
111  {
112  tresult.ref().field() = f1.field();
113  }
114 
115  return tresult;
116  }
117 };
118 
119 
120 //- Global function forwards to reuseTmpDimensionedField::New
121 template<class TypeR, class GeoMesh>
122 tmp<DimensionedField<TypeR, GeoMesh>> New
123 (
125  const word& name,
126  const dimensionSet& dimensions,
127  const bool initCopy = false
128 )
129 {
131  (
132  tf1,
133  name,
134  dimensions,
135  initCopy
136  );
137 }
138 
139 
140 template<class TypeR, class Type1, class Type12, class Type2, class GeoMesh>
141 struct reuseTmpTmpDimensionedField
142 {
144  (
147  const word& name,
148  const dimensionSet& dimensions
149  )
150  {
151  const auto& f1 = tf1();
152 
154  (
155  name,
156  f1.mesh(),
157  dimensions
158  );
159  }
160 };
161 
162 
163 template<class TypeR, class Type1, class Type12, class GeoMesh>
164 struct reuseTmpTmpDimensionedField<TypeR, Type1, Type12, TypeR, GeoMesh>
165 {
167  (
170  const word& name,
171  const dimensionSet& dimensions
172  )
173  {
174  if (tf2.movable())
175  {
176  auto& f2 = tf2.constCast();
177 
178  f2.rename(name);
179  f2.dimensions().reset(dimensions);
180  return tf2;
181  }
182 
183  const auto& f1 = tf1();
184 
186  (
187  name,
188  f1.mesh(),
189  dimensions
190  );
191  }
192 };
193 
194 
195 template<class TypeR, class Type2, class GeoMesh>
196 struct reuseTmpTmpDimensionedField<TypeR, TypeR, TypeR, Type2, GeoMesh>
197 {
199  (
202  const word& name,
203  const dimensionSet& dimensions
204  )
205  {
206  if (tf1.movable())
207  {
208  auto& f1 = tf1.constCast();
209 
210  f1.rename(name);
211  f1.dimensions().reset(dimensions);
212  return tf1;
213  }
214 
215  const auto& f1 = tf1();
216 
218  (
219  name,
220  f1.mesh(),
221  dimensions
222  );
223  }
224 };
225 
226 
227 template<class TypeR, class GeoMesh>
228 struct reuseTmpTmpDimensionedField<TypeR, TypeR, TypeR, TypeR, GeoMesh>
229 {
231  (
234  const word& name,
235  const dimensionSet& dimensions
236  )
237  {
238  if (tf1.movable())
239  {
240  auto& f1 = tf1.constCast();
241 
242  f1.rename(name);
243  f1.dimensions().reset(dimensions);
244  return tf1;
245  }
246  if (tf2.movable())
247  {
248  auto& f2 = tf2.constCast();
249 
250  f2.rename(name);
251  f2.dimensions().reset(dimensions);
252  return tf2;
253  }
254 
255  const auto& f1 = tf1();
256 
258  (
259  name,
260  f1.mesh(),
261  dimensions
262  );
263  }
264 };
265 
266 
267 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268 
269 } // End namespace Foam
270 
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 
273 #endif
274 
275 // ************************************************************************* //
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
static tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< Type1, GeoMesh >> &tf1, const tmp< DimensionedField< Type2, GeoMesh >> &tf2, const word &name, const dimensionSet &dimensions)
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Definition: dimensionSet.H:105
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
static tmp< DimensionedField< TypeR, GeoMesh > > New(const DimensionedField< Type1, GeoMesh > &f1, const word &name, const dimensionSet &dimensions)
Pass-through to New DimensionedField.
const Mesh & mesh() const noexcept
Return mesh.
virtual void rename(const word &newName)
Rename.
Definition: regIOobject.C:484
const Field< Type > & field() const noexcept
Return const-reference to the field values.
static tmp< DimensionedField< Type, GeoMesh > > New(const word &name, IOobjectOption::registerOption regOpt, const Mesh &mesh, const dimensionSet &dims, const Field< Type > &iField)
Return tmp field (NO_READ, NO_WRITE) from name, mesh, dimensions, copy of internal field...
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:42
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Namespace for OpenFOAM.
const dimensionSet & dimensions() const noexcept
Return dimensions.