All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BinSum.C
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-2018 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 \*---------------------------------------------------------------------------*/
25 
26 #include "BinSum.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class IndexType, class List, class CombineOp>
32 (
33  const IndexType min,
34  const IndexType max,
35  const IndexType delta
36 )
37 :
38  List(ceil((max-min)/delta), Zero),
39  min_(min),
40  max_(max),
41  delta_(delta),
42  lowSum_(Zero),
43  highSum_(Zero)
44 {}
45 
46 
47 template<class IndexType, class List, class CombineOp>
49 (
50  const IndexType min,
51  const IndexType max,
52  const IndexType delta,
53  const UList<IndexType>& indexVals,
54  const List& vals,
55  const CombineOp& cop
56 )
57 :
58  List(ceil((max-min)/delta), Zero),
59  min_(min),
60  max_(max),
61  delta_(delta),
62  lowSum_(Zero),
63  highSum_(Zero)
64 {
65  forAll(indexVals, i)
66  {
67  add(indexVals[i], vals[i], cop);
68  }
69 }
70 
71 
72 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
73 
74 template<class IndexType, class List, class CombineOp>
76 (
77  const IndexType& indexVal,
78  const typename List::const_reference val,
79  const CombineOp& cop
80 )
81 {
82  if (indexVal < min_)
83  {
84  cop(lowSum_, val);
85  }
86  else if (indexVal >= max_)
87  {
88  cop(highSum_, val);
89  }
90  else
91  {
92  label index = (indexVal-min_)/delta_;
93  cop(this->operator[](index), val);
94  }
95 }
96 
97 
98 template<class IndexType, class List, class CombineOp>
100 (
101  const UList<IndexType>& indexVals,
102  const List& vals,
103  const CombineOp& cop
104 )
105 {
106  forAll(indexVals, i)
107  {
108  add(indexVals[i], vals[i], cop);
109  }
110 }
111 
112 
113 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
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
static const zero Zero
Definition: zero.H:97
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
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
const T & const_reference
Type that can be used for storing into.
Definition: UList.H:256