BinSum.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2012-2016 OpenFOAM Foundation
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Class
27 Foam::BinSum
28
29Description
30 Sums into bins
31
32SourceFiles
33 BinSum.C
34
35\*---------------------------------------------------------------------------*/
36
37#ifndef BinSum_H
38#define BinSum_H
39
40#include "ops.H"
41
42// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43
44namespace Foam
45{
46
47
48/*---------------------------------------------------------------------------*\
49 Class BinSum Declaration
50\*---------------------------------------------------------------------------*/
51
52template
53<
54 class IndexType,
55 class List,
56 class CombineOp = plusEqOp<typename List::value_type>
58class BinSum
59:
60 public List
61{
62 // Private data
63
64 const IndexType min_;
65
66 const IndexType max_;
67
68 const IndexType delta_;
69
70
71 //- Sum < lowest bin
72 typename List::value_type lowSum_;
73
74 //- Sum of >= highest bin
75 typename List::value_type highSum_;
76
77public:
78
79 // Constructors
80
81 //- Construct given min, max, delta
82 BinSum
83 (
84 const IndexType min,
85 const IndexType max,
86 const IndexType delta
87 );
88
89 //- Construct given min, max, delta and data
90 BinSum
91 (
92 const IndexType min,
93 const IndexType max,
94 const IndexType delta,
95 const UList<IndexType>& indexVals,
96 const List& vals,
97 const CombineOp& cop = plusEqOp<typename List::value_type>()
98 );
99
100
101 // Access
102
103 //- Return the delta
104 inline IndexType delta() const
105 {
106 return delta_;
107 }
108
109 //- Return the sum of all added elements < min
110 inline const IndexType& lowSum() const
111 {
112 return lowSum_;
113 }
114
115 //- Return the sum of all added elements >= max
116 inline const IndexType& highSum() const
117 {
118 return highSum_;
119 }
120
121 void add
122 (
123 const IndexType& indexVal,
124 const typename List::const_reference val,
125 const CombineOp& cop = plusEqOp<typename List::value_type>()
126 );
127
128 void add
129 (
130 const UList<IndexType>& indexVals,
131 const List& vals,
132 const CombineOp& cop = plusEqOp<typename List::value_type>()
133 );
134};
135
136
137// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
138
139} // End namespace Foam
140
141// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
142
143#ifdef NoRepository
144 #include "BinSum.C"
145#endif
146
147// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
148
149#endif
150
151// ************************************************************************* //
Sums into bins.
Definition: BinSum.H:60
void add(const IndexType &indexVal, const typename List::const_reference val, const CombineOp &cop=plusEqOp< typename List::value_type >())
Definition: BinSum.C:78
const IndexType & lowSum() const
Return the sum of all added elements < min.
Definition: BinSum.H:109
IndexType delta() const
Return the delta.
Definition: BinSum.H:103
const IndexType & highSum() const
Return the sum of all added elements >= max.
Definition: BinSum.H:115
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
unsigned int const_reference
Definition: bitSet.H:124
Namespace for OpenFOAM.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
Various functors for unary and binary operations. Can be used for parallel combine-reduce operations ...