33 namespace distributionModels
49 xy_(distributionModelDict_.lookup(
"distribution")),
50 nEntries_(xy_.size()),
52 maxValue_(xy_[nEntries_-1][0]),
55 cumulative_(distributionModelDict_.lookupOrDefault(
"cumulative",
false))
60 if (cumulative_ && xy_[0][1] != 0)
63 <<
type() <<
"distribution: " 64 <<
"The cumulative distribution must start from zero." 68 for (
label i=0; i<nEntries_; i++)
70 if (i > 0 && xy_[i][0] <= xy_[i-1][0])
73 <<
type() <<
"distribution: " 74 <<
"The points must be specified in ascending order." 81 <<
type() <<
"distribution: " 82 <<
"The distribution can't be negative." 86 if (i > 0 && cumulative_ && xy_[i][1] < xy_[i-1][1])
89 <<
type() <<
"distribution: " 90 <<
"Cumulative distribution must be non-decreasing." 99 for (
label i=1; i<nEntries_; i++)
102 scalar
k = (xy_[i][1] - xy_[i-1][1])/(xy_[i][0] - xy_[i-1][0]);
103 scalar d = xy_[i-1][1] - k*xy_[i-1][0];
105 scalar
y1 = xy_[i][0]*(0.5*k*xy_[i][0] + d);
106 scalar
y0 = xy_[i-1][0]*(0.5*k*xy_[i-1][0] + d);
107 scalar area = y1 -
y0;
111 integral_[i] = xy_[i][1];
116 integral_[i] = area + integral_[i-1];
118 y1 =
sqr(xy_[i][0])*(1.0/3.0*k*xy_[i][0] + 0.5*d);
119 y0 =
sqr(xy_[i-1][0])*(1.0/3.0*k*xy_[i-1][0] + 0.5*d);
120 meanValue_ += y1 -
y0;
125 scalar sumArea = integral_.last();
127 for (
label i=0; i<nEntries_; i++)
129 xy_[i][1] /= sumArea;
130 integral_[i] /= sumArea;
133 meanValue_ /= sumArea;
134 meanValue_ = cumulative_ ? (maxValue_ - meanValue_) : meanValue_;
144 nEntries_(p.nEntries_),
145 minValue_(p.minValue_),
146 maxValue_(p.maxValue_),
147 meanValue_(p.meanValue_),
148 integral_(p.integral_),
149 cumulative_(p.cumulative_)
167 while (integral_[n] <= y)
172 scalar
k = (xy_[
n][1] - xy_[n-1][1])/(xy_[n][0] - xy_[n-1][0]);
173 scalar d = xy_[n-1][1] - k*xy_[n-1][0];
180 scalar
alpha = y + xy_[n-1][0]*(0.5*k*xy_[n-1][0] + d) - integral_[n-1];
187 scalar q = -2.0*alpha/
k;
188 scalar sqrtEr =
sqrt(0.25*p*p - q);
190 scalar x1 = -0.5*p + sqrtEr;
191 scalar x2 = -0.5*p - sqrtEr;
192 if ((x1 >= xy_[n-1][0]) && (x1 <= xy_[n][0]))
virtual scalar sample() const
Sample the distributionModel.
virtual scalar minValue() const
Return the minimum value.
Random & rndGen_
Reference to the random number generator.
A list of keyword definitions, which are a keyword followed by any number of values (e...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
volScalarField alpha(IOobject("alpha", runTime.timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), lambda *max(Ua &U, zeroSensitivity))
dimensionedScalar sqrt(const dimensionedScalar &ds)
virtual ~general()
Destructor.
dimensionedScalar y0(const dimensionedScalar &ds)
label k
Boltzmann constant.
Macros for easy insertion into run-time selection tables.
Type sample01()
Advance the state and return a sample of a given type from a.
virtual scalar meanValue() const
Return the mean value.
errorManip< error > abort(error &err)
dimensionedScalar y1(const dimensionedScalar &ds)
defineTypeNameAndDebug(exponential, 0)
general(const dictionary &dict, Random &rndGen)
Construct from components.
A library of runtime-selectable distribution models.
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
A general distribution model where the distribution is specified as (point, value) pairs...
virtual scalar maxValue() const
Return the maximum value.
dimensioned< scalar > mag(const dimensioned< Type > &)
addToRunTimeSelectionTable(distributionModel, exponential, dictionary)