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-------------------------------------------------------------------------------
10License
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
26Class
27 Foam::distributionModels::binned
28
29Description
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
42Usage
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
82SourceFiles
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
95namespace Foam
96{
97
98// Forward declaration of classes
99class Istream;
100class Ostream;
101
102namespace distributionModels
103{
104 class binned;
105}
106
107// Forward declaration of friend functions and operators
108Istream& operator>>(Istream&, distributionModels::binned&);
109Ostream& operator<<(Ostream&, const distributionModels::binned&);
110
111namespace distributionModels
112{
113
114/*---------------------------------------------------------------------------*\
115 Class binned Declaration
116\*---------------------------------------------------------------------------*/
117
118class 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
139public:
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,
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
178 // Member Functions
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// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207#endif
208
209// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Random number generator.
Definition: Random.H:60
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
Templated vector space.
Definition: VectorSpace.H:79
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A library of runtime-selectable doubly-truncated probability distribution models. Returns random samp...
Particle-size distribution model wherein random samples are drawn from a given discrete set of (bin,...
Definition: binned.H:156
virtual scalar meanValue() const
Return the arithmetic mean of the distribution data.
Definition: binned.C:204
virtual dictionary writeDict(const word &dictName) const
Write data in dictionary format.
Definition: binned.C:225
binned(const dictionary &dict, Random &rndGen)
Construct from dictionary.
Definition: binned.C:94
virtual autoPtr< distributionModel > clone() const
Construct and return a clone.
Definition: binned.H:200
virtual void writeData(Ostream &os) const
Write data to stream.
Definition: binned.C:217
virtual scalar sample() const
Sample the distribution.
Definition: binned.C:188
void operator=(const binned &)=delete
No copy assignment.
TypeName("binned")
Runtime type information.
virtual void readDict(const dictionary &dict)
Read data from dictionary.
Definition: binned.C:237
virtual void readData(Istream &os)
Read data from stream.
Definition: binned.C:210
virtual ~binned()=default
Destructor.
static const char * header
Definition: binned.H:179
A class for handling words, derived from Foam::string.
Definition: word.H:68
volScalarField & p
OBJstream os(runTime.globalPath()/outputName)
const word dictName("faMeshDefinition")
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Istream & operator>>(Istream &, directionInfo &)
dictionary dict
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73
Random rndGen
Definition: createFields.H:23