uniform.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-2024 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::distributions::uniform
26 
27 Description
28  Distribution in which all values between a specified minimum and maximum
29  have the same probability
30 
31 Usage
32  Example usage:
33  \verbatim
34  {
35  type uniform;
36  Q 0;
37  min 0.5;
38  max 1;
39  }
40  \endverbatim
41 
42 SourceFiles
43  uniform.C
44 
45 See also
46  Foam::distribution
47 
48 \*---------------------------------------------------------------------------*/
49 
50 #ifndef uniform_H
51 #define uniform_H
52 
53 #include "distribution.H"
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 namespace Foam
58 {
59 namespace distributions
60 {
61 
62 /*---------------------------------------------------------------------------*\
63  Class uniform Declaration
64 \*---------------------------------------------------------------------------*/
65 
66 class uniform
67 :
68  public FieldDistribution<distribution, uniform>
69 {
70  // Private Data
71 
72  //- Distribution minimum
73  const scalar min_;
74 
75  //- Distribution maximum
76  const scalar max_;
77 
78  //- Cached indefinite integral of the PDF at the minimum value
79  const scalar Phi0_;
80 
81  //- Cached indefinite integral of the PDF at the maximum value
82  const scalar Phi1_;
83 
84 
85  // Private Member Functions
86 
87  //- Calculate the indefinite integral of the PDF at the given values
88  template<class Type>
89  static auto Phi(const Type& x, const label q);
90 
91 
92 public:
93 
94  //- Runtime type information
95  TypeName("uniform");
96 
97 
98  // Constructors
99 
100  //- Construct from a dictionary
101  uniform
102  (
103  const unitConversion& units,
104  const dictionary& dict,
105  const label sampleQ,
107  );
108 
109  //- Construct copy
110  uniform(const uniform& d, const label sampleQ);
111 
112  //- Construct and return a clone
113  virtual autoPtr<distribution> clone(const label sampleQ) const
114  {
115  return autoPtr<distribution>(new uniform(*this, sampleQ));
116  }
117 
118 
119  //- Destructor
120  virtual ~uniform();
121 
122 
123  // Member Functions
124 
125  //- Sample the distribution
126  virtual scalar sample() const;
127 
128  //- Sample the distribution
130 
131  //- Return the minimum value
132  virtual scalar min() const;
133 
134  //- Return the maximum value
135  virtual scalar max() const;
136 
137  //- Return the mean value
138  virtual scalar mean() const;
139 
140  //- Return the integral of the PDF multiplied by an integer power of x
142  (
143  const scalarField& x,
144  const label e,
145  const bool consistent = false
146  ) const;
147 
148  //- Write to a stream
149  virtual void write(Ostream& os, const unitConversion& units) const;
150 
151  //- Return values to plot the probability density function
152  virtual tmp<scalarField> plotPDF(const scalarField& x) const;
153 };
154 
155 
156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157 
158 } // End namespace distributions
159 } // End namespace Foam
160 
161 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
162 
163 #endif
164 
165 // ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
autoPtr< distribution > clone() const
Construct and return a clone.
Definition: distribution.H:168
label sampleQ() const
Access the sample size exponent.
Definition: distribution.C:134
label q() const
Return the effective distribution size exponent.
Definition: distribution.H:107
Distribution in which all values between a specified minimum and maximum have the same probability.
Definition: uniform.H:68
virtual tmp< scalarField > integralPDFxPow(const scalarField &x, const label e, const bool consistent=false) const
Return the integral of the PDF multiplied by an integer power of x.
Definition: uniform.C:139
virtual scalar min() const
Return the minimum value.
Definition: uniform.C:119
virtual scalar sample() const
Sample the distribution.
Definition: uniform.C:103
uniform(const unitConversion &units, const dictionary &dict, const label sampleQ, randomGenerator &&rndGen)
Construct from a dictionary.
Definition: uniform.C:60
virtual tmp< scalarField > plotPDF(const scalarField &x) const
Return values to plot the probability density function.
Definition: uniform.C:164
TypeName("uniform")
Runtime type information.
virtual void write(Ostream &os, const unitConversion &units) const
Write to a stream.
Definition: uniform.C:151
virtual ~uniform()
Destructor.
Definition: uniform.C:97
virtual scalar max() const
Return the maximum value.
Definition: uniform.C:125
virtual scalar mean() const
Return the mean value.
Definition: uniform.C:131
Random number generator.
A class for managing temporary objects.
Definition: tmp.H:55
Unit conversion structure. Contains the associated dimensions and the multiplier with which to conver...
Namespace for OpenFOAM.
const doubleScalar e
Definition: doubleScalar.H:106
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
const HashTable< unitConversion > & units()
Get the table of unit conversions.
dictionary dict
randomGenerator rndGen(653213)