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 | 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
26\*---------------------------------------------------------------------------*/
27
28#include "BinSum.H"
29
30// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31
32template<class IndexType, class List, class CombineOp>
34(
35 const IndexType min,
36 const IndexType max,
37 const IndexType delta
38)
39:
40 List(ceil((max-min)/delta), Zero),
41 min_(min),
42 max_(max),
43 delta_(delta),
44 lowSum_(Zero),
45 highSum_(Zero)
46{}
47
48
49template<class IndexType, class List, class CombineOp>
51(
52 const IndexType min,
53 const IndexType max,
54 const IndexType delta,
55 const UList<IndexType>& indexVals,
56 const List& vals,
57 const CombineOp& cop
58)
59:
60 List(ceil((max-min)/delta), Zero),
61 min_(min),
62 max_(max),
63 delta_(delta),
64 lowSum_(Zero),
65 highSum_(Zero)
66{
67 forAll(indexVals, i)
68 {
69 add(indexVals[i], vals[i], cop);
70 }
71}
72
73
74// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
75
76template<class IndexType, class List, class CombineOp>
78(
79 const IndexType& indexVal,
80 const typename List::const_reference val,
81 const CombineOp& cop
82)
83{
84 if (indexVal < min_)
85 {
86 cop(lowSum_, val);
87 }
88 else if (indexVal >= max_)
89 {
90 cop(highSum_, val);
91 }
92 else
93 {
94 label index = (indexVal-min_)/delta_;
95 cop(this->operator[](index), val);
96 }
97}
98
99
100template<class IndexType, class List, class CombineOp>
102(
103 const UList<IndexType>& indexVals,
104 const List& vals,
105 const CombineOp& cop
106)
107{
108 forAll(indexVals, i)
109 {
110 add(indexVals[i], vals[i], cop);
111 }
112}
113
114
115// ************************************************************************* //
scalar delta
Y[inertIndex] max(0.0)
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
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
Sums a given list of (at least two or more) fields and outputs the result into a new field,...
Definition: add.H:161
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333