All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FieldReuseFunctions.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-2018 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 FieldReuseFunctions_H
27 #define FieldReuseFunctions_H
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 template<class TypeR>
37 tmp<Field<TypeR>> New
38 (
39  const tmp<Field<TypeR>>& tf1,
40  const bool initRet = false
41 )
42 {
43  if (tf1.isTmp())
44  {
45  return tf1;
46  }
47  else
48  {
49  tmp<Field<TypeR>> rtf(new Field<TypeR>(tf1().size()));
50 
51  if (initRet)
52  {
53  rtf.ref() = tf1();
54  }
55 
56  return rtf;
57  }
58 }
59 
60 
61 template<class TypeR, class Type1>
62 class reuseTmp
63 {
64 public:
65 
66  static tmp<Field<TypeR>> New(const tmp<Field<Type1>>& tf1)
67  {
68  return tmp<Field<TypeR>>(new Field<TypeR>(tf1().size()));
69  }
70 };
71 
72 
73 template<class TypeR>
74 class reuseTmp<TypeR, TypeR>
75 {
76 public:
77 
78  static tmp<Field<TypeR>> New(const tmp<Field<TypeR>>& tf1)
79  {
80  if (tf1.isTmp())
81  {
82  return tf1;
83  }
84  else
85  {
86  return tmp<Field<TypeR>>(new Field<TypeR>(tf1().size()));
87  }
88  }
89 };
90 
91 
92 template<class TypeR, class Type1, class Type12, class Type2>
94 {
95 public:
96 
97  static tmp<Field<TypeR>> New
98  (
99  const tmp<Field<Type1>>& tf1,
100  const tmp<Field<Type2>>& tf2
101  )
102  {
103  return tmp<Field<TypeR>>(new Field<TypeR>(tf1().size()));
104  }
105 };
106 
107 
108 template<class TypeR, class Type1, class Type12>
109 class reuseTmpTmp<TypeR, Type1, Type12, TypeR>
110 {
111 public:
112 
113  static tmp<Field<TypeR>> New
114  (
115  const tmp<Field<Type1>>& tf1,
116  const tmp<Field<TypeR>>& tf2
117  )
118  {
119  if (tf2.isTmp())
120  {
121  return tf2;
122  }
123  else
124  {
125  return tmp<Field<TypeR>>(new Field<TypeR>(tf1().size()));
126  }
127  }
128 };
129 
130 
131 template<class TypeR, class Type2>
132 class reuseTmpTmp<TypeR, TypeR, TypeR, Type2>
133 {
134 public:
135 
136  static tmp<Field<TypeR>> New
137  (
138  const tmp<Field<TypeR>>& tf1,
139  const tmp<Field<Type2>>& tf2
140  )
141  {
142  if (tf1.isTmp())
143  {
144  return tf1;
145  }
146  else
147  {
148  return tmp<Field<TypeR>>(new Field<TypeR>(tf1().size()));
149  }
150  }
151 };
152 
153 
154 template<class TypeR>
155 class reuseTmpTmp<TypeR, TypeR, TypeR, TypeR>
156 {
157 public:
158 
159  static tmp<Field<TypeR>> New
160  (
161  const tmp<Field<TypeR>>& tf1,
162  const tmp<Field<TypeR>>& tf2
163  )
164  {
165  if (tf1.isTmp())
166  {
167  return tf1;
168  }
169  else if (tf2.isTmp())
170  {
171  return tf2;
172  }
173  else
174  {
175  return tmp<Field<TypeR>>(new Field<TypeR>(tf1().size()));
176  }
177  }
178 };
179 
180 
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 
183 } // End namespace Foam
184 
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 
187 #endif
188 
189 // ************************************************************************* //
static tmp< Field< TypeR > > New(const tmp< Field< Type1 >> &tf1)
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
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< Field< TypeR > > New(const tmp< Field< TypeR >> &tf1)
A class for managing temporary objects.
Definition: PtrList.H:53
Namespace for OpenFOAM.