From 6f3e9c1572b4d84e8f290380dfcf7534cc811a27 Mon Sep 17 00:00:00 2001 From: mattijs <mattijs> Date: Mon, 23 Jul 2012 12:15:16 +0100 Subject: [PATCH] ENH: BinSum: added construct from values --- src/OpenFOAM/containers/Lists/BinSum/BinSum.C | 40 +++++++++++++++++++ src/OpenFOAM/containers/Lists/BinSum/BinSum.H | 18 +++++++++ 2 files changed, 58 insertions(+) diff --git a/src/OpenFOAM/containers/Lists/BinSum/BinSum.C b/src/OpenFOAM/containers/Lists/BinSum/BinSum.C index 6854597644a..1e099613269 100644 --- a/src/OpenFOAM/containers/Lists/BinSum/BinSum.C +++ b/src/OpenFOAM/containers/Lists/BinSum/BinSum.C @@ -44,6 +44,31 @@ Foam::BinSum<IndexType, List, CombineOp>::BinSum {} +template<class IndexType, class List, class CombineOp> +Foam::BinSum<IndexType, List, CombineOp>::BinSum +( + const IndexType min, + const IndexType max, + const IndexType delta, + const UList<IndexType>& indexVals, + const List& vals, + const CombineOp& cop +) +: + List(ceil((max-min)/delta), pTraits<typename List::value_type>::zero), + min_(min), + max_(max), + delta_(delta), + lowSum_(pTraits<typename List::value_type>::zero), + highSum_(pTraits<typename List::value_type>::zero) +{ + forAll(indexVals, i) + { + add(indexVals[i], vals[i], cop); + } +} + + // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // template<class IndexType, class List, class CombineOp> @@ -70,4 +95,19 @@ void Foam::BinSum<IndexType, List, CombineOp>::add } +template<class IndexType, class List, class CombineOp> +void Foam::BinSum<IndexType, List, CombineOp>::add +( + const UList<IndexType>& indexVals, + const List& vals, + const CombineOp& cop +) +{ + forAll(indexVals, i) + { + add(indexVals[i], vals[i], cop); + } +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/containers/Lists/BinSum/BinSum.H b/src/OpenFOAM/containers/Lists/BinSum/BinSum.H index 6e0195a780f..3cf09bc3a77 100644 --- a/src/OpenFOAM/containers/Lists/BinSum/BinSum.H +++ b/src/OpenFOAM/containers/Lists/BinSum/BinSum.H @@ -84,6 +84,17 @@ public: const IndexType delta ); + //- Construct given min, max, delta and data + BinSum + ( + const IndexType min, + const IndexType max, + const IndexType delta, + const UList<IndexType>& indexVals, + const List& vals, + const CombineOp& cop = plusEqOp<typename List::value_type>() + ); + // Access @@ -111,6 +122,13 @@ public: const typename List::const_reference val, const CombineOp& cop = plusEqOp<typename List::value_type>() ); + + void add + ( + const UList<IndexType>& indexVals, + const List& vals, + const CombineOp& cop = plusEqOp<typename List::value_type>() + ); }; -- GitLab