general.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) 2011-2019 OpenFOAM Foundation
9  Copyright (C) 2016-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::distributionModels::general
29 
30 Description
31  Particle-size distribution model wherein random samples are
32  drawn from a given arbitrary probability density function
33  or cumulative distribution function. Input distributions are
34  specified as pairs of (size, probability) (i.e. (point, value) ).
35 
36 Usage
37  Minimal example by using \c constant/<CloudProperties>:
38  \verbatim
39  subModels
40  {
41  injectionModels
42  {
43  <name>
44  {
45  ...
46 
47  sizeDistribution
48  {
49  type general;
50  generalDistribution
51  {
52  cumulative false;
53 
54  distribution
55  (
56  (<size1> <probability1>)
57  (<size2> <probability2>)
58  ...
59  (<sizeN> <probabilityN>)
60  );
61  }
62  }
63  }
64  }
65  }
66  \endverbatim
67 
68  where the entries mean:
69  \table
70  Property | Description | Type | Reqd | Deflt
71  type | Type name: general | word | yes | -
72  generalDistribution | Distribution settings | dict | yes | -
73  distribution | <size>-<probability> pairs | dict | yes | -
74  <size> | Particle size | scalar | yes | -
75  <probability> | Volume fraction/probability | scalar | yes | -
76  cumulative | Flag to determine if input distribution is specified <!--
77  --> as cumulative or as density | bool | no | false
78  \endtable
79 
80 Note
81  - An example for a pair within \c distribution subdictionary
82  can be given as follows: "(1e-07 1.3)" means 1.3\% of particles
83  are modelled with a particle diameter of "1e-7" [m], and so on.
84  - Variation between input pairs is assumed to be linear.
85  - Elements in the second column (i.e. probability) are normalised.
86  - Elements in the second column for cumulative distribution
87  functions must start from zero and must be non-decreasing (i.e. monotonic).
88  - Elements in the first column (i.e. size) must be specified
89  in an ascending order.
90  - Input pairs cannot contain any negative element.
91 
92 SourceFiles
93  general.C
94 
95 \*---------------------------------------------------------------------------*/
96 
97 #ifndef distributionModels_general_H
98 #define distributionModels_general_H
99 
100 #include "distributionModel.H"
101 #include "Vector.H"
102 #include "VectorSpace.H"
103 #include "Field.H"
104 
105 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
106 
107 namespace Foam
108 {
109 namespace distributionModels
110 {
111  // Forward Declarations
112  class general;
113 }
114 
115 // Forward Declarations
116 Istream& operator>>(Istream&, distributionModels::general&);
117 Ostream& operator<<(Ostream&, const distributionModels::general&);
118 
119 namespace distributionModels
120 {
121 
122 /*---------------------------------------------------------------------------*\
123  Class general Declaration
124 \*---------------------------------------------------------------------------*/
125 
126 class general
127 :
128  public distributionModel
129 {
130  typedef VectorSpace<Vector<scalar>, scalar, 2> pair;
131 
132  // Private Data
133 
134  //- List of (x, y=f(x)) pairs
135  List<pair> xy_;
136 
137  //- Number of entries in the xy_ list
138  label nEntries_;
139 
140  //- Mean of the distribution
141  scalar meanValue_;
142 
143  //- Values of cumulative distribution function
144  List<scalar> integral_;
145 
146  //- Flag to determine if input is specified as cumulative or as density
147  bool cumulative_;
148 
149 
150  // Private Member Functions
151 
152  //- Initialise the distribution parameters
153  void initialise();
154 
155 
156 public:
157 
158  //- Runtime type information
159  TypeName("general");
160 
161 
162  // Constructors
163 
164  //- Construct from components
166 
167  //- Construct from components
168  // Allows negative entries
169  general
170  (
171  const UList<scalar>& sampleData,
172  const scalar binWidth,
173  Random& rndGen
174  );
175 
176  //- Copy construct
177  general(const general& p);
178 
179  //- Construct and return a clone
180  virtual autoPtr<distributionModel> clone() const
181  {
182  return autoPtr<distributionModel>(new general(*this));
183  }
184 
185  //- No copy assignment
186  void operator=(const general&) = delete;
187 
188 
189  //- Destructor
190  virtual ~general() = default;
191 
192 
193  // Member Functions
194 
195  //- Bin boundaries
196  virtual tmp<scalarField> x() const;
197 
198  //- Probabilities
199  virtual tmp<scalarField> y() const;
200 
201  //- Sample the distribution
202  virtual scalar sample() const;
203 
204  //- Return the arithmetic mean of the distribution data
205  virtual scalar meanValue() const;
206 
207  //- Write data to stream
208  virtual void writeData(Ostream& os) const;
209 
210  //- Read data from stream
211  virtual void readData(Istream& os);
212 
213  //- Write data in dictionary format
214  virtual dictionary writeDict(const word& dictName) const;
215 
216  //- Read data from dictionary
217  virtual void readDict(const dictionary& dict);
218 };
219 
220 
221 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
222 
223 } // End namespace distributionModels
224 } // End namespace Foam
225 
226 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
227 
228 #endif
229 
230 // ************************************************************************* //
virtual scalar sample() const
Sample the distribution.
Definition: general.C:229
dictionary dict
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
TypeName("general")
Runtime type information.
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 autoPtr< distributionModel > clone() const
Construct and return a clone.
Definition: general.H:242
virtual ~general()=default
Destructor.
A class for handling words, derived from Foam::string.
Definition: word.H:63
Istream & operator>>(Istream &, directionInfo &)
void operator=(const general &)=delete
No copy assignment.
virtual scalar meanValue() const
Return the arithmetic mean of the distribution data.
Definition: general.C:274
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
OBJstream os(runTime.globalPath()/outputName)
virtual tmp< scalarField > x() const
Bin boundaries.
Definition: general.C:327
virtual tmp< scalarField > y() const
Probabilities.
Definition: general.C:341
virtual void writeData(Ostream &os) const
Write data to stream.
Definition: general.C:288
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
general(const dictionary &dict, Random &rndGen)
Construct from components.
Definition: general.C:90
virtual void readData(Istream &os)
Read data from stream.
Definition: general.C:280
Particle-size distribution model wherein random samples are drawn from a given arbitrary probability ...
Definition: general.H:165
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
virtual dictionary writeDict(const word &dictName) const
Write data in dictionary format.
Definition: general.C:296
volScalarField & p
A class for managing temporary objects.
Definition: HashPtrTable.H:50
virtual void readDict(const dictionary &dict)
Read data from dictionary.
Definition: general.C:309
Namespace for OpenFOAM.