Loading...
Searching...
No Matches
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{
51template<class Type>
52class Distribution;
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;
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
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
130 List<List<Pair<scalar>>> normalised() const;
131
132 //- Return the distribution of the total bin weights
133 List<List < Pair<scalar>>> raw() const;
134
135 //- Return the cumulative normalised distribution and
136 // integration locations (at end of bins)
137 List<List<Pair<scalar>>> cumulativeNormalised() const;
138
139 //- Return the cumulative total bin weights and integration
140 // locations (at end of bins)
141 List<List<Pair<scalar>>> cumulativeRaw() const;
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
168
169 friend Istream& operator>> <Type>
170 (
171 Istream&,
173 );
174
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.
List< List< Pair< scalar > > > cumulativeNormalised() const
Return the cumulative normalised distribution and.
Type mean() const
List< label > keys(direction cmpt) const
void add(const Type &valueToAdd, const Type &weight=pTraits< Type >::one)
Add a value to the distribution, optionally specifying a weight.
~Distribution()
Destructor.
const List< label > & listStarts() const
Return the List start bin indices.
pTraits< Type >::cmptType cmptType
Component type.
Type median() const
Distribution()
Construct null.
scalar totalWeight(direction cmpt) const
Sum the total weight added to the component in the.
void clear()
Resets the Distribution by clearing the stored lists.
Pair< label > validLimits(direction cmpt) const
Returns the indices of the first and last non-zero entries.
const Type & binWidth() const
Return the bin width.
void operator=(const Distribution< Type > &)
List< List< Pair< scalar > > > cumulativeRaw() const
Return the cumulative total bin weights and integration.
List< List< Pair< scalar > > > raw() const
Return the distribution of the total bin weights.
label index(direction cmpt, label n)
Return the appropriate List index for the given bin index.
List< List< Pair< scalar > > > normalised() const
Return the normalised distribution (probability density).
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:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
An ordered pair of two objects of type <T> with first() and second() elements.
Definition Pair.H:66
A class for handling file names.
Definition fileName.H:75
A traits class, which is primarily used for primitives and vector-space.
Definition pTraits.H:64
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
Istream & operator>>(Istream &, directionInfo &)
uint8_t direction
Definition direction.H:49
runTime write()