1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2009-2011 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
28 Accumulating histogram of component values.
29 Specified bin resolution, automatic generation of bins.
36 \*---------------------------------------------------------------------------*/
38 #ifndef Distribution_H
39 #define Distribution_H
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 Istream& operator>>(Istream&, Distribution<Type>&);
56 Ostream& operator<<(Ostream&, const Distribution<Type>&);
58 /*---------------------------------------------------------------------------*\
59 Class Distribution Declaration
60 \*---------------------------------------------------------------------------*/
65 public List< List<scalar> >
69 //- Width of the bin for each component
72 //- The start bin index of each component
73 List<label> listStarts_;
79 typedef typename pTraits<Type>::cmptType cmptType;
87 //- Construct from separate binWidth for each component
88 Distribution(const Type& binWidth);
91 Distribution(const Distribution& d);
99 //- Sum the total weight added to the component in the
101 scalar totalWeight(direction cmpt) const;
103 List<label> keys(direction cmpt) const;
105 //- Return the appropriate List index for the given bin index.
106 // Resizes the List if required
107 label index(direction cmpt, label n);
109 //- Returns the indices of the first and last non-zero entries
110 Pair<label> validLimits(direction cmpt) const;
114 // From http://mathworld.wolfram.com/StatisticalMedian.html
115 // The statistical median is the value of the Distribution
116 // variable where the cumulative Distribution = 0.5.
119 //- Add a value to the distribution, optionally specifying a weight
122 const Type& valueToAdd,
123 const Type& weight = pTraits<Type>::one
126 //- Return the normalised distribution (probability density)
128 List< List<Pair<scalar> > > normalised() const;
130 //- Return the distribution of the total bin weights
131 List< List < Pair<scalar> > > raw() const;
133 //- Return the cumulative normalised distribution and
134 // integration locations (at end of bins)
135 List< List<Pair<scalar> > > cumulativeNormalised() const;
137 //- Return the cumulative total bin weights and integration
138 // locations (at end of bins)
139 List< List<Pair<scalar> > > cumulativeRaw() const;
141 //- Resets the Distribution by clearing the stored lists.
142 // Leaves the same number of them and the same binWidth.
148 //- Return the bin width
149 inline const Type& binWidth() const;
151 //- Return the List start bin indices
152 inline const List<label>& listStarts() const;
156 //- Write the distribution to file: key normalised raw.
157 // Produces a separate file for each component.
158 void write(const fileName& filePrefix) const;
163 void operator=(const Distribution<Type>&);
165 // IOstream Operators
167 friend Istream& operator>> <Type>
173 friend Ostream& operator<< <Type>
176 const Distribution<Type>&
181 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
184 Distribution<Type> operator+
186 const Distribution<Type>&,
187 const Distribution<Type>&
191 } // End namespace Foam
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 #include "DistributionI.H"
197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200 # include "Distribution.C"
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207 // ************************************************************************* //