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-2024 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 #include "GeometricField.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 
38 template<class Type, class GeoMesh, template<class> class PrimitiveField>
40 {
42 
43  if (tgf.isTmp())
44  {
45  if (geoField::debug)
46  {
47  const geoField& gf = tgf();
48  const typename geoField::Boundary& gbf = gf.boundaryField();
49 
50  forAll(gbf, patchi)
51  {
52  if
53  (
54  !polyPatch::constraintType(gbf[patchi].patch().type())
55  && !isA<typename geoField::Patch::Calculated>(gbf[patchi])
56  )
57  {
59  << "Attempt to reuse temporary with non-reusable BC "
60  << gbf[patchi].type() << endl;
61 
62  return false;
63  }
64  }
65  }
66 
67  return true;
68  }
69  else
70  {
71  return false;
72  }
73 }
74 
75 
76 template<class TypeR, class GeoMesh>
78 (
80  const word& name,
81  const dimensionSet& dimensions,
82  const bool initRet = false
83 )
84 {
86  const_cast<GeometricField<TypeR, GeoMesh, Field>&>(tgf1());
87 
88  if (reusable(tgf1))
89  {
90  gf1.rename(name);
92  return tgf1;
93  }
94  else
95  {
97  (
99  (
100  name,
101  gf1.mesh(),
102  dimensions
103  )
104  );
105 
106  if (initRet)
107  {
108  rtgf.ref() == tgf1();
109  }
110 
111  return rtgf;
112  }
113 }
114 
115 
116 template
117 <
118  class TypeR,
119  class Type1,
120  class GeoMesh,
121  template<class> class PrimitiveField
122 >
124 {
125 public:
126 
128  (
130  const word& name,
131  const dimensionSet& dimensions
132  )
133  {
135 
137  (
138  name,
139  gf1.mesh(),
140  dimensions
141  );
142  }
143 };
144 
145 
146 template<class TypeR, class GeoMesh>
147 class reuseTmpGeometricField<TypeR, TypeR, GeoMesh, Field>
148 {
149 public:
150 
152  (
154  const word& name,
155  const dimensionSet& dimensions
156  )
157  {
159  const_cast<GeometricField<TypeR, GeoMesh, Field>&>(tgf1());
160 
161  if (reusable(tgf1))
162  {
163  gf1.rename(name);
164  gf1.dimensions().reset(dimensions);
165  return tgf1;
166  }
167  else
168  {
170  (
171  name,
172  gf1.mesh(),
173  dimensions
174  );
175  }
176  }
177 };
178 
179 
180 template
181 <
182  class TypeR,
183  class Type1,
184  class Type2,
185  class GeoMesh,
186  template<class> class PrimitiveField1,
187  template<class> class PrimitiveField2
188 >
190 {
191 public:
192 
194  (
197  const word& name,
198  const dimensionSet& dimensions
199  )
200  {
202 
204  (
205  name,
206  gf1.mesh(),
207  dimensions
208  );
209  }
210 };
211 
212 
213 template
214 <
215  class TypeR,
216  class Type1,
217  class GeoMesh,
218  template<class> class PrimitiveField1
219 >
221 <TypeR, Type1, TypeR, GeoMesh, PrimitiveField1, Field>
222 {
223 public:
224 
226  (
229  const word& name,
230  const dimensionSet& dimensions
231  )
232  {
234 
236  const_cast<GeometricField<TypeR, GeoMesh, Field>&>(tgf2());
237 
238  if (reusable(tgf2))
239  {
240  gf2.rename(name);
241  gf2.dimensions().reset(dimensions);
242  return tgf2;
243  }
244  else
245  {
247  (
248  name,
249  gf1.mesh(),
250  dimensions
251  );
252  }
253  }
254 };
255 
256 
257 template
258 <
259  class TypeR,
260  class Type2,
261  class GeoMesh,
262  template<class> class PrimitiveField2
263 >
265 <TypeR, TypeR, Type2, GeoMesh, Field, PrimitiveField2>
266 {
267 public:
268 
270  (
273  const word& name,
274  const dimensionSet& dimensions
275  )
276  {
278  const_cast<GeometricField<TypeR, GeoMesh, Field>&>(tgf1());
279 
280  if (reusable(tgf1))
281  {
282  gf1.rename(name);
283  gf1.dimensions().reset(dimensions);
284  return tgf1;
285  }
286  else
287  {
289  (
290  name,
291  gf1.mesh(),
292  dimensions
293  );
294  }
295  }
296 };
297 
298 
299 template<class TypeR, class GeoMesh>
300 class reuseTmpTmpGeometricField<TypeR, TypeR, TypeR, GeoMesh, Field, Field>
301 {
302 public:
303 
305  (
308  const word& name,
309  const dimensionSet& dimensions
310  )
311  {
313  const_cast<GeometricField<TypeR, GeoMesh, Field>&>(tgf1());
315  const_cast<GeometricField<TypeR, GeoMesh, Field>&>(tgf2());
316 
317  if (reusable(tgf1))
318  {
319  gf1.rename(name);
320  gf1.dimensions().reset(dimensions);
321  return tgf1;
322  }
323  else if (reusable(tgf2))
324  {
325  gf2.rename(name);
326  gf2.dimensions().reset(dimensions);
327  return tgf2;
328  }
329  else
330  {
332  (
333  name,
334  gf1.mesh(),
335  dimensions
336  );
337  }
338  }
339 };
340 
341 
342 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
343 
344 } // End namespace Foam
345 
346 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
347 
348 #endif
349 
350 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
const dimensionSet & dimensions() const
Return dimensions.
const Mesh & mesh() const
Return mesh.
Pre-declare SubField and related Field type.
Definition: Field.H:83
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:47
Generic GeometricField class.
static tmp< GeometricField< Type, GeoMesh, PrimitiveField > > New(const word &name, const Internal &, const PtrList< Patch > &, const HashPtrTable< Source > &=HashPtrTable< Source >())
Return a temporary field constructed from name,.
Dimension set for the base types.
Definition: dimensionSet.H:125
void reset(const dimensionSet &)
Definition: dimensionSet.C:126
static bool constraintType(const word &pt)
Return true if the given type is a constraint type.
Definition: polyPatch.C:238
virtual void rename(const word &newName)
Rename.
Definition: regIOobject.C:417
static tmp< GeometricField< TypeR, GeoMesh, Field > > New(const tmp< GeometricField< TypeR, GeoMesh, Field >> &tgf1, const word &name, const dimensionSet &dimensions)
static tmp< GeometricField< TypeR, GeoMesh, Field > > New(const tmp< GeometricField< Type1, GeoMesh, PrimitiveField >> &tgf1, const word &name, const dimensionSet &dimensions)
static tmp< GeometricField< TypeR, GeoMesh, Field > > New(const tmp< GeometricField< Type1, GeoMesh, PrimitiveField1 >> &tgf1, const tmp< GeometricField< TypeR, GeoMesh, Field >> &tgf2, const word &name, const dimensionSet &dimensions)
static tmp< GeometricField< TypeR, GeoMesh, Field > > New(const tmp< GeometricField< TypeR, GeoMesh, Field >> &tgf1, const tmp< GeometricField< Type2, GeoMesh, PrimitiveField2 >> &tgf2, const word &name, const dimensionSet &dimensions)
static tmp< GeometricField< TypeR, GeoMesh, Field > > New(const tmp< GeometricField< TypeR, GeoMesh, Field >> &tgf1, const tmp< GeometricField< TypeR, GeoMesh, Field >> &tgf2, const word &name, const dimensionSet &dimensions)
static tmp< GeometricField< TypeR, GeoMesh, Field > > New(const tmp< GeometricField< Type1, GeoMesh, PrimitiveField1 >> &tgf1, const tmp< GeometricField< Type2, GeoMesh, PrimitiveField2 >> &tgf2, const word &name, const dimensionSet &dimensions)
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:197
A class for handling words, derived from string.
Definition: word.H:62
label patchi
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
const HashTable< dimensionSet > & dimensions()
Get the table of dimension sets.
Definition: dimensionSets.C:96
bool reusable(const tmp< GeometricField< Type, GeoMesh, PrimitiveField >> &tgf)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488