diff --git a/src/OpenFOAM/containers/Lists/ListOps/ListOps.H b/src/OpenFOAM/containers/Lists/ListOps/ListOps.H index d0689b0eb1955f82bb2ffee45f8d72e846a49fa0..86fdc7ba5140b4841587c24e0f4be3649b91b30d 100644 --- a/src/OpenFOAM/containers/Lists/ListOps/ListOps.H +++ b/src/OpenFOAM/containers/Lists/ListOps/ListOps.H @@ -245,6 +245,15 @@ template<class Container, class T, int nRows, int nColumns> List<Container> initListList(const T[nRows][nColumns]); +//- Helper class for list to append y onto the end of x +template<class T> +class ListAppendEqOp +{ +public: + void operator()(List<T>& x, const List<T>& y) const; +}; + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C b/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C index be6337a4283e6e5f039ba9a8fc5e6ee9cb52fb87..49daa408c1b6c3775b71bfec2566f1321b69ce4c 100644 --- a/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C +++ b/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C @@ -684,4 +684,26 @@ Foam::List<Container> Foam::initListList(const T elems[nRows][nColumns]) } +template<class T> +void Foam::ListAppendEqOp<T>::operator()(List<T>& x, const List<T>& y) const +{ + if (y.size()) + { + if (x.size()) + { + label sz = x.size(); + x.setSize(sz + y.size()); + forAll(y, i) + { + x[sz++] = y[i]; + } + } + else + { + x = y; + } + } +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/ops/ops.H b/src/OpenFOAM/primitives/ops/ops.H index 66d793084962f6706f6bf5eb20abc7c3a64f215a..cab91fcfb5eee81d71a4cb8280b8d21e0c25e1a0 100644 --- a/src/OpenFOAM/primitives/ops/ops.H +++ b/src/OpenFOAM/primitives/ops/ops.H @@ -90,40 +90,68 @@ EqOp(nopEq, (void)x) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#define Op(opName, op) \ - \ -template<class T, class T1, class T2> \ -class opName##Op3 \ -{ \ -public: \ - \ - T operator()(const T1& x, const T2& y) const \ - { \ - return op; \ - } \ -}; \ - \ -template<class T1, class T2> \ -class opName##Op2 \ -{ \ -public: \ - \ - T1 operator()(const T1& x, const T2& y) const \ - { \ - return op; \ - } \ -}; \ - \ -template<class T> \ -class opName##Op \ -{ \ -public: \ - \ - T operator()(const T& x, const T& y) const \ - { \ - return op; \ - } \ -}; +#define Op(opName, op) \ + \ + template<class T, class T1, class T2> \ + class opName##Op3 \ + { \ + public: \ + \ + T operator()(const T1& x, const T2& y) const \ + { \ + return op; \ + } \ + }; \ + \ + template<class T1, class T2> \ + class opName##Op2 \ + { \ + public: \ + \ + T1 operator()(const T1& x, const T2& y) const \ + { \ + return op; \ + } \ + }; \ + \ + template<class T> \ + class opName##Op \ + { \ + public: \ + \ + T operator()(const T& x, const T& y) const \ + { \ + return op; \ + } \ + }; + + +#define weightedOp(opName, op) \ + \ + template<class Type, class CombineOp> \ + class opName##WeightedOp \ + { \ + const CombineOp& cop_; \ + \ + public: \ + \ + opName##WeightedOp(const CombineOp& cop) \ + : \ + cop_(cop) \ + {} \ + \ + void operator() \ + ( \ + Type& x, \ + const label index, \ + const Type& y, \ + const scalar weight \ + ) const \ + { \ + cop_(x, op); \ + } \ + }; \ + Op(sum, x + y) @@ -147,6 +175,8 @@ Op(lessEq, x <= y) Op(greater, x > y) Op(greaterEq, x >= y) +weightedOp(multiply, weight * y) + #undef Op diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C index 1f9f4c66ec68de7c06a16114e741bd9d5449a2f0..fc60cd2fbba5c8d30cac94380afff83e05c7a7c9 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/AMIInterpolation.C @@ -27,63 +27,6 @@ License #include "meshTools.H" #include "mapDistribute.H" -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -namespace Foam -{ - //- Helper class for list - template<class T> - class ListPlusEqOp - { - public: - void operator()(List<T>& x, const List<T> y) const - { - if (y.size()) - { - if (x.size()) - { - label sz = x.size(); - x.setSize(sz + y.size()); - forAll(y, i) - { - x[sz++] = y[i]; - } - } - else - { - x = y; - } - } - } - }; - - //- Combine operator for interpolateToSource/Target - template<class Type, class CombineOp> - class combineBinaryOp - { - const CombineOp& cop_; - - public: - - combineBinaryOp(const CombineOp& cop) - : - cop_(cop) - {} - - void operator() - ( - Type& x, - const label faceI, - const Type& y, - const scalar weight - ) const - { - cop_(x, weight*y); - } - }; -} - - // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // template<class SourcePatch, class TargetPatch> @@ -1550,7 +1493,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update } // send data back to originating procs. Note that contributions - // from different processors get added (ListPlusEqOp) + // from different processors get added (ListAppendEqOp) mapDistribute::distribute ( @@ -1560,7 +1503,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update map.constructMap(), map.subMap(), tgtAddress_, - ListPlusEqOp<label>(), + ListAppendEqOp<label>(), labelList() ); @@ -1572,7 +1515,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update map.constructMap(), map.subMap(), tgtWeights_, - ListPlusEqOp<scalar>(), + ListAppendEqOp<scalar>(), scalarList() ); @@ -1787,7 +1730,12 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::interpolateToSource ) ); - interpolateToSource(fld, combineBinaryOp<Type, CombineOp>(cop), tresult()); + interpolateToSource + ( + fld, + multiplyWeightedOp<Type, CombineOp>(cop), + tresult() + ); return tresult; } @@ -1824,7 +1772,12 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::interpolateToTarget ) ); - interpolateToTarget(fld, combineBinaryOp<Type, CombineOp>(cop), tresult()); + interpolateToTarget + ( + fld, + multiplyWeightedOp<Type, CombineOp>(cop), + tresult() + ); return tresult; }