binned.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) 2015-2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::distributionModels::binned
28 
29 Description
30  Particle-size distribution model wherein random samples are
31  drawn from a given discrete set of (\c bin, \c probability) pairs,
32  where in terms of its meaning, \c bins correspond to particle sizes
33  and \c probabilities correspond to (relative) probability of occurrences.
34 
35  The second column (i.e. \c probability) are normalised by the sum of all
36  its values, resulting in a normalised column in the domain of [0,1].
37  To generate a sample, first a sample drawn from the uniform probability
38  density function on the unit interval (i.e. \c u), and then, the \c bin
39  corresponding to the first \c probability larger than \c u is fetched
40  as the particle size to be further processed.
41 
42 Usage
43  Minimal example by using \c constant/<CloudProperties>:
44  \verbatim
45  subModels
46  {
47  injectionModels
48  {
49  <name>
50  {
51  ...
52 
53  sizeDistribution
54  {
55  type binned;
56  binnedDistribution
57  {
58  distribution
59  (
60  (<bin1> <probability1>)
61  (<bin2> <probability2>)
62  ...
63  (<binN> <probabilityN>)
64  );
65  }
66  }
67  }
68  }
69  }
70  \endverbatim
71 
72  where the entries mean:
73  \table
74  Property | Description | Type | Reqd | Deflt
75  type | Type name: binned | word | yes | -
76  binnedDistribution | Distribution settings | dict | yes | -
77  distribution | <bin>-<probability> pairs | dict | yes | -
78  <bin> | Particle size | scalar | yes | -
79  <probability> | Probability of occurrence | scalar | yes | -
80  \endtable
81 
82 SourceFiles
83  binned.C
84 
85 \*---------------------------------------------------------------------------*/
86 
87 #ifndef distributionModels_binned_H
88 #define distributionModels_binned_H
89 
90 #include "distributionModel.H"
91 #include "Field.H"
92 
93 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
94 
95 namespace Foam
96 {
97 
98 // Forward declaration of classes
99 class Istream;
100 class Ostream;
101 
102 namespace distributionModels
103 {
104  class binned;
105 }
106 
107 // Forward declaration of friend functions and operators
108 Istream& operator>>(Istream&, distributionModels::binned&);
109 Ostream& operator<<(Ostream&, const distributionModels::binned&);
110 
111 namespace distributionModels
112 {
113 
114 /*---------------------------------------------------------------------------*\
115  Class binned Declaration
116 \*---------------------------------------------------------------------------*/
117 
118 class binned
119 :
120  public distributionModel
121 {
122  typedef VectorSpace<Vector<scalar>, scalar, 2> pair;
123 
124  // Private Data
125 
126  // List of (bin probability) pairs
127  List<pair> xy_;
128 
129  //- Mean of the distribution
130  scalar meanValue_;
131 
132 
133  // Private Member Functions
134 
135  //- Initialise the distribution parameters
136  void initialise();
137 
138 
139 public:
140 
141  //- Runtime type information
142  TypeName("binned");
143 
144  static const char* header;
145 
146 
147  // Constructors
148 
149  //- Construct from dictionary
150  binned(const dictionary& dict, Random& rndGen);
151 
152  //- Construct from components
153  // Allows negative entries
154  binned
155  (
156  const UList<scalar>& sampleData,
157  const scalar binWidth,
158  Random& rndGen
159  );
160 
161  //- Copy construct
162  binned(const binned& p);
163 
164  //- Construct and return a clone
165  virtual autoPtr<distributionModel> clone() const
166  {
167  return autoPtr<distributionModel>(new binned(*this));
168  }
169 
170  //- No copy assignment
171  void operator=(const binned&) = delete;
172 
173 
174  //- Destructor
175  virtual ~binned() = default;
176 
177 
178  // Member Functions
179 
180  //- Sample the distribution
181  virtual scalar sample() const;
182 
183  //- Return the arithmetic mean of the distribution data
184  virtual scalar meanValue() const;
185 
186  //- Write data to stream
187  virtual void writeData(Ostream& os) const;
188 
189  //- Read data from stream
190  virtual void readData(Istream& os);
191 
192  //- Write data in dictionary format
193  virtual dictionary writeDict(const word& dictName) const;
194 
195  //- Read data from dictionary
196  virtual void readDict(const dictionary& dict);
197 };
198 
199 
200 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
201 
202 } // End namespace distributionModels
203 } // End namespace Foam
204 
205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
206 
207 #endif
208 
209 // ************************************************************************* //
Foam::Random
Random number generator.
Definition: Random.H:59
Foam::distributionModels::binned::readDict
virtual void readDict(const dictionary &dict)
Read data from dictionary.
Definition: binned.C:237
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::distributionModels::binned::writeData
virtual void writeData(Ostream &os) const
Write data to stream.
Definition: binned.C:217
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::distributionModels::binned::TypeName
TypeName("binned")
Runtime type information.
dictName
const word dictName("faMeshDefinition")
Foam::distributionModels::binned::readData
virtual void readData(Istream &os)
Read data from stream.
Definition: binned.C:210
Foam::distributionModels::binned
Particle-size distribution model wherein random samples are drawn from a given discrete set of (bin,...
Definition: binned.H:153
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::distributionModel
A library of runtime-selectable doubly-truncated probability distribution models. Returns random samp...
Definition: distributionModel.H:72
Foam::VectorSpace
Templated vector space.
Definition: VectorSpace.H:56
Foam::distributionModels::binned::meanValue
virtual scalar meanValue() const
Return the arithmetic mean of the distribution data.
Definition: binned.C:204
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::distributionModels::binned::sample
virtual scalar sample() const
Sample the distribution.
Definition: binned.C:188
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Field.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::distributionModels::binned::~binned
virtual ~binned()=default
Destructor.
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam::distributionModels::binned::header
static const char * header
Definition: binned.H:179
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::distributionModels::binned::binned
binned(const dictionary &dict, Random &rndGen)
Construct from dictionary.
Definition: binned.C:94
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::distributionModels::binned::clone
virtual autoPtr< distributionModel > clone() const
Construct and return a clone.
Definition: binned.H:200
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
Foam::distributionModels::binned::writeDict
virtual dictionary writeDict(const word &dictName) const
Write data in dictionary format.
Definition: binned.C:225
rndGen
Random rndGen
Definition: createFields.H:23
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::distributionModels::binned::operator=
void operator=(const binned &)=delete
No copy assignment.
distributionModel.H