multiFixedValue.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::multiFixedValue
26 
27 Description
28  Distribution which comprises a list of fixed values with given
29  probabilities. The probabilities are normalised so that they sum to one, so
30  they can be provided as fractions or percentages or with any other
31  arbitrary scale factor.
32 
33 Usage
34  Example usage:
35  \verbatim
36  {
37  type multiFixedValue;
38  values
39  (
40  (1e-6 30)
41  (2e-6 60)
42  (5e-6 10)
43  );
44  }
45  \endverbatim
46 
47 SourceFiles
48  multiFixedValue.C
49 
50 See also
51  Foam::distribution
52 
53 \*---------------------------------------------------------------------------*/
54 
55 #ifndef multiFixedValue_H
56 #define multiFixedValue_H
57 
58 #include "distribution.H"
59 #include "TableReader.H"
60 
61 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
62 
63 namespace Foam
64 {
65 namespace distributions
66 {
67 
68 /*---------------------------------------------------------------------------*\
69  Class multiFixedValue Declaration
70 \*---------------------------------------------------------------------------*/
71 
72 class multiFixedValue
73 :
74  public FieldDistribution<distribution, multiFixedValue>
75 {
76  // Private Data
77 
78  //- Table reader
79  const autoPtr<TableReader<scalar>> reader_;
80 
81  //- X-coordinates
82  scalarField x_;
83 
84  //- Probabilities
85  scalarField P_;
86 
87  //- Cumulative sum of the probabilities
88  scalarField sumP_;
89 
90 
91 public:
92 
93  //- Runtime type information
94  TypeName("multiFixedValue");
95 
96 
97  // Constructors
98 
99  //- Construct from a dictionary
101  (
102  const unitConversion& units,
103  const dictionary& dict,
104  const label sampleQ,
106  );
107 
108  //- Construct copy
109  multiFixedValue(const multiFixedValue& d, const label sampleQ);
110 
111  //- Construct and return a clone
112  virtual autoPtr<distribution> clone(const label sampleQ) const
113  {
114  return autoPtr<distribution>(new multiFixedValue(*this, sampleQ));
115  }
116 
117 
118  //- Destructor
119  virtual ~multiFixedValue();
120 
121 
122  // Member Functions
123 
124  //- Sample the distribution
125  virtual scalar sample() const;
126 
127  //- Sample the distribution
129 
130  //- Return the minimum value
131  virtual scalar min() const;
132 
133  //- Return the maximum value
134  virtual scalar max() const;
135 
136  //- Return the mean value
137  virtual scalar mean() const;
138 
139  //- Return the integral of the PDF multiplied by an integer power of x
141  (
142  const scalarField& x,
143  const label e,
144  const bool consistent = false
145  ) const;
146 
147  //- Write to a stream
148  virtual void write(Ostream& os, const unitConversion& units) const;
149 
150  //- Return coordinates to plot across the range of the distribution
151  virtual tmp<scalarField> plotX(const label n) const;
152 
153  //- Return values to plot the probability density function
154  virtual tmp<scalarField> plotPDF(const scalarField& x) const;
155 };
156 
157 
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159 
160 } // End namespace distributions
161 } // End namespace Foam
162 
163 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 
165 #endif
166 
167 // ************************************************************************* //
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 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
Distribution which comprises a list of fixed values with given probabilities. The probabilities are n...
multiFixedValue(const unitConversion &units, const dictionary &dict, const label sampleQ, randomGenerator &&rndGen)
Construct from a dictionary.
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.
virtual scalar min() const
Return the minimum value.
virtual scalar sample() const
Sample the distribution.
TypeName("multiFixedValue")
Runtime type information.
virtual tmp< scalarField > plotPDF(const scalarField &x) const
Return values to plot the probability density function.
virtual void write(Ostream &os, const unitConversion &units) const
Write to a stream.
virtual scalar max() const
Return the maximum value.
virtual scalar mean() const
Return the mean value.
virtual tmp< scalarField > plotX(const label n) const
Return coordinates to plot across the range of the distribution.
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)