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-2025 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  const label comm = UPstream::worldComm \
230 ); \
231  \
232 template<class Type, template<class> class PatchField, class GeoMesh> \
233 dimensioned<ReturnType> Func \
234 ( \
235  const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1, \
236  const label comm = UPstream::worldComm \
237 );
238 
241 UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(MinMax<Type>, minMax, plusOp)
243 
244 #undef UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY
245 
246 
247 #define UNARY_REDUCTION_FUNCTION(ReturnType, Func) \
248  \
249  \
250 template<class Type, template<class> class PatchField, class GeoMesh> \
251 dimensioned<ReturnType> Func \
252 ( \
253  const GeometricField<Type, PatchField, GeoMesh>& f1, \
254  const label comm = UPstream::worldComm \
255 ); \
256  \
257 template<class Type, template<class> class PatchField, class GeoMesh> \
258 dimensioned<ReturnType> Func \
259 ( \
260  const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1, \
261  const label comm = UPstream::worldComm \
262 );
263 
267 
268 #undef UNARY_REDUCTION_FUNCTION
269 
270 
271 BINARY_FUNCTION(Type, Type, Type, max)
272 BINARY_FUNCTION(Type, Type, Type, min)
273 BINARY_FUNCTION(Type, Type, Type, cmptMultiply)
274 BINARY_FUNCTION(Type, Type, Type, cmptDivide)
275 
276 BINARY_TYPE_FUNCTION(Type, Type, Type, max)
277 BINARY_TYPE_FUNCTION(Type, Type, Type, min)
278 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
279 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
280 
281 // ------------------------------------------------------------------------- //
282 
283 // Clamp Methods
284 
285 template<class Type, template<class> class PatchField, class GeoMesh>
286 void clamp
287 (
288  GeometricField<Type, PatchField, GeoMesh>& result,
289  const GeometricField<Type, PatchField, GeoMesh>& f1,
291 );
292 
293 template<class Type, template<class> class PatchField, class GeoMesh>
294 tmp<GeometricField<Type, PatchField, GeoMesh>>
295 clamp
296 (
297  const GeometricField<Type, PatchField, GeoMesh>& f1,
299 );
300 
301 template<class Type, template<class> class PatchField, class GeoMesh>
302 tmp<GeometricField<Type, PatchField, GeoMesh>>
303 clamp
304 (
305  const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1,
307 );
308 
309 BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax<Type>, clamp)
310 
311 
312 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
313 
314 TERNARY_FUNCTION(Type, Type, Type, scalar, lerp)
315 TERNARY_TYPE_FUNCTION_FFS(Type, Type, Type, scalar, lerp)
316 
317 
318 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
319 
320 UNARY_OPERATOR(Type, Type, -, negate, transform)
321 
322 BINARY_OPERATOR(Type, Type, scalar, *, '*', multiply)
323 BINARY_OPERATOR(Type, scalar, Type, *, '*', multiply)
324 BINARY_OPERATOR(Type, Type, scalar, /, '|', divide)
325 
326 BINARY_TYPE_OPERATOR_SF(Type, scalar, Type, *, '*', multiply)
327 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, *, '*', multiply)
328 
329 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, '|', divide)
330 
331 
332 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
333 
334 #define PRODUCT_OPERATOR(product, Op, OpFunc) \
335  \
336 template \
337 <class Type1, class Type2, template<class> class PatchField, class GeoMesh> \
338 void OpFunc \
339 ( \
340  GeometricField \
341  <typename product<Type1, Type2>::type, PatchField, GeoMesh>& result, \
342  const GeometricField<Type1, PatchField, GeoMesh>& f1, \
343  const GeometricField<Type2, PatchField, GeoMesh>& f2 \
344 ); \
345  \
346 template \
347 <class Type1, class Type2, template<class> class PatchField, class GeoMesh> \
348 tmp \
349 < \
350  GeometricField \
351  <typename product<Type1, Type2>::type, PatchField, GeoMesh> \
352 > \
353 operator Op \
354 ( \
355  const GeometricField<Type1, PatchField, GeoMesh>& f1, \
356  const GeometricField<Type2, PatchField, GeoMesh>& f2 \
357 ); \
358  \
359 template \
360 <class Type1, class Type2, template<class> class PatchField, class GeoMesh> \
361 tmp \
362 < \
363  GeometricField \
364  <typename product<Type1, Type2>::type, PatchField, GeoMesh> \
365 > \
366 operator Op \
367 ( \
368  const GeometricField<Type1, PatchField, GeoMesh>& f1, \
369  const tmp<GeometricField<Type2, PatchField, GeoMesh>>& tf2 \
370 ); \
371  \
372 template \
373 <class Type1, class Type2, template<class> class PatchField, class GeoMesh> \
374 tmp \
375 < \
376  GeometricField \
377  <typename product<Type1, Type2>::type, PatchField, GeoMesh> \
378 > \
379 operator Op \
380 ( \
381  const tmp<GeometricField<Type1, PatchField, GeoMesh>>& tf1, \
382  const GeometricField<Type2, PatchField, GeoMesh>& f2 \
383 ); \
384  \
385 template \
386 <class Type1, class Type2, template<class> class PatchField, class GeoMesh> \
387 tmp \
388 < \
389  GeometricField \
390  <typename product<Type1, Type2>::type, PatchField, GeoMesh> \
391 > \
392 operator Op \
393 ( \
394  const tmp<GeometricField<Type1, PatchField, GeoMesh>>& tf1, \
395  const tmp<GeometricField<Type2, PatchField, GeoMesh>>& tf2 \
396 ); \
397  \
398 template \
399 <class Form, class Type, template<class> class PatchField, class GeoMesh> \
400 void OpFunc \
401 ( \
402  GeometricField \
403  <typename product<Type, Form>::type, PatchField, GeoMesh>& result, \
404  const GeometricField<Type, PatchField, GeoMesh>& f1, \
405  const dimensioned<Form>& dvs \
406 ); \
407  \
408 template \
409 <class Form, class Type, template<class> class PatchField, class GeoMesh> \
410 tmp \
411 < \
412  GeometricField \
413  <typename product<Type, Form>::type, PatchField, GeoMesh> \
414 > \
415 operator Op \
416 ( \
417  const GeometricField<Type, PatchField, GeoMesh>& f1, \
418  const dimensioned<Form>& dvs \
419 ); \
420  \
421 template \
422 < \
423  class Form, \
424  class Cmpt, \
425  direction nCmpt, \
426  class Type, template<class> class PatchField, \
427  class GeoMesh \
428 > \
429 tmp \
430 < \
431  GeometricField \
432  <typename product<Form, Type>::type, PatchField, GeoMesh> \
433 > \
434 operator Op \
435 ( \
436  const GeometricField<Type, PatchField, GeoMesh>& f1, \
437  const VectorSpace<Form,Cmpt,nCmpt>& vs \
438 ); \
439  \
440 template \
441 <class Form, class Type, template<class> class PatchField, class GeoMesh> \
442 tmp \
443 < \
444  GeometricField \
445  <typename product<Type, Form>::type, PatchField, GeoMesh> \
446 > \
447 operator Op \
448 ( \
449  const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1, \
450  const dimensioned<Form>& dvs \
451 ); \
452  \
453 template \
454 < \
455  class Form, \
456  class Cmpt, \
457  direction nCmpt, \
458  class Type, template<class> class PatchField, \
459  class GeoMesh \
460 > \
461 tmp \
462 < \
463  GeometricField \
464  <typename product<Form, Type>::type, PatchField, GeoMesh> \
465 > \
466 operator Op \
467 ( \
468  const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1, \
469  const VectorSpace<Form,Cmpt,nCmpt>& vs \
470 ); \
471  \
472 template \
473 <class Form, class Type, template<class> class PatchField, class GeoMesh> \
474 void OpFunc \
475 ( \
476  GeometricField \
477  <typename product<Form, Type>::type, PatchField, GeoMesh>& result, \
478  const dimensioned<Form>& dvs, \
479  const GeometricField<Type, PatchField, GeoMesh>& f2 \
480 ); \
481  \
482 template \
483 <class Form, class Type, template<class> class PatchField, class GeoMesh> \
484 tmp \
485 < \
486  GeometricField \
487  <typename product<Form, Type>::type, PatchField, GeoMesh> \
488 > \
489 operator Op \
490 ( \
491  const dimensioned<Form>& dvs, \
492  const GeometricField<Type, PatchField, GeoMesh>& f2 \
493 ); \
494  \
495 template \
496 < \
497  class Form, \
498  class Cmpt, \
499  direction nCmpt, \
500  class Type, template<class> class PatchField, \
501  class GeoMesh \
502 > \
503 tmp \
504 < \
505  GeometricField \
506  <typename product<Form, Type>::type, PatchField, GeoMesh> \
507 > \
508 operator Op \
509 ( \
510  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
511  const GeometricField<Type, PatchField, GeoMesh>& f2 \
512 ); \
513  \
514 template \
515 <class Form, class Type, template<class> class PatchField, class GeoMesh> \
516 tmp \
517 < \
518  GeometricField \
519  <typename product<Form, Type>::type, PatchField, GeoMesh> \
520 > \
521 operator Op \
522 ( \
523  const dimensioned<Form>& dvs, \
524  const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf2 \
525 ); \
526  \
527 template \
528 < \
529  class Form, \
530  class Cmpt, \
531  direction nCmpt, \
532  class Type, template<class> class PatchField, \
533  class GeoMesh \
534 > \
535 tmp \
536 < \
537  GeometricField \
538  <typename product<Form, Type>::type, PatchField, GeoMesh> \
539 > \
540 operator Op \
541 ( \
542  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
543  const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf2 \
544 );
545 
546 PRODUCT_OPERATOR(typeOfSum, +, add)
547 PRODUCT_OPERATOR(typeOfSum, -, subtract)
548 
549 PRODUCT_OPERATOR(outerProduct, *, outer)
550 PRODUCT_OPERATOR(crossProduct, ^, cross)
551 PRODUCT_OPERATOR(innerProduct, &, dot)
552 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
553 
554 #undef PRODUCT_OPERATOR
555 
556 
557 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
558 
559 } // End namespace Foam
560 
561 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
562 
563 #include "undefFieldFunctionsM.H"
564 
565 // ************************************************************************* //
#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:46
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)
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &f1, const label comm)
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)
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &f1, const label comm)
dimensioned< scalarMinMax > minMaxMag(const DimensionedField< Type, GeoMesh > &f1, const label comm)
Scalar specific part of the implementation of GeometricField.
#define BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func)
#define UNARY_REDUCTION_FUNCTION(ReturnType, Func)
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)
refinementData transform(const tensor &, const refinementData val)
No-op rotational transform for base types.
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)
Represents 0/1 range or concept. Used for tagged dispatch or clamping.
Definition: pTraits.H:51
symmTypeOfRank< typename pTraits< arg1 >::cmptType, arg2 *direction(pTraits< arg1 >::rank) >::type type
Definition: products.H:176
dimensioned< typename typeOfMag< Type >::type > sumMag(const DimensionedField< Type, GeoMesh > &f1, const label comm)
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
#define PRODUCT_OPERATOR(product, Op, OpFunc)
#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)
#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