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-2022 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 
39 template<class TypeR, class Type1, class GeoMesh>
41 {
43  (
45  const word& name,
46  const dimensionSet& dimensions
47  )
48  {
49  const auto& df1 = tdf1();
50 
52  (
53  IOobject
54  (
55  name,
56  df1.instance(),
57  df1.db()
58  ),
59  df1.mesh(),
60  dimensions
61  );
62  }
63 };
64 
65 
66 template<class TypeR, class GeoMesh>
67 struct reuseTmpDimensionedField<TypeR, TypeR, GeoMesh>
68 {
69  //- Allow optional copy assignment of the initial content
70  //- for identical input and output types
72  (
74  const word& name,
75  const dimensionSet& dimensions,
76  const bool initCopy = false
77  )
78  {
79  if (tdf1.movable())
80  {
81  auto& df1 = tdf1.constCast();
82 
83  df1.rename(name);
84  df1.dimensions().reset(dimensions);
85  return tdf1;
86  }
87 
88  const auto& df1 = tdf1();
89 
91  (
92  IOobject
93  (
94  name,
95  df1.instance(),
96  df1.db()
97  ),
98  df1.mesh(),
99  dimensions
100  );
101 
102  if (initCopy)
103  {
104  tresult.ref().field() = tdf1().field();
105  }
106 
107  return tresult;
108  }
109 };
110 
111 
112 //- Global function forwards to reuseTmpDimensionedField::New
113 template<class TypeR, class GeoMesh>
115 (
117  const word& name,
118  const dimensionSet& dimensions,
119  const bool initCopy = false
120 )
121 {
123  (
124  tdf1,
125  name,
126  dimensions,
127  initCopy
128  );
129 }
131 
132 template<class TypeR, class Type1, class Type12, class Type2, class GeoMesh>
134 {
136  (
139  const word& name,
140  const dimensionSet& dimensions
141  )
142  {
143  const auto& df1 = tdf1();
144 
146  (
147  IOobject
148  (
149  name,
150  df1.instance(),
151  df1.db()
152  ),
153  df1.mesh(),
154  dimensions
155  );
156  }
157 };
159 
160 template<class TypeR, class Type1, class Type12, class GeoMesh>
161 struct reuseTmpTmpDimensionedField<TypeR, Type1, Type12, TypeR, GeoMesh>
162 {
164  (
167  const word& name,
168  const dimensionSet& dimensions
169  )
170  {
171  if (tdf2.movable())
172  {
173  auto& df2 = tdf2.constCast();
174 
175  df2.rename(name);
176  df2.dimensions().reset(dimensions);
177  return tdf2;
178  }
179 
180  const auto& df1 = tdf1();
181 
183  (
184  IOobject
185  (
186  name,
187  df1.instance(),
188  df1.db()
189  ),
190  df1.mesh(),
191  dimensions
192  );
193  }
194 };
196 
197 template<class TypeR, class Type2, class GeoMesh>
198 struct reuseTmpTmpDimensionedField<TypeR, TypeR, TypeR, Type2, GeoMesh>
199 {
201  (
204  const word& name,
205  const dimensionSet& dimensions
206  )
207  {
208  if (tdf1.movable())
209  {
210  auto& df1 = tdf1.constCast();
211 
212  df1.rename(name);
213  df1.dimensions().reset(dimensions);
214  return tdf1;
215  }
216 
217  const auto& df1 = tdf1();
218 
220  (
221  IOobject
222  (
223  name,
224  df1.instance(),
225  df1.db()
226  ),
227  df1.mesh(),
228  dimensions
229  );
230  }
231 };
233 
234 template<class TypeR, class GeoMesh>
235 struct reuseTmpTmpDimensionedField<TypeR, TypeR, TypeR, TypeR, GeoMesh>
236 {
238  (
241  const word& name,
242  const dimensionSet& dimensions
243  )
244  {
245  if (tdf1.movable())
246  {
247  auto& df1 = tdf1.constCast();
248 
249  df1.rename(name);
250  df1.dimensions().reset(dimensions);
251  return tdf1;
252  }
253  if (tdf2.movable())
254  {
255  auto& df2 = tdf2.constCast();
256 
257  df2.rename(name);
258  df2.dimensions().reset(dimensions);
259  return tdf2;
260  }
261 
262  const auto& df1 = tdf1();
263 
265  (
266  IOobject
267  (
268  name,
269  df1.instance(),
270  df1.db()
271  ),
272  df1.mesh(),
273  dimensions
274  );
275  }
276 };
277 
278 
279 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
280 
281 } // End namespace Foam
282 
283 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
284 
285 #endif
286 
287 // ************************************************************************* //
static tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< Type1, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
static tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< Type1, GeoMesh >> &tdf1, const tmp< DimensionedField< Type2, GeoMesh >> &tdf2, const word &name, const dimensionSet &dimensions)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
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 INVALID.
Definition: exprTraits.C:52
A class for handling words, derived from Foam::string.
Definition: word.H:63
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
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:166
Namespace for OpenFOAM.