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 | 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 FieldFieldReuseFunctions_H
27 #define FieldFieldReuseFunctions_H
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 template<template<class> class Field, class TypeR, class Type1>
38 {
39 public:
40 
42  (
43  const tmp<FieldField<Field, Type1> >& tf1
44  )
45  {
47  (
49  );
50  }
51 
52  static void clear(const tmp<FieldField<Field, Type1> >& tf1)
53  {
54  tf1.clear();
55  }
56 };
57 
58 
59 template<template<class> class Field, class TypeR>
60 class reuseTmpFieldField<Field, TypeR, TypeR>
61 {
62 public:
63 
65  (
66  const tmp<FieldField<Field, TypeR> >& tf1
67  )
68  {
69  if (tf1.isTmp())
70  {
71  return tf1;
72  }
73  else
74  {
76  (
78  );
79  }
80  }
81 
82  static void clear(const tmp<FieldField<Field, TypeR> >& tf1)
83  {
84  if (tf1.isTmp())
85  {
86  tf1.ptr();
87  }
88  }
89 };
90 
91 
92 template
93 <
94  template<class> class Field,
95  class TypeR,
96  class Type1,
97  class Type12,
98  class Type2
99 >
101 {
102 public:
103 
105  (
106  const tmp<FieldField<Field, Type1> >& tf1,
107  const tmp<FieldField<Field, Type2> >& tf2
108  )
109  {
111  (
113  );
114  }
115 
116  static void clear
117  (
118  const tmp<FieldField<Field, Type1> >& tf1,
119  const tmp<FieldField<Field, Type2> >& tf2
120  )
121  {
122  tf1.clear();
123  tf2.clear();
124  }
125 };
126 
127 
128 template<template<class> class Field, class TypeR, class Type1, class Type12>
129 class reuseTmpTmpFieldField<Field, TypeR, Type1, Type12, TypeR>
130 {
131 public:
132 
134  (
135  const tmp<FieldField<Field, Type1> >& tf1,
136  const tmp<FieldField<Field, TypeR> >& tf2
137  )
138  {
139  if (tf2.isTmp())
140  {
141  return tf2;
142  }
143  else
144  {
146  (
148  );
149  }
150  }
151 
152  static void clear
153  (
154  const tmp<FieldField<Field, Type1> >& tf1,
155  const tmp<FieldField<Field, TypeR> >& tf2
156  )
157  {
158  tf1.clear();
159  if (tf2.isTmp())
160  {
161  tf2.ptr();
162  }
163  }
164 };
165 
166 
167 template<template<class> class Field, class TypeR, class Type2>
168 class reuseTmpTmpFieldField<Field, TypeR, TypeR, TypeR, Type2>
169 {
170 public:
171 
173  (
174  const tmp<FieldField<Field, TypeR> >& tf1,
175  const tmp<FieldField<Field, Type2> >& tf2
176  )
177  {
178  if (tf1.isTmp())
179  {
180  return tf1;
181  }
182  else
183  {
185  (
187  );
188  }
189  }
190 
191  static void clear
192  (
193  const tmp<FieldField<Field, TypeR> >& tf1,
194  const tmp<FieldField<Field, Type2> >& tf2
195  )
196  {
197  if (tf1.isTmp())
198  {
199  tf1.ptr();
200  }
201  tf2.clear();
202  }
203 };
204 
205 
206 template<template<class> class Field, class TypeR>
207 class reuseTmpTmpFieldField<Field, TypeR, TypeR, TypeR, TypeR>
208 {
209 public:
210 
212  (
213  const tmp<FieldField<Field, TypeR> >& tf1,
214  const tmp<FieldField<Field, TypeR> >& tf2
215  )
216  {
217  if (tf1.isTmp())
218  {
219  return tf1;
220  }
221  else if (tf2.isTmp())
222  {
223  return tf2;
224  }
225  else
226  {
228  (
230  );
231  }
232  }
233 
234  static void clear
235  (
236  const tmp<FieldField<Field, TypeR> >& tf1,
237  const tmp<FieldField<Field, TypeR> >& tf2
238  )
239  {
240  if (tf1.isTmp())
241  {
242  tf1.ptr();
243  tf2.clear();
244  }
245  else if (tf2.isTmp())
246  {
247  tf1.clear();
248  tf2.ptr();
249  }
250  }
251 };
252 
253 
254 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
255 
256 } // End namespace Foam
257 
258 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
259 
260 #endif
261 
262 // ************************************************************************* //
Foam::reuseTmpFieldField
Definition: FieldFieldReuseFunctions.H:37
Foam::FieldField
Generic field type.
Definition: FieldField.H:51
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::reuseTmpTmpFieldField
Definition: FieldFieldReuseFunctions.H:100
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::FieldField::NewCalculatedType
static tmp< FieldField< Field, Type > > NewCalculatedType(const FieldField< Field, Type2 > &ff)
Return a pointer to a new calculatedFvPatchFieldField created on.
Definition: FieldField.C:193
Foam::reuseTmpFieldField::clear
static void clear(const tmp< FieldField< Field, Type1 > > &tf1)
Definition: FieldFieldReuseFunctions.H:52
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::reuseTmpTmpFieldField::clear
static void clear(const tmp< FieldField< Field, Type1 > > &tf1, const tmp< FieldField< Field, Type2 > > &tf2)
Definition: FieldFieldReuseFunctions.H:117
Foam::reuseTmpFieldField< Field, TypeR, TypeR >::clear
static void clear(const tmp< FieldField< Field, TypeR > > &tf1)
Definition: FieldFieldReuseFunctions.H:82
Foam::reuseTmpFieldField::New
static tmp< FieldField< Field, TypeR > > New(const tmp< FieldField< Field, Type1 > > &tf1)
Definition: FieldFieldReuseFunctions.H:42
Foam::reuseTmpTmpFieldField::New
static tmp< FieldField< Field, TypeR > > New(const tmp< FieldField< Field, Type1 > > &tf1, const tmp< FieldField< Field, Type2 > > &tf2)
Definition: FieldFieldReuseFunctions.H:105