RosinRammler.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "RosinRammler.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 namespace distributions
34 {
37 }
38 }
39 
40 
41 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
42 
44 (
45  const label q,
46  const scalarField& x
47 ) const
48 {
49  const scalarField xByDPowNm1(pow(x/d_, n_ - 1));
50  return integerPow(x, q)*(n_/d_)*xByDPowNm1*exp(- xByDPowNm1*x/d_);
51 }
52 
53 
55 (
56  const scalarField& x
57 ) const
58 {
59  return - exp(- pow(x/d_, n_));
60 }
61 
62 
63 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
64 
66 (
67  const unitConversion& units,
68  const dictionary& dict,
69  const label sampleQ,
71 )
72 :
74  (
75  typeName,
76  units,
77  dict,
78  sampleQ,
79  std::move(rndGen)
80  ),
81  min_(dict.lookupBackwardsCompatible<scalar>({"min", "minValue"}, units)),
82  max_(dict.lookupBackwardsCompatible<scalar>({"max", "maxValue"}, units)),
83  d_(dict.lookup<scalar>("d", units)),
84  n_(dict.lookup<scalar>("n", unitless))
85 {
86  validateBounds(dict);
87  validatePositive(dict);
88  mean();
89 }
90 
91 
93 (
94  const RosinRammler& d,
95  const label sampleQ
96 )
97 :
99  min_(d.min_),
100  max_(d.max_),
101  d_(d.d_),
102  n_(d.n_)
103 {}
104 
105 
106 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
107 
109 {}
110 
111 
112 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
113 
115 {
116  const scalar s = rndGen_.sample01<scalar>();
117  const Pair<scalar>& Phi01 = this->Phi01();
118  const scalar PhiS = (1 - s)*Phi01[0] + s*Phi01[1];
119  return d_*pow(- log(- PhiS), 1/n_);
120 }
121 
122 
124 {
125  return min_;
126 }
127 
128 
130 {
131  return max_;
132 }
133 
134 
136 (
137  Ostream& os,
138  const unitConversion& units
139 ) const
140 {
142 
143  writeEntry(os, "min", units, min_);
144  writeEntry(os, "max", units, max_);
145  writeEntry(os, "d", units, d_);
146  writeEntry(os, "n", unitless, n_);
147 }
148 
149 
152 {
154  tx.ref()[0] = Foam::max(tx.ref()[0], q() < 0 ? min_/2 : rootVSmall);
155  return tx;
156 }
157 
158 
159 // ************************************************************************* //
label n
Macros for easy insertion into run-time selection tables.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Base class for statistical distributions.
Definition: distribution.H:76
virtual tmp< scalarField > plotX(const label n) const
Return coordinates to plot across the range of the distribution.
Definition: distribution.C:166
Rosin-Rammler distribution, scaled so that it spans between a specified minimum and maximum value,...
Definition: RosinRammler.H:77
virtual scalar min() const
Return the minimum value.
Definition: RosinRammler.C:123
RosinRammler(const unitConversion &units, const dictionary &dict, const label sampleQ, randomGenerator &&rndGen)
Construct from a dictionary.
Definition: RosinRammler.C:66
virtual ~RosinRammler()
Destructor.
Definition: RosinRammler.C:108
virtual void write(Ostream &os, const unitConversion &units) const
Write to a stream.
Definition: RosinRammler.C:136
virtual scalar sampleForZeroQ() const
Sample the distribution for zero effective size exponent.
Definition: RosinRammler.C:114
virtual scalar max() const
Return the maximum value.
Definition: RosinRammler.C:129
virtual tmp< scalarField > plotX(const label n) const
Return coordinates to plot across the range of the distribution.
Definition: RosinRammler.C:151
virtual tmp< scalarField > phi(const label q, const scalarField &x) const
Return values of the un-normalised PDF for the given size exponent.
Definition: RosinRammler.C:44
virtual tmp< scalarField > PhiForZeroQ(const scalarField &x) const
Return values of the un-normalised CDF for zero effective size.
Definition: RosinRammler.C:55
Base class for distributions that have a closed integral form for the cumulative density function (CD...
Random number generator.
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:197
Unit conversion structure. Contains the associated dimensions and the multiplier with which to conver...
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), lagrangian::cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
defineTypeNameAndDebug(exponential, 0)
addToRunTimeSelectionTable(distribution, exponential, dictionary)
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
Namespace for OpenFOAM.
dimensionedScalar exp(const dimensionedScalar &ds)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
scalar integerPow(const scalar x, const label e)
Compute the power of the number x to the integer e.
Definition: scalarI.H:30
dimensionedScalar log(const dimensionedScalar &ds)
const HashTable< unitConversion > & units()
Get the table of unit conversions.
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
void pow(LagrangianPatchField< typename powProduct< Type, r >::type > &f, const LagrangianPatchField< Type > &f1)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
const unitConversion unitless
dictionary dict
randomGenerator rndGen(653213)