Loading...
Searching...
No Matches
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-2023 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 Foam_FieldReuseFunctions_H
30#define Foam_FieldReuseFunctions_H
31
32// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33
34namespace Foam
35{
36
37// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38// One-parameter versions
40template<class TypeR, class Type1>
41struct reuseTmp
42{
43 //- Pass-through to tmp New
44 static tmp<Field<TypeR>> New(const Field<Type1>& f1)
45 {
46 return tmp<Field<TypeR>>::New(f1.size());
47 }
48
49 //- Dissimilar types: just use size
50 static tmp<Field<TypeR>> New(const tmp<Field<Type1>>& tf1)
51 {
52 return tmp<Field<TypeR>>::New(tf1().size());
53 }
54};
56
57template<class TypeR>
58struct reuseTmp<TypeR, TypeR>
59{
60 //- Identical input and return types:
61 //- allow optional copy assignment of the initial content
62 static tmp<Field<TypeR>> New
63 (
64 const tmp<Field<TypeR>>& tf1,
65 const bool initCopy = false
66 )
67 {
68 if (tf1.movable())
69 {
70 return tf1;
71 }
72
73 auto rtf = tmp<Field<TypeR>>::New(tf1().size());
74
75 if (initCopy)
76 {
77 rtf.ref() = tf1();
78 }
79
80 return rtf;
81 }
82};
83
84
85//- This global function forwards to reuseTmp::New
86template<class TypeR> tmp<Field<TypeR>> New
88 const tmp<Field<TypeR>>& tf1,
89 const bool initCopy = false
90)
91{
92 return reuseTmp<TypeR, TypeR>::New(tf1, initCopy);
93}
94
95
96// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
97// Two-parameter versions
98
99template<class TypeR, class Type1, class Type12, class Type2>
100struct reuseTmpTmp
102 //- Dissimilar types: just use size
103 static tmp<Field<TypeR>> New
104 (
105 const tmp<Field<Type1>>& tf1,
106 const tmp<Field<Type2>>& tf2
107 )
108 {
109 return tmp<Field<TypeR>>::New(tf1().size());
110 }
111};
112
113
114template<class TypeR, class Type1, class Type12>
115struct reuseTmpTmp<TypeR, Type1, Type12, TypeR>
116{
117 //- Second input has return type
119 (
120 const tmp<Field<Type1>>& tf1,
121 const tmp<Field<TypeR>>& tf2
122 )
124 if (tf2.movable())
125 {
126 return tf2;
127 }
128
129 return tmp<Field<TypeR>>::New(tf1().size());
130 }
131};
132
133
134template<class TypeR, class Type2>
135struct reuseTmpTmp<TypeR, TypeR, TypeR, Type2>
136{
137 //- First input has return type
138 static tmp<Field<TypeR>> New
139 (
140 const tmp<Field<TypeR>>& tf1,
141 const tmp<Field<Type2>>& tf2
142 )
143 {
144 if (tf1.movable())
146 return tf1;
147 }
148
149 return tmp<Field<TypeR>>::New(tf1().size());
150 }
151};
152
153
154template<class TypeR>
155struct reuseTmpTmp<TypeR, TypeR, TypeR, TypeR>
156{
157 //- Both inputs have return type
158 static tmp<Field<TypeR>> New
159 (
160 const tmp<Field<TypeR>>& tf1,
161 const tmp<Field<TypeR>>& tf2
163 {
164 if (tf1.movable())
165 {
166 return tf1;
168 if (tf2.movable())
169 {
170 return tf2;
171 }
172
173 return tmp<Field<TypeR>>::New(tf1().size());
174 }
175};
176
177
178// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
179
180} // End namespace Foam
181
182// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183
184#endif
185
186// ************************************************************************* //
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
A class for managing temporary objects.
Definition tmp.H:75
Namespace for OpenFOAM.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
static tmp< Field< TypeR > > New(const tmp< Field< Type1 > > &tf1, const tmp< Field< TypeR > > &tf2)
Second input has return type.
static tmp< Field< TypeR > > New(const tmp< Field< TypeR > > &tf1, const tmp< Field< Type2 > > &tf2)
First input has return type.
static tmp< Field< TypeR > > New(const tmp< Field< TypeR > > &tf1, const tmp< Field< TypeR > > &tf2)
Both inputs have return type.
static tmp< Field< TypeR > > New(const tmp< Field< Type1 > > &tf1, const tmp< Field< Type2 > > &tf2)
Dissimilar types: just use size.
static tmp< Field< TypeR > > New(const tmp< Field< TypeR > > &tf1, const bool initCopy=false)
Identical input and return types: allow optional copy assignment of the initial content.
static tmp< Field< TypeR > > New(const tmp< Field< Type1 > > &tf1)
Dissimilar types: just use size.
static tmp< Field< TypeR > > New(const Field< Type1 > &f1)
Pass-through to tmp New.