FieldFieldReuseFunctions.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 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 FieldFieldReuseFunctions_H
27 #define FieldFieldReuseFunctions_H
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 template<template<class> class Field, class TypeR>
37 tmp<FieldField<Field, TypeR>> New
38 (
39  const tmp<FieldField<Field, TypeR>>& tf1,
40  const bool initRet = false
41 )
42 {
43  if (tf1.isTmp())
44  {
45  return tf1;
46  }
47  else
48  {
50  (
52  );
53 
54  if (initRet)
55  {
56  rtf.ref() = tf1();
57  }
58 
59  return rtf;
60  }
61 }
62 
63 
64 template<template<class> class Field, class TypeR, class Type1>
66 {
67 public:
68 
70  (
71  const tmp<FieldField<Field, Type1>>& tf1
72  )
73  {
75  (
77  );
78  }
79 };
80 
81 
82 template<template<class> class Field, class TypeR>
83 class reuseTmpFieldField<Field, TypeR, TypeR>
84 {
85 public:
86 
88  (
89  const tmp<FieldField<Field, TypeR>>& tf1
90  )
91  {
92  if (tf1.isTmp())
93  {
94  return tf1;
95  }
96  else
97  {
99  (
101  );
102  }
103  }
104 };
105 
106 
107 template<template<class> class Field, class TypeR, class Type1, class Type2>
109 {
110 public:
111 
113  (
114  const tmp<FieldField<Field, Type1>>& tf1,
115  const tmp<FieldField<Field, Type2>>& tf2
116  )
117  {
119  (
121  );
122  }
123 };
124 
125 
126 template<template<class> class Field, class TypeR, class Type1>
127 class reuseTmpTmpFieldField<Field, TypeR, Type1, TypeR>
128 {
129 public:
130 
132  (
133  const tmp<FieldField<Field, Type1>>& tf1,
134  const tmp<FieldField<Field, TypeR>>& tf2
135  )
136  {
137  if (tf2.isTmp())
138  {
139  return tf2;
140  }
141  else
142  {
144  (
146  );
147  }
148  }
149 };
150 
151 
152 template<template<class> class Field, class TypeR, class Type2>
153 class reuseTmpTmpFieldField<Field, TypeR, TypeR, Type2>
154 {
155 public:
156 
158  (
159  const tmp<FieldField<Field, TypeR>>& tf1,
160  const tmp<FieldField<Field, Type2>>& tf2
161  )
162  {
163  if (tf1.isTmp())
164  {
165  return tf1;
166  }
167  else
168  {
170  (
172  );
173  }
174  }
175 };
176 
177 
178 template<template<class> class Field, class TypeR>
179 class reuseTmpTmpFieldField<Field, TypeR, TypeR, TypeR>
180 {
181 public:
182 
184  (
185  const tmp<FieldField<Field, TypeR>>& tf1,
186  const tmp<FieldField<Field, TypeR>>& tf2
187  )
188  {
189  if (tf1.isTmp())
190  {
191  return tf1;
192  }
193  else if (tf2.isTmp())
194  {
195  return tf2;
196  }
197  else
198  {
200  (
202  );
203  }
204  }
205 };
206 
207 
208 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
209 
210 } // End namespace Foam
211 
212 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
213 
214 #endif
215 
216 // ************************************************************************* //
static tmp< FieldField< Field, TypeR > > New(const tmp< FieldField< Field, Type1 >> &tf1)
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
Generic field type.
Definition: FieldField.H:51
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Pre-declare SubField and related Field type.
Definition: Field.H:56
static tmp< FieldField< Field, Type > > NewCalculatedType(const FieldField< Field, Type2 > &ff)
Return a pointer to a new calculatedFvPatchFieldField created on.
Definition: FieldField.C:197
A class for managing temporary objects.
Definition: PtrList.H:53
Namespace for OpenFOAM.