/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\/ 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 3 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, see . \*---------------------------------------------------------------------------*/ #include "PstreamReduceOps.H" #include "FieldFieldReuseFunctions.H" #define TEMPLATE template class Field, class Type> #include "FieldFieldFunctionsM.C" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { /* * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * */ template class Field, class Type> void component ( FieldField::cmptType>& sf, const FieldField& f, const direction d ) { forAll(sf, i) { component(sf[i], f[i], d); } } template class Field, class Type> void T(FieldField& f1, const FieldField& f2) { forAll(f1, i) { T(f1[i], f2[i]); } } template class Field, class Type, int r> void pow ( FieldField::type>& f, const FieldField& vf ) { forAll(f, i) { pow(f[i], vf[i]); } } template class Field, class Type, int r> tmp::type> > pow ( const FieldField& f, typename powProduct::type ) { typedef typename powProduct::type powProductType; tmp > tRes ( FieldField::NewCalculatedType(f) ); pow(tRes(), f); return tRes; } template class Field, class Type, int r> tmp::type> > pow ( const tmp >& tf, typename powProduct::type ) { typedef typename powProduct::type powProductType; tmp > tRes ( reuseTmpFieldField::New(tf) ); pow(tRes(), tf()); reuseTmpFieldField::clear(tf); return tRes; } template class Field, class Type> void sqr ( FieldField::type>& f, const FieldField& vf ) { forAll(f, i) { sqr(f[i], vf[i]); } } template class Field, class Type> tmp::type> > sqr(const FieldField& f) { typedef typename outerProduct::type outerProductType; tmp > tRes ( FieldField::NewCalculatedType(f) ); sqr(tRes(), f); return tRes; } template class Field, class Type> tmp::type> > sqr(const tmp >& tf) { typedef typename outerProduct::type outerProductType; tmp > tRes ( reuseTmpFieldField::New(tf) ); sqr(tRes(), tf()); reuseTmpFieldField::clear(tf); return tRes; } template class Field, class Type> void magSqr(FieldField& sf, const FieldField& f) { forAll(sf, i) { magSqr(sf[i], f[i]); } } template class Field, class Type> tmp > magSqr(const FieldField& f) { tmp > tRes ( FieldField::NewCalculatedType(f) ); magSqr(tRes(), f); return tRes; } template class Field, class Type> tmp > magSqr(const tmp >& tf) { tmp > tRes ( reuseTmpFieldField::New(tf) ); magSqr(tRes(), tf()); reuseTmpFieldField::clear(tf); return tRes; } template class Field, class Type> void mag(FieldField& sf, const FieldField& f) { forAll(sf, i) { mag(sf[i], f[i]); } } template class Field, class Type> tmp > mag(const FieldField& f) { tmp > tRes ( FieldField::NewCalculatedType(f) ); mag(tRes(), f); return tRes; } template class Field, class Type> tmp > mag(const tmp >& tf) { tmp > tRes ( reuseTmpFieldField::New(tf) ); mag(tRes(), tf()); reuseTmpFieldField::clear(tf); return tRes; } template class Field, class Type> void cmptMax ( FieldField::cmptType>& cf, const FieldField& f ) { forAll(cf, i) { cmptMax(cf[i], f[i]); } } template class Field, class Type> tmp::cmptType> > cmptMax ( const FieldField& f ) { typedef typename FieldField::cmptType cmptType; tmp > tRes ( FieldField::NewCalculatedType(f) ); cmptMax(tRes(), f); return tRes; } template class Field, class Type> tmp::cmptType> > cmptMax ( const tmp >& tf ) { typedef typename FieldField::cmptType cmptType; tmp > tRes ( reuseTmpFieldField::New(tf) ); cmptMax(tRes(), tf()); reuseTmpFieldField::clear(tf); return tRes; } template class Field, class Type> void cmptMin ( FieldField::cmptType>& cf, const FieldField& f ) { forAll(cf, i) { cmptMin(cf[i], f[i]); } } template class Field, class Type> tmp::cmptType> > cmptMin ( const FieldField& f ) { typedef typename FieldField::cmptType cmptType; tmp > tRes ( FieldField::NewCalculatedType(f) ); cmptMin(tRes(), f); return tRes; } template class Field, class Type> tmp::cmptType> > cmptMin ( const tmp >& tf ) { typedef typename FieldField::cmptType cmptType; tmp > tRes ( reuseTmpFieldField::New(tf) ); cmptMin(tRes(), tf()); reuseTmpFieldField::clear(tf); return tRes; } template class Field, class Type> void cmptAv ( FieldField::cmptType>& cf, const FieldField& f ) { forAll(cf, i) { cmptAv(cf[i], f[i]); } } template class Field, class Type> tmp::cmptType> > cmptAv ( const FieldField& f ) { typedef typename FieldField::cmptType cmptType; tmp > tRes ( FieldField::NewCalculatedType(f) ); cmptAv(tRes(), f); return tRes; } template class Field, class Type> tmp::cmptType> > cmptAv ( const tmp >& tf ) { typedef typename FieldField::cmptType cmptType; tmp > tRes ( reuseTmpFieldField::New(tf) ); cmptAv(tRes(), tf()); reuseTmpFieldField::clear(tf); return tRes; } template class Field, class Type> void cmptMag ( FieldField& cf, const FieldField& f ) { forAll(cf, i) { cmptMag(cf[i], f[i]); } } template class Field, class Type> tmp > cmptMag ( const FieldField& f ) { tmp > tRes ( FieldField::NewCalculatedType(f) ); cmptMag(tRes(), f); return tRes; } template class Field, class Type> tmp > cmptMag ( const tmp >& tf ) { tmp > tRes ( reuseTmpFieldField::New(tf) ); cmptMag(tRes(), tf()); reuseTmpFieldField::clear(tf); return tRes; } #define TMP_UNARY_FUNCTION(returnType, func) \ \ template class Field, class Type> \ returnType func(const tmp >& tf1) \ { \ returnType res = func(tf1()); \ tf1.clear(); \ return res; \ } template class Field, class Type> Type max(const FieldField& f) { label i = 0; while (i < f.size() && !f[i].size()) i++; if (i < f.size()) { Type Max(max(f[i])); for (label j=i+1; j::min; } } TMP_UNARY_FUNCTION(Type, max) template class Field, class Type> Type min(const FieldField& f) { label i = 0; while (i < f.size() && !f[i].size()) i++; if (i < f.size()) { label i = 0; while (!f[i].size()) i++; Type Min(min(f[i])); for (label j=i+1; j::max; } } TMP_UNARY_FUNCTION(Type, min) template class Field, class Type> Type sum(const FieldField& f) { if (f.size()) { Type Sum = pTraits::zero; forAll(f, i) { Sum += sum(f[i]); } return Sum; } else { return pTraits::zero; } } TMP_UNARY_FUNCTION(Type, sum) template class Field, class Type> scalar sumMag(const FieldField& f) { if (f.size()) { scalar SumMag = 0.0; forAll(f, i) { SumMag += sumMag(f[i]); } return SumMag; } else { return 0.0; } } TMP_UNARY_FUNCTION(scalar, sumMag) template class Field, class Type> Type average(const FieldField& f) { if (f.size()) { label n = 0; forAll(f, i) { n += f[i].size(); } if (n == 0) { WarningIn("average(const FieldField&) const") << "empty fieldField, returning zero" << endl; return pTraits::zero; } Type avrg = sum(f)/n; return avrg; } else { WarningIn("average(const FieldField&) const") << "empty fieldField, returning zero" << endl; return pTraits::zero; } } TMP_UNARY_FUNCTION(Type, average) #include "PstreamReduceOps.H" #define G_UNARY_FUNCTION(returnType, gFunc, func, rFunc) \ \ template class Field, class Type> \ returnType gFunc(const FieldField& 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, gSumMag, sumMag, sum) #undef G_UNARY_FUNCTION template class Field, class Type> Type gAverage(const FieldField& f) { label n = 0; forAll(f, i) { n += f[i].size(); } reduce(n, sumOp