29 #define TEMPLATE template<class Type>
62 template<
class Type,
int r>
72 powProductType, res, =,
pow, Type, vf, powProductType,
77 template<
class Type,
int r>
90 pow<Type, r>(tRes(),
f);
94 template<
class Type,
int r>
104 pow<Type, r>(tRes(),
tf());
300 #define TMP_UNARY_FUNCTION(ReturnType, Func) \
302 template<class Type> \
303 ReturnType Func(const tmp<Field<Type> >& tf1) \
305 ReturnType res = Func(tf1()); \
365 if (f1.size() && (f1.size() == f2.size()))
367 scalar SumProd = 0.0;
451 Type avrg =
sum(f)/f.size();
458 <<
"empty field, returning zero" <<
endl;
467 #define G_UNARY_FUNCTION(ReturnType, gFunc, Func, rFunc) \
469 template<class Type> \
470 ReturnType gFunc(const UList<Type>& f) \
472 ReturnType res = Func(f); \
473 reduce(res, rFunc##Op<Type>()); \
476 TMP_UNARY_FUNCTION(ReturnType, gFunc)
485 #undef G_UNARY_FUNCTION
490 scalar SumProd =
sumProd(f1, f2);
511 Type avrg =
gSum(f)/n;
517 WarningIn(
"gAverage(const UList<Type>&)")
518 <<
"empty field, returning zero." <<
endl;
526 #undef TMP_UNARY_FUNCTION
556 #define PRODUCT_OPERATOR(product, Op, OpFunc) \
558 template<class Type1, class Type2> \
561 Field<typename product<Type1, Type2>::type>& res, \
562 const UList<Type1>& f1, \
563 const UList<Type2>& f2 \
566 typedef typename product<Type1, Type2>::type productType; \
567 TFOR_ALL_F_OP_F_OP_F(productType, res, =, Type1, f1, Op, Type2, f2) \
570 template<class Type1, class Type2> \
571 tmp<Field<typename product<Type1, Type2>::type> > \
572 operator Op(const UList<Type1>& f1, const UList<Type2>& f2) \
574 typedef typename product<Type1, Type2>::type productType; \
575 tmp<Field<productType> > tRes(new Field<productType>(f1.size())); \
576 OpFunc(tRes(), f1, f2); \
580 template<class Type1, class Type2> \
581 tmp<Field<typename product<Type1, Type2>::type> > \
582 operator Op(const UList<Type1>& f1, const tmp<Field<Type2> >& tf2) \
584 typedef typename product<Type1, Type2>::type productType; \
585 tmp<Field<productType> > tRes = reuseTmp<productType, Type2>::New(tf2); \
586 OpFunc(tRes(), f1, tf2()); \
587 reuseTmp<productType, Type2>::clear(tf2); \
591 template<class Type1, class Type2> \
592 tmp<Field<typename product<Type1, Type2>::type> > \
593 operator Op(const tmp<Field<Type1> >& tf1, const UList<Type2>& f2) \
595 typedef typename product<Type1, Type2>::type productType; \
596 tmp<Field<productType> > tRes = reuseTmp<productType, Type1>::New(tf1); \
597 OpFunc(tRes(), tf1(), f2); \
598 reuseTmp<productType, Type1>::clear(tf1); \
602 template<class Type1, class Type2> \
603 tmp<Field<typename product<Type1, Type2>::type> > \
604 operator Op(const tmp<Field<Type1> >& tf1, const tmp<Field<Type2> >& tf2) \
606 typedef typename product<Type1, Type2>::type productType; \
607 tmp<Field<productType> > tRes = \
608 reuseTmpTmp<productType, Type1, Type1, Type2>::New(tf1, tf2); \
609 OpFunc(tRes(), tf1(), tf2()); \
610 reuseTmpTmp<productType, Type1, Type1, Type2>::clear(tf1, tf2); \
614 template<class Type, class Form, class Cmpt, int nCmpt> \
617 Field<typename product<Type, Form>::type>& res, \
618 const UList<Type>& f1, \
619 const VectorSpace<Form,Cmpt,nCmpt>& vs \
622 typedef typename product<Type, Form>::type productType; \
623 TFOR_ALL_F_OP_F_OP_S \
624 (productType, res, =,Type, f1, Op, Form, static_cast<const Form&>(vs))\
627 template<class Type, class Form, class Cmpt, int nCmpt> \
628 tmp<Field<typename product<Type, Form>::type> > \
629 operator Op(const UList<Type>& f1, const VectorSpace<Form,Cmpt,nCmpt>& vs) \
631 typedef typename product<Type, Form>::type productType; \
632 tmp<Field<productType> > tRes(new Field<productType>(f1.size())); \
633 OpFunc(tRes(), f1, static_cast<const Form&>(vs)); \
637 template<class Type, class Form, class Cmpt, int nCmpt> \
638 tmp<Field<typename product<Type, Form>::type> > \
641 const tmp<Field<Type> >& tf1, \
642 const VectorSpace<Form,Cmpt,nCmpt>& vs \
645 typedef typename product<Type, Form>::type productType; \
646 tmp<Field<productType> > tRes = reuseTmp<productType, Type>::New(tf1); \
647 OpFunc(tRes(), tf1(), static_cast<const Form&>(vs)); \
648 reuseTmp<productType, Type>::clear(tf1); \
652 template<class Form, class Cmpt, int nCmpt, class Type> \
655 Field<typename product<Form, Type>::type>& res, \
656 const VectorSpace<Form,Cmpt,nCmpt>& vs, \
657 const UList<Type>& f1 \
660 typedef typename product<Form, Type>::type productType; \
661 TFOR_ALL_F_OP_S_OP_F \
662 (productType, res, =,Form,static_cast<const Form&>(vs), Op, Type, f1) \
665 template<class Form, class Cmpt, int nCmpt, class Type> \
666 tmp<Field<typename product<Form, Type>::type> > \
667 operator Op(const VectorSpace<Form,Cmpt,nCmpt>& vs, const UList<Type>& f1) \
669 typedef typename product<Form, Type>::type productType; \
670 tmp<Field<productType> > tRes(new Field<productType>(f1.size())); \
671 OpFunc(tRes(), static_cast<const Form&>(vs), f1); \
675 template<class Form, class Cmpt, int nCmpt, class Type> \
676 tmp<Field<typename product<Form, Type>::type> > \
679 const VectorSpace<Form,Cmpt,nCmpt>& vs, const tmp<Field<Type> >& tf1 \
682 typedef typename product<Form, Type>::type productType; \
683 tmp<Field<productType> > tRes = reuseTmp<productType, Type>::New(tf1); \
684 OpFunc(tRes(), static_cast<const Form&>(vs), tf1()); \
685 reuseTmp<productType, Type>::clear(tf1); \
697 #undef PRODUCT_OPERATOR