multiNormal.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2013 OpenFOAM Foundation
9  Copyright (C) 2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::distributionModels::multiNormal
29 
30 Description
31  Particle-size distribution model wherein random samples are drawn
32  from a mixture of a finite set of doubly-truncated univariate normal
33  probability density functions:
34 
35  \f[
36  g (\mathbf{x}; \mathbf{\mu}, \mathbf{\sigma}, A, B) =
37  \sum_i w_i f(x_i; \mu_i, \sigma_i, A, B)
38  \f]
39  with for any distribution:
40 
41  \f[
42  f(x; \mu, \sigma, A, B) =
43  \frac{1}{\sigma}
44  \frac{
45  \phi \left( \frac{x - \mu}{\sigma} \right)
46  }{
47  \Phi \left( \frac{B - \mu}{\sigma} \right)
48  - \Phi \left( \frac{A - \mu}{\sigma} \right)
49  }
50  \f]
51  where
52 
53  \vartable
54  f(x; \mu, \sigma, A, B) | Doubly-truncated univariate normal distribution
55  \mu | Mean of the parent general normal distribution
56  \sigma | Standard deviation of the parent general normal distribution
57  \phi(\cdot) | General normal probability density function
58  \Phi(\cdot) | General normal cumulative distribution function
59  x | Sample
60  A | Minimum of the distribution (the same for each distribution)
61  B | Maximum of the distribution (the same for each distribution)
62  w_i | Weighting factor
63  \endvartable
64 
65  Constraints:
66  - \f$ \infty > B > A > 0 \f$
67  - \f$ x \in [B,A] \f$
68  - \f$ \sigma^2 > 0 \f$
69  - \f$ w_i >= 0 \f$
70 
71  Random samples are generated by a combination of the inverse transform
72  sampling technique and categorical sampling in three steps:
73  - Draw a sample from the uniform probability density function
74  on the unit interval \f$u = (0, 1)\f$
75  - Find the interval among normalised cumulative weight intervals
76  wherein \f$ u \f$ resides
77  - Draw a sample from the distribution corresponding to the interval by
78  using the quantile function of the doubly-truncated univariate normal
79  probability density function by the following expressions (similar to
80  \c distributionModels::normal):
81 
82  \f[
83  x = \mu + \sigma \sqrt{2} \, {erf}^{-1} \left( 2 p - 1 \right)
84  \f]
85  with
86 
87  \f[
88  p = u \,
89  \left(
90  \Phi\left(
91  \frac{B - \mu}{\sigma}
92  \right)
93  - \Phi\left(
94  \frac{A - \mu}{\sigma}
95  \right)
96  \right)
97  + \Phi\left( \frac{A - \mu}{\sigma} \right)
98  \f]
99 
100  \f[
101  \Phi(\xi) =
102  \frac{1}{2}
103  \left(
104  1 + {erf}\left(\frac{\xi - \mu}{\sigma \sqrt{2} }\right)
105  \right)
106  \f]
107  where \f$ u \f$ is another sample drawn from the uniform probability
108  density function on the unit interval \f$ (0, 1) \f$.
109 
110 Usage
111  Minimal example by using \c constant/<CloudProperties>:
112  \verbatim
113  subModels
114  {
115  injectionModels
116  {
117  <name>
118  {
119  ...
120 
121  sizeDistribution
122  {
123  type multiNormal;
124  multiNormalDistribution
125  {
126  minValue <min>;
127  maxValue <max>;
128  mu
129  (
130  <mean1>
131  <mean2>
132  ...
133  );
134  sigma
135  (
136  <standard deviation1>
137  <standard deviation2>
138  ...
139  );
140  weight
141  (
142  <weight1>
143  <weight2>
144  ...
145  );
146  }
147  }
148  }
149  }
150  }
151  \endverbatim
152 
153  where the entries mean:
154  \table
155  Property | Description | Type | Reqd | Deflt
156  type | Type name: multiNormal | word | yes | -
157  multiNormalDistribution | Distribution settings | dict | yes | -
158  minValue | Minimum of the distribution | scalar | yes | -
159  maxValue | Maximum of the distribution | scalar | yes | -
160  mu | List of means of parent general normal <!--
161  --> distributions | scalarList | yes | -
162  sigma | List of standard deviations of parent <!--
163  --> general normal distributions | scalarList | yes | -
164  weight | List of weights of a given distribution in <!--
165  --> the distribution mixture | scalarList | yes | -
166  \endtable
167 
168 Notes
169  - The sum of normal distributions (i.e. a mixture distribution) should not
170  be confused with the sum of normally-distributed random variables.
171  - \c minValue and \c maxValue are the same for all distributions
172  in the distribution mixture.
173  - \c weight should always be input in a non-decreasing (i.e. monotonic) order.
174 
175 SourceFiles
176  multiNormal.C
177 
178 \*---------------------------------------------------------------------------*/
179 
180 #ifndef distributionModels_multiNormal_H
181 #define distributionModels_multiNormal_H
182 
183 #include "distributionModel.H"
184 
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 
187 namespace Foam
188 {
189 namespace distributionModels
190 {
191 
192 /*---------------------------------------------------------------------------*\
193  Class multiNormal Declaration
194 \*---------------------------------------------------------------------------*/
195 
196 class multiNormal
197 :
198  public distributionModel
199 {
200  // Private Data
201 
202  //- List of means of the parent general normal distributions
203  List<scalar> mu_;
204 
205  //- List of standard deviations of
206  //- the parent general normal distributions
207  List<scalar> sigma_;
208 
209  //- List of weights of a given distribution in the mixture
210  List<scalar> weight_;
211 
212 
213 public:
214 
215  //- Runtime type information
216  TypeName("multiNormal");
217 
218 
219  // Constructors
220 
221  //- Construct from components
222  multiNormal(const dictionary& dict, Random& rndGen);
223 
224  //- Copy construct
225  multiNormal(const multiNormal& p);
226 
227  //- Construct and return a clone
228  virtual autoPtr<distributionModel> clone() const
229  {
230  return autoPtr<distributionModel>(new multiNormal(*this));
231  }
232 
233  //- No copy assignment
234  void operator=(const multiNormal&) = delete;
235 
236 
237  //- Destructor
238  virtual ~multiNormal() = default;
239 
240 
241  // Member Functions
242 
243  //- Sample the distribution
244  virtual scalar sample() const;
245 
246  //- Sample the normal distribution
247  scalar sample(const scalar mu, const scalar sigma) const;
248 
249  //- Return the theoretical mean of the distribution
250  virtual scalar meanValue() const;
251 };
252 
253 
254 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
255 
256 } // End namespace distributionModels
257 } // End namespace Foam
258 
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
260 
261 #endif
262 
263 // ************************************************************************* //
Foam::Random
Random number generator.
Definition: Random.H:59
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::constant::physicoChemical::mu
const dimensionedScalar mu
Atomic mass unit.
Definition: createFieldRefs.H:4
Foam::distributionModels::multiNormal::TypeName
TypeName("multiNormal")
Runtime type information.
Foam::distributionModel
A library of runtime-selectable doubly-truncated probability distribution models. Returns random samp...
Definition: distributionModel.H:72
Foam::distributionModels::multiNormal
Particle-size distribution model wherein random samples are drawn from a mixture of a finite set of d...
Definition: multiNormal.H:285
Foam::distributionModels::multiNormal::operator=
void operator=(const multiNormal &)=delete
No copy assignment.
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::distributionModels::multiNormal::clone
virtual autoPtr< distributionModel > clone() const
Construct and return a clone.
Definition: multiNormal.H:317
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::List< scalar >
Foam::distributionModels::multiNormal::meanValue
virtual scalar meanValue() const
Return the theoretical mean of the distribution.
Definition: multiNormal.C:175
rndGen
Random rndGen
Definition: createFields.H:23
Foam::distributionModels::multiNormal::~multiNormal
virtual ~multiNormal()=default
Destructor.
sigma
dimensionedScalar sigma("sigma", dimMass/sqr(dimTime), transportProperties)
Foam::distributionModels::multiNormal::sample
virtual scalar sample() const
Sample the distribution.
Definition: multiNormal.C:131
Foam::distributionModels::multiNormal::multiNormal
multiNormal(const dictionary &dict, Random &rndGen)
Construct from components.
Definition: multiNormal.C:49
distributionModel.H