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 | Copyright (C) 2011 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, class Type1>
37 class reuseTmp
38 {
39 public:
40 
41  static tmp<Field<TypeR> > New(const tmp<Field<Type1> >& tf1)
42  {
43  return tmp<Field<TypeR> >(new Field<TypeR>(tf1().size()));
44  }
45 
46  static void clear(const tmp<Field<Type1> >& tf1)
47  {
48  tf1.clear();
49  }
50 };
51 
52 
53 template<class TypeR>
54 class reuseTmp<TypeR, TypeR>
55 {
56 public:
57 
58  static tmp<Field<TypeR> > New(const tmp<Field<TypeR> >& tf1)
59  {
60  if (tf1.isTmp())
61  {
62  return tf1;
63  }
64  else
65  {
66  return tmp<Field<TypeR> >(new Field<TypeR>(tf1().size()));
67  }
68  }
69 
70  static void clear(const tmp<Field<TypeR> >& tf1)
71  {
72  if (tf1.isTmp())
73  {
74  tf1.ptr();
75  }
76  }
77 };
78 
79 
80 template<class TypeR, class Type1, class Type12, class Type2>
82 {
83 public:
84 
85  static tmp<Field<TypeR> > New
86  (
87  const tmp<Field<Type1> >& tf1,
88  const tmp<Field<Type2> >& tf2
89  )
90  {
91  return tmp<Field<TypeR> >(new Field<TypeR>(tf1().size()));
92  }
93 
94  static void clear
95  (
96  const tmp<Field<Type1> >& tf1,
97  const tmp<Field<Type2> >& tf2
98  )
99  {
100  tf1.clear();
101  tf2.clear();
102  }
103 };
104 
105 
106 template<class TypeR, class Type1, class Type12>
107 class reuseTmpTmp<TypeR, Type1, Type12, TypeR>
108 {
109 public:
110 
111  static tmp<Field<TypeR> > New
112  (
113  const tmp<Field<Type1> >& tf1,
114  const tmp<Field<TypeR> >& tf2
115  )
116  {
117  if (tf2.isTmp())
118  {
119  return tf2;
120  }
121  else
122  {
123  return tmp<Field<TypeR> >(new Field<TypeR>(tf1().size()));
124  }
125  }
126 
127  static void clear
128  (
129  const tmp<Field<Type1> >& tf1,
130  const tmp<Field<TypeR> >& tf2
131  )
132  {
133  tf1.clear();
134  if (tf2.isTmp())
135  {
136  tf2.ptr();
137  }
138  }
139 };
140 
141 
142 template<class TypeR, class Type2>
143 class reuseTmpTmp<TypeR, TypeR, TypeR, Type2>
144 {
145 public:
146 
147  static tmp<Field<TypeR> > New
148  (
149  const tmp<Field<TypeR> >& tf1,
150  const tmp<Field<Type2> >& tf2
151  )
152  {
153  if (tf1.isTmp())
154  {
155  return tf1;
156  }
157  else
158  {
159  return tmp<Field<TypeR> >(new Field<TypeR>(tf1().size()));
160  }
161  }
162 
163  static void clear
164  (
165  const tmp<Field<TypeR> >& tf1,
166  const tmp<Field<Type2> >& tf2
167  )
168  {
169  if (tf1.isTmp())
170  {
171  tf1.ptr();
172  }
173  tf2.clear();
174  }
175 };
176 
177 
178 template<class TypeR>
179 class reuseTmpTmp<TypeR, TypeR, TypeR, TypeR>
180 {
181 public:
182 
183  static tmp<Field<TypeR> > New
184  (
185  const tmp<Field<TypeR> >& tf1,
186  const tmp<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  {
199  return tmp<Field<TypeR> >(new Field<TypeR>(tf1().size()));
200  }
201  }
202 
203  static void clear
204  (
205  const tmp<Field<TypeR> >& tf1,
206  const tmp<Field<TypeR> >& tf2
207  )
208  {
209  if (tf1.isTmp())
210  {
211  tf1.ptr();
212  tf2.clear();
213  }
214  else if (tf2.isTmp())
215  {
216  tf1.clear();
217  tf2.ptr();
218  }
219  }
220 };
221 
222 
223 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
224 
225 } // End namespace Foam
226 
227 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
228 
229 #endif
230 
231 // ************************************************************************* //
Foam::reuseTmp< TypeR, TypeR >::New
static tmp< Field< TypeR > > New(const tmp< Field< TypeR > > &tf1)
Definition: FieldReuseFunctions.H:58
Foam::reuseTmp::clear
static void clear(const tmp< Field< Type1 > > &tf1)
Definition: FieldReuseFunctions.H:46
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::reuseTmp::New
static tmp< Field< TypeR > > New(const tmp< Field< Type1 > > &tf1)
Definition: FieldReuseFunctions.H:41
Foam::reuseTmp< TypeR, TypeR >::clear
static void clear(const tmp< Field< TypeR > > &tf1)
Definition: FieldReuseFunctions.H:70
Foam::reuseTmpTmp::clear
static void clear(const tmp< Field< Type1 > > &tf1, const tmp< Field< Type2 > > &tf2)
Definition: FieldReuseFunctions.H:95
Foam::reuseTmp
Definition: FieldReuseFunctions.H:37
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::reuseTmpTmp
Definition: FieldReuseFunctions.H:81
Foam::reuseTmpTmp::New
static tmp< Field< TypeR > > New(const tmp< Field< Type1 > > &tf1, const tmp< Field< Type2 > > &tf2)
Definition: FieldReuseFunctions.H:86