/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA \*---------------------------------------------------------------------------*/ #include "PstreamReduceOps.H" #include "FieldReuseFunctions.H" #define TEMPLATE template #include "FieldFunctionsM.C" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { /* * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * */ template void component ( Field::cmptType>& res, const UList& f, const direction d ) { typedef typename Field::cmptType cmptType; TFOR_ALL_F_OP_F_FUNC_S ( cmptType, res, =, Type, f, .component, const direction, d ) } template void T(Field& res, const UList& f) { TFOR_ALL_F_OP_F_FUNC(Type, res, =, Type, f, T) } template void pow ( Field::type>& res, const UList& vf ) { typedef typename powProduct::type powProductType; TFOR_ALL_F_OP_FUNC_F_S ( powProductType, res, =, pow, Type, vf, powProductType, pTraits::zero ) } template tmp::type> > pow ( const UList& f, typename powProduct::type ) { typedef typename powProduct::type powProductType; tmp > tRes ( new Field(f.size()) ); pow(tRes(), f); return tRes; } template tmp::type> > pow ( const tmp >& tf, typename powProduct::type ) { typedef typename powProduct::type powProductType; tmp > tRes = reuseTmp::New(tf); pow(tRes(), tf()); reuseTmp::clear(tf); return tRes; } template void sqr ( Field::type>& res, const UList& vf ) { typedef typename outerProduct::type outerProductType; TFOR_ALL_F_OP_FUNC_F(outerProductType, res, =, sqr, Type, vf) } template tmp::type> > sqr(const UList& f) { typedef typename outerProduct::type outerProductType; tmp > tRes ( new Field(f.size()) ); sqr(tRes(), f); return tRes; } template tmp::type> > sqr(const tmp >& tf) { typedef typename outerProduct::type outerProductType; tmp > tRes = reuseTmp::New(tf); sqr(tRes(), tf()); reuseTmp::clear(tf); return tRes; } template void magSqr(Field& res, const UList& f) { TFOR_ALL_F_OP_FUNC_F(scalar, res, =, magSqr, Type, f) } template tmp > magSqr(const UList& f) { tmp > tRes(new Field(f.size())); magSqr(tRes(), f); return tRes; } template tmp > magSqr(const tmp >& tf) { tmp > tRes = reuseTmp::New(tf); magSqr(tRes(), tf()); reuseTmp::clear(tf); return tRes; } template void mag(Field& res, const UList& f) { TFOR_ALL_F_OP_FUNC_F(scalar, res, =, mag, Type, f) } template tmp > mag(const UList& f) { tmp > tRes(new Field(f.size())); mag(tRes(), f); return tRes; } template tmp > mag(const tmp >& tf) { tmp > tRes = reuseTmp::New(tf); mag(tRes(), tf()); reuseTmp::clear(tf); return tRes; } template void cmptMax(Field::cmptType>& res, const UList& f) { typedef typename Field::cmptType cmptType; TFOR_ALL_F_OP_FUNC_F(cmptType, res, =, cmptMax, Type, f) } template tmp::cmptType> > cmptMax(const UList& f) { typedef typename Field::cmptType cmptType; tmp > tRes(new Field(f.size())); cmptMax(tRes(), f); return tRes; } template tmp::cmptType> > cmptMax(const tmp >& tf) { typedef typename Field::cmptType cmptType; tmp > tRes = reuseTmp::New(tf); cmptMax(tRes(), tf()); reuseTmp::clear(tf); return tRes; } template void cmptMin(Field::cmptType>& res, const UList& f) { typedef typename Field::cmptType cmptType; TFOR_ALL_F_OP_FUNC_F(cmptType, res, =, cmptMin, Type, f) } template tmp::cmptType> > cmptMin(const UList& f) { typedef typename Field::cmptType cmptType; tmp > tRes(new Field(f.size())); cmptMin(tRes(), f); return tRes; } template tmp::cmptType> > cmptMin(const tmp >& tf) { typedef typename Field::cmptType cmptType; tmp > tRes = reuseTmp::New(tf); cmptMin(tRes(), tf()); reuseTmp::clear(tf); return tRes; } template void cmptAv(Field::cmptType>& res, const UList& f) { typedef typename Field::cmptType cmptType; TFOR_ALL_F_OP_FUNC_F(cmptType, res, =, cmptAv, Type, f) } template tmp::cmptType> > cmptAv(const UList& f) { typedef typename Field::cmptType cmptType; tmp > tRes(new Field(f.size())); cmptAv(tRes(), f); return tRes; } template tmp::cmptType> > cmptAv(const tmp >& tf) { typedef typename Field::cmptType cmptType; tmp > tRes = reuseTmp::New(tf); cmptAv(tRes(), tf()); reuseTmp::clear(tf); return tRes; } template void cmptMag(Field& res, const UList& f) { TFOR_ALL_F_OP_FUNC_F(Type, res, =, cmptMag, Type, f) } template tmp > cmptMag(const UList& f) { tmp > tRes(new Field(f.size())); cmptMag(tRes(), f); return tRes; } template tmp > cmptMag(const tmp >& tf) { tmp > tRes = reuseTmp::New(tf); cmptMag(tRes(), tf()); reuseTmp::clear(tf); return tRes; } #define TMP_UNARY_FUNCTION(ReturnType, Func) \ \ template \ ReturnType Func(const tmp >& tf1) \ { \ ReturnType res = Func(tf1()); \ tf1.clear(); \ return res; \ } template Type max(const UList& f) { if (f.size()) { Type Max(f[0]); TFOR_ALL_S_OP_FUNC_F_S(Type, Max, =, max, Type, f, Type, Max) return Max; } else { WarningIn("max(const UList&)") << "empty field, returning zero" << endl; return pTraits::zero; } } TMP_UNARY_FUNCTION(Type, max) template Type min(const UList& f) { if (f.size()) { Type Min(f[0]); TFOR_ALL_S_OP_FUNC_F_S(Type, Min, =, min, Type, f, Type, Min) return Min; } else { WarningIn("min(const UList&)") << "empty field, returning zero" << endl; return pTraits::zero; } } TMP_UNARY_FUNCTION(Type, min) template Type sum(const UList& f) { if (f.size()) { Type Sum = pTraits::zero; TFOR_ALL_S_OP_F(Type, Sum, +=, Type, f) return Sum; } else { return pTraits::zero; } } TMP_UNARY_FUNCTION(Type, sum) template scalar sumProd(const UList& f1, const UList& f2) { if (f1.size() && (f1.size() == f2.size())) { scalar SumProd = 0.0; TFOR_ALL_S_OP_F_OP_F(scalar, SumProd, +=, Type, f1, *, Type, f2) return SumProd; } else { return 0.0; } } template Type sumCmptProd(const UList& f1, const UList& f2) { if (f1.size() && (f1.size() == f2.size())) { Type SumProd = pTraits::zero; TFOR_ALL_S_OP_FUNC_F_F(Type, SumProd, +=, cmptMultiply, Type, f1, Type, f2) return SumProd; } else { return pTraits::zero; } } template scalar sumSqr(const UList& f) { if (f.size()) { scalar SumSqr = 0.0; TFOR_ALL_S_OP_FUNC_F(scalar, SumSqr, +=, sqr, Type, f) return SumSqr; } else { return 0.0; } } TMP_UNARY_FUNCTION(scalar, sumSqr) template scalar sumMag(const UList& f) { if (f.size()) { scalar SumMag = 0.0; TFOR_ALL_S_OP_FUNC_F(scalar, SumMag, +=, mag, Type, f) return SumMag; } else { return 0.0; } } TMP_UNARY_FUNCTION(scalar, sumMag) template Type sumCmptMag(const UList& f) { if (f.size()) { Type SumMag = pTraits::zero; TFOR_ALL_S_OP_FUNC_F(scalar, SumMag, +=, cmptMag, Type, f) return SumMag; } else { return pTraits::zero; } } TMP_UNARY_FUNCTION(Type, sumCmptMag) template Type average(const UList& f) { if (f.size()) { Type avrg = sum(f)/f.size(); return avrg; } else { WarningIn("average(const UList&)") << "empty field, returning zero" << endl; return pTraits::zero; } } TMP_UNARY_FUNCTION(Type, average) #define G_UNARY_FUNCTION(ReturnType, gFunc, Func, rFunc) \ \ template \ ReturnType gFunc(const UList& f) \ { \ ReturnType res = Func(f); \ reduce(res, rFunc##Op()); \ return res; \ } \ TMP_UNARY_FUNCTION(ReturnType, gFunc) G_UNARY_FUNCTION(Type, gMax, max, max) G_UNARY_FUNCTION(Type, gMin, min, min) G_UNARY_FUNCTION(Type, gSum, sum, sum) G_UNARY_FUNCTION(scalar, gSumSqr, sumSqr, sum) G_UNARY_FUNCTION(scalar, gSumMag, sumMag, sum) G_UNARY_FUNCTION(Type, gSumCmptMag, sumCmptMag, sum) #undef G_UNARY_FUNCTION template scalar gSumProd(const UList& f1, const UList& f2) { scalar SumProd = sumProd(f1, f2); reduce(SumProd, sumOp()); return SumProd; } template Type gSumCmptProd(const UList& f1, const UList& f2) { Type SumProd = sumCmptProd(f1, f2); reduce(SumProd, sumOp()); return SumProd; } template Type gAverage(const UList& f) { label n = f.size(); reduce(n, sumOp