GeometricFieldReuseFunctions.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) 2011-2016 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  IOobject
103  (
104  name,
105  gf1.instance(),
106  gf1.db()
107  ),
108  gf1.mesh(),
109  dimensions
110  )
111  );
112 
113  if (initRet)
114  {
115  rtgf.ref() == tgf1();
116  }
117 
118  return rtgf;
119  }
120 }
121 
122 
123 template
124 <
125  class TypeR,
126  class Type1,
127  template<class> class PatchField,
128  class GeoMesh
129 >
131 {
132 public:
133 
135  (
137  const word& name,
138  const dimensionSet& dimensions
139  )
140  {
141  const GeometricField<Type1, PatchField, GeoMesh>& gf1 = tgf1();
142 
144  (
146  (
147  IOobject
148  (
149  name,
150  gf1.instance(),
151  gf1.db()
152  ),
153  gf1.mesh(),
154  dimensions
155  )
156  );
157  }
158 };
159 
160 
161 template<class TypeR, template<class> class PatchField, class GeoMesh>
162 class reuseTmpGeometricField<TypeR, TypeR, PatchField, GeoMesh>
163 {
164 public:
165 
167  (
169  const word& name,
170  const dimensionSet& dimensions
171  )
172  {
174  const_cast<GeometricField<TypeR, PatchField, GeoMesh>& >(tgf1());
175 
176  if (reusable(tgf1))
177  {
178  gf1.rename(name);
179  gf1.dimensions().reset(dimensions);
180  return tgf1;
181  }
182  else
183  {
185  (
187  (
188  IOobject
189  (
190  name,
191  gf1.instance(),
192  gf1.db()
193  ),
194  gf1.mesh(),
195  dimensions
196  )
197  );
198  }
199  }
200 };
201 
202 
203 template
204 <
205  class TypeR,
206  class Type1,
207  class Type12,
208  class Type2,
209  template<class> class PatchField,
210  class GeoMesh
211 >
213 {
214 public:
215 
217  (
220  const word& name,
221  const dimensionSet& dimensions
222  )
223  {
224  const GeometricField<Type1, PatchField, GeoMesh>& gf1 = tgf1();
225 
227  (
229  (
230  IOobject
231  (
232  name,
233  gf1.instance(),
234  gf1.db()
235  ),
236  gf1.mesh(),
237  dimensions
238  )
239  );
240  }
241 };
242 
243 
244 template
245 <
246  class TypeR,
247  class Type1,
248  class Type12,
249  template<class> class PatchField,
250  class GeoMesh
251 >
253  <TypeR, Type1, Type12, TypeR, PatchField, GeoMesh>
254 {
255 public:
256 
258  (
261  const word& name,
262  const dimensionSet& dimensions
263  )
264  {
265  const GeometricField<Type1, PatchField, GeoMesh>& gf1 = tgf1();
267  const_cast<GeometricField<TypeR, PatchField, GeoMesh>& >(tgf2());
268 
269  if (reusable(tgf2))
270  {
271  gf2.rename(name);
272  gf2.dimensions().reset(dimensions);
273  return tgf2;
274  }
275  else
276  {
278  (
280  (
281  IOobject
282  (
283  name,
284  gf1.instance(),
285  gf1.db()
286  ),
287  gf1.mesh(),
288  dimensions
289  )
290  );
291  }
292  }
293 };
294 
295 
296 template
297 <
298  class TypeR,
299  class Type2,
300  template<class> class PatchField,
301  class GeoMesh
302 >
303 class reuseTmpTmpGeometricField<TypeR, TypeR, TypeR, Type2, PatchField, GeoMesh>
304 {
305 public:
306 
308  (
311  const word& name,
312  const dimensionSet& dimensions
313  )
314  {
316  const_cast<GeometricField<TypeR, PatchField, GeoMesh>& >(tgf1());
317 
318  if (reusable(tgf1))
319  {
320  gf1.rename(name);
321  gf1.dimensions().reset(dimensions);
322  return tgf1;
323  }
324  else
325  {
327  (
329  (
330  IOobject
331  (
332  name,
333  gf1.instance(),
334  gf1.db()
335  ),
336  gf1.mesh(),
337  dimensions
338  )
339  );
340  }
341  }
342 };
343 
344 
345 template<class TypeR, template<class> class PatchField, class GeoMesh>
346 class reuseTmpTmpGeometricField<TypeR, TypeR, TypeR, TypeR, PatchField, GeoMesh>
347 {
348 public:
349 
351  (
354  const word& name,
355  const dimensionSet& dimensions
356  )
357  {
359  const_cast<GeometricField<TypeR, PatchField, GeoMesh>& >(tgf1());
361  const_cast<GeometricField<TypeR, PatchField, GeoMesh>& >(tgf2());
362 
363  if (reusable(tgf1))
364  {
365  gf1.rename(name);
366  gf1.dimensions().reset(dimensions);
367  return tgf1;
368  }
369  else if (reusable(tgf2))
370  {
371  gf2.rename(name);
372  gf2.dimensions().reset(dimensions);
373  return tgf2;
374  }
375  else
376  {
378  (
380  (
381  IOobject
382  (
383  name,
384  gf1.instance(),
385  gf1.db()
386  ),
387  gf1.mesh(),
388  dimensions
389  )
390  );
391  }
392  }
393 };
394 
395 
396 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
397 
398 } // End namespace Foam
399 
400 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
401 
402 #endif
403 
404 // ************************************************************************* //
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:428
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:253
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: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:402
fileName::Type type(const fileName &, const bool followLink=true)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:485
void reset(const dimensionSet &)
Definition: dimensionSet.C:108
const fileName & instance() const
Definition: IOobject.H:386
label patchi
#define WarningInFunction
Report a warning using Foam::Warning.
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:46
A class for managing temporary objects.
Definition: PtrList.H:53
const objectRegistry & db() const
Return the local objectRegistry.
Definition: IOobject.C:331
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
Namespace for OpenFOAM.