distribution.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 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 // Forward declaration of friend functions and operators
49 
50 class distribution;
51 
52 Ostream& operator<<(Ostream&, const distribution&);
53 
54 
55 /*---------------------------------------------------------------------------*\
56  Class distribution Declaration
57 \*---------------------------------------------------------------------------*/
58 
59 class distribution
60 :
61  public Map<label>
62 {
63  // Private Data
64 
65  scalar binWidth_;
66 
67 
68 public:
69 
70  //- Runtime type information
71 
72  TypeName("distribution");
73 
74  // Static functions
75 
76  //- Write to file
77 
78  static void write
79  (
80  const fileName& file,
81  const List<Pair<scalar>>& pairs
82  );
83 
84 
85  // Constructors
86 
87  //- Construct null
88  distribution();
89 
90  //- Construct from binWidth
91  distribution(const scalar binWidth);
92 
93  //- Copy constructor
94  distribution(const distribution&);
95 
96 
97  //- Destructor
98  virtual ~distribution();
99 
100 
101  // Member Functions
102 
103  label totalEntries() const;
104 
105  scalar approxTotalEntries() const;
106 
107  scalar mean() const;
108 
109  scalar median();
110 
111  //- Add a value to the appropriate bin of the distribution.
112  void add(const scalar valueToAdd);
113 
114  void add(const label valueToAdd);
115 
116  void insertMissingKeys();
117 
119 
121 
122  List<Pair<scalar>> normalisedShifted(scalar shiftValue);
123 
125 
126 
127  // Access
128 
129  inline scalar binWidth() const;
130 
131 
132  // Member Operators
133 
134  void operator=(const distribution&);
135 
136 
137  // IOstream Operators
138 
139  friend Ostream& operator<<(Ostream&, const distribution&);
140 };
141 
142 
143 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
144 
145 } // End namespace Foam
146 
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
148 
149 #include "distributionI.H"
150 
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 
153 #endif
154 
155 // ************************************************************************* //
distribution()
Construct null.
Definition: distribution.C:55
scalar approxTotalEntries() const
Definition: distribution.C:112
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
A class for handling file names.
Definition: fileName.H:79
scalar mean() const
Definition: distribution.C:125
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
virtual ~distribution()
Destructor.
Definition: distribution.C:78
void add(const scalar valueToAdd)
Add a value to the appropriate bin of the distribution.
Definition: distribution.C:212
TypeName("distribution")
Runtime type information.
friend Ostream & operator<<(Ostream &, const distribution &)
Accumulating histogram of values. Specified bin resolution automatic generation of bins...
Definition: distribution.H:58
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
static void write(const fileName &file, const List< Pair< scalar >> &pairs)
Write to file.
Definition: distribution.C:39
List< Pair< scalar > > normalised()
Definition: distribution.C:271
List< Pair< scalar > > normalisedMinusMean()
Definition: distribution.C:301
scalar binWidth() const
Definition: distributionI.H:28
List< Pair< scalar > > normalisedShifted(scalar shiftValue)
Definition: distribution.C:308
Ostream & operator<<(Ostream &, const ensightPart &)
void operator=(const distribution &)
Definition: distribution.C:444
label totalEntries() const
Definition: distribution.C:84
List< Pair< scalar > > raw()
Definition: distribution.C:419
Namespace for OpenFOAM.
A HashTable to objects of type <T> with a label key.
Definition: Map.H:49