FieldReuseFunctions.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) 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 FieldReuseFunctions_H
30#define FieldReuseFunctions_H
31
32// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33
34namespace Foam
35{
36
37// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38
39template<class TypeR, class Type1>
41{
42 static tmp<Field<TypeR>> New(const tmp<Field<Type1>>& tf1)
43 {
44 return tmp<Field<TypeR>>::New(tf1().size());
45 }
46};
47
48
49template<class TypeR>
50struct reuseTmp<TypeR, TypeR>
51{
53 (
54 const tmp<Field<TypeR>>& tf1,
55 const bool initCopy = false
56 )
57 {
58 if (tf1.isTmp())
59 {
60 return tf1;
61 }
62
63 auto rtf = tmp<Field<TypeR>>::New(tf1().size());
64
65 if (initCopy)
66 {
67 rtf.ref() = tf1();
68 }
69
70 return rtf;
71 }
72};
73
74
75//- This global function forwards to reuseTmp::New
76template<class TypeR> tmp<Field<TypeR>> New
77(
78 const tmp<Field<TypeR>>& tf1,
79 const bool initCopy = false
80)
81{
82 return reuseTmp<TypeR, TypeR>::New(tf1, initCopy);
83}
84
85
86template<class TypeR, class Type1, class Type12, class Type2>
88{
90 (
91 const tmp<Field<Type1>>& tf1,
92 const tmp<Field<Type2>>& tf2
93 )
94 {
95 return tmp<Field<TypeR>>::New(tf1().size());
96 }
97};
98
99
100template<class TypeR, class Type1, class Type12>
101struct reuseTmpTmp<TypeR, Type1, Type12, TypeR>
102{
104 (
105 const tmp<Field<Type1>>& tf1,
106 const tmp<Field<TypeR>>& tf2
107 )
108 {
109 if (tf2.isTmp())
110 {
111 return tf2;
112 }
113
114 return tmp<Field<TypeR>>::New(tf1().size());
115 }
116};
117
118
119template<class TypeR, class Type2>
120struct reuseTmpTmp<TypeR, TypeR, TypeR, Type2>
121{
123 (
124 const tmp<Field<TypeR>>& tf1,
125 const tmp<Field<Type2>>& tf2
126 )
127 {
128 if (tf1.isTmp())
129 {
130 return tf1;
131 }
132
133 return tmp<Field<TypeR>>::New(tf1().size());
134 }
135};
136
137
138template<class TypeR>
139struct reuseTmpTmp<TypeR, TypeR, TypeR, TypeR>
140{
142 (
143 const tmp<Field<TypeR>>& tf1,
144 const tmp<Field<TypeR>>& tf2
145 )
146 {
147 if (tf1.isTmp())
148 {
149 return tf1;
150 }
151 else if (tf2.isTmp())
152 {
153 return tf2;
154 }
155
156 return tmp<Field<TypeR>>::New(tf1().size());
157 }
158};
159
160
161// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
162
163} // End namespace Foam
164
165// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
166
167#endif
168
169// ************************************************************************* //
Generic templated field type.
Definition: Field.H:82
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
A class for managing temporary objects.
Definition: tmp.H:65
Namespace for OpenFOAM.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
static tmp< Field< TypeR > > New(const tmp< Field< Type1 > > &tf1, const tmp< Field< TypeR > > &tf2)
static tmp< Field< TypeR > > New(const tmp< Field< TypeR > > &tf1, const tmp< Field< Type2 > > &tf2)
static tmp< Field< TypeR > > New(const tmp< Field< TypeR > > &tf1, const tmp< Field< TypeR > > &tf2)
static tmp< Field< TypeR > > New(const tmp< Field< Type1 > > &tf1, const tmp< Field< Type2 > > &tf2)
static tmp< Field< TypeR > > New(const tmp< Field< TypeR > > &tf1, const bool initCopy=false)
static tmp< Field< TypeR > > New(const tmp< Field< Type1 > > &tf1)