multiNormal.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::multiNormal
26 
27 Description
28  Multiple superimposed normal distributions
29 
30  \f[
31  PDF(x) = \sum_i S_i \frac{1}{\sigma_i \sqrt{2 \pi}} \\
32  \exp \left( \frac{1}{2} \left( \frac{x - \mu_i}{\sigma_i} \\
33  \right)^2 \right)
34  \f]
35 
36 Usage
37  Example usage:
38  \verbatim
39  {
40  type multiNormal;
41  Q 0;
42  min 0.001;
43  max 0.019;
44  mu (0.005 0.011 0.015);
45  sigma (0.002 0.001 0.0015);
46  strength (2 1 3);
47  }
48  \endverbatim
49 
50 SourceFiles
51  multiNormal.C
52 
53 See also
54  Foam::distribution
55  Foam::distributions::normal
56 
57 \*---------------------------------------------------------------------------*/
58 
59 #ifndef multiNormal_H
60 #define multiNormal_H
61 
62 #include "normal.H"
63 
64 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
65 
66 namespace Foam
67 {
68 namespace distributions
69 {
70 
71 /*---------------------------------------------------------------------------*\
72  Class multiNormal Declaration
73 \*---------------------------------------------------------------------------*/
74 
75 class multiNormal
76 :
77  public FieldDistribution<unintegrableForNonZeroQ, multiNormal>
78 {
79  // Private Data
80 
81  //- Relative strengths of the different distributions
82  const scalarList cumulativeStrengths_;
83 
84  //- Normal distributions
85  PtrList<normal> distributions_;
86 
87 
88  // Private Member Functions
89 
90  //- Normalise the strengths
91  static scalarList readCumulativeStrengths(const dictionary& dict);
92 
93  //- Return values of the un-multiNormalised PDF for the given size
94  // exponent and x-coordinates.
95  virtual tmp<scalarField> phi
96  (
97  const label q,
98  const scalarField& x
99  ) const;
100 
101  //- Return values of the un-multiNormalised CDF for the given size
102  // exponent and x-coordinates.
103  virtual tmp<scalarField> Phi
104  (
105  const label q,
106  const scalarField& x
107  ) const;
108 
109 
110 public:
111 
112  //- Runtime type information
113  TypeName("multiNormal");
114 
115 
116  // Constructors
117 
118  //- Construct from a dictionary
120  (
121  const unitConversion& units,
122  const dictionary& dict,
123  const label sampleQ,
125  );
126 
127  //- Construct copy
128  multiNormal(const multiNormal& d, const label sampleQ);
129 
130  //- Construct and return a clone
131  virtual autoPtr<distribution> clone(const label sampleQ) const
132  {
133  return autoPtr<distribution>(new multiNormal(*this, sampleQ));
134  }
135 
136 
137  //- Destructor
138  virtual ~multiNormal();
139 
140 
141  // Member Functions
142 
143  //- Sample the distribution
144  virtual scalar sample() const;
145 
146  //- Sample the distribution
148 
149  //- Return the minimum value
150  virtual scalar min() const;
151 
152  //- Return the maximum value
153  virtual scalar max() const;
154 
155  //- Write stream
156  virtual void write(Ostream& os, const unitConversion& units) const;
157 
158  //- Return coordinates to plot across the range of the distribution
159  virtual tmp<scalarField> x(const label n) const;
160 };
161 
162 
163 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 
165 } // End namespace distributions
166 } // End namespace Foam
167 
168 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
169 
170 #endif
171 
172 // ************************************************************************* //
label n
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
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
virtual autoPtr< distribution > clone(const label sampleQ) const
Construct and return a clone.
Definition: multiNormal.H:128
virtual scalar min() const
Return the minimum value.
Definition: multiNormal.C:249
virtual scalar sample() const
Sample the distribution.
Definition: multiNormal.C:226
virtual tmp< scalarField > x(const label n) const
Return coordinates to plot across the range of the distribution.
Definition: multiNormal.C:285
virtual ~multiNormal()
Destructor.
Definition: multiNormal.C:220
virtual void write(Ostream &os, const unitConversion &units) const
Write stream.
Definition: multiNormal.C:262
multiNormal(const unitConversion &units, const dictionary &dict, const label sampleQ, randomGenerator &&rndGen)
Construct from a dictionary.
Definition: multiNormal.C:114
virtual scalar max() const
Return the maximum value.
Definition: multiNormal.C:255
TypeName("multiNormal")
Runtime type information.
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.
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)