BinSum.C
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 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 :
39  min_(min),
40  max_(max),
41  delta_(delta),
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 :
59  min_(min),
60  max_(max),
61  delta_(delta),
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 // ************************************************************************* //
BinSum.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
delta
scalar delta
Definition: LISASMDCalcMethod2.H:8
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:870
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::BinSum::BinSum
BinSum(const IndexType min, const IndexType max, const IndexType delta)
Construct given min, max, delta.
Definition: BinSum.C:32
Foam::List
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
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:50
Foam::UList
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
Foam::min
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::BinSum::add
void add(const IndexType &indexVal, const typename List::const_reference val, const CombineOp &cop=plusEqOp< typename List::value_type >())
Definition: BinSum.C:76