FieldFieldReuseFunctions.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-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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_FieldFieldReuseFunctions_H
30 #define Foam_FieldFieldReuseFunctions_H
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 // One-parameter versions
39 
40 template<template<class> class Field, class TypeR, class Type1>
41 struct reuseTmpFieldField
42 {
43  //- Pass-through to NewCalculatedType
45  (
46  const FieldField<Field, Type1>& f1
47  )
48  {
50  }
51 
52  //- Dissimilar types: just use size
54  (
55  const tmp<FieldField<Field, Type1>>& tf1
56  )
57  {
59  }
60 };
61 
62 
63 template<template<class> class Field, class TypeR>
64 struct reuseTmpFieldField<Field, TypeR, TypeR>
65 {
66  //- Identical input and return types:
67  //- allow optional copy assignment of the initial content
69  (
70  const tmp<FieldField<Field, TypeR>>& tf1,
71  const bool initCopy = false
72  )
73  {
74  if (tf1.movable())
75  {
76  return tf1;
77  }
78 
79  auto tresult = FieldField<Field, TypeR>::NewCalculatedType(tf1());
80 
81  if (initCopy)
82  {
83  tresult.ref() = tf1();
84  }
85 
86  return tresult;
87  }
88 };
89 
90 
91 //- This global function forwards to reuseTmpFieldField::New
92 template<template<class> class Field, class TypeR>
93 tmp<FieldField<Field, TypeR>> New
94 (
96  const bool initCopy = false
97 )
98 {
100 }
101 
102 
103 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
104 // Two-parameter versions
105 
106 template
107 <
108  template<class> class Field,
109  class TypeR,
110  class Type1,
111  class Type12,
112  class Type2
113 >
114 struct reuseTmpTmpFieldField
115 {
116  //- Dissimilar types: just use size
118  (
119  const tmp<FieldField<Field, Type1>>& tf1,
120  const tmp<FieldField<Field, Type2>>& tf2
121  )
122  {
124  }
125 };
126 
127 
128 template<template<class> class Field, class TypeR, class Type1, class Type12>
129 struct reuseTmpTmpFieldField<Field, TypeR, Type1, Type12, TypeR>
130 {
131  //- Second input has return type
133  (
134  const tmp<FieldField<Field, Type1>>& tf1,
135  const tmp<FieldField<Field, TypeR>>& tf2
136  )
137  {
138  if (tf2.movable())
139  {
140  return tf2;
141  }
142 
144  }
145 };
146 
147 
148 template<template<class> class Field, class TypeR, class Type2>
149 struct reuseTmpTmpFieldField<Field, TypeR, TypeR, TypeR, Type2>
150 {
151  //- First input has return type
152  static tmp<FieldField<Field, TypeR>> New
153  (
155  const tmp<FieldField<Field, Type2>>& tf2
156  )
157  {
158  if (tf1.movable())
159  {
160  return tf1;
161  }
162 
164  }
165 };
166 
167 
168 template<template<class> class Field, class TypeR>
169 struct reuseTmpTmpFieldField<Field, TypeR, TypeR, TypeR, TypeR>
170 {
171  //- Both inputs have return type
172  static tmp<FieldField<Field, TypeR>> New
173  (
174  const tmp<FieldField<Field, TypeR>>& tf1,
175  const tmp<FieldField<Field, TypeR>>& tf2
176  )
177  {
178  if (tf1.movable())
179  {
180  return tf1;
181  }
182  if (tf2.movable())
183  {
184  return tf2;
185  }
186 
188  }
189 };
190 
191 
192 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
193 
194 } // End namespace Foam
195 
196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
197 
198 #endif
199 
200 // ************************************************************************* //
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.
A field of fields is a PtrList of fields with reference counting.
Definition: FieldField.H:51
Generic templated field type.
Definition: Field.H:62
static tmp< FieldField< Field, Type > > NewCalculatedType(const FieldField< Field, Type2 > &ff)
Return a pointer to a new calculatedFvPatchFieldField created on.
Definition: FieldField.C:191
static tmp< FieldField< Field, TypeR > > New(const tmp< FieldField< Field, Type1 >> &tf1, const tmp< FieldField< Field, Type2 >> &tf2)
Dissimilar types: just use size.
static tmp< FieldField< Field, TypeR > > New(const FieldField< Field, Type1 > &f1)
Pass-through to NewCalculatedType.
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Namespace for OpenFOAM.