Go to the documentation of this file.
36 namespace distributionModels
46 void Foam::distributionModels::general::initialise()
48 static scalar eps = ROOTVSMALL;
50 const label nEntries = xy_.size();
56 for (label i = 1; i < nEntries; i++)
58 scalar
k = (xy_[i][1] - xy_[i-1][1])/(xy_[i][0] - xy_[i-1][0] + eps);
59 scalar d = xy_[i-1][1] -
k*xy_[i-1][0];
60 scalar
y1 = xy_[i][0]*(0.5*
k*xy_[i][0] + d);
61 scalar
y0 = xy_[i-1][0]*(0.5*
k*xy_[i-1][0] + d);
64 integral_[i] =
area + integral_[i-1];
67 scalar sumArea = integral_.last();
71 for (label i=0; i < nEntries; i++)
73 xy_[i][1] /= sumArea + eps;
74 integral_[i] /= sumArea + eps;
88 xy_(distributionModelDict_.lookup(
"distribution")),
101 const scalar binWidth,
118 label bin0 = floor(
minValue/binWidth);
119 label bin1 = ceil(
maxValue/binWidth);
120 label nEntries = bin1 - bin0;
125 <<
"Data cannot be binned - zero bins generated" <<
nl
126 <<
" Bin width : " << binWidth <<
nl
127 <<
" Sample data : " << sampleData
133 xy_.setSize(nEntries);
136 for (label bini = 0; bini < nEntries; ++bini)
138 xy_[bini][0] = (bin0 + bini)*binWidth;
145 label bini = floor(sampleData[i]/binWidth) - bin0;
157 meanValue_(
p.meanValue_),
158 integral_(
p.integral_)
172 scalar
y = rndGen_.sample01<scalar>();
176 while (integral_[
n] <=
y)
181 scalar
k = (xy_[
n][1] - xy_[
n-1][1])/(xy_[
n][0] - xy_[
n-1][0]);
182 scalar d = xy_[
n-1][1] -
k*xy_[
n-1][0];
184 scalar
alpha =
y + xy_[
n-1][0]*(0.5*
k*xy_[
n-1][0] + d) - integral_[
n-1];
192 scalar sqrtEr =
sqrt(0.25*
p*
p - q);
194 scalar x1 = -0.5*
p + sqrtEr;
195 scalar x2 = -0.5*
p - sqrtEr;
196 if ((x1 >= xy_[
n-1][0]) && (x1 <= xy_[
n][0]))
216 return xy_.first()[0];
222 return xy_.last()[0];
267 xy_.setSize(
x.size());
A class for handling words, derived from Foam::string.
virtual tmp< Field< scalar > > x() const
Bin boundaries.
virtual ~general()
Destructor.
dimensionedScalar y1(const dimensionedScalar &ds)
virtual scalar meanValue() const
Return the mean value.
virtual scalar minValue() const
Return the minimum value.
A class for managing temporary objects.
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
addToRunTimeSelectionTable(distributionModel, binned, dictionary)
const word dictName("blockMeshDict")
Istream & operator>>(Istream &, directionInfo &)
Ostream & endl(Ostream &os)
Add newline and flush stream.
A library of runtime-selectable distribution models.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
general distribution model
#define forAll(list, i)
Loop across all elements in list.
virtual tmp< Field< scalar > > y() const
Probabilities.
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
virtual scalar sample() const
Sample the distributionModel.
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
General relative velocity model.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
virtual void readDict(const dictionary &dict)
Read data from dictionary.
dimensionedScalar y0(const dimensionedScalar &ds)
virtual dictionary writeDict(const word &dictName) const
Write data in dictionary format.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Macros for easy insertion into run-time selection tables.
general(const dictionary &dict, Random &rndGen)
Construct from components.
virtual scalar maxValue() const
Return the maximum value.
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
defineTypeNameAndDebug(binned, 0)
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
label k
Boltzmann constant.
virtual void readData(Istream &os)
Read data from stream.
const wordList area
Standard area field types (scalar, vector, tensor, etc)
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
void setSize(const label newSize)
Alias for resize(const label)
virtual void writeData(Ostream &os) const
Write data to stream.
#define WarningInFunction
Report a warning using Foam::Warning.