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 | Copyright (C) 2011-2015 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 Class
25  Foam::distribution
26 
27 Description
28  Accumulating histogram of values. Specified bin resolution
29  automatic generation of bins.
30 
31 SourceFiles
32  distributionI.H
33  distribution.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef distribution_H
38 #define distribution_H
39 
40 #include "Map.H"
41 #include "Pair.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 /*---------------------------------------------------------------------------*\
49  Class distribution Declaration
50 \*---------------------------------------------------------------------------*/
51 
52 class distribution
53 :
54  public Map<label>
55 {
56  // Private data
57 
58  scalar binWidth_;
59 
60 
61 public:
62 
63  //- Runtime type information
64 
65  TypeName("distribution");
66 
67  // Static functions
68 
69  //- Write to file
70 
71  static void write
72  (
73  const fileName& file,
74  const List<Pair<scalar> >& pairs
75  );
76 
77 
78  // Constructors
79 
80  //- Construct null
81  distribution();
82 
83  //- Construct from binWidth
84  distribution(const scalar binWidth);
85 
86  //- Construct as copy
87  distribution(const distribution&);
88 
89 
90  //- Destructor
91  virtual ~distribution();
92 
93 
94  // Member Functions
95 
96  label totalEntries() const;
97 
98  scalar approxTotalEntries() const;
99 
100  scalar mean() const;
101 
102  scalar median();
103 
104  //- Add a value to the appropriate bin of the distribution.
105  void add(const scalar valueToAdd);
106 
107  void add(const label valueToAdd);
108 
109  void insertMissingKeys();
110 
112 
114 
115  List<Pair<scalar> > normalisedShifted(scalar shiftValue);
116 
118 
119 
120  // Access
121 
122  inline scalar binWidth() const;
123 
124 
125  // Member Operators
126 
127  void operator=(const distribution&);
128 
129 
130  // IOstream Operators
131 
132  friend Ostream& operator<<(Ostream&, const distribution&);
133 };
134 
135 
136 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
137 
138 } // End namespace Foam
139 
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
141 
142 #include "distributionI.H"
143 
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 
146 #endif
147 
148 // ************************************************************************* //
static void write(const fileName &file, const List< Pair< scalar > > &pairs)
Write to file.
Definition: distribution.C:39
List< Pair< scalar > > normalisedShifted(scalar shiftValue)
Definition: distribution.C:308
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: contiguous.H:49
A HashTable to objects of type <T> with a label key.
Definition: Map.H:49
TypeName("distribution")
Runtime type information.
distribution()
Construct null.
Definition: distribution.C:55
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
scalar mean() const
Definition: distribution.C:125
void add(const scalar valueToAdd)
Add a value to the appropriate bin of the distribution.
Definition: distribution.C:212
Accumulating histogram of values. Specified bin resolution automatic generation of bins...
Definition: distribution.H:51
Namespace for OpenFOAM.
scalar approxTotalEntries() const
Definition: distribution.C:112
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
List< Pair< scalar > > normalised()
Definition: distribution.C:271
friend Ostream & operator<<(Ostream &, const distribution &)
List< Pair< scalar > > raw()
Definition: distribution.C:419
void operator=(const distribution &)
Definition: distribution.C:444
List< Pair< scalar > > normalisedMinusMean()
Definition: distribution.C:301
A class for handling file names.
Definition: fileName.H:69
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
label totalEntries() const
Definition: distribution.C:84
virtual ~distribution()
Destructor.
Definition: distribution.C:78
scalar binWidth() const
Definition: distributionI.H:28