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 
110 // Forward declaration of classes
111 class Istream;
112 class Ostream;
113 
114 namespace distributionModels
115 {
116  class general;
117 }
118 
119 // Forward declaration of friend functions and operators
120 Istream& operator>>(Istream&, distributionModels::general&);
121 Ostream& operator<<(Ostream&, const distributionModels::general&);
122 
123 namespace distributionModels
124 {
125 
126 /*---------------------------------------------------------------------------*\
127  Class general Declaration
128 \*---------------------------------------------------------------------------*/
129 
130 class general
131 :
132  public distributionModel
133 {
134  typedef VectorSpace<Vector<scalar>, scalar, 2> pair;
135 
136  // Private Data
137 
138  //- List of (x, y=f(x)) pairs
139  List<pair> xy_;
140 
141  //- Number of entries in the xy_ list
142  label nEntries_;
143 
144  //- Mean of the distribution
145  scalar meanValue_;
146 
147  //- Values of cumulative distribution function
148  List<scalar> integral_;
149 
150  //- Flag to determine if input is specified as cumulative or as density
151  bool cumulative_;
152 
153 
154  // Private Member Functions
155 
156  //- Initialise the distribution parameters
157  void initialise();
158 
159 
160 public:
161 
162  //- Runtime type information
163  TypeName("general");
164 
165 
166  // Constructors
167 
168  //- Construct from components
169  general(const dictionary& dict, Random& rndGen);
170 
171  //- Construct from components
172  // Allows negative entries
174  (
175  const UList<scalar>& sampleData,
176  const scalar binWidth,
177  Random& rndGen
178  );
179 
180  //- Copy construct
181  general(const general& p);
182 
183  //- Construct and return a clone
184  virtual autoPtr<distributionModel> clone() const
185  {
186  return autoPtr<distributionModel>(new general(*this));
187  }
188 
189  //- No copy assignment
190  void operator=(const general&) = delete;
191 
192 
193  //- Destructor
194  virtual ~general() = default;
195 
196 
197  // Member Functions
198 
199  //- Bin boundaries
200  virtual tmp<scalarField> x() const;
201 
202  //- Probabilities
203  virtual tmp<scalarField> y() const;
204 
205  //- Sample the distribution
206  virtual scalar sample() const;
207 
208  //- Return the arithmetic mean of the distribution data
209  virtual scalar meanValue() const;
210 
211  //- Write data to stream
212  virtual void writeData(Ostream& os) const;
213 
214  //- Read data from stream
215  virtual void readData(Istream& os);
216 
217  //- Write data in dictionary format
218  virtual dictionary writeDict(const word& dictName) const;
219 
220  //- Read data from dictionary
221  virtual void readDict(const dictionary& dict);
222 };
223 
224 
225 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226 
227 } // End namespace distributionModels
228 } // End namespace Foam
229 
230 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
231 
232 #endif
233 
234 // ************************************************************************* //
Foam::Random
Random number generator.
Definition: Random.H:59
VectorSpace.H
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::distributionModels::general::x
virtual tmp< scalarField > x() const
Bin boundaries.
Definition: general.C:334
Foam::distributionModels::general::meanValue
virtual scalar meanValue() const
Return the arithmetic mean of the distribution data.
Definition: general.C:281
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::distributionModels::general::operator=
void operator=(const general &)=delete
No copy assignment.
dictName
const word dictName("faMeshDefinition")
Vector.H
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::distributionModels::general::~general
virtual ~general()=default
Destructor.
Foam::distributionModels::general
Particle-size distribution model wherein random samples are drawn from a given arbitrary probability ...
Definition: general.H:173
Foam::distributionModels::general::y
virtual tmp< scalarField > y() const
Probabilities.
Definition: general.C:348
Foam::VectorSpace
Templated vector space.
Definition: VectorSpace.H:56
Foam::distributionModels::general::sample
virtual scalar sample() const
Sample the distribution.
Definition: general.C:236
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
general
General relative velocity model.
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::distributionModels::general::readDict
virtual void readDict(const dictionary &dict)
Read data from dictionary.
Definition: general.C:316
Field.H
Foam::distributionModels::general::TypeName
TypeName("general")
Runtime type information.
Foam::distributionModels::general::writeDict
virtual dictionary writeDict(const word &dictName) const
Write data in dictionary format.
Definition: general.C:303
dict
dictionary dict
Definition: searchingEngine.H:14
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
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::distributionModels::general::general
general(const dictionary &dict, Random &rndGen)
Construct from components.
Definition: general.C:97
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::distributionModels::general::clone
virtual autoPtr< distributionModel > clone() const
Construct and return a clone.
Definition: general.H:227
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::general::readData
virtual void readData(Istream &os)
Read data from stream.
Definition: general.C:287
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::general::writeData
virtual void writeData(Ostream &os) const
Write data to stream.
Definition: general.C:295
distributionModel.H