All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
normal.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::normal
26 
27 Description
28  Normal distribution, scaled so that it spans between a specified
29  minimum and maximum value, rather than from zero to infinity
30 
31  \f[
32  PDF(x) = \frac{1}{\sigma \sqrt{2 \pi}} \exp \\
33  \left( - \frac{1}{2} \left( \frac{x - \mu}{\sigma} \right)^2 \right)
34  \f]
35 
36 Usage
37  Example usage:
38  \verbatim
39  {
40  type normal;
41  Q 0;
42  min 0.001;
43  max 0.019;
44  mu 0.011;
45  sigma 0.003;
46  }
47  \endverbatim
48 
49 SourceFiles
50  normal.C
51 
52 See also
53  Foam::distribution
54 
55 \*---------------------------------------------------------------------------*/
56 
57 #ifndef normal_H
58 #define normal_H
59 
60 #include "unintegrable.H"
61 
62 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
63 
64 namespace Foam
65 {
66 namespace distributions
67 {
68 
69 /*---------------------------------------------------------------------------*\
70  Class normal Declaration
71 \*---------------------------------------------------------------------------*/
72 
73 class normal
74 :
75  public FieldDistribution<unintegrableForNonZeroQ, normal>
76 {
77  // Private Data
78 
79  //- Minimum value
80  const scalar min_;
81 
82  //- Maximum value
83  const scalar max_;
84 
85  //- Mean
86  const scalar mu_;
87 
88  //- Standard deviation
89  const scalar sigma_;
90 
91 
92  // Private Member Functions
93 
94  //- Return values of the un-normalised PDF for the given size exponent
95  // and x-coordinates.
96  virtual tmp<scalarField> phi
97  (
98  const label q,
99  const scalarField& x
100  ) const;
101 
102  //- Return values of the un-normalised CDF for the given size exponent
103  // and x-coordinates.
104  virtual tmp<scalarField> Phi
105  (
106  const label q,
107  const scalarField& x
108  ) const;
109 
110  //- Sample the distribution for zero effective size exponent
111  scalar sampleForZeroQ(const scalar s) const;
112 
113 
114 public:
115 
116  //- Runtime type information
117  TypeName("normal");
118 
119 
120  //- Permit the multiNormal distribution to use private parts of this class
121  friend class multiNormal;
122 
123 
124  // Constructors
125 
126  //- Construct from a dictionary
127  normal
128  (
129  const unitConversion& units,
130  const dictionary& dict,
131  const label sampleQ,
133  );
134 
135  //- Construct from components
136  normal
137  (
138  const label Q,
139  const label sampleQ,
141  const label n,
142  const scalar min,
143  const scalar max,
144  const scalar mu,
145  const scalar sigma
146  );
147 
148  //- Construct copy
149  normal(const normal& d, const label sampleQ);
150 
151  //- Construct and return a clone
152  virtual autoPtr<distribution> clone(const label sampleQ) const
153  {
154  return autoPtr<distribution>(new normal(*this, sampleQ));
155  }
156 
157 
158  //- Destructor
159  virtual ~normal();
160 
161 
162  // Member Functions
163 
164  //- Sample the distribution
165  virtual scalar sample() const;
166 
167  //- Sample the distribution
169 
170  //- Return the minimum value
171  virtual scalar min() const;
172 
173  //- Return the maximum value
174  virtual scalar max() const;
175 
176  //- Return the mean value
177  virtual scalar mean() const;
178 
179  //- Return the mean value
180  inline scalar mu() const
181  {
182  return mu_;
183  }
184 
185  //- Return the standard deviation
186  inline scalar sigma() const
187  {
188  return sigma_;
189  }
190 
191  //- Write to a stream
192  virtual void write(Ostream& os, const unitConversion& units) const;
193 
194  //- Return coordinates to plot across the range of the distribution
195  virtual tmp<scalarField> x(const label n) const;
196 };
197 
198 
199 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200 
201 } // End namespace distributions
202 } // End namespace Foam
203 
204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205 
206 #endif
207 
208 // ************************************************************************* //
label n
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 keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Multiple superimposed normal distributions.
Definition: multiNormal.H:75
Normal distribution, scaled so that it spans between a specified minimum and maximum value,...
Definition: normal.H:74
virtual autoPtr< distribution > clone(const label sampleQ) const
Construct and return a clone.
Definition: normal.H:150
scalar sigma() const
Return the standard deviation.
Definition: normal.H:184
virtual scalar min() const
Return the minimum value.
Definition: normal.C:172
virtual scalar sample() const
Sample the distribution.
Definition: normal.C:159
normal(const unitConversion &units, const dictionary &dict, const label sampleQ, randomGenerator &&rndGen)
Construct from a dictionary.
Definition: normal.C:89
virtual tmp< scalarField > x(const label n) const
Return coordinates to plot across the range of the distribution.
Definition: normal.C:221
virtual ~normal()
Destructor.
Definition: normal.C:153
scalar mu() const
Return the mean value.
Definition: normal.H:178
virtual void write(Ostream &os, const unitConversion &units) const
Write to a stream.
Definition: normal.C:206
TypeName("normal")
Runtime type information.
virtual scalar max() const
Return the maximum value.
Definition: normal.C:178
virtual scalar mean() const
Return the mean value.
Definition: normal.C:184
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...
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Namespace for OpenFOAM.
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)