GeometricFieldFunctions.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2018-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "GeometricScalarField.H"
30 
31 #define TEMPLATE \
32  template<class Type, template<class> class PatchField, class GeoMesh>
34 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 
40 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
41 
42 template<class Type, template<class> class PatchField, class GeoMesh>
43 void component
44 (
45  GeometricField
46  <
48  PatchField,
49  GeoMesh
50  >& result,
51  const GeometricField<Type, PatchField, GeoMesh>& f1,
52  const direction d
53 );
54 
55 template<class Type, template<class> class PatchField, class GeoMesh>
56 void T
57 (
58  GeometricField<Type, PatchField, GeoMesh>& result,
59  const GeometricField<Type, PatchField, GeoMesh>& f1
60 );
61 
62 template
63 <
64  class Type,
65  template<class> class PatchField,
66  class GeoMesh,
67  direction r
68 >
69 void pow
70 (
71  GeometricField
72  <typename powProduct<Type, r>::type, PatchField, GeoMesh>& result,
73  const GeometricField<Type, PatchField, GeoMesh>& f1
74 );
75 
76 template
77 <
78  class Type,
79  template<class> class PatchField,
80  class GeoMesh,
81  direction r
82 >
83 tmp
84 <
85  GeometricField
86  <typename powProduct<Type, r>::type, PatchField, GeoMesh>
87 >
88 pow
89 (
90  const GeometricField<Type, PatchField, GeoMesh>& f1,
92 );
93 
94 template
95 <
96  class Type,
97  template<class> class PatchField,
98  class GeoMesh,
99  direction r
100 >
101 tmp
102 <
103  GeometricField
104  <typename powProduct<Type, r>::type, PatchField, GeoMesh>
105 >
106 pow
107 (
108  const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1,
110 );
111 
112 template<class Type, template<class> class PatchField, class GeoMesh>
113 void sqr
114 (
115  GeometricField
116  <typename outerProduct<Type, Type>::type, PatchField, GeoMesh>& f1,
117  const GeometricField<Type, PatchField, GeoMesh>& gf1
118 );
119 
120 template<class Type, template<class> class PatchField, class GeoMesh>
121 tmp
122 <
123  GeometricField
124  <
126  PatchField,
127  GeoMesh
128  >
129 >
130 sqr(const GeometricField<Type, PatchField, GeoMesh>& f1);
131 
132 template<class Type, template<class> class PatchField, class GeoMesh>
133 tmp
134 <
135  GeometricField
136  <
138  PatchField,
139  GeoMesh
140  >
141 >
142 sqr(const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1);
143 
144 template<class Type, template<class> class PatchField, class GeoMesh>
145 void magSqr
146 (
147  GeometricField<typename typeOfMag<Type>::type, PatchField, GeoMesh>& result,
148  const GeometricField<Type, PatchField, GeoMesh>& f1
149 );
150 
151 template<class Type, template<class> class PatchField, class GeoMesh>
153 magSqr
154 (
155  const GeometricField<Type, PatchField, GeoMesh>& f1
156 );
157 
158 template<class Type, template<class> class PatchField, class GeoMesh>
160 magSqr
161 (
162  const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1
163 );
164 
165 template<class Type, template<class> class PatchField, class GeoMesh>
166 void mag
167 (
168  GeometricField<typename typeOfMag<Type>::type, PatchField, GeoMesh>& result,
169  const GeometricField<Type, PatchField, GeoMesh>& tf1
170 );
171 
172 template<class Type, template<class> class PatchField, class GeoMesh>
174 mag
175 (
176  const GeometricField<Type, PatchField, GeoMesh>& f1
177 );
178 
179 template<class Type, template<class> class PatchField, class GeoMesh>
181 mag
182 (
183  const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1
184 );
185 
186 template<class Type, template<class> class PatchField, class GeoMesh>
187 void cmptAv
188 (
189  GeometricField
190  <
192  PatchField,
193  GeoMesh
194  >& result,
195  const GeometricField<Type, PatchField, GeoMesh>& f1
196 );
197 
198 template<class Type, template<class> class PatchField, class GeoMesh>
199 tmp
200 <
201  GeometricField
202  <
204  PatchField,
205  GeoMesh
206  >
207 >
208 cmptAv(const GeometricField<Type, PatchField, GeoMesh>& f1);
209 
210 template<class Type, template<class> class PatchField, class GeoMesh>
211 tmp
212 <
213  GeometricField
214  <
216  PatchField,
217  GeoMesh
218  >
219 >
220 cmptAv(const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1);
221 
222 
223 #define UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(ReturnType, Func, BinaryOp) \
224  \
225 template<class Type, template<class> class PatchField, class GeoMesh> \
226 dimensioned<ReturnType> Func \
227 ( \
228  const GeometricField<Type, PatchField, GeoMesh>& f1 \
229 ); \
230  \
231 template<class Type, template<class> class PatchField, class GeoMesh> \
232 dimensioned<ReturnType> Func \
233 ( \
234  const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1 \
235 );
236 
239 UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(MinMax<Type>, minMax, minMaxOp)
241 
242 #undef UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY
243 
244 
245 #define UNARY_REDUCTION_FUNCTION(ReturnType, Func, gFunc) \
246  \
247 template<class Type, template<class> class PatchField, class GeoMesh> \
248 dimensioned<ReturnType> Func \
249 ( \
250  const GeometricField<Type, PatchField, GeoMesh>& f1 \
251 ); \
252  \
253 template<class Type, template<class> class PatchField, class GeoMesh> \
254 dimensioned<ReturnType> Func \
255 ( \
256  const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1 \
257 );
258 
262 
263 #undef UNARY_REDUCTION_FUNCTION
264 
265 
266 BINARY_FUNCTION(Type, Type, Type, max)
267 BINARY_FUNCTION(Type, Type, Type, min)
268 BINARY_FUNCTION(Type, Type, Type, cmptMultiply)
269 BINARY_FUNCTION(Type, Type, Type, cmptDivide)
270 
271 BINARY_TYPE_FUNCTION(Type, Type, Type, max)
272 BINARY_TYPE_FUNCTION(Type, Type, Type, min)
273 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
274 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
275 
276 // ------------------------------------------------------------------------- //
277 
278 // Clamp Methods
279 
280 template<class Type, template<class> class PatchField, class GeoMesh>
281 void clamp
282 (
283  GeometricField<Type, PatchField, GeoMesh>& result,
284  const GeometricField<Type, PatchField, GeoMesh>& f1,
285  const Foam::zero_one
286 );
287 
288 template<class Type, template<class> class PatchField, class GeoMesh>
289 tmp<GeometricField<Type, PatchField, GeoMesh>>
290 clamp
291 (
292  const GeometricField<Type, PatchField, GeoMesh>& f1,
293  const Foam::zero_one
294 );
295 
296 template<class Type, template<class> class PatchField, class GeoMesh>
297 tmp<GeometricField<Type, PatchField, GeoMesh>>
298 clamp
299 (
300  const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1,
301  const Foam::zero_one
302 );
303 
304 BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax<Type>, clamp)
305 
306 
307 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
308 
309 TERNARY_FUNCTION(Type, Type, Type, scalar, lerp)
310 TERNARY_TYPE_FUNCTION_FFS(Type, Type, Type, scalar, lerp)
311 
312 
313 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
314 
315 UNARY_OPERATOR(Type, Type, -, negate, transform)
316 
317 BINARY_OPERATOR(Type, Type, scalar, *, '*', multiply)
318 BINARY_OPERATOR(Type, scalar, Type, *, '*', multiply)
319 BINARY_OPERATOR(Type, Type, scalar, /, '|', divide)
320 
321 BINARY_TYPE_OPERATOR_SF(Type, scalar, Type, *, '*', multiply)
322 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, *, '*', multiply)
323 
324 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, '|', divide)
325 
326 
327 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
328 
329 #define PRODUCT_OPERATOR(product, Op, OpFunc) \
330  \
331 template \
332 <class Type1, class Type2, template<class> class PatchField, class GeoMesh> \
333 void OpFunc \
334 ( \
335  GeometricField \
336  <typename product<Type1, Type2>::type, PatchField, GeoMesh>& result, \
337  const GeometricField<Type1, PatchField, GeoMesh>& f1, \
338  const GeometricField<Type2, PatchField, GeoMesh>& f2 \
339 ); \
340  \
341 template \
342 <class Type1, class Type2, template<class> class PatchField, class GeoMesh> \
343 tmp \
344 < \
345  GeometricField \
346  <typename product<Type1, Type2>::type, PatchField, GeoMesh> \
347 > \
348 operator Op \
349 ( \
350  const GeometricField<Type1, PatchField, GeoMesh>& f1, \
351  const GeometricField<Type2, PatchField, GeoMesh>& f2 \
352 ); \
353  \
354 template \
355 <class Type1, class Type2, template<class> class PatchField, class GeoMesh> \
356 tmp \
357 < \
358  GeometricField \
359  <typename product<Type1, Type2>::type, PatchField, GeoMesh> \
360 > \
361 operator Op \
362 ( \
363  const GeometricField<Type1, PatchField, GeoMesh>& f1, \
364  const tmp<GeometricField<Type2, PatchField, GeoMesh>>& tf2 \
365 ); \
366  \
367 template \
368 <class Type1, class Type2, template<class> class PatchField, class GeoMesh> \
369 tmp \
370 < \
371  GeometricField \
372  <typename product<Type1, Type2>::type, PatchField, GeoMesh> \
373 > \
374 operator Op \
375 ( \
376  const tmp<GeometricField<Type1, PatchField, GeoMesh>>& tf1, \
377  const GeometricField<Type2, PatchField, GeoMesh>& f2 \
378 ); \
379  \
380 template \
381 <class Type1, class Type2, template<class> class PatchField, class GeoMesh> \
382 tmp \
383 < \
384  GeometricField \
385  <typename product<Type1, Type2>::type, PatchField, GeoMesh> \
386 > \
387 operator Op \
388 ( \
389  const tmp<GeometricField<Type1, PatchField, GeoMesh>>& tf1, \
390  const tmp<GeometricField<Type2, PatchField, GeoMesh>>& tf2 \
391 ); \
392  \
393 template \
394 <class Form, class Type, template<class> class PatchField, class GeoMesh> \
395 void OpFunc \
396 ( \
397  GeometricField \
398  <typename product<Type, Form>::type, PatchField, GeoMesh>& result, \
399  const GeometricField<Type, PatchField, GeoMesh>& f1, \
400  const dimensioned<Form>& dvs \
401 ); \
402  \
403 template \
404 <class Form, class Type, template<class> class PatchField, class GeoMesh> \
405 tmp \
406 < \
407  GeometricField \
408  <typename product<Type, Form>::type, PatchField, GeoMesh> \
409 > \
410 operator Op \
411 ( \
412  const GeometricField<Type, PatchField, GeoMesh>& f1, \
413  const dimensioned<Form>& dvs \
414 ); \
415  \
416 template \
417 < \
418  class Form, \
419  class Cmpt, \
420  direction nCmpt, \
421  class Type, template<class> class PatchField, \
422  class GeoMesh \
423 > \
424 tmp \
425 < \
426  GeometricField \
427  <typename product<Form, Type>::type, PatchField, GeoMesh> \
428 > \
429 operator Op \
430 ( \
431  const GeometricField<Type, PatchField, GeoMesh>& f1, \
432  const VectorSpace<Form,Cmpt,nCmpt>& vs \
433 ); \
434  \
435 template \
436 <class Form, class Type, template<class> class PatchField, class GeoMesh> \
437 tmp \
438 < \
439  GeometricField \
440  <typename product<Type, Form>::type, PatchField, GeoMesh> \
441 > \
442 operator Op \
443 ( \
444  const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1, \
445  const dimensioned<Form>& dvs \
446 ); \
447  \
448 template \
449 < \
450  class Form, \
451  class Cmpt, \
452  direction nCmpt, \
453  class Type, template<class> class PatchField, \
454  class GeoMesh \
455 > \
456 tmp \
457 < \
458  GeometricField \
459  <typename product<Form, Type>::type, PatchField, GeoMesh> \
460 > \
461 operator Op \
462 ( \
463  const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1, \
464  const VectorSpace<Form,Cmpt,nCmpt>& vs \
465 ); \
466  \
467 template \
468 <class Form, class Type, template<class> class PatchField, class GeoMesh> \
469 void OpFunc \
470 ( \
471  GeometricField \
472  <typename product<Form, Type>::type, PatchField, GeoMesh>& result, \
473  const dimensioned<Form>& dvs, \
474  const GeometricField<Type, PatchField, GeoMesh>& f2 \
475 ); \
476  \
477 template \
478 <class Form, class Type, template<class> class PatchField, class GeoMesh> \
479 tmp \
480 < \
481  GeometricField \
482  <typename product<Form, Type>::type, PatchField, GeoMesh> \
483 > \
484 operator Op \
485 ( \
486  const dimensioned<Form>& dvs, \
487  const GeometricField<Type, PatchField, GeoMesh>& f2 \
488 ); \
489  \
490 template \
491 < \
492  class Form, \
493  class Cmpt, \
494  direction nCmpt, \
495  class Type, template<class> class PatchField, \
496  class GeoMesh \
497 > \
498 tmp \
499 < \
500  GeometricField \
501  <typename product<Form, Type>::type, PatchField, GeoMesh> \
502 > \
503 operator Op \
504 ( \
505  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
506  const GeometricField<Type, PatchField, GeoMesh>& f2 \
507 ); \
508  \
509 template \
510 <class Form, class Type, template<class> class PatchField, class GeoMesh> \
511 tmp \
512 < \
513  GeometricField \
514  <typename product<Form, Type>::type, PatchField, GeoMesh> \
515 > \
516 operator Op \
517 ( \
518  const dimensioned<Form>& dvs, \
519  const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf2 \
520 ); \
521  \
522 template \
523 < \
524  class Form, \
525  class Cmpt, \
526  direction nCmpt, \
527  class Type, template<class> class PatchField, \
528  class GeoMesh \
529 > \
530 tmp \
531 < \
532  GeometricField \
533  <typename product<Form, Type>::type, PatchField, GeoMesh> \
534 > \
535 operator Op \
536 ( \
537  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
538  const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf2 \
539 );
540 
541 PRODUCT_OPERATOR(typeOfSum, +, add)
542 PRODUCT_OPERATOR(typeOfSum, -, subtract)
543 
544 PRODUCT_OPERATOR(outerProduct, *, outer)
545 PRODUCT_OPERATOR(crossProduct, ^, cross)
546 PRODUCT_OPERATOR(innerProduct, &, dot)
547 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
548 
549 #undef PRODUCT_OPERATOR
550 
551 
552 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
553 
554 } // End namespace Foam
555 
556 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
557 
558 #include "undefFieldFunctionsM.H"
559 
560 // ************************************************************************* //
dimensioned< typename typeOfMag< Type >::type > sumMag(const DimensionedField< Type, GeoMesh > &f1)
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &f1)
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &f1)
#define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
type
Types of root.
Definition: Roots.H:52
void divide(DimensionedField< Type, GeoMesh > &result, const DimensionedField< Type, GeoMesh > &f1, const DimensionedField< scalar, GeoMesh > &f2)
uint8_t direction
Definition: direction.H:48
MinMax< scalar > scalarMinMax
A scalar min/max range.
Definition: MinMax.H:97
tmp< DimensionedField< typename DimensionedField< Type, GeoMesh >::cmptType, GeoMesh >> cmptAv(const DimensionedField< Type, GeoMesh > &f1)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Field< Type >::cmptType cmptType
Component type of the field elements.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
dimensionedSymmTensor sqr(const dimensionedVector &dv)
#define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc)
#define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpName, OpFunc)
void cross(FieldField< Field1, typename crossProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:118
#define BINARY_TYPE_FUNCTION(ReturnType, Type1, Type2, Func)
void dotdot(FieldField< Field1, typename scalarProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
void subtract(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
void outer(FieldField< Field1, typename outerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
void dot(FieldField< Field1, typename innerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
#define UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(ReturnType, Func, BinaryOp)
MinMax< label > minMax(const labelHashSet &set)
Find the min/max values of labelHashSet.
Definition: hashSets.C:54
#define BINARY_FUNCTION(ReturnType, Type1, Type2, Func)
Scalar specific part of the implementation of GeometricField.
Type gSum(const FieldField< Field, Type > &f)
void negate(DimensionedField< Type, GeoMesh > &result, const DimensionedField< Type, GeoMesh > &f1)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:26
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
dimensioned< Type > lerp(const dimensioned< Type > &a, const dimensioned< Type > &b, const scalar t)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
typeOfMag< Type >::type gSumMag(const FieldField< Field, Type > &f)
Represents 0/1 range or concept. Used for tagged dispatch or clamping.
Definition: pTraits.H:84
symmTypeOfRank< typename pTraits< arg1 >::cmptType, arg2 *direction(pTraits< arg1 >::rank) >::type type
Definition: products.H:176
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
#define UNARY_REDUCTION_FUNCTION(ReturnType, Func, gFunc)
#define PRODUCT_OPERATOR(product, Op, OpFunc)
dimensioned< scalarMinMax > minMaxMag(const DimensionedField< Type, GeoMesh > &f1)
Type gAverage(const FieldField< Field, Type > &f)
BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax< Type >, clip)
#define UNARY_OPERATOR(ReturnType, Type1, Op, OpFunc, Dfunc)
#define TERNARY_TYPE_FUNCTION_FFS(ReturnType, Type1, Type2, Type3, Func)
void multiply(DimensionedField< Type, GeoMesh > &result, const DimensionedField< Type, GeoMesh > &f1, const DimensionedField< scalar, GeoMesh > &f2)
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:521
#define TERNARY_FUNCTION(ReturnType, Type1, Type2, Type3, Func)
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Namespace for OpenFOAM.
dimensionSet clamp(const dimensionSet &a, const dimensionSet &range)
Definition: dimensionSet.C:271
pTraits< typename pTraits< arg1 >::cmptType >::magType type
Definition: products.H:96