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) 2004-2010, 2018-2019 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  | Copyright (C) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #ifndef DimensionedFieldReuseFunctions_H
29 #define DimensionedFieldReuseFunctions_H
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 
38 template<class TypeR, class Type1, class GeoMesh>
40 {
42  (
44  const word& name,
45  const dimensionSet& dimensions
46  )
47  {
48  const auto& df1 = tdf1();
49 
51  (
52  IOobject
53  (
54  name,
55  df1.instance(),
56  df1.db()
57  ),
58  df1.mesh(),
59  dimensions
60  );
61  }
62 };
63 
64 
65 template<class TypeR, class GeoMesh>
66 struct reuseTmpDimensionedField<TypeR, TypeR, GeoMesh>
67 {
69  (
71  const word& name,
72  const dimensionSet& dimensions
73  )
74  {
75  if (tdf1.isTmp())
76  {
77  auto& df1 = tdf1.constCast();
78 
79  df1.rename(name);
80  df1.dimensions().reset(dimensions);
81  return tdf1;
82  }
83 
84  const auto& df1 = tdf1();
85 
87  (
88  IOobject
89  (
90  name,
91  df1.instance(),
92  df1.db()
93  ),
94  df1.mesh(),
95  dimensions
96  );
97  }
98 };
99 
100 
101 //- Global function forwards to reuseTmpDimensionedField::New
102 template<class TypeR, class GeoMesh>
103 tmp<DimensionedField<TypeR, GeoMesh>> New
104 (
106  const word& name,
107  const dimensionSet& dimensions
108 )
109 {
111  (
112  tdf1,
113  name,
114  dimensions
115  );
116 }
117 
118 
119 template<class TypeR, class Type1, class Type12, class Type2, class GeoMesh>
121 {
123  (
126  const word& name,
127  const dimensionSet& dimensions
128  )
129  {
130  const auto& df1 = tdf1();
131 
133  (
134  IOobject
135  (
136  name,
137  df1.instance(),
138  df1.db()
139  ),
140  df1.mesh(),
141  dimensions
142  );
143  }
144 };
145 
146 
147 template<class TypeR, class Type1, class Type12, class GeoMesh>
148 struct reuseTmpTmpDimensionedField<TypeR, Type1, Type12, TypeR, GeoMesh>
149 {
151  (
154  const word& name,
155  const dimensionSet& dimensions
156  )
157  {
158  if (tdf2.isTmp())
159  {
160  auto& df2 = tdf2.constCast();
161 
162  df2.rename(name);
163  df2.dimensions().reset(dimensions);
164  return tdf2;
165  }
166 
167  const auto& df1 = tdf1();
168 
170  (
171  IOobject
172  (
173  name,
174  df1.instance(),
175  df1.db()
176  ),
177  df1.mesh(),
178  dimensions
179  );
180  }
181 };
182 
183 
184 template<class TypeR, class Type2, class GeoMesh>
185 struct reuseTmpTmpDimensionedField<TypeR, TypeR, TypeR, Type2, GeoMesh>
186 {
188  (
191  const word& name,
192  const dimensionSet& dimensions
193  )
194  {
195  if (tdf1.isTmp())
196  {
197  auto& df1 = tdf1.constCast();
198 
199  df1.rename(name);
200  df1.dimensions().reset(dimensions);
201  return tdf1;
202  }
203 
204  const auto& df1 = tdf1();
205 
207  (
208  IOobject
209  (
210  name,
211  df1.instance(),
212  df1.db()
213  ),
214  df1.mesh(),
215  dimensions
216  );
217  }
218 };
219 
220 
221 template<class TypeR, class GeoMesh>
222 struct reuseTmpTmpDimensionedField<TypeR, TypeR, TypeR, TypeR, GeoMesh>
223 {
225  (
228  const word& name,
229  const dimensionSet& dimensions
230  )
231  {
232  if (tdf1.isTmp())
233  {
234  auto& df1 = tdf1.constCast();
235 
236  df1.rename(name);
237  df1.dimensions().reset(dimensions);
238  return tdf1;
239  }
240  else if (tdf2.isTmp())
241  {
242  auto& df2 = tdf2.constCast();
243 
244  df2.rename(name);
245  df2.dimensions().reset(dimensions);
246  return tdf2;
247  }
248 
249  const auto& df1 = tdf1();
250 
252  (
253  IOobject
254  (
255  name,
256  df1.instance(),
257  df1.db()
258  ),
259  df1.mesh(),
260  dimensions
261  );
262  }
263 };
264 
265 
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
267 
268 } // End namespace Foam
269 
270 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
271 
272 #endif
273 
274 // ************************************************************************* //
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:95
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:61
Foam::reuseTmpTmpDimensionedField::New
static tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< Type1, GeoMesh >> &tdf1, const tmp< DimensionedField< Type2, GeoMesh >> &tdf2, const word &name, const dimensionSet &dimensions)
Definition: DimensionedFieldReuseFunctions.H:123
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:58
Foam::dimensionSet
Dimension set for the base types.
Definition: dimensionSet.H:64
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:75
Foam::GeoMesh
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:48
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:32
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:104
Foam::reuseTmpTmpDimensionedField
Definition: DimensionedFieldReuseFunctions.H:120
Foam::reuseTmpDimensionedField
Definition: DimensionedFieldReuseFunctions.H:39
Foam::reuseTmpDimensionedField::New
static tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< Type1, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Definition: DimensionedFieldReuseFunctions.H:42
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:53