DimensionedFieldFunctions.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-2023 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 #include "DimensionedScalarField.H"
27 
28 #define TEMPLATE \
29  template \
30  < \
31  class Type, \
32  class GeoMesh, \
33  template<class> class PrimitiveField \
34  >
35 #define TEMPLATE2 \
36  template \
37  < \
38  class Type, \
39  class GeoMesh, \
40  template<class> class PrimitiveField1, \
41  template<class> class PrimitiveField2 \
42  >
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 // * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * //
51 
52 template
53 <
54  class Type,
55  class GeoMesh,
56  template<class> class PrimitiveField,
57  direction r
58 >
59 tmp<DimensionedField<typename powProduct<Type, r>::type, GeoMesh, Field>>
60 pow
61 (
62  const DimensionedField<Type, GeoMesh, PrimitiveField>& df,
64 );
65 
66 template
67 <
68  class Type,
69  class GeoMesh,
70  template<class> class PrimitiveField,
71  direction r
72 >
73 tmp<DimensionedField<typename powProduct<Type, r>::type, GeoMesh, Field>>
74 pow
75 (
76  const tmp<DimensionedField<Type, GeoMesh, PrimitiveField>>& tdf,
78 );
79 
80 template<class Type, class GeoMesh, template<class> class PrimitiveField>
81 tmp
82 <
83  DimensionedField
84  <
86  GeoMesh,
87  Field
88  >
89 >
90 sqr(const DimensionedField<Type, GeoMesh, PrimitiveField>& df);
91 
92 template<class Type, class GeoMesh, template<class> class PrimitiveField>
93 tmp
94 <
95  DimensionedField
96  <
98  GeoMesh,
99  Field
100  >
101 >
102 sqr(const tmp<DimensionedField<Type, GeoMesh, PrimitiveField>>& tdf);
103 
104 template<class Type, class GeoMesh, template<class> class PrimitiveField>
105 tmp<DimensionedField<scalar, GeoMesh, Field>> magSqr
106 (
107  const DimensionedField<Type, GeoMesh, PrimitiveField>& df
108 );
109 
110 template<class Type, class GeoMesh, template<class> class PrimitiveField>
111 tmp<DimensionedField<scalar, GeoMesh, Field>> magSqr
112 (
113  const tmp<DimensionedField<Type, GeoMesh, PrimitiveField>>& tdf
114 );
115 
116 template<class Type, class GeoMesh, template<class> class PrimitiveField>
117 tmp<DimensionedField<scalar, GeoMesh, Field>> mag
118 (
119  const DimensionedField<Type, GeoMesh, PrimitiveField>& df
120 );
121 
122 template<class Type, class GeoMesh, template<class> class PrimitiveField>
123 tmp<DimensionedField<scalar, GeoMesh, Field>> mag
124 (
125  const tmp<DimensionedField<Type, GeoMesh, PrimitiveField>>& tdf
126 );
127 
128 template<class Type, class GeoMesh, template<class> class PrimitiveField>
129 tmp
130 <
131  DimensionedField
132  <
134  GeoMesh,
135  Field
136  >
137 >
138 cmptAv(const DimensionedField<Type, GeoMesh, PrimitiveField>& df);
139 
140 template<class Type, class GeoMesh, template<class> class PrimitiveField>
141 tmp
142 <
143  DimensionedField
144  <
146  GeoMesh,
147  Field
148  >
149 >
150 cmptAv(const tmp<DimensionedField<Type, GeoMesh, PrimitiveField>>& tdf);
151 
152 UNARY_FUNCTION(Type, Type, cmptMag, cmptMag);
153 
154 
155 #define UNARY_REDUCTION_FUNCTION(returnType, func, dfunc) \
156  \
157 template<class Type, class GeoMesh, template<class> class PrimitiveField> \
158 dimensioned<returnType> func \
159 ( \
160  const DimensionedField<Type, GeoMesh, PrimitiveField>& df \
161 ); \
162 template<class Type, class GeoMesh, template<class> class PrimitiveField> \
163 dimensioned<returnType> func \
164 ( \
165  const tmp<DimensionedField<Type, GeoMesh, PrimitiveField>>& tdf1 \
166 );
167 
173 
174 #undef UNARY_REDUCTION_FUNCTION
175 
176 
177 BINARY_FUNCTION(Type, Type, Type, max)
178 BINARY_FUNCTION(Type, Type, Type, min)
179 BINARY_FUNCTION(Type, Type, Type, cmptMultiply)
180 BINARY_FUNCTION(Type, Type, Type, cmptDivide)
181 
182 BINARY_TYPE_FUNCTION(Type, Type, Type, max)
183 BINARY_TYPE_FUNCTION(Type, Type, Type, min)
184 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
185 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
186 
187 
188 // * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * //
189 
190 UNARY_OPERATOR(Type, Type, -, negate, transform)
191 
192 BINARY_OPERATOR(Type, Type, scalar, *, '*', multiply)
193 BINARY_OPERATOR(Type, scalar, Type, *, '*', multiply)
194 BINARY_OPERATOR(Type, Type, scalar, /, '|', divide)
195 
196 BINARY_TYPE_OPERATOR_SF(Type, scalar, Type, *, '*', multiply)
197 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, *, '*', multiply)
198 
199 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, '|', divide)
200 
201 
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203 
204 #define PRODUCT_OPERATOR(product, op, opFunc) \
205  \
206 template \
207 < \
208  class Type1, \
209  class Type2, \
210  class GeoMesh, \
211  template<class> class PrimitiveField1, \
212  template<class> class PrimitiveField2 \
213 > \
214 tmp \
215 < \
216  DimensionedField \
217  < \
218  typename product<Type1, Type2>::type, \
219  GeoMesh, \
220  Field \
221  > \
222 > \
223 operator op \
224 ( \
225  const DimensionedField<Type1, GeoMesh, PrimitiveField1>& df1, \
226  const DimensionedField<Type2, GeoMesh, PrimitiveField2>& df2 \
227 ); \
228  \
229 template \
230 < \
231  class Type1, \
232  class Type2, \
233  class GeoMesh, \
234  template<class> class PrimitiveField1, \
235  template<class> class PrimitiveField2 \
236 > \
237 tmp \
238 < \
239  DimensionedField \
240  < \
241  typename product<Type1, Type2>::type, \
242  GeoMesh, \
243  Field \
244  > \
245 > \
246 operator op \
247 ( \
248  const DimensionedField<Type1, GeoMesh, PrimitiveField1>& df1, \
249  const tmp<DimensionedField<Type2, GeoMesh, PrimitiveField2>>& tdf2 \
250 ); \
251  \
252 template \
253 < \
254  class Type1, \
255  class Type2, \
256  class GeoMesh, \
257  template<class> class PrimitiveField1, \
258  template<class> class PrimitiveField2 \
259 > \
260 tmp \
261 < \
262  DimensionedField \
263  < \
264  typename product<Type1, Type2>::type, \
265  GeoMesh, \
266  Field \
267  > \
268 > \
269 operator op \
270 ( \
271  const tmp<DimensionedField<Type1, GeoMesh, PrimitiveField1>>& tdf1, \
272  const DimensionedField<Type2, GeoMesh, PrimitiveField2>& df2 \
273 ); \
274  \
275 template \
276 < \
277  class Type1, \
278  class Type2, \
279  class GeoMesh, \
280  template<class> class PrimitiveField1, \
281  template<class> class PrimitiveField2 \
282 > \
283 tmp \
284 < \
285  DimensionedField \
286  < \
287  typename product<Type1, Type2>::type, \
288  GeoMesh, \
289  Field \
290  > \
291 > \
292 operator op \
293 ( \
294  const tmp<DimensionedField<Type1, GeoMesh, PrimitiveField1>>& tdf1, \
295  const tmp<DimensionedField<Type2, GeoMesh, PrimitiveField2>>& tdf2 \
296 ); \
297  \
298 template \
299 < \
300  class Form, \
301  class Type, \
302  class GeoMesh, \
303  template<class> class PrimitiveField \
304 > \
305 tmp<DimensionedField<typename product<Type, Form>::type, GeoMesh, Field>> \
306 operator op \
307 ( \
308  const DimensionedField<Type, GeoMesh, PrimitiveField>& df1, \
309  const dimensioned<Form>& dvs \
310 ); \
311  \
312 template \
313 < \
314  class Form, \
315  class Cmpt, \
316  direction nCmpt, \
317  class Type, \
318  class GeoMesh, \
319  template<class> class PrimitiveField \
320 > \
321 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh, Field>> \
322 operator op \
323 ( \
324  const DimensionedField<Type, GeoMesh, PrimitiveField>& df1, \
325  const VectorSpace<Form,Cmpt,nCmpt>& vs \
326 ); \
327  \
328 template \
329 < \
330  class Form, \
331  class Type, \
332  class GeoMesh, \
333  template<class> class PrimitiveField \
334 > \
335 tmp<DimensionedField<typename product<Type, Form>::type, GeoMesh, Field>> \
336 operator op \
337 ( \
338  const tmp<DimensionedField<Type, GeoMesh, PrimitiveField>>& tdf1, \
339  const dimensioned<Form>& dvs \
340 ); \
341  \
342 template \
343 < \
344  class Form, \
345  class Cmpt, \
346  direction nCmpt, \
347  class Type, \
348  class GeoMesh, \
349  template<class> class PrimitiveField \
350 > \
351 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh, Field>> \
352 operator op \
353 ( \
354  const tmp<DimensionedField<Type, GeoMesh, PrimitiveField>>& tdf1, \
355  const VectorSpace<Form,Cmpt,nCmpt>& vs \
356 ); \
357  \
358 template \
359 < \
360  class Form, \
361  class Type, \
362  class GeoMesh, \
363  template<class> class PrimitiveField \
364 > \
365 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh, Field>> \
366 operator op \
367 ( \
368  const dimensioned<Form>& dvs, \
369  const DimensionedField<Type, GeoMesh, PrimitiveField>& df1 \
370 ); \
371  \
372 template \
373 < \
374  class Form, \
375  class Cmpt, \
376  direction nCmpt, \
377  class Type, \
378  class GeoMesh, \
379  template<class> class PrimitiveField \
380 > \
381 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh, Field>> \
382 operator op \
383 ( \
384  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
385  const DimensionedField<Type, GeoMesh, PrimitiveField>& df1 \
386 ); \
387  \
388 template \
389 < \
390  class Form, \
391  class Type, \
392  class GeoMesh, \
393  template<class> class PrimitiveField \
394 > \
395 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh, Field>> \
396 operator op \
397 ( \
398  const dimensioned<Form>& dvs, \
399  const tmp<DimensionedField<Type, GeoMesh, PrimitiveField>>& tdf1 \
400 ); \
401  \
402 template \
403 < \
404  class Form, \
405  class Cmpt, \
406  direction nCmpt, \
407  class Type, \
408  class GeoMesh, \
409  template<class> class PrimitiveField \
410 > \
411 tmp<DimensionedField<typename product<Form, Type>::type, GeoMesh, Field>> \
412 operator op \
413 ( \
414  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
415  const tmp<DimensionedField<Type, GeoMesh, PrimitiveField>>& tdf1 \
416 );
417 
418 PRODUCT_OPERATOR(typeOfSum, +, add)
419 PRODUCT_OPERATOR(typeOfSum, -, subtract)
420 
421 PRODUCT_OPERATOR(outerProduct, *, outer)
422 PRODUCT_OPERATOR(crossProduct, ^, cross)
423 PRODUCT_OPERATOR(innerProduct, &, dot)
424 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
425 
426 #undef PRODUCT_OPERATOR
427 
428 
429 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
430 
431 } // End namespace Foam
432 
433 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
434 
435 #include "undefFieldFunctionsM.H"
436 
437 // ************************************************************************* //
#define BINARY_TYPE_FUNCTION(ReturnType, Type1, Type2, Func)
#define UNARY_REDUCTION_FUNCTION(returnType, func, dfunc)
#define PRODUCT_OPERATOR(product, op, opFunc)
Scalar specific part of the implementation of DimensionedField.
#define BINARY_TYPE_OPERATOR_FS(TYPE, op, opFunc)
#define BINARY_FUNCTION(func)
#define BINARY_OPERATOR(Template, Type, Type1, Type2, op, opFunc)
#define UNARY_OPERATOR(op, opFunc)
#define UNARY_FUNCTION(Template, Type, Type1, func)
#define BINARY_TYPE_OPERATOR_SF(TYPE, op, opFunc)
PrimitiveField< Type >::cmptType cmptType
Component type of the elements of the field.
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:90
symmTypeOfRank< typename pTraits< arg1 >::cmptType, arg2 *direction(pTraits< arg1 >::rank) >::type type
Definition: products.H:136
Namespace for OpenFOAM.
void subtract(LagrangianPatchField< typename typeOfSum< Type1, Type2 >::type > &f, const LagrangianPatchField< Type1 > &f1, const LagrangianPatchField< Type2 > &f2)
void dot(LagrangianPatchField< typename innerProduct< Type1, Type2 >::type > &f, const LagrangianPatchField< Type1 > &f1, const LagrangianPatchField< Type2 > &f2)
void negate(LagrangianPatchField< Type > &f, const LagrangianPatchField< Type > &f1)
void cmptMultiply(LagrangianPatchField< Type > &f, const LagrangianPatchField< Type > &f1, const LagrangianPatchField< Type > &f2)
Type gSum(const FieldField< Field, Type > &f)
void outer(LagrangianPatchField< typename outerProduct< Type1, Type2 >::type > &f, const LagrangianPatchField< Type1 > &f1, const LagrangianPatchField< Type2 > &f2)
void divide(LagrangianPatchField< Type > &f, const LagrangianPatchField< Type > &f1, const LagrangianPatchField< scalar > &f2)
void dotdot(LagrangianPatchField< typename scalarProduct< Type1, Type2 >::type > &f, const LagrangianPatchField< Type1 > &f1, const LagrangianPatchField< Type2 > &f2)
scalar gSumMag(const FieldField< Field, Type > &f)
void cmptDivide(LagrangianPatchField< Type > &f, const LagrangianPatchField< Type > &f1, const LagrangianPatchField< Type > &f2)
dimensioned< Type > average(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
dimensioned< scalar > sumMag(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
void cross(LagrangianPatchField< typename crossProduct< Type1, Type2 >::type > &f, const LagrangianPatchField< Type1 > &f1, const LagrangianPatchField< Type2 > &f2)
void mag(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
void pow(LagrangianPatchField< typename powProduct< Type, r >::type > &f, const LagrangianPatchField< Type > &f1)
void multiply(LagrangianPatchField< Type > &f, const LagrangianPatchField< scalar > &f1, const LagrangianPatchField< Type > &f2)
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:501
void cmptAv(LagrangianPatchField< typename LagrangianPatchField< Type >::cmptType > &f, const LagrangianPatchField< Type > &f1)
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
void sqr(LagrangianPatchField< typename outerProduct< Type, Type >::type > &f, const LagrangianPatchField< Type > &f1)
Type gAverage(const FieldField< Field, Type > &f)
void magSqr(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
Type gMin(const FieldField< Field, Type > &f)
void add(LagrangianPatchField< typename typeOfSum< Type1, Type2 >::type > &f, const LagrangianPatchField< Type1 > &f1, const LagrangianPatchField< Type2 > &f2)
Type gMax(const FieldField< Field, Type > &f)
void cmptMag(LagrangianPatchField< Type > &f, const LagrangianPatchField< Type > &f1)
uint8_t direction
Definition: direction.H:45