general.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-2021 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::distributionModels::general
26 
27 Description
28  A general distribution model where the distribution is specified as
29  (point, value) pairs. By default the values are assumed to represent
30  a probability density function, but the model also supports specifying a
31  cumulative distribution function. In both cases it is assumed that the
32  function is linear between the specified points.
33 
34  In both modes of operation the values are automatically normalised.
35 
36 SourceFiles
37  general.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef general_H
42 #define general_H
43 
44 #include "distributionModel.H"
45 #include "Vector.H"
46 #include "VectorSpace.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 namespace distributionModels
53 {
54 
55 /*---------------------------------------------------------------------------*\
56  Class general Declaration
57 \*---------------------------------------------------------------------------*/
58 
59 class general
60 :
61  public distributionModel
62 {
63  // Private Data
64 
65  typedef VectorSpace<Vector<scalar>, scalar, 2> pair;
66 
67  //- List of (x, y=f(x)) pairs
68  List<pair> xy_;
69 
70  //- Amount of entries in the xy_ list
71  label nEntries_;
72 
73  //- Distribution minimum
74  scalar minValue_;
75 
76  //- Distribution maximum
77  scalar maxValue_;
78 
79  //- Distribution mean
80  scalar meanValue_;
81 
82  //- Values of cumulative distribution function
83  List<scalar> integral_;
84 
85  //- Is the distribution specified as cumulative or as density
86  Switch cumulative_;
87 
88 
89 public:
90 
91  //- Runtime type information
92  TypeName("general");
93 
94 
95  // Constructors
96 
97  //- Construct from components
99 
100  //- Construct copy
101  general(const general& p);
102 
103  //- Construct and return a clone
104  virtual autoPtr<distributionModel> clone() const
105  {
106  return autoPtr<distributionModel>(new general(*this));
107  }
108 
109 
110  //- Destructor
111  virtual ~general();
112 
113 
114  // Member Functions
115 
116  //- Sample the distributionModel
117  virtual scalar sample() const;
118 
119  //- Return the minimum value
120  virtual scalar minValue() const;
121 
122  //- Return the maximum value
123  virtual scalar maxValue() const;
124 
125  //- Return the mean value
126  virtual scalar meanValue() const;
127 };
128 
129 
130 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
131 
132 } // End namespace distributionModels
133 } // End namespace Foam
134 
135 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
136 
137 #endif
138 
139 // ************************************************************************* //
virtual scalar sample() const
Sample the distributionModel.
Definition: general.C:161
virtual scalar minValue() const
Return the minimum value.
Definition: general.C:210
dictionary dict
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
TypeName("general")
Runtime type information.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Templated vector space.
Definition: VectorSpace.H:53
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none/any.
Definition: Switch.H:60
virtual ~general()
Destructor.
Definition: general.C:155
virtual autoPtr< distributionModel > clone() const
Construct and return a clone.
Definition: general.H:103
Random rndGen(label(0))
virtual scalar meanValue() const
Return the mean value.
Definition: general.C:222
Random number generator.
Definition: Random.H:57
general(const dictionary &dict, Random &rndGen)
Construct from components.
Definition: general.C:43
A library of runtime-selectable distribution models.
A general distribution model where the distribution is specified as (point, value) pairs...
Definition: general.H:58
virtual scalar maxValue() const
Return the maximum value.
Definition: general.C:216
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
volScalarField & p
Namespace for OpenFOAM.