44 for (
label i = 1; i <
x.size(); ++ i)
46 result[i] = result[i - 1] + (
x[i] -
x[i - 1])*(
y[i] +
y[i - 1])/2;
64 for (
label i = 1; i <
x.size(); ++ i)
66 const scalar x0 =
x[i - 1], x1 =
x[i];
67 const scalar
y0 =
y[i - 1],
y1 =
y[i];
70 result[i - 1] + (x1 - x0)*(2*x0*
y0 + x0*
y1 + x1*
y0 + 2*x1*
y1)/6;
91 while (i <
x.size() &&
x[i] < xStar[0])
97 scalar integral_PDFxPowE_0_j = 0;
99 for (
label iStar = 0; iStar < xStar.
size() - 1; ++ iStar)
101 const scalar xPowE1_j =
integerPow(xStar[iStar],
e + 1);
103 auto integral_xPowE1_j_x = [&](
const scalar
x)
107 const scalar integral_xPowE_j_x =
109 ?
log(
x/xStar[iStar])
110 : (xPowE1_i - xPowE1_j)/(
e + 1);
111 const scalar integral_xPowE1_j_x =
113 ?
log(
x/xStar[iStar])
114 : (xPowE1_i*
x - xPowE1_j*xStar[iStar])/(
e + 2);
117 yStar[iStar]*integral_xPowE_j_x
118 + (yStar[iStar + 1] - yStar[iStar])
119 /(xStar[iStar + 1] - xStar[iStar])
120 *(integral_xPowE1_j_x - xStar[iStar]*integral_xPowE_j_x);
123 while (i <
x.size() &&
x[i] < xStar[iStar + 1])
125 result[i] = integral_PDFxPowE_0_j + integral_xPowE1_j_x(
x[i]);
130 integral_PDFxPowE_0_j += integral_xPowE1_j_x(xStar[iStar + 1]);
135 result[i] = integral_PDFxPowE_0_j;
151 scalar
f = (
s - Phi[0])/(Phi[1] - Phi[0]);
154 return (1 -
f)*
x[0] +
f*
x[1];
167 scalar
f = (
s - Phi[0])/(Phi[1] - Phi[0]);
170 const scalar a = (
x[1] -
x[0])*(phi[1] - phi[0])/2;
171 const scalar
b = Phi[1] - Phi[0] - a;
172 const scalar
c = Phi[0] -
s;
189 return (1 -
f)*
x[0] +
f*
x[1];
202 for (; i <
x.size() && Phi[i + 1] <
s; ++ i);
209 {Phi[i], Phi[i + 1]},
225 for (; i <
x.size() && Phi[i + 1] <
s; ++ i);
232 {phi[i], phi[i + 1]},
233 {Phi[i], Phi[i + 1]},
243 if (xPtr_.valid())
return xPtr_();
250 const scalar
f = scalar(i)/(n_ + 1);
251 x[i] = (1 -
f)*this->
min() + f*this->
max();
261 const scalar dPhi = (Phi.
last() - Phi.
first())/(n_ - 1);
263 if (distribution::debug)
265 scalar
error = -vGreat;
266 for (
label i = 0; i < n_ - 1; ++ i)
271 Info<<
indent <<
"Interval spacing iteration #" << iter
272 <<
", error=" << error <<
endl;
277 x.first() = this->
min();
279 for (
label i0 = 0, i = 1; i0 < n_ - 1; ++ i0)
281 while (Phi[i0 + 1] > i*dPhi)
286 {xPrev[i0], xPrev[i0 + 1]},
287 {phi[i0], phi[i0 + 1]},
288 {Phi[i0], Phi[i0 + 1]},
292 x[i] = (
x[i] + xNext)/2;
298 x.last() = this->
max();
307 if (PDFPtr_.valid())
return PDFPtr_();
309 const Pair<scalar> Phi01 = this->Phi01();
311 PDFPtr_.set((phi(this->q(),
x())/(Phi01[1] - Phi01[0])).ptr());
325 return integrate(
x, phi(q,
x));
342 if (Phi01Ptr_.valid())
return Phi01Ptr_();
362 n_((1<<
dict.lookupOrDefault<
label>(
"level", 16)) + 1)
396 if (d.Phi01Ptr_.valid())
400 if (d.PDFPtr_.valid())
418 const scalar
s = this->rndGen_.template sample01<scalar>();
420 const scalar dCDF = scalar(1)/(n_ - 1);
421 const label samplei = floor(
s/dCDF);
426 {
x()[samplei],
x()[samplei + 1]},
427 {PDF()[samplei], PDF()[samplei + 1]},
428 {samplei*dCDF, (samplei + 1)*dCDF},
439 return (Mu01[1] - Mu01[0])/(Phi01[1] - Phi01[0]);
451 return interpolateIntegrateXPow(this->
x(), e, this->PDF(),
x);
464 label n = n_ - 1, level = 0;
465 while (
n >>= 1) ++ level;
476 return this->clipPDF(
x, phi/(Phi01[1] - Phi01[0]));
#define forAll(list, i)
Loop across all elements in list.
Macros for easy insertion into run-time selection tables.
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,...
Templated storage for the roots of polynomial equations, plus flags to indicate the nature of the roo...
void type(const direction i, const rootType t)
Set the type of the i-th root.
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.
virtual void write(Ostream &os, const unitConversion &units) const
Write to a stream.
Base class for distributions that do not have a closed integral form for the cumulative density funct...
virtual tmp< scalarField > Phi(const label q, const scalarField &x) const
Return values of the un-normalised CDF for the given size exponent.
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 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.
unintegrable(const word &name, 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 ~unintegrable()
Destructor.
static tmp< scalarField > integrateX(const scalarField &x, const scalarField &y)
Integrate the values x*y with respect to the coordinates x.
const Pair< scalar > & Phi01() const
Access cached values of the un-normalised CDF at the minimum and.
virtual scalar mean() const
Return the mean value.
static scalar sampleInterval(const Pair< scalar > &x, const Pair< scalar > &Phi, const scalar s)
Sample an interval, given the interval's bounding x-coordinates,.
static tmp< scalarField > interpolateIntegrateXPow(const scalarField &xStar, const label e, const scalarField &yStar, const scalarField &x)
Integrate the values x^e*y with respect to the coordinates x,.
Class to handle errors and exceptions in a simple, consistent stream-based manner.
Quadratic equation of the form a*x^2 + b*x + c = 0.
Roots< 2 > roots(const bool real=false) const
Get the roots.
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.
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))
const dimensionedScalar c
Speed of light in a vacuum.
void writeEntryIfDifferent(Ostream &os, const word &entryName, const EntryType &value1, const EntryType &value2)
Helper function to write the keyword and entry only if the.
label log2(label i)
Return the log base 2 by successive bit-shifting of the given label.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Ostream & endl(Ostream &os)
Add newline and flush stream.
dimensionedScalar y0(const dimensionedScalar &ds)
scalar integerPow(const scalar x, const label e)
Compute the power of the number x to the integer e.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
dimensionedScalar log(const dimensionedScalar &ds)
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
const HashTable< unitConversion > & units()
Get the table of unit conversions.
dimensionedScalar y1(const dimensionedScalar &ds)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
void pow3(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
void sqrt(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
Ostream & indent(Ostream &os)
Indent stream.
randomGenerator rndGen(653213)