Loading...
Searching...
No Matches
FieldFunctions.C
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) 2019-2025 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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 "PstreamReduceOps.H"
30#include "FieldReuseFunctions.H"
31
32#define TEMPLATE template<class Type>
33#include "FieldFunctionsM.C"
34
35// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37namespace Foam
38{
39
40/* * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * */
41
42template<class Type>
43void component
44(
45 Field<typename Field<Type>::cmptType>& result,
46 const UList<Type>& f1,
47 const direction d
48)
49{
50 typedef typename Field<Type>::cmptType resultType;
51
53 (
54 resultType, result, =, Type, f1, .component, const direction, d
55 )
56}
57
58
59template<class Type>
60void T(Field<Type>& result, const UList<Type>& f1)
61{
62 TFOR_ALL_F_OP_F_FUNC(Type, result, =, Type, f1, T)
63}
64
65
66template<class Type, direction r>
67void pow
68(
69 Field<typename powProduct<Type, r>::type>& result,
70 const UList<Type>& f1
71)
72{
73 typedef typename powProduct<Type, r>::type resultType;
74
76 (
77 resultType, result, =, pow, Type, f1, resultType,
79 )
80}
81
82template<class Type, direction r>
83tmp<Field<typename powProduct<Type, r>::type>>
84pow
85(
86 const UList<Type>& f1,
88)
89{
90 typedef typename powProduct<Type, r>::type resultType;
91 auto tres = tmp<Field<resultType>>::New(f1.size());
92 pow<Type, r>(tres.ref(), f1);
93 return tres;
94}
95
96template<class Type, direction r>
97tmp<Field<typename powProduct<Type, r>::type>>
98pow
99(
100 const tmp<Field<Type>>& tf1,
102)
103{
104 typedef typename powProduct<Type, r>::type resultType;
105 auto tres = reuseTmp<resultType, Type>::New(tf1);
106 pow<Type, r>(tres.ref(), tf1());
107 tf1.clear();
108 return tres;
109}
110
111
112template<class Type>
113void sqr
114(
115 Field<typename outerProduct<Type, Type>::type>& result,
116 const UList<Type>& f1
117)
118{
119 typedef typename outerProduct<Type, Type>::type resultType;
120
121 TFOR_ALL_F_OP_FUNC_F(resultType, result, =, sqr, Type, f1)
122}
123
124template<class Type>
125tmp<Field<typename outerProduct<Type, Type>::type>>
126sqr(const UList<Type>& f1)
127{
128 typedef typename outerProduct<Type, Type>::type resultType;
129 auto tres = tmp<Field<resultType>>::New(f1.size());
130 sqr(tres.ref(), f1);
131 return tres;
132}
133
134template<class Type>
135tmp<Field<typename outerProduct<Type, Type>::type>>
136sqr(const tmp<Field<Type>>& tf1)
137{
138 typedef typename outerProduct<Type, Type>::type resultType;
139 auto tres = reuseTmp<resultType, Type>::New(tf1);
140 sqr(tres.ref(), tf1());
141 tf1.clear();
142 return tres;
143}
144
145
146template<class Type>
147void magSqr
148(
149 Field<typename typeOfMag<Type>::type>& result,
150 const UList<Type>& f1
151)
152{
153 typedef typename typeOfMag<Type>::type resultType;
154
155 TFOR_ALL_F_OP_FUNC_F(resultType, result, =, magSqr, Type, f1)
156}
157
158template<class Type>
159tmp<Field<typename typeOfMag<Type>::type>>
160magSqr(const UList<Type>& f1)
161{
162 typedef typename typeOfMag<Type>::type resultType;
163
164 auto tres = tmp<Field<resultType>>::New(f1.size());
165 magSqr(tres.ref(), f1);
166 return tres;
167}
168
169template<class Type>
170tmp<Field<typename typeOfMag<Type>::type>>
171magSqr(const tmp<Field<Type>>& tf1)
172{
173 typedef typename typeOfMag<Type>::type resultType;
174
175 auto tres = reuseTmp<resultType, Type>::New(tf1);
176 magSqr(tres.ref(), tf1());
177 tf1.clear();
178 return tres;
179}
180
181
182template<class Type>
183void mag
184(
185 Field<typename typeOfMag<Type>::type>& result,
186 const UList<Type>& f1
187)
188{
189 typedef typename typeOfMag<Type>::type resultType;
190
191 TFOR_ALL_F_OP_FUNC_F(resultType, result, =, mag, Type, f1)
192}
193
194template<class Type>
195tmp<Field<typename typeOfMag<Type>::type>>
196mag(const UList<Type>& f1)
197{
198 typedef typename typeOfMag<Type>::type resultType;
199
200 auto tres = tmp<Field<resultType>>::New(f1.size());
201 mag(tres.ref(), f1);
202 return tres;
203}
204
205template<class Type>
206tmp<Field<typename typeOfMag<Type>::type>>
207mag(const tmp<Field<Type>>& tf1)
208{
209 typedef typename typeOfMag<Type>::type resultType;
210
211 auto tres = reuseTmp<resultType, Type>::New(tf1);
212 mag(tres.ref(), tf1());
213 tf1.clear();
214 return tres;
215}
216
217
218template<class Type>
219void cmptMax
220(
221 Field<typename Field<Type>::cmptType>& result,
222 const UList<Type>& f1
223)
225 typedef typename Field<Type>::cmptType resultType;
226
227 TFOR_ALL_F_OP_FUNC_F(resultType, result, =, cmptMax, Type, f1)
228}
229
230template<class Type>
231tmp<Field<typename Field<Type>::cmptType>> cmptMax(const UList<Type>& f1)
232{
233 typedef typename Field<Type>::cmptType resultType;
234 auto tres = tmp<Field<resultType>>::New(f1.size());
235 cmptMax(tres.ref(), f1);
236 return tres;
237}
238
239template<class Type>
240tmp<Field<typename Field<Type>::cmptType>> cmptMax(const tmp<Field<Type>>& tf1)
241{
242 typedef typename Field<Type>::cmptType resultType;
243 auto tres = reuseTmp<resultType, Type>::New(tf1);
244 cmptMax(tres.ref(), tf1());
245 tf1.clear();
246 return tres;
247}
248
249
250template<class Type>
251void cmptMin
252(
253 Field<typename Field<Type>::cmptType>& result,
254 const UList<Type>& f1
255)
257 typedef typename Field<Type>::cmptType resultType;
258
259 TFOR_ALL_F_OP_FUNC_F(resultType, result, =, cmptMin, Type, f1)
260}
261
262template<class Type>
263tmp<Field<typename Field<Type>::cmptType>> cmptMin(const UList<Type>& f1)
264{
265 typedef typename Field<Type>::cmptType resultType;
266 auto tres = tmp<Field<resultType>>::New(f1.size());
267 cmptMin(tres.ref(), f1);
268 return tres;
269}
270
271template<class Type>
272tmp<Field<typename Field<Type>::cmptType>> cmptMin(const tmp<Field<Type>>& tf1)
273{
274 typedef typename Field<Type>::cmptType resultType;
275 auto tres = reuseTmp<resultType, Type>::New(tf1);
276 cmptMin(tres.ref(), tf1());
277 tf1.clear();
278 return tres;
279}
280
281
282template<class Type>
283void cmptAv
284(
285 Field<typename Field<Type>::cmptType>& result,
286 const UList<Type>& f1
287)
289 typedef typename Field<Type>::cmptType resultType;
290
291 TFOR_ALL_F_OP_FUNC_F(resultType, result, =, cmptAv, Type, f1)
292}
293
294template<class Type>
295tmp<Field<typename Field<Type>::cmptType>> cmptAv(const UList<Type>& f1)
296{
297 typedef typename Field<Type>::cmptType resultType;
298 auto tres = tmp<Field<resultType>>::New(f1.size());
299 cmptAv(tres.ref(), f1);
300 return tres;
301}
302
303template<class Type>
304tmp<Field<typename Field<Type>::cmptType>> cmptAv(const tmp<Field<Type>>& tf1)
305{
306 typedef typename Field<Type>::cmptType resultType;
307 auto tres = reuseTmp<resultType, Type>::New(tf1);
308 cmptAv(tres.ref(), tf1());
309 tf1.clear();
310 return tres;
311}
312
313
314template<class Type>
315void cmptMag(Field<Type>& result, const UList<Type>& f1)
316{
317 TFOR_ALL_F_OP_FUNC_F(Type, result, =, cmptMag, Type, f1)
318}
319
320template<class Type>
321tmp<Field<Type>> cmptMag(const UList<Type>& f1)
323 auto tres = tmp<Field<Type>>::New(f1.size());
324 cmptMag(tres.ref(), f1);
325 return tres;
326}
327
328template<class Type>
329tmp<Field<Type>> cmptMag(const tmp<Field<Type>>& tf1)
330{
331 auto tres = New(tf1);
332 cmptMag(tres.ref(), tf1());
333 tf1.clear();
334 return tres;
335}
336
337
338template<class Type>
339void cmptMagSqr(Field<Type>& result, const UList<Type>& f1)
340{
341 TFOR_ALL_F_OP_FUNC_F(Type, result, =, cmptMagSqr, Type, f1)
342}
343
344template<class Type>
345tmp<Field<Type>> cmptMagSqr(const UList<Type>& f1)
347 auto tres = tmp<Field<Type>>::New(f1.size());
348 cmptMagSqr(tres.ref(), f1);
349 return tres;
350}
351
352template<class Type>
353tmp<Field<Type>> cmptMagSqr(const tmp<Field<Type>>& tf1)
354{
355 auto tres = New(tf1);
356 cmptMagSqr(tres.ref(), tf1());
357 tf1.clear();
358 return tres;
359}
360
361
362#define TMP_UNARY_FUNCTION(ReturnType, Func) \
363 \
364template<class Type> \
365ReturnType Func(const tmp<Field<Type>>& tf1) \
366{ \
367 ReturnType res = Func(tf1()); \
368 tf1.clear(); \
369 return res; \
370}
371
372template<class Type>
373Type max(const UList<Type>& f1)
374{
375 if (f1.size())
376 {
377 Type result(f1[0]);
378 TFOR_ALL_S_OP_FUNC_F_S(Type, result, =, max, Type, f1, Type, result)
379 return result;
380 }
382 return pTraits<Type>::min;
383}
384
386
387template<class Type>
388Type min(const UList<Type>& f1)
389{
390 if (f1.size())
391 {
392 Type result(f1[0]);
393 TFOR_ALL_S_OP_FUNC_F_S(Type, result, =, min, Type, f1, Type, result)
394 return result;
395 }
397 return pTraits<Type>::max;
398}
399
401
402template<class Type>
403Type sum(const UList<Type>& f1)
404{
405 typedef typename Foam::typeOfSolve<Type>::type resultType;
406
407 resultType result = Zero;
408
409 if (f1.size())
410 {
411 // Use resultType() as functional cast
412 TFOR_ALL_S_OP_FUNC_F(resultType, result, +=, resultType, Type, f1)
413 }
414
415 return Type(result);
416}
417
420
421// From MinMaxOps.H:
422// - Foam::minMax(const UList<Type>&)
423// - Foam::minMaxMag(const UList<Type>&)
424
427
428
429template<class Type>
430Type maxMagSqr(const UList<Type>& f1)
431{
432 if (f1.size())
433 {
434 Type result(f1[0]);
435 TFOR_ALL_S_OP_FUNC_F_S
436 (
437 Type,
438 result,
439 =,
440 maxMagSqrOp<Type>(),
441 Type,
442 f1,
443 Type,
444 result
446 return result;
447 }
449 return Zero;
450}
451
453
454template<class Type>
455Type minMagSqr(const UList<Type>& f1)
456{
457 if (f1.size())
458 {
459 Type result(f1[0]);
461 (
462 Type,
463 result,
464 =,
465 minMagSqrOp<Type>(),
466 Type,
467 f1,
468 Type,
469 result
471 return result;
472 }
473
474 return pTraits<Type>::rootMax;
475}
476
478
479template<class Type>
480typename scalarProduct<Type, Type>::type
481sumProd(const UList<Type>& f1, const UList<Type>& f2)
482{
483 typedef typename scalarProduct<Type, Type>::type resultType;
484
485 resultType result = Zero;
486 if (f1.size() && (f1.size() == f2.size()))
487 {
488 TFOR_ALL_S_OP_F_OP_F(resultType, result, +=, Type, f1, &&, Type, f2)
489 }
490 return result;
491}
492
493
494template<class Type>
495Type sumCmptProd(const UList<Type>& f1, const UList<Type>& f2)
496{
497 Type result = Zero;
498 if (f1.size() && (f1.size() == f2.size()))
499 {
501 (
502 Type,
503 result,
504 +=,
506 Type,
507 f1,
508 Type,
509 f2
510 )
512 return result;
513}
514
515
516template<class Type>
518sumSqr(const UList<Type>& f1)
519{
520 typedef typename outerProduct1<Type>::type resultType;
521
522 resultType result = Zero;
523 if (f1.size())
524 {
525 TFOR_ALL_S_OP_FUNC_F(resultType, result, +=, sqr, Type, f1)
526 }
527 return result;
528}
529
530template<class Type>
532sumSqr(const tmp<Field<Type>>& tf1)
533{
534 typedef typename outerProduct1<Type>::type resultType;
535 resultType result = sumSqr(tf1());
536 tf1.clear();
537 return result;
538}
539
540
541template<class Type>
543sumMag(const UList<Type>& f1)
544{
545 typedef typename typeOfMag<Type>::type resultType;
546
547 resultType result = Zero;
548 if (f1.size())
549 {
550 TFOR_ALL_S_OP_FUNC_F(resultType, result, +=, mag, Type, f1)
551 }
552 return result;
553}
554
556
557
558template<class Type>
559Type sumCmptMag(const UList<Type>& f1)
560{
561 Type result = Zero;
562 if (f1.size())
563 {
564 TFOR_ALL_S_OP_FUNC_F(Type, result, +=, cmptMag, Type, f1)
566 return result;
567}
568
570
571template<class Type>
572Type average(const UList<Type>& f1)
573{
574 if (f1.size())
575 {
576 Type result = sum(f1)/f1.size();
577
578 return result;
579 }
582 << "empty field, returning zero" << endl;
583
584 return Zero;
585}
586
588
589
590// With reduction on ReturnType
591#define G_UNARY_FUNCTION(ReturnType, gFunc, Func, rFunc) \
592 \
593template<class Type> \
594ReturnType gFunc(const UList<Type>& f, const label comm) \
595{ \
596 ReturnType res = Func(f); \
597 Foam::reduce(res, rFunc##Op<ReturnType>(), UPstream::msgType(), comm); \
598 return res; \
599} \
600TMP_UNARY_FUNCTION(ReturnType, gFunc)
601
608
611
614
615#undef G_UNARY_FUNCTION
616
617
618template<class Type>
620(
621 const UList<Type>& f1,
622 const UList<Type>& f2,
623 const label comm
624)
625{
626 typedef typename scalarProduct<Type, Type>::type resultType;
628 resultType result = sumProd(f1, f2);
630 return result;
631}
632
633template<class Type>
634Type gSumCmptProd
635(
636 const UList<Type>& f1,
637 const UList<Type>& f2,
638 const label comm
639)
641 Type result = sumCmptProd(f1, f2);
642 Foam::reduce(result, sumOp<Type>(), UPstream::msgType(), comm);
643 return result;
644}
645
646template<class Type>
647Type gAverage
648(
649 const UList<Type>& f1,
650 const label comm
651)
652{
653 label count = f1.size();
654 Type result = sum(f1);
655
656 // Communicator is not disabled
657 if (comm >= 0)
658 {
659 Foam::sumReduce(result, count, UPstream::msgType(), comm);
660 }
661
662 if (count > 0)
663 {
664 return result/count;
665 }
668 << "empty field, returning zero." << endl;
669
670 return Zero;
671}
672
674
675
676template<class Type>
678(
679 const UList<scalar>& weights,
680 const UList<Type>& fld,
681 const label comm
682)
683{
684 scalar weight(0);
685 Type result = Zero;
686
687 const label loopLen = fld.size();
688
689 /* pragmas... */
690 for (label i = 0; i < loopLen; ++i)
691 {
692 const scalar w = Foam::mag(weights[i]);
693 weight += w;
694 result += w*fld[i];
695 }
696
697 // Communicator is not disabled
698 if (comm >= 0)
699 {
700 Foam::sumReduce(result, weight, UPstream::msgType(), comm);
701 }
702
703 if (weight > ROOTVSMALL)
704 {
705 // With minimal rounding to protect against aggressive optimization
706 return result/(weight + ROOTVSMALL);
707 }
708 else
710 return Zero;
711 }
712}
713
714
715template<class Type>
716Type gWeightedSum
717(
718 const UList<scalar>& weights,
719 const UList<Type>& fld,
720 const label comm
721)
722{
723 Type result = Zero;
724
725 const label loopLen = fld.size();
726
727 /* pragmas... */
728 for (label i = 0; i < loopLen; ++i)
729 {
730 result += Foam::mag(weights[i])*fld[i];
731 }
732
733 // Communicator is not disabled
734 if (comm >= 0)
735 {
736 Foam::reduce(result, sumOp<Type>(), UPstream::msgType(), comm);
737 }
738
739 return result;
740}
742
743#undef TMP_UNARY_FUNCTION
744
745
746// Implement BINARY_FUNCTION_TRANSFORM_FS for clamp
747template<class Type>
748void clamp
749(
750 Field<Type>& result,
751 const UList<Type>& f1,
752 const MinMax<Type>& range
753)
754{
755 // Note: no checks for bad/invalid clamping ranges
756
757 if (result.cdata() == f1.cdata())
758 {
759 // Apply in-place
760 result.clamp_range(range);
761 }
762 else
763 {
764 std::transform
765 (
766 f1.cbegin(),
767 f1.cbegin(result.size()),
768 result.begin(),
770 );
771 }
772}
773
774template<class Type>
775void clamp
776(
777 Field<Type>& result,
778 const UList<Type>& f1,
779 const Foam::zero_one& // Note: macros generate a const reference
780)
781{
782 if (result.cdata() == f1.cdata())
783 {
784 // Apply in-place
785 result.clamp_range(Foam::zero_one{});
786 }
787 else
788 {
789 std::transform
790 (
791 f1.cbegin(),
792 f1.cbegin(result.size()),
793 result.begin(),
795 );
803BINARY_FUNCTION(Type, Type, Type, max)
804BINARY_FUNCTION(Type, Type, Type, min)
805BINARY_FUNCTION(Type, Type, Type, cmptMultiply)
806BINARY_FUNCTION(Type, Type, Type, cmptDivide)
807
808BINARY_TYPE_FUNCTION(Type, Type, Type, max)
809BINARY_TYPE_FUNCTION(Type, Type, Type, min)
810BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
811BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
812
813/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
815TERNARY_FUNCTION(Type, Type, Type, scalar, lerp)
816TERNARY_TYPE_FUNCTION_FFS(Type, Type, Type, scalar, lerp)
819/* * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * */
821UNARY_OPERATOR(Type, Type, -, negate)
822
823BINARY_OPERATOR(Type, Type, scalar, *, multiply)
824BINARY_OPERATOR(Type, scalar, Type, *, multiply)
825BINARY_OPERATOR(Type, Type, scalar, /, divide)
826
827BINARY_TYPE_OPERATOR_SF(Type, scalar, Type, *, multiply)
828BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, *, multiply)
829
830BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, divide)
831
832
833// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
834
835#define PRODUCT_OPERATOR(product, Op, OpFunc) \
836 \
837template<class Type1, class Type2> \
838void OpFunc \
839( \
840 Field<typename product<Type1, Type2>::type>& result, \
841 const UList<Type1>& f1, \
842 const UList<Type2>& f2 \
843) \
844{ \
845 typedef typename product<Type1, Type2>::type resultType; \
846 TFOR_ALL_F_OP_F_OP_F(resultType, result, =, Type1, f1, Op, Type2, f2) \
847} \
848 \
849template<class Type1, class Type2> \
850tmp<Field<typename product<Type1, Type2>::type>> \
851operator Op(const UList<Type1>& f1, const UList<Type2>& f2) \
852{ \
853 typedef typename product<Type1, Type2>::type resultType; \
854 auto tres = tmp<Field<resultType>>::New(f1.size()); \
855 OpFunc(tres.ref(), f1, f2); \
856 return tres; \
857} \
858 \
859template<class Type1, class Type2> \
860tmp<Field<typename product<Type1, Type2>::type>> \
861operator Op(const UList<Type1>& f1, const tmp<Field<Type2>>& tf2) \
862{ \
863 typedef typename product<Type1, Type2>::type resultType; \
864 auto tres = reuseTmp<resultType, Type2>::New(tf2); \
865 OpFunc(tres.ref(), f1, tf2()); \
866 tf2.clear(); \
867 return tres; \
868} \
869 \
870template<class Type1, class Type2> \
871tmp<Field<typename product<Type1, Type2>::type>> \
872operator Op(const tmp<Field<Type1>>& tf1, const UList<Type2>& f2) \
873{ \
874 typedef typename product<Type1, Type2>::type resultType; \
875 auto tres = reuseTmp<resultType, Type1>::New(tf1); \
876 OpFunc(tres.ref(), tf1(), f2); \
877 tf1.clear(); \
878 return tres; \
879} \
880 \
881template<class Type1, class Type2> \
882tmp<Field<typename product<Type1, Type2>::type>> \
883operator Op(const tmp<Field<Type1>>& tf1, const tmp<Field<Type2>>& tf2) \
884{ \
885 typedef typename product<Type1, Type2>::type resultType; \
886 auto tres = reuseTmpTmp<resultType, Type1, Type1, Type2>::New(tf1, tf2); \
887 OpFunc(tres.ref(), tf1(), tf2()); \
888 tf1.clear(); \
889 tf2.clear(); \
890 return tres; \
891} \
892 \
893template<class Type, class Form, class Cmpt, direction nCmpt> \
894void OpFunc \
895( \
896 Field<typename product<Type, Form>::type>& result, \
897 const UList<Type>& f1, \
898 const VectorSpace<Form,Cmpt,nCmpt>& vs \
899) \
900{ \
901 typedef typename product<Type, Form>::type resultType; \
902 TFOR_ALL_F_OP_F_OP_S \
903 (resultType, result, =,Type, f1, Op, Form, static_cast<const Form&>(vs))\
904} \
905 \
906template<class Type, class Form, class Cmpt, direction nCmpt> \
907tmp<Field<typename product<Type, Form>::type>> \
908operator Op(const UList<Type>& f1, const VectorSpace<Form,Cmpt,nCmpt>& vs) \
909{ \
910 typedef typename product<Type, Form>::type resultType; \
911 auto tres = tmp<Field<resultType>>::New(f1.size()); \
912 OpFunc(tres.ref(), f1, static_cast<const Form&>(vs)); \
913 return tres; \
914} \
915 \
916template<class Type, class Form, class Cmpt, direction nCmpt> \
917tmp<Field<typename product<Type, Form>::type>> \
918operator Op \
919( \
920 const tmp<Field<Type>>& tf1, \
921 const VectorSpace<Form,Cmpt,nCmpt>& vs \
922) \
923{ \
924 typedef typename product<Type, Form>::type resultType; \
925 auto tres = reuseTmp<resultType, Type>::New(tf1); \
926 OpFunc(tres.ref(), tf1(), static_cast<const Form&>(vs)); \
927 tf1.clear(); \
928 return tres; \
929} \
930 \
931template<class Form, class Cmpt, direction nCmpt, class Type> \
932void OpFunc \
933( \
934 Field<typename product<Form, Type>::type>& result, \
935 const VectorSpace<Form,Cmpt,nCmpt>& vs, \
936 const UList<Type>& f1 \
937) \
938{ \
939 typedef typename product<Form, Type>::type resultType; \
940 TFOR_ALL_F_OP_S_OP_F \
941 (resultType, result, =,Form,static_cast<const Form&>(vs), Op, Type, f1)\
942} \
943 \
944template<class Form, class Cmpt, direction nCmpt, class Type> \
945tmp<Field<typename product<Form, Type>::type>> \
946operator Op(const VectorSpace<Form,Cmpt,nCmpt>& vs, const UList<Type>& f1) \
947{ \
948 typedef typename product<Form, Type>::type resultType; \
949 auto tres = tmp<Field<resultType>>::New(f1.size()); \
950 OpFunc(tres.ref(), static_cast<const Form&>(vs), f1); \
951 return tres; \
952} \
953 \
954template<class Form, class Cmpt, direction nCmpt, class Type> \
955tmp<Field<typename product<Form, Type>::type>> \
956operator Op \
957( \
958 const VectorSpace<Form,Cmpt,nCmpt>& vs, const tmp<Field<Type>>& tf1 \
959) \
960{ \
961 typedef typename product<Form, Type>::type resultType; \
962 auto tres = reuseTmp<resultType, Type>::New(tf1); \
963 OpFunc(tres.ref(), static_cast<const Form&>(vs), tf1()); \
964 tf1.clear(); \
965 return tres; \
970
975
976#undef PRODUCT_OPERATOR
977
978
979// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
980
981} // End namespace Foam
982
983// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
984
985#include "undefFieldFunctionsM.H"
986
987// ************************************************************************* //
#define BINARY_FUNCTION(ReturnType, Type1, Type2, Func)
#define UNARY_OPERATOR(ReturnType, Type1, Op, OpFunc, Dfunc)
#define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
#define TERNARY_FUNCTION(ReturnType, Type1, Type2, Type3, Func)
#define TERNARY_TYPE_FUNCTION_FFS(ReturnType, Type1, Type2, Type3, Func)
#define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc)
#define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpName, OpFunc)
#define BINARY_TYPE_FUNCTION(ReturnType, Type1, Type2, Func)
#define G_UNARY_FUNCTION(ReturnType, gFunc, Func, rFunc)
#define TMP_UNARY_FUNCTION(ReturnType, Func)
#define BINARY_FUNCTION_INTERFACE_FS(ReturnType, Type1, Type2, Func)
#define TFOR_ALL_S_OP_F_OP_F(typeS, s, OP1, typeF1, f1, OP2, typeF2, f2)
Definition FieldM.H:540
#define TFOR_ALL_F_OP_FUNC_F_S(typeF1, f1, OP, FUNC, typeF2, f2, typeS, s)
Definition FieldM.H:237
#define TFOR_ALL_F_OP_F_FUNC(typeF1, f1, OP, typeF2, f2, FUNC)
Definition FieldM.H:170
#define TFOR_ALL_F_OP_F_FUNC_S(typeF1, f1, OP, typeF2, f2, FUNC, typeS, s)
Definition FieldM.H:317
#define TFOR_ALL_S_OP_FUNC_F(typeS, s, OP, FUNC, typeF, f)
Definition FieldM.H:558
#define TFOR_ALL_S_OP_FUNC_F_S(typeS1, s1, OP, FUNC, typeF, f, typeS2, s2)
Definition FieldM.H:259
#define TFOR_ALL_F_OP_FUNC_F(typeF1, f1, OP, FUNC, typeF2, f2)
Definition FieldM.H:148
#define TFOR_ALL_S_OP_FUNC_F_F(typeS, s, OP, FUNC, typeF1, f1, typeF2, f2)
Definition FieldM.H:215
scalar range
Inter-processor communication reduction functions.
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edges")));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
void clamp_range(const Type &lower, const Type &upper)
Clamp field values (in-place) to the specified range.
Definition Field.C:712
pTraits< Type >::cmptType cmptType
Component type.
Definition Field.H:178
A min/max value pair with additional methods. In addition to conveniently storing values,...
Definition MinMax.H:106
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
iterator begin() noexcept
Return an iterator to begin traversing the UList.
Definition UListI.H:410
const T * cdata() const noexcept
Return pointer to the underlying array serving as data storage.
Definition UListI.H:267
const_iterator cbegin() const noexcept
Return const_iterator to begin traversing the constant UList.
Definition UListI.H:424
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
static int & msgType() noexcept
Message tag of standard messages.
Definition UPstream.H:1926
Outer-product of identical types.
Definition products.H:129
typeOfRank< typenamepTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank)>::type type
Definition products.H:118
A traits class, which is primarily used for primitives and vector-space.
Definition pTraits.H:64
symmTypeOfRank< typenamepTraits< arg1 >::cmptType, arg2 *direction(pTraits< arg1 >::rank)>::type type
Definition products.H:176
pTraits< arg1 >::cmptType type
Definition products.H:163
A class for managing temporary objects.
Definition tmp.H:75
The magnitude type for given argument.
Definition products.H:93
pTraits< typenamepTraits< arg1 >::cmptType >::magType type
Definition products.H:96
Represents 0/1 range or concept. Used for tagged dispatch or clamping.
Definition pTraits.H:51
const volScalarField & T
#define PRODUCT_OPERATOR(product, op, opFunc)
#define WarningInFunction
Report a warning using Foam::Warning.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition BitOps.H:73
Namespace for OpenFOAM.
Type gAverage(const FieldField< Field, Type > &f, const label comm)
The global arithmetic average of a FieldField.
dimensioned< scalarMinMax > minMaxMag(const DimensionedField< Type, GeoMesh > &f1, const label comm)
scalarProduct< Type, Type >::type gSumProd(const UList< Type > &f1, const UList< Type > &f2, const label comm)
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition hashSets.C:40
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
Type gSum(const FieldField< Field, Type > &f)
Type gWeightedAverage(const UList< scalar > &weights, const UList< Type > &fld, const label comm)
The global weighted average of a field, using the mag() of the weights.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
void subtract(DimensionedField< scalar, GeoMesh > &result, const dimensioned< scalar > &dt1, const DimensionedField< scalar, GeoMesh > &f2)
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
Type sumCmptMag(const UList< Type > &f1)
void cmptMin(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
Type sumCmptProd(const UList< Type > &f1, const UList< Type > &f2)
dimensionSet clamp(const dimensionSet &a, const dimensionSet &range)
void divide(DimensionedField< Type, GeoMesh > &result, const DimensionedField< Type, GeoMesh > &f1, const DimensionedField< scalar, GeoMesh > &f2)
Type minMagSqr(const UList< Type > &f1)
MinMax< scalar > scalarMinMax
A scalar min/max range.
Definition MinMax.H:97
void dot(FieldField< Field1, typename innerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Type gWeightedSum(const UList< scalar > &weights, const UList< Type > &fld, const label comm)
The global weighted sum (integral) of a field, using the mag() of the weights.
scalarMinMax gMinMaxMag(const FieldField< Field, Type > &f)
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
Type gMaxMagSqr(const UList< Type > &f, const label comm)
MinMax< label > minMax(const labelHashSet &set)
Find the min/max values of labelHashSet.
Definition hashSets.C:54
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
void add(DimensionedField< scalar, GeoMesh > &result, const dimensioned< scalar > &dt1, const DimensionedField< scalar, GeoMesh > &f2)
tmp< DimensionedField< typename DimensionedField< Type, GeoMesh >::cmptType, GeoMesh > > cmptAv(const DimensionedField< Type, GeoMesh > &f1)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
outerProduct1< Type >::type sumSqr(const UList< Type > &f1)
complex sumProd(const UList< complex > &f1, const UList< complex > &f2)
Sum product.
void reduce(T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce).
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition hashSets.C:26
void cmptMagSqr(Field< Type > &result, const UList< Type > &f1)
uint8_t direction
Definition direction.H:49
void cmptMax(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
MinMax< Type > gMinMax(const FieldField< Field, Type > &f)
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &f1, const label comm)
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
typeOfMag< Type >::type gSumMag(const FieldField< Field, Type > &f)
void dotdot(FieldField< Field1, typename scalarProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
void sumReduce(T &value, CountType &count, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) the sum of value and counter (eg, for averaging).
Type gMin(const FieldField< Field, Type > &f)
void cmptMag(FieldField< Field, Type > &cf, const FieldField< Field, Type > &f)
void cross(FieldField< Field1, typename crossProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
outerProduct1< Type >::type gSumSqr(const UList< Type > &f, const label comm)
void negate(DimensionedField< Type, GeoMesh > &result, const DimensionedField< Type, GeoMesh > &f1)
Type gMinMagSqr(const UList< Type > &f, const label comm)
Type maxMagSqr(const UList< Type > &f1)
void multiply(DimensionedField< Type, GeoMesh > &result, const DimensionedField< Type, GeoMesh > &f1, const DimensionedField< scalar, GeoMesh > &f2)
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &f1, const label comm)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Type gSumCmptMag(const UList< Type > &f, const label comm)
Type gMax(const FieldField< Field, Type > &f)
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
void outer(FieldField< Field1, typename outerProduct< 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)
Type gSumCmptProd(const UList< Type > &f1, const UList< Type > &f2, const label comm)
dimensioned< typename typeOfMag< Type >::type > sumMag(const DimensionedField< Type, GeoMesh > &f1, const label comm)
Unary function for applying component-wise clamping.
Definition MinMaxOps.H:68
static tmp< Field< TypeR > > New(const Field< Type1 > &f1)
Pass-through to tmp New.