GeometricFieldReuseFunctions.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 GeometricFieldReuseFunctions_H
27 #define GeometricFieldReuseFunctions_H
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 template
37 <
38  class Type,
39  template<class> class PatchField,
40  class GeoMesh
41 >
43 {
44  if (tgf.isTmp())
45  {
47  {
50  Boundary& gbf = gf.boundaryField();
51 
52  forAll(gbf, patchi)
53  {
54  if
55  (
56  !polyPatch::constraintType(gbf[patchi].patch().type())
57  && !isA<typename PatchField<Type>::Calculated>(gbf[patchi])
58  )
59  {
61  << "Attempt to reuse temporary with non-reusable BC "
62  << gbf[patchi].type() << endl;
63 
64  return false;
65  }
66  }
67  }
68 
69  return true;
70  }
71  else
72  {
73  return false;
74  }
75 }
76 
77 
78 template<class TypeR, template<class> class PatchField, class GeoMesh>
80 (
82  const word& name,
83  const dimensionSet& dimensions,
84  const bool initRet = false
85 )
86 {
88  const_cast<GeometricField<TypeR, PatchField, GeoMesh>& >(tgf1());
89 
90  if (reusable(tgf1))
91  {
92  gf1.rename(name);
93  gf1.dimensions().reset(dimensions);
94  return tgf1;
95  }
96  else
97  {
99  (
101  (
102  name,
103  gf1.mesh(),
104  dimensions
105  )
106  );
107 
108  if (initRet)
109  {
110  rtgf.ref() == tgf1();
111  }
112 
113  return rtgf;
114  }
115 }
116 
117 
118 template
119 <
120  class TypeR,
121  class Type1,
122  template<class> class PatchField,
123  class GeoMesh
124 >
126 {
127 public:
128 
130  (
132  const word& name,
133  const dimensionSet& dimensions
134  )
135  {
136  const GeometricField<Type1, PatchField, GeoMesh>& gf1 = tgf1();
137 
139  (
140  name,
141  gf1.mesh(),
142  dimensions
143  );
144  }
145 };
146 
147 
148 template<class TypeR, template<class> class PatchField, class GeoMesh>
149 class reuseTmpGeometricField<TypeR, TypeR, PatchField, GeoMesh>
150 {
151 public:
152 
154  (
156  const word& name,
157  const dimensionSet& dimensions
158  )
159  {
161  const_cast<GeometricField<TypeR, PatchField, GeoMesh>& >(tgf1());
162 
163  if (reusable(tgf1))
164  {
165  gf1.rename(name);
166  gf1.dimensions().reset(dimensions);
167  return tgf1;
168  }
169  else
170  {
172  (
173  name,
174  gf1.mesh(),
175  dimensions
176  );
177  }
178  }
179 };
180 
181 
182 template
183 <
184  class TypeR,
185  class Type1,
186  class Type2,
187  template<class> class PatchField,
188  class GeoMesh
189 >
191 {
192 public:
193 
195  (
198  const word& name,
199  const dimensionSet& dimensions
200  )
201  {
202  const GeometricField<Type1, PatchField, GeoMesh>& gf1 = tgf1();
203 
205  (
206  name,
207  gf1.mesh(),
208  dimensions
209  );
210  }
211 };
212 
213 
214 template
215 <
216  class TypeR,
217  class Type1,
218  template<class> class PatchField,
219  class GeoMesh
220 >
221 class reuseTmpTmpGeometricField<TypeR, Type1, TypeR, PatchField, GeoMesh>
222 {
223 public:
224 
226  (
229  const word& name,
230  const dimensionSet& dimensions
231  )
232  {
233  const GeometricField<Type1, PatchField, GeoMesh>& gf1 = tgf1();
235  const_cast<GeometricField<TypeR, PatchField, GeoMesh>& >(tgf2());
236 
237  if (reusable(tgf2))
238  {
239  gf2.rename(name);
240  gf2.dimensions().reset(dimensions);
241  return tgf2;
242  }
243  else
244  {
246  (
247  name,
248  gf1.mesh(),
249  dimensions
250  );
251  }
252  }
253 };
254 
255 
256 template
257 <
258  class TypeR,
259  class Type2,
260  template<class> class PatchField,
261  class GeoMesh
262 >
263 class reuseTmpTmpGeometricField<TypeR, TypeR, Type2, PatchField, GeoMesh>
264 {
265 public:
266 
268  (
271  const word& name,
272  const dimensionSet& dimensions
273  )
274  {
276  const_cast<GeometricField<TypeR, PatchField, GeoMesh>& >(tgf1());
277 
278  if (reusable(tgf1))
279  {
280  gf1.rename(name);
281  gf1.dimensions().reset(dimensions);
282  return tgf1;
283  }
284  else
285  {
287  (
288  name,
289  gf1.mesh(),
290  dimensions
291  );
292  }
293  }
294 };
295 
296 
297 template<class TypeR, template<class> class PatchField, class GeoMesh>
298 class reuseTmpTmpGeometricField<TypeR, TypeR, TypeR, PatchField, GeoMesh>
299 {
300 public:
301 
303  (
306  const word& name,
307  const dimensionSet& dimensions
308  )
309  {
311  const_cast<GeometricField<TypeR, PatchField, GeoMesh>& >(tgf1());
313  const_cast<GeometricField<TypeR, PatchField, GeoMesh>& >(tgf2());
314 
315  if (reusable(tgf1))
316  {
317  gf1.rename(name);
318  gf1.dimensions().reset(dimensions);
319  return tgf1;
320  }
321  else if (reusable(tgf2))
322  {
323  gf2.rename(name);
324  gf2.dimensions().reset(dimensions);
325  return tgf2;
326  }
327  else
328  {
330  (
331  name,
332  gf1.mesh(),
333  dimensions
334  );
335  }
336  }
337 };
338 
339 
340 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
341 
342 } // End namespace Foam
343 
344 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
345 
346 #endif
347 
348 // ************************************************************************* //
bool isA(const Type &t)
Check if a dynamic_cast to typeid is possible.
Definition: typeInfo.H:134
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
const Boundary & boundaryField() const
Return const-reference to the boundary field.
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
static tmp< GeometricField< Type, PatchField, GeoMesh > > New(const word &name, const Internal &, const PtrList< PatchField< Type >> &)
Return a temporary field constructed from name,.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Generic GeometricField class.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
static bool constraintType(const word &pt)
Return true if the given type is a constraint type.
Definition: polyPatch.C:265
const dimensionSet & dimensions() const
Return dimensions.
Dimension set for the base types.
Definition: dimensionSet.H:121
A class for handling words, derived from string.
Definition: word.H:59
static tmp< GeometricField< TypeR, PatchField, GeoMesh > > New(const tmp< GeometricField< Type1, PatchField, GeoMesh >> &tgf1, const word &name, const dimensionSet &dimensions)
const Mesh & mesh() const
Return mesh.
bool reusable(const tmp< GeometricField< Type, PatchField, GeoMesh >> &tgf)
virtual void rename(const word &newName)
Rename.
Definition: regIOobject.C:417
void reset(const dimensionSet &)
Definition: dimensionSet.C:108
label patchi
#define WarningInFunction
Report a warning using Foam::Warning.
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
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.