35 namespace distributions
67 reader_->read({defaultUnits,
unitAny},
dict,
"distribution");
70 if (values.
first().second() != 0)
73 << typeName <<
": The cumulative distribution function does not "
77 for (
label i = 1; i < values.
size(); ++ i)
79 if (values[i].
first() - values[i - 1].
first() < 0)
82 << typeName <<
": The cumulative distribution function is not "
89 << typeName <<
": The cumulative distribution function is not "
95 x_.resize(values.
size());
98 x_[i] = values[i].
first();
102 CDF_.resize(values.
size());
104 for (
label i = 1; i < values.
size(); ++ i)
109 *(values[i].second() - values[i - 1].second());
116 PDF_.resize(values.
size() - 1);
119 PDF_[i] = (CDF_[i + 1] - CDF_[i])/(x_[i + 1] - x_[i]);
123 validateBounds(
dict);
124 if (q() != 0) validatePositive(
dict);
135 reader_(d.reader_, false),
141 if (
q() == d.
q())
return;
150 *(d.CDF_[i] - d.CDF_[i - 1]);
157 PDF_[i] = (CDF_[i + 1] - CDF_[i])/(x_[i + 1] - x_[i]);
211 while (i <
x.size() &&
x[i] < xStar[0])
217 scalar integral_PDFxPowE_0_j = 0;
219 for (
label iStar = 0; iStar < xStar.
size() - 1; ++ iStar)
221 const scalar xPowE1_j =
integerPow(xStar[iStar],
e + 1);
223 auto integral_xPowE1_j_x = [&](
const scalar
x)
227 const scalar integral_xPowE_j_x =
229 ?
log(
x/xStar[iStar])
230 : (xPowE1_i - xPowE1_j)/(
e + 1);
232 return yStar[iStar]*integral_xPowE_j_x;
235 while (i <
x.size() &&
x[i] < xStar[iStar + 1])
237 result[i] = integral_PDFxPowE_0_j + integral_xPowE1_j_x(
x[i]);
242 integral_PDFxPowE_0_j += integral_xPowE1_j_x(xStar[iStar + 1]);
247 result[i] = integral_PDFxPowE_0_j;
267 for (
label i = 1; i < CDF_.size(); ++ i)
272 *(CDF_[i] - CDF_[i - 1]);
282 values[i].
first() = x_[i];
283 values[i].second() = CDF[i];
285 reader_->write(os, {
units,
unitAny}, values,
"distribution");
292 const scalar x0 =
min(), x1 =
max(), d = 0.1*(x1 - x0);
297 result[0] =
Foam::max(x0 - d, q() < 0 ? x0/2 : rootVSmall);
301 result[2*i + 1] = result[2*i + 2] = x_[i];
304 result[2*x_.size() + 1] = x1 + d;
316 result[0] = result[1] = 0;
320 result[2*i + 2] = result[2*i + 3] = PDF_[i];
323 result[2*PDF_.size() + 2] = result[2*PDF_.size() + 3] = 0;
#define forAll(list, i)
Loop across all elements in list.
Macros for easy insertion into run-time selection tables.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void size(const label)
Override size to be inconsistent with allocated storage.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Base class to read table data for tables.
T & first()
Return the first element of the list.
T & last()
Return the last element of the list.
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Base class for statistical distributions.
label q() const
Return the effective distribution size exponent.
Distribution in which the cumulative distribution function is given as a table of values.
virtual ~tabulatedCumulative()
Destructor.
virtual tmp< scalarField > integralPDFxPow(const scalarField &x, const label e, const bool consistent=false) const
Return the integral of the PDF multiplied by an integer power of x.
virtual scalar min() const
Return the minimum value.
virtual scalar sample() const
Sample the distribution.
tabulatedCumulative(const unitConversion &units, const dictionary &dict, const label sampleQ, randomGenerator &&rndGen)
Construct from a dictionary.
virtual tmp< scalarField > plotPDF(const scalarField &x) const
Return values to plot the probability density function.
virtual void write(Ostream &os, const unitConversion &units) const
Write to a stream.
virtual scalar max() const
Return the maximum value.
virtual scalar mean() const
Return the mean value.
virtual tmp< scalarField > plotX(const label n) const
Return coordinates to plot across the range of the distribution.
virtual scalar sample() const
Sample the distribution.
static tmp< scalarField > integrate(const scalarField &x, const scalarField &y)
Integrate the values y with respect to the coordinates x.
A class for managing temporary objects.
T & ref() const
Return non-const reference or generate a fatal error.
Unit conversion structure. Contains the associated dimensions and the multiplier with which to conver...
A class for handling words, derived from string.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
autoPtr< CompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const viscosity &viscosity)
defineTypeNameAndDebug(exponential, 0)
addToRunTimeSelectionTable(distribution, exponential, dictionary)
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
const unitConversion unitAny
errorManip< error > abort(error &err)
scalar integerPow(const scalar x, const label e)
Compute the power of the number x to the integer e.
labelList second(const UList< labelPair > &p)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
dimensionedScalar log(const dimensionedScalar &ds)
labelList first(const UList< labelPair > &p)
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
const HashTable< unitConversion > & units()
Get the table of unit conversions.
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
randomGenerator rndGen(653213)