Distribution.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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-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
26Class
27 Foam::Distribution
28
29Description
30 Accumulating histogram of component values.
31 Specified bin resolution, automatic generation of bins.
32
33SourceFiles
34 DistributionI.H
35 Distribution.C
36 DistributionIO.C
37
38\*---------------------------------------------------------------------------*/
39
40#ifndef Distribution_H
41#define Distribution_H
42
43#include "List.H"
44#include "Pair.H"
45
46// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47
48namespace Foam
49{
50
51template<class Type>
52class Distribution;
53
54template<class Type>
56
57template<class Type>
59
60/*---------------------------------------------------------------------------*\
61 Class Distribution Declaration
62\*---------------------------------------------------------------------------*/
63
64template<class Type>
65class Distribution
66:
67 public List<List<scalar>>
68{
69 // Private data
70
71 //- Width of the bin for each component
72 Type binWidth_;
73
74 //- The start bin index of each component
75 List<label> listStarts_;
76
77
78public:
79
80 //- Component type
81 typedef typename pTraits<Type>::cmptType cmptType;
82
83
84 // Constructors
85
86 //- Construct null
88
89 //- Construct from separate binWidth for each component
90 Distribution(const Type& binWidth);
91
92 //- Construct as copy
93 Distribution(const Distribution& d);
94
95
96 //- Destructor
98
99 // Member Functions
100
101 //- Sum the total weight added to the component in the
102 // argument
103 scalar totalWeight(direction cmpt) const;
104
105 List<label> keys(direction cmpt) const;
106
107 //- Return the appropriate List index for the given bin index.
108 // Resizes the List if required
109 label index(direction cmpt, label n);
110
111 //- Returns the indices of the first and last non-zero entries
113
114 Type mean() const;
115
116 // From http://mathworld.wolfram.com/StatisticalMedian.html
117 // The statistical median is the value of the Distribution
118 // variable where the cumulative Distribution = 0.5.
119 Type median() const;
120
121 //- Add a value to the distribution, optionally specifying a weight
122 void add
123 (
124 const Type& valueToAdd,
125 const Type& weight = pTraits<Type>::one
126 );
127
128 //- Return the normalised distribution (probability density)
129 // and bins
131
132 //- Return the distribution of the total bin weights
134
135 //- Return the cumulative normalised distribution and
136 // integration locations (at end of bins)
138
139 //- Return the cumulative total bin weights and integration
140 // locations (at end of bins)
142
143 //- Resets the Distribution by clearing the stored lists.
144 // Leaves the same number of them and the same binWidth.
145 void clear();
146
147
148 // Access
149
150 //- Return the bin width
151 inline const Type& binWidth() const;
152
153 //- Return the List start bin indices
154 inline const List<label>& listStarts() const;
155
156 // Write
157
158 //- Write the distribution to file: key normalised raw.
159 // Produces a separate file for each component.
160 void write(const fileName& filePrefix) const;
161
162
163 // Member Operators
164
165 void operator=(const Distribution<Type>&);
166
167 // IOstream Operators
169 friend Istream& operator>> <Type>
170 (
171 Istream&,
173 );
175 friend Ostream& operator<< <Type>
176 (
177 Ostream&,
178 const Distribution<Type>&
179 );
180};
181
182
183// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
184
185template<class Type>
186Distribution<Type> operator+
187(
188 const Distribution<Type>&,
189 const Distribution<Type>&
190);
191
192
193} // End namespace Foam
194
195// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
196
197#include "DistributionI.H"
198
199// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200
201#ifdef NoRepository
202 #include "Distribution.C"
203#endif
204
205// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
206
207#endif
208
209// ************************************************************************* //
label n
Accumulating histogram of component values. Specified bin resolution, automatic generation of bins.
Definition: Distribution.H:67
List< List< Pair< scalar > > > cumulativeNormalised() const
Return the cumulative normalised distribution and.
Definition: Distribution.C:421
Type mean() const
Definition: Distribution.C:193
List< label > keys(direction cmpt) const
Definition: Distribution.C:88
void add(const Type &valueToAdd, const Type &weight=pTraits< Type >::one)
Add a value to the distribution, optionally specifying a weight.
Definition: Distribution.C:309
~Distribution()
Destructor.
Definition: Distribution.C:65
const List< label > & listStarts() const
Return the List start bin indices.
Definition: DistributionI.H:40
pTraits< Type >::cmptType cmptType
Component type.
Definition: Distribution.H:80
Type median() const
Definition: Distribution.C:222
Distribution()
Construct null.
Definition: Distribution.C:36
scalar totalWeight(direction cmpt) const
Sum the total weight added to the component in the.
Definition: Distribution.C:72
void clear()
Resets the Distribution by clearing the stored lists.
Definition: Distribution.C:488
Pair< label > validLimits(direction cmpt) const
Returns the indices of the first and last non-zero entries.
Definition: Distribution.C:162
const Type & binWidth() const
Return the bin width.
Definition: DistributionI.H:32
void operator=(const Distribution< Type > &)
Definition: Distribution.C:557
List< List< Pair< scalar > > > cumulativeRaw() const
Return the cumulative total bin weights and integration.
Definition: Distribution.C:457
List< List< Pair< scalar > > > raw() const
Return the distribution of the total bin weights.
Definition: Distribution.C:379
label index(direction cmpt, label n)
Return the appropriate List index for the given bin index.
Definition: Distribution.C:96
List< List< Pair< scalar > > > normalised() const
Return the normalised distribution (probability density)
Definition: Distribution.C:331
Distribution(const Distribution &d)
Construct as copy.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
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
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: Pair.H:69
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:66
A class for handling file names.
Definition: fileName.H:76
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:62
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Istream & operator>>(Istream &, directionInfo &)
uint8_t direction
Definition: direction.H:56
runTime write()