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