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-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 "PstreamReduceOps.H"
30 #include "FieldReuseFunctions.H"
31 
32 #define TEMPLATE template<class Type>
33 #include "FieldFunctionsM.C"
34 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 
40 /* * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * */
41 
42 template<class Type>
43 void 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 
59 template<class Type>
60 void T(Field<Type>& result, const UList<Type>& f1)
61 {
62  TFOR_ALL_F_OP_F_FUNC(Type, result, =, Type, f1, T)
63 }
64 
65 
66 template<class Type, direction r>
67 void 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 
82 template<class Type, direction r>
84 pow
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 
96 template<class Type, direction r>
98 pow
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 
112 template<class Type>
113 void 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 
124 template<class Type>
126 sqr(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 
134 template<class Type>
136 sqr(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 
146 template<class Type>
147 void 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 
158 template<class Type>
160 magSqr(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 
169 template<class Type>
171 magSqr(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 
182 template<class Type>
183 void 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 
194 template<class Type>
196 mag(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 
205 template<class Type>
207 mag(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 
218 template<class Type>
219 void cmptMax
220 (
221  Field<typename Field<Type>::cmptType>& result,
222  const UList<Type>& f1
223 )
224 {
225  typedef typename Field<Type>::cmptType resultType;
226 
227  TFOR_ALL_F_OP_FUNC_F(resultType, result, =, cmptMax, Type, f1)
228 }
229 
230 template<class Type>
231 tmp<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 
239 template<class Type>
240 tmp<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 
250 template<class Type>
251 void cmptMin
252 (
253  Field<typename Field<Type>::cmptType>& result,
254  const UList<Type>& f1
255 )
256 {
257  typedef typename Field<Type>::cmptType resultType;
258 
259  TFOR_ALL_F_OP_FUNC_F(resultType, result, =, cmptMin, Type, f1)
260 }
261 
262 template<class Type>
263 tmp<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 
271 template<class Type>
272 tmp<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 
282 template<class Type>
283 void cmptAv
284 (
285  Field<typename Field<Type>::cmptType>& result,
286  const UList<Type>& f1
287 )
288 {
289  typedef typename Field<Type>::cmptType resultType;
290 
291  TFOR_ALL_F_OP_FUNC_F(resultType, result, =, cmptAv, Type, f1)
292 }
293 
294 template<class Type>
295 tmp<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 
303 template<class Type>
304 tmp<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 
314 template<class Type>
315 void cmptMag(Field<Type>& result, const UList<Type>& f1)
316 {
317  TFOR_ALL_F_OP_FUNC_F(Type, result, =, cmptMag, Type, f1)
318 }
319 
320 template<class Type>
321 tmp<Field<Type>> cmptMag(const UList<Type>& f1)
322 {
323  auto tres = tmp<Field<Type>>::New(f1.size());
324  cmptMag(tres.ref(), f1);
325  return tres;
326 }
327 
328 template<class Type>
329 tmp<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 
338 template<class Type>
339 void cmptMagSqr(Field<Type>& result, const UList<Type>& f1)
340 {
341  TFOR_ALL_F_OP_FUNC_F(Type, result, =, cmptMagSqr, Type, f1)
342 }
343 
344 template<class Type>
345 tmp<Field<Type>> cmptMagSqr(const UList<Type>& f1)
346 {
347  auto tres = tmp<Field<Type>>::New(f1.size());
348  cmptMagSqr(tres.ref(), f1);
349  return tres;
350 }
351 
352 template<class Type>
353 tmp<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  \
364 template<class Type> \
365 ReturnType Func(const tmp<Field<Type>>& tf1) \
366 { \
367  ReturnType res = Func(tf1()); \
368  tf1.clear(); \
369  return res; \
370 }
371 
372 template<class Type>
373 Type 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 
385 TMP_UNARY_FUNCTION(Type, max)
386 
387 template<class Type>
388 Type 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 
400 TMP_UNARY_FUNCTION(Type, min)
401 
402 template<class Type>
403 Type 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 
429 template<class Type>
430 Type maxMagSqr(const UList<Type>& f1)
431 {
432  if (f1.size())
433  {
434  Type result(f1[0]);
436  (
437  Type,
438  result,
439  =,
441  Type,
442  f1,
443  Type,
444  result
445  )
446  return result;
447  }
449  return Zero;
450 }
451 
453 
454 template<class Type>
455 Type minMagSqr(const UList<Type>& f1)
456 {
457  if (f1.size())
458  {
459  Type result(f1[0]);
461  (
462  Type,
463  result,
464  =,
466  Type,
467  f1,
468  Type,
469  result
470  )
471  return result;
472  }
473 
474  return pTraits<Type>::rootMax;
475 }
476 
478 
479 template<class Type>
480 typename scalarProduct<Type, Type>::type
481 sumProd(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 
494 template<class Type>
495 Type 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  +=,
505  cmptMultiply,
506  Type,
507  f1,
508  Type,
509  f2
510  )
511  }
512  return result;
513 }
514 
515 
516 template<class Type>
518 sumSqr(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 
530 template<class Type>
532 sumSqr(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 
541 template<class Type>
542 typename typeOfMag<Type>::type
543 sumMag(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 
558 template<class Type>
559 Type 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)
565  }
566  return result;
567 }
568 
570 
571 template<class Type>
572 Type 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  \
593 template<class Type> \
594 ReturnType gFunc(const UList<Type>& f, const label comm) \
595 { \
596  ReturnType res = Func(f); \
597  reduce(res, rFunc##Op<ReturnType>(), UPstream::msgType(), comm); \
598  return res; \
599 } \
600 TMP_UNARY_FUNCTION(ReturnType, gFunc)
601 
604 G_UNARY_FUNCTION(Type, gSum, sum, sum)
608 
611 
614 
615 #undef G_UNARY_FUNCTION
616 
617 
618 template<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;
627 
628  resultType result = sumProd(f1, f2);
629  reduce(result, sumOp<resultType>(), UPstream::msgType(), comm);
630  return result;
631 }
632 
633 template<class Type>
634 Type gSumCmptProd
635 (
636  const UList<Type>& f1,
637  const UList<Type>& f2,
638  const label comm
639 )
640 {
641  Type result = sumCmptProd(f1, f2);
642  reduce(result, sumOp<Type>(), UPstream::msgType(), comm);
643  return result;
644 }
645 
646 template<class Type>
647 Type gAverage
648 (
649  const UList<Type>& f1,
650  const label comm
651 )
652 {
653  label n = f1.size();
654  Type s = sum(f1);
655  sumReduce(s, n, UPstream::msgType(), comm);
656 
657  if (n > 0)
658  {
659  Type result = s/n;
660 
661  return result;
662  }
665  << "empty field, returning zero." << endl;
666 
667  return Zero;
668 }
669 
672 #undef TMP_UNARY_FUNCTION
673 
674 
675 // Implement BINARY_FUNCTION_TRANSFORM_FS for clamp
676 template<class Type>
677 void clamp
678 (
679  Field<Type>& result,
680  const UList<Type>& f1,
681  const MinMax<Type>& range
682 )
683 {
684  // Note: no checks for bad/invalid clamping ranges
685 
686  if (result.cdata() == f1.cdata())
687  {
688  // Apply in-place
689  result.clamp_range(range);
690  }
691  else
692  {
694  (
695  f1.cbegin(),
696  f1.cbegin(result.size()),
697  result.begin(),
699  );
700  }
701 }
702 
703 template<class Type>
704 void clamp
705 (
706  Field<Type>& result,
707  const UList<Type>& f1,
708  const Foam::zero_one& // Note: macros generate a const reference
709 )
710 {
711  if (result.cdata() == f1.cdata())
712  {
713  // Apply in-place
714  result.clamp_range(Foam::zero_one{});
715  }
716  else
717  {
719  (
720  f1.cbegin(),
721  f1.cbegin(result.size()),
722  result.begin(),
723  clampOp<Type>(Foam::zero_one{})
724  );
725  }
726 }
727 
728 BINARY_FUNCTION_INTERFACE_FS(Type, Type, MinMax<Type>, clamp)
730 
731 
732 BINARY_FUNCTION(Type, Type, Type, max)
733 BINARY_FUNCTION(Type, Type, Type, min)
734 BINARY_FUNCTION(Type, Type, Type, cmptMultiply)
735 BINARY_FUNCTION(Type, Type, Type, cmptDivide)
736 
737 BINARY_TYPE_FUNCTION(Type, Type, Type, max)
738 BINARY_TYPE_FUNCTION(Type, Type, Type, min)
739 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
740 BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
741 
742 BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax<Type>, clip) // Same as clamp
743 
744 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
745 
746 TERNARY_FUNCTION(Type, Type, Type, scalar, lerp)
747 TERNARY_TYPE_FUNCTION_FFS(Type, Type, Type, scalar, lerp)
748 
749 
750 /* * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * */
751 
752 UNARY_OPERATOR(Type, Type, -, negate)
753 
754 BINARY_OPERATOR(Type, Type, scalar, *, multiply)
755 BINARY_OPERATOR(Type, scalar, Type, *, multiply)
756 BINARY_OPERATOR(Type, Type, scalar, /, divide)
757 
758 BINARY_TYPE_OPERATOR_SF(Type, scalar, Type, *, multiply)
759 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, *, multiply)
760 
761 BINARY_TYPE_OPERATOR_FS(Type, Type, scalar, /, divide)
762 
763 
764 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
765 
766 #define PRODUCT_OPERATOR(product, Op, OpFunc) \
767  \
768 template<class Type1, class Type2> \
769 void OpFunc \
770 ( \
771  Field<typename product<Type1, Type2>::type>& result, \
772  const UList<Type1>& f1, \
773  const UList<Type2>& f2 \
774 ) \
775 { \
776  typedef typename product<Type1, Type2>::type resultType; \
777  TFOR_ALL_F_OP_F_OP_F(resultType, result, =, Type1, f1, Op, Type2, f2) \
778 } \
779  \
780 template<class Type1, class Type2> \
781 tmp<Field<typename product<Type1, Type2>::type>> \
782 operator Op(const UList<Type1>& f1, const UList<Type2>& f2) \
783 { \
784  typedef typename product<Type1, Type2>::type resultType; \
785  auto tres = tmp<Field<resultType>>::New(f1.size()); \
786  OpFunc(tres.ref(), f1, f2); \
787  return tres; \
788 } \
789  \
790 template<class Type1, class Type2> \
791 tmp<Field<typename product<Type1, Type2>::type>> \
792 operator Op(const UList<Type1>& f1, const tmp<Field<Type2>>& tf2) \
793 { \
794  typedef typename product<Type1, Type2>::type resultType; \
795  auto tres = reuseTmp<resultType, Type2>::New(tf2); \
796  OpFunc(tres.ref(), f1, tf2()); \
797  tf2.clear(); \
798  return tres; \
799 } \
800  \
801 template<class Type1, class Type2> \
802 tmp<Field<typename product<Type1, Type2>::type>> \
803 operator Op(const tmp<Field<Type1>>& tf1, const UList<Type2>& f2) \
804 { \
805  typedef typename product<Type1, Type2>::type resultType; \
806  auto tres = reuseTmp<resultType, Type1>::New(tf1); \
807  OpFunc(tres.ref(), tf1(), f2); \
808  tf1.clear(); \
809  return tres; \
810 } \
811  \
812 template<class Type1, class Type2> \
813 tmp<Field<typename product<Type1, Type2>::type>> \
814 operator Op(const tmp<Field<Type1>>& tf1, const tmp<Field<Type2>>& tf2) \
815 { \
816  typedef typename product<Type1, Type2>::type resultType; \
817  auto tres = reuseTmpTmp<resultType, Type1, Type1, Type2>::New(tf1, tf2); \
818  OpFunc(tres.ref(), tf1(), tf2()); \
819  tf1.clear(); \
820  tf2.clear(); \
821  return tres; \
822 } \
823  \
824 template<class Type, class Form, class Cmpt, direction nCmpt> \
825 void OpFunc \
826 ( \
827  Field<typename product<Type, Form>::type>& result, \
828  const UList<Type>& f1, \
829  const VectorSpace<Form,Cmpt,nCmpt>& vs \
830 ) \
831 { \
832  typedef typename product<Type, Form>::type resultType; \
833  TFOR_ALL_F_OP_F_OP_S \
834  (resultType, result, =,Type, f1, Op, Form, static_cast<const Form&>(vs))\
835 } \
836  \
837 template<class Type, class Form, class Cmpt, direction nCmpt> \
838 tmp<Field<typename product<Type, Form>::type>> \
839 operator Op(const UList<Type>& f1, const VectorSpace<Form,Cmpt,nCmpt>& vs) \
840 { \
841  typedef typename product<Type, Form>::type resultType; \
842  auto tres = tmp<Field<resultType>>::New(f1.size()); \
843  OpFunc(tres.ref(), f1, static_cast<const Form&>(vs)); \
844  return tres; \
845 } \
846  \
847 template<class Type, class Form, class Cmpt, direction nCmpt> \
848 tmp<Field<typename product<Type, Form>::type>> \
849 operator Op \
850 ( \
851  const tmp<Field<Type>>& tf1, \
852  const VectorSpace<Form,Cmpt,nCmpt>& vs \
853 ) \
854 { \
855  typedef typename product<Type, Form>::type resultType; \
856  auto tres = reuseTmp<resultType, Type>::New(tf1); \
857  OpFunc(tres.ref(), tf1(), static_cast<const Form&>(vs)); \
858  tf1.clear(); \
859  return tres; \
860 } \
861  \
862 template<class Form, class Cmpt, direction nCmpt, class Type> \
863 void OpFunc \
864 ( \
865  Field<typename product<Form, Type>::type>& result, \
866  const VectorSpace<Form,Cmpt,nCmpt>& vs, \
867  const UList<Type>& f1 \
868 ) \
869 { \
870  typedef typename product<Form, Type>::type resultType; \
871  TFOR_ALL_F_OP_S_OP_F \
872  (resultType, result, =,Form,static_cast<const Form&>(vs), Op, Type, f1)\
873 } \
874  \
875 template<class Form, class Cmpt, direction nCmpt, class Type> \
876 tmp<Field<typename product<Form, Type>::type>> \
877 operator Op(const VectorSpace<Form,Cmpt,nCmpt>& vs, const UList<Type>& f1) \
878 { \
879  typedef typename product<Form, Type>::type resultType; \
880  auto tres = tmp<Field<resultType>>::New(f1.size()); \
881  OpFunc(tres.ref(), static_cast<const Form&>(vs), f1); \
882  return tres; \
883 } \
884  \
885 template<class Form, class Cmpt, direction nCmpt, class Type> \
886 tmp<Field<typename product<Form, Type>::type>> \
887 operator Op \
888 ( \
889  const VectorSpace<Form,Cmpt,nCmpt>& vs, const tmp<Field<Type>>& tf1 \
890 ) \
891 { \
892  typedef typename product<Form, Type>::type resultType; \
893  auto tres = reuseTmp<resultType, Type>::New(tf1); \
894  OpFunc(tres.ref(), static_cast<const Form&>(vs), tf1()); \
895  tf1.clear(); \
896  return tres; \
897 }
901 
906 
907 #undef PRODUCT_OPERATOR
908 
909 
910 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
911 
912 } // End namespace Foam
913 
914 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
915 
916 #include "undefFieldFunctionsM.H"
917 
918 // ************************************************************************* //
dimensioned< typename typeOfMag< Type >::type > sumMag(const DimensionedField< Type, GeoMesh > &f1)
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
void cmptMax(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
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:46
Inter-processor communication reduction functions.
tmp< DimensionedField< typename DimensionedField< Type, GeoMesh >::cmptType, GeoMesh >> cmptAv(const DimensionedField< Type, GeoMesh > &f1)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
#define TMP_UNARY_FUNCTION(ReturnType, Func)
Type gMin(const FieldField< Field, Type > &f)
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)
pTraits< Type >::cmptType cmptType
Component type.
Definition: Field.H:123
A min/max value pair with additional methods. In addition to conveniently storing values...
Definition: HashSet.H:72
void sumReduce(T &value, label &count, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) the sum of both value and count (for averaging) ...
Type minMagSqr(const UList< Type > &f1)
Outer-product of identical types.
Definition: products.H:126
scalarProduct< Type, Type >::type gSumProd(const UList< Type > &f1, const UList< Type > &f2, const label comm)
#define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc)
#define TFOR_ALL_F_OP_F_FUNC(typeF1, f1, OP, typeF2, f2, FUNC)
Definition: FieldM.H:170
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
static tmp< Field< TypeR > > New(const Field< Type1 > &f1)
Pass-through to tmp New.
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:75
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 gSumCmptMag(const UList< Type > &f, const label comm)
void clamp_range(const Type &lower, const Type &upper)
Clamp field values (in-place) to the specified range.
Definition: Field.C:678
void clip(Field< Type > &result, const UList< Type > &f1, const MinMax< Type > &s2)
#define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpName, OpFunc)
The magnitude type for given argument.
Definition: products.H:92
void cross(FieldField< Field1, typename crossProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:1229
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)
#define TFOR_ALL_F_OP_FUNC_F(typeF1, f1, OP, FUNC, typeF2, f2)
Definition: FieldM.H:148
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)
Type sumCmptProd(const UList< Type > &f1, const UList< Type > &f2)
Type maxMagSqr(const UList< Type > &f1)
void outer(FieldField< Field1, typename outerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
scalar range
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 > &)
complex sumProd(const UList< complex > &f1, const UList< complex > &f2)
Sum product.
Definition: complexField.C:245
MinMax< label > minMax(const labelHashSet &set)
Find the min/max values of labelHashSet.
Definition: hashSets.C:54
Type gMaxMagSqr(const UList< Type > &f, const label comm)
#define BINARY_FUNCTION(ReturnType, Type1, Type2, Func)
#define TFOR_ALL_S_OP_FUNC_F(typeS, s, OP, FUNC, typeF, f)
Definition: FieldM.H:558
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
Type gMinMagSqr(const UList< Type > &f, const label comm)
outerProduct1< Type >::type sumSqr(const UList< Type > &f1)
Type gSumCmptProd(const UList< Type > &f1, const UList< Type > &f2, const label comm)
Unary function for applying component-wise clamping.
Definition: MinMaxOps.H:67
Type gSum(const FieldField< Field, Type > &f)
void cmptMagSqr(Field< Type > &result, const UList< Type > &f1)
Generic templated field type.
Definition: Field.H:62
#define G_UNARY_FUNCTION(ReturnType, gFunc, Func, rFunc)
#define TFOR_ALL_S_OP_FUNC_F_S(typeS1, s1, OP, FUNC, typeF, f, typeS2, s2)
Definition: FieldM.H:259
#define TFOR_ALL_S_OP_FUNC_F_F(typeS, s, OP, FUNC, typeF1, f1, typeF2, f2)
Definition: FieldM.H:215
MinMax< Type > gMinMax(const FieldField< Field, Type > &f)
pTraits< arg1 >::cmptType type
Definition: products.H:163
Type sumCmptMag(const UList< Type > &f1)
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
iterator begin() noexcept
Return an iterator to begin traversing the UList.
Definition: UListI.H:391
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
void cmptMag(FieldField< Field, Type > &cf, const FieldField< Field, Type > &f)
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Type gMax(const FieldField< Field, Type > &f)
#define TFOR_ALL_S_OP_F_OP_F(typeS, s, OP1, typeF1, f1, OP2, typeF2, f2)
Definition: FieldM.H:540
outerProduct1< Type >::type gSumSqr(const UList< Type > &f, const label comm)
scalarMinMax gMinMaxMag(const FieldField< Field, Type > &f)
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:65
symmTypeOfRank< typename pTraits< arg1 >::cmptType, arg2 *direction(pTraits< arg1 >::rank) >::type type
Definition: products.H:176
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
dimensioned< scalarMinMax > minMaxMag(const DimensionedField< Type, GeoMesh > &f1)
#define WarningInFunction
Report a warning using Foam::Warning.
Type gAverage(const FieldField< Field, Type > &f)
#define TFOR_ALL_F_OP_F_FUNC_S(typeF1, f1, OP, typeF2, f2, FUNC, typeS, s)
Definition: FieldM.H:317
#define BINARY_FUNCTION_INTERFACE_FS(ReturnType, Type1, Type2, Func)
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
Reduce inplace (cf. MPI Allreduce) using specified communication schedule.
BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax< Type >, clip)
const_iterator cbegin() const noexcept
Return const_iterator to begin traversing the constant UList.
Definition: UListI.H:405
label n
#define UNARY_OPERATOR(ReturnType, Type1, Op, OpFunc, Dfunc)
const Type * cdata() const noexcept
Return pointer to the underlying array serving as data storage.
Definition: UListI.H:265
#define TERNARY_TYPE_FUNCTION_FFS(ReturnType, Type1, Type2, Type3, Func)
A class for managing temporary objects.
Definition: HashPtrTable.H:50
void cmptMin(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
void multiply(DimensionedField< Type, GeoMesh > &result, const DimensionedField< Type, GeoMesh > &f1, const DimensionedField< scalar, GeoMesh > &f2)
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
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)
#define PRODUCT_OPERATOR(product, Op, OpFunc)
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
#define TFOR_ALL_F_OP_FUNC_F_S(typeF1, f1, OP, FUNC, typeF2, f2, typeS, s)
Definition: FieldM.H:237
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127