BinSum.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2012-2019 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 
76 public:
77 
78  // Constructors
79 
80  //- Construct given min, max, delta
81  BinSum
82  (
83  const IndexType min,
84  const IndexType max,
85  const IndexType delta
86  );
87 
88  //- Construct given min, max, delta and data
89  BinSum
90  (
91  const IndexType min,
92  const IndexType max,
93  const IndexType delta,
94  const UList<IndexType>& indexVals,
95  const List& vals,
96  const CombineOp& cop = plusEqOp<typename List::value_type>()
97  );
98 
99 
100  // Access
101 
102  //- Return the delta
103  inline IndexType delta() const
104  {
105  return delta_;
106  }
107 
108  //- Return the sum of all added elements < min
109  inline const IndexType& lowSum() const
110  {
111  return lowSum_;
112  }
113 
114  //- Return the sum of all added elements >= max
115  inline const IndexType& highSum() const
116  {
117  return highSum_;
118  }
119 
120  void add
121  (
122  const IndexType& indexVal,
123  const typename List::const_reference val,
124  const CombineOp& cop = plusEqOp<typename List::value_type>()
125  );
126 
127  void add
128  (
129  const UList<IndexType>& indexVals,
130  const List& vals,
131  const CombineOp& cop = plusEqOp<typename List::value_type>()
132  );
133 };
134 
135 
136 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
137 
138 } // End namespace Foam
139 
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
141 
142 #ifdef NoRepository
143  #include "BinSum.C"
144 #endif
145 
146 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
147 
148 #endif
149 
150 // ************************************************************************* //
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Combination-Reduction operation for a parallel run.
const IndexType & highSum() const
Return the sum of all added elements >= max.
Definition: BinSum.H:114
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
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
const IndexType & lowSum() const
Return the sum of all added elements < min.
Definition: BinSum.H:108
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
IndexType delta() const
Return the delta.
Definition: BinSum.H:102
const T & const_reference
Type that can be used for storing into.
Definition: UList.H:256
Sums into bins.
Definition: BinSum.H:55
T value_type
Type of values the UList contains.
Definition: UList.H:248
Namespace for OpenFOAM.