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 namespace distributionModels
99 {
100  // Forward Declarations
101  class binned;
102 }
103 
104 // Forward Declarations
105 Istream& operator>>(Istream&, distributionModels::binned&);
106 Ostream& operator<<(Ostream&, const distributionModels::binned&);
107 
108 namespace distributionModels
109 {
110 
111 /*---------------------------------------------------------------------------*\
112  Class binned Declaration
113 \*---------------------------------------------------------------------------*/
114 
115 class binned
116 :
117  public distributionModel
118 {
119  typedef VectorSpace<Vector<scalar>, scalar, 2> pair;
120 
121  // Private Data
122 
123  // List of (bin probability) pairs
124  List<pair> xy_;
125 
126  //- Mean of the distribution
127  scalar meanValue_;
128 
129 
130  // Private Member Functions
131 
132  //- Initialise the distribution parameters
133  void initialise();
134 
135 
136 public:
137 
138  //- Runtime type information
139  TypeName("binned");
140 
141  static const char* header;
142 
143 
144  // Constructors
145 
146  //- Construct from dictionary
147  binned(const dictionary& dict, Random& rndGen);
148 
149  //- Construct from components
150  // Allows negative entries
151  binned
152  (
153  const UList<scalar>& sampleData,
154  const scalar binWidth,
155  Random& rndGen
156  );
157 
158  //- Copy construct
159  binned(const binned& p);
160 
161  //- Construct and return a clone
162  virtual autoPtr<distributionModel> clone() const
163  {
164  return autoPtr<distributionModel>(new binned(*this));
165  }
166 
167  //- No copy assignment
168  void operator=(const binned&) = delete;
169 
170 
171  //- Destructor
172  virtual ~binned() = default;
173 
174 
175  // Member Functions
176 
177  //- Sample the distribution
178  virtual scalar sample() const;
179 
180  //- Return the arithmetic mean of the distribution data
181  virtual scalar meanValue() const;
182 
183  //- Write data to stream
184  virtual void writeData(Ostream& os) const;
185 
186  //- Read data from stream
187  virtual void readData(Istream& os);
188 
189  //- Write data in dictionary format
190  virtual dictionary writeDict(const word& dictName) const;
191 
192  //- Read data from dictionary
193  virtual void readDict(const dictionary& dict);
194 };
195 
196 
197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
198 
199 } // End namespace distributionModels
200 } // End namespace Foam
201 
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203 
204 #endif
205 
206 // ************************************************************************* //
virtual autoPtr< distributionModel > clone() const
Construct and return a clone.
Definition: binned.H:208
TypeName("binned")
Runtime type information.
dictionary dict
virtual void readData(Istream &os)
Read data from stream.
Definition: binned.C:203
virtual scalar meanValue() const
Return the arithmetic mean of the distribution data.
Definition: binned.C:197
Particle-size distribution model wherein random samples are drawn from a given discrete set of (bin...
Definition: binned.H:146
binned(const dictionary &dict, Random &rndGen)
Construct from dictionary.
Definition: binned.C:87
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Random rndGen
Definition: createFields.H:23
const word dictName("faMeshDefinition")
virtual void writeData(Ostream &os) const
Write data to stream.
Definition: binned.C:210
static const char * header
Definition: binned.H:178
A class for handling words, derived from Foam::string.
Definition: word.H:63
Istream & operator>>(Istream &, directionInfo &)
virtual scalar sample() const
Sample the distribution.
Definition: binned.C:181
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:105
Random number generator.
Definition: Random.H:55
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
virtual dictionary writeDict(const word &dictName) const
Write data in dictionary format.
Definition: binned.C:218
OBJstream os(runTime.globalPath()/outputName)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
virtual void readDict(const dictionary &dict)
Read data from dictionary.
Definition: binned.C:230
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
virtual ~binned()=default
Destructor.
volScalarField & p
Namespace for OpenFOAM.
void operator=(const binned &)=delete
No copy assignment.