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-2018 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 Type12,
187  class Type2,
188  template<class> class PatchField,
189  class GeoMesh
190 >
192 {
193 public:
194 
196  (
199  const word& name,
200  const dimensionSet& dimensions
201  )
202  {
203  const GeometricField<Type1, PatchField, GeoMesh>& gf1 = tgf1();
204 
206  (
207  name,
208  gf1.mesh(),
209  dimensions
210  );
211  }
212 };
213 
214 
215 template
216 <
217  class TypeR,
218  class Type1,
219  class Type12,
220  template<class> class PatchField,
221  class GeoMesh
222 >
224  <TypeR, Type1, Type12, TypeR, PatchField, GeoMesh>
225 {
226 public:
227 
229  (
232  const word& name,
233  const dimensionSet& dimensions
234  )
235  {
236  const GeometricField<Type1, PatchField, GeoMesh>& gf1 = tgf1();
238  const_cast<GeometricField<TypeR, PatchField, GeoMesh>& >(tgf2());
239 
240  if (reusable(tgf2))
241  {
242  gf2.rename(name);
243  gf2.dimensions().reset(dimensions);
244  return tgf2;
245  }
246  else
247  {
249  (
250  name,
251  gf1.mesh(),
252  dimensions
253  );
254  }
255  }
256 };
257 
258 
259 template
260 <
261  class TypeR,
262  class Type2,
263  template<class> class PatchField,
264  class GeoMesh
265 >
266 class reuseTmpTmpGeometricField<TypeR, TypeR, TypeR, Type2, PatchField, GeoMesh>
267 {
268 public:
269 
271  (
274  const word& name,
275  const dimensionSet& dimensions
276  )
277  {
279  const_cast<GeometricField<TypeR, PatchField, GeoMesh>& >(tgf1());
280 
281  if (reusable(tgf1))
282  {
283  gf1.rename(name);
284  gf1.dimensions().reset(dimensions);
285  return tgf1;
286  }
287  else
288  {
290  (
291  name,
292  gf1.mesh(),
293  dimensions
294  );
295  }
296  }
297 };
298 
299 
300 template<class TypeR, template<class> class PatchField, class GeoMesh>
301 class reuseTmpTmpGeometricField<TypeR, TypeR, TypeR, TypeR, PatchField, GeoMesh>
302 {
303 public:
304 
306  (
309  const word& name,
310  const dimensionSet& dimensions
311  )
312  {
314  const_cast<GeometricField<TypeR, PatchField, GeoMesh>& >(tgf1());
316  const_cast<GeometricField<TypeR, PatchField, GeoMesh>& >(tgf2());
317 
318  if (reusable(tgf1))
319  {
320  gf1.rename(name);
321  gf1.dimensions().reset(dimensions);
322  return tgf1;
323  }
324  else if (reusable(tgf2))
325  {
326  gf2.rename(name);
327  gf2.dimensions().reset(dimensions);
328  return tgf2;
329  }
330  else
331  {
333  (
334  name,
335  gf1.mesh(),
336  dimensions
337  );
338  }
339  }
340 };
341 
342 
343 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
344 
345 } // End namespace Foam
346 
347 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
348 
349 #endif
350 
351 // ************************************************************************* //
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:174
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
Generic GeometricField class.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
static tmp< GeometricField< Type, PatchField, GeoMesh > > New(const word &name, const Mesh &, const dimensionSet &, const word &patchFieldType=PatchField< Type >::calculatedType())
Return a temporary field constructed from name, mesh, dimensionSet.
static bool constraintType(const word &pt)
Return true if the given type is a constraint type.
Definition: polyPatch.C:246
const dimensionSet & dimensions() const
Return dimensions.
Dimension set for the base types.
Definition: dimensionSet.H:120
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:410
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.