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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2018-2019 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#ifndef GeometricFieldReuseFunctions_H
30#define GeometricFieldReuseFunctions_H
31
32// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33
34namespace Foam
35{
36
37// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38
39//- Test if a tmp GeometricField is reusable, which means that it has been
40//- allocated (not a const-reference).
41//
42// When GeometricField debug is on, also checks that the patches have
43// reusable types.
44template
45<
46 class Type,
47 template<class> class PatchField,
48 class GeoMesh
49>
51{
52 if (tgf.isTmp())
53 {
55 {
56 for (const auto& p : tgf().boundaryField())
57 {
58 if
59 (
60 !polyPatch::constraintType(p.patch().type())
61 && !isA<typename PatchField<Type>::Calculated>(p)
62 )
63 {
65 << "Attempt to reuse temporary with non-reusable BC "
66 << p.type() << endl;
67
68 return false;
69 }
70 }
71 }
72
73 return true;
74 }
75
76 return false;
77}
78
79
80template
81<
82 class TypeR,
83 class Type1,
84 template<class> class PatchField,
85 class GeoMesh
86>
88{
90 (
92 const word& name,
93 const dimensionSet& dimensions
94 )
95 {
96 const auto& gf1 = tgf1();
97
99 (
101 (
102 name,
103 gf1.instance(),
104 gf1.db()
105 ),
106 gf1.mesh(),
107 dimensions
108 );
109 }
110};
111
112
113template<class TypeR, template<class> class PatchField, class GeoMesh>
114struct reuseTmpGeometricField<TypeR, TypeR, PatchField, GeoMesh>
115{
116 //- Since the input and output types are identical, also allow
117 //- optional copy assignment of the initial content.
119 (
121 const word& name,
122 const dimensionSet& dimensions,
123 const bool initCopy = false
124 )
125 {
126 if (reusable(tgf1))
127 {
128 auto& gf1 = tgf1.constCast();
129
130 gf1.rename(name);
131 gf1.dimensions().reset(dimensions);
132 return tgf1;
133 }
134
135 const auto& gf1 = tgf1();
136
138 (
140 (
141 name,
142 gf1.instance(),
143 gf1.db()
144 ),
145 gf1.mesh(),
146 dimensions
147 );
148
149 if (initCopy)
150 {
151 rtgf.ref() == gf1;
152 }
153
154 return rtgf;
155 }
156};
157
158
159//- This global function forwards to reuseTmpGeometricField::New
160template<class TypeR, template<class> class PatchField, class GeoMesh>
161tmp
162<
163 GeometricField<TypeR, PatchField, GeoMesh>
165(
167 const word& name,
168 const dimensionSet& dimensions,
169 const bool initCopy = false
170)
171{
173 (
174 tgf1,
175 name,
176 dimensions,
177 initCopy
178 );
179}
180
181
182template
183<
184 class TypeR,
185 class Type1,
186 class Type12,
187 class Type2,
188 template<class> class PatchField,
189 class GeoMesh
190>
192{
194 (
197 const word& name,
198 const dimensionSet& dimensions
199 )
200 {
201 const auto& gf1 = tgf1();
202
204 (
206 (
207 name,
208 gf1.instance(),
209 gf1.db()
210 ),
211 gf1.mesh(),
212 dimensions
213 );
214 }
215};
216
217
218template
219<
220 class TypeR,
221 class Type1,
222 class Type12,
223 template<class> class PatchField,
224 class GeoMesh
225>
227<
228 TypeR, Type1, Type12, TypeR, PatchField, GeoMesh
229>
230{
232 (
235 const word& name,
236 const dimensionSet& dimensions
237 )
238 {
239 if (reusable(tgf2))
240 {
241 auto& gf2 = tgf2.constCast();
242
243 gf2.rename(name);
244 gf2.dimensions().reset(dimensions);
245 return tgf2;
246 }
247
248 const auto& gf1 = tgf1();
249
251 (
253 (
254 name,
255 gf1.instance(),
256 gf1.db()
257 ),
258 gf1.mesh(),
259 dimensions
260 );
261 }
262};
263
264
265template
266<
267 class TypeR,
268 class Type2,
269 template<class> class PatchField,
270 class GeoMesh
271>
273<
274 TypeR, TypeR, TypeR, Type2, PatchField, GeoMesh
275>
276{
278 (
281 const word& name,
282 const dimensionSet& dimensions
283 )
284 {
285 if (reusable(tgf1))
286 {
287 auto& gf1 = tgf1.constCast();
288
289 gf1.rename(name);
290 gf1.dimensions().reset(dimensions);
291 return tgf1;
292 }
293
294 const auto& gf1 = tgf1();
295
297 (
299 (
300 name,
301 gf1.instance(),
302 gf1.db()
303 ),
304 gf1.mesh(),
305 dimensions
306 );
307 }
308};
309
310
311template<class TypeR, template<class> class PatchField, class GeoMesh>
313<
314 TypeR, TypeR, TypeR, TypeR, PatchField, GeoMesh
315>
316{
318 (
321 const word& name,
322 const dimensionSet& dimensions
323 )
324 {
325 if (reusable(tgf1))
326 {
327 auto& gf1 = tgf1.constCast();
328
329 gf1.rename(name);
330 gf1.dimensions().reset(dimensions);
331 return tgf1;
332 }
333 else if (reusable(tgf2))
334 {
335 auto& gf2 = tgf2.constCast();
336
337 gf2.rename(name);
338 gf2.dimensions().reset(dimensions);
339 return tgf2;
340 }
341
342 const auto& gf1 = tgf1();
343
345 (
347 (
348 name,
349 gf1.instance(),
350 gf1.db()
351 ),
352 gf1.mesh(),
353 dimensions
354 );
355 }
356};
357
358
359
360// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
361
362} // End namespace Foam
363
364// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
365
366#endif
367
368// ************************************************************************* //
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:49
Generic GeometricField class.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
virtual const word & constraintType() const
Return the constraint type this pointPatch implements.
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Definition: dimensionSet.H:109
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
volScalarField & p
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
const TargetType * isA(const Type &t)
Check if dynamic_cast to TargetType is possible.
Definition: typeInfo.H:197
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
bool reusable(const tmp< GeometricField< Type, PatchField, GeoMesh > > &tgf)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
static tmp< GeometricField< TypeR, PatchField, GeoMesh > > New(const tmp< GeometricField< TypeR, PatchField, GeoMesh > > &tgf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
static tmp< GeometricField< TypeR, PatchField, GeoMesh > > New(const tmp< GeometricField< Type1, PatchField, GeoMesh > > &tgf1, const word &name, const dimensionSet &dimensions)
static tmp< GeometricField< TypeR, PatchField, GeoMesh > > New(const tmp< GeometricField< Type1, PatchField, GeoMesh > > &tgf1, const tmp< GeometricField< TypeR, PatchField, GeoMesh > > &tgf2, const word &name, const dimensionSet &dimensions)
static tmp< GeometricField< TypeR, PatchField, GeoMesh > > New(const tmp< GeometricField< TypeR, PatchField, GeoMesh > > &tgf1, const tmp< GeometricField< Type2, PatchField, GeoMesh > > &tgf2, const word &name, const dimensionSet &dimensions)
static tmp< GeometricField< TypeR, PatchField, GeoMesh > > New(const tmp< GeometricField< TypeR, PatchField, GeoMesh > > &tgf1, const tmp< GeometricField< TypeR, PatchField, GeoMesh > > &tgf2, const word &name, const dimensionSet &dimensions)
static tmp< GeometricField< TypeR, PatchField, GeoMesh > > New(const tmp< GeometricField< Type1, PatchField, GeoMesh > > &tgf1, const tmp< GeometricField< Type2, PatchField, GeoMesh > > &tgf2, const word &name, const dimensionSet &dimensions)