37 listStarts_(
pTraits<Type>::nComponents, 0)
46 listStarts_(
pTraits<Type>::nComponents, 0)
73 scalar sumOfWeights = 0.0;
75 forAll(cmptDistribution, i)
77 sumOfWeights += cmptDistribution[i];
91 keys[
k] += listStarts_[cmpt];
107 if (cmptDistribution.
empty())
111 cmptDistribution.
setSize(2, 0.0);
113 listStarts_[cmpt] =
n;
118 label listIndex = -1;
120 label& listStart = listStarts_[cmpt];
122 label testIndex = n - listStart;
133 forAll(cmptDistribution, i)
135 newCmptDistribution[i + sOld] = cmptDistribution[i];
138 cmptDistribution = newCmptDistribution;
143 listIndex =
index(cmpt, n);
145 else if (testIndex > cmptDistribution.
size() - 1)
149 cmptDistribution.
setSize(2*cmptDistribution.
size(), 0.0);
153 listIndex =
index(cmpt, n);
157 listIndex = n - listStart;
176 forAll(cmptDistribution, i)
178 if (cmptDistribution[i] > 0.0)
180 if (limits.
first() == -1)
199 Type meanValue(
Zero);
201 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
228 Type medianValue(
Zero);
232 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
238 if (normDist.
size() == 1)
245 && normDist[0].second()*
component(binWidth_, cmpt) > 0.5
256 scalar Sk = (normDist[0].second())*
component(binWidth_, cmpt);
258 setComponent(medianValue, cmpt) = 0.5*(xk - xkm1)/(Sk) + xkm1;
262 label previousNonZeroIndex = 0;
264 scalar cumulative = 0.0;
271 + (normDist[nD].second()*
component(binWidth_, cmpt))
280 normDist[previousNonZeroIndex].
first()
285 + (normDist[nD].second()*
component(binWidth_, cmpt));
287 scalar Skm1 = cumulative;
290 (0.5 - Skm1)*(xk - xkm1)/(Sk - Skm1) + xkm1;
294 else if (
mag(normDist[nD].second()) > VSMALL)
297 normDist[nD].second()*
component(binWidth_, cmpt);
299 previousNonZeroIndex = nD;
314 const Type& valueToAdd,
318 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
328 cmptDistribution[listIndex] +=
component(weight, cmpt);
339 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
343 if (cmptDistribution.
empty())
367 normDist[i].
first() =
368 (0.5 + scalar(key))*
component(binWidth_, cmpt);
370 normDist[i].second() =
377 return normDistribution;
387 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
391 if (cmptDistribution.
empty())
413 rawDist[i].
first() = (0.5 + scalar(key))*
component(binWidth_, cmpt);
415 rawDist[i].second() = cmptDistribution[
k];
419 return rawDistribution;
430 normalisedDistribution;
432 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
435 normalisedDistribution[cmpt];
438 cumulativeNormalisedDistribution[cmpt];
444 cumNormalisedCmpt[i].
first() =
445 normalisedCmpt[i].
first()
448 cumNormalisedCmpt[i].second() =
449 normalisedCmpt[i].second()*
component(binWidth_, cmpt) +
sum;
451 sum = cumNormalisedCmpt[i].second();
455 return cumulativeNormalisedDistribution;
467 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
477 cumRawCmpt[i].
first() =
481 cumRawCmpt[i].second() = rawCmpt[i].second() +
sum;
483 sum = cumRawCmpt[i].second();
487 return cumulativeRawDistribution;
494 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
496 (*this)[cmpt].clear();
498 listStarts_[cmpt] = 0;
510 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
518 os <<
"# key normalised raw" <<
endl;
522 os << normPairs[i].
first()
523 <<
' ' << normPairs[i].second()
524 <<
' ' << rawPairs[i].second()
533 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
544 os <<
"# key normalised raw" <<
endl;
548 os << normPairs[i].
first()
549 <<
' ' << normPairs[i].second()
550 <<
' ' << rawPairs[i].second()
560 void Foam::Distribution<Type>::operator=
569 <<
"Attempted assignment to self" 575 binWidth_ = rhs.binWidth();
577 listStarts_ = rhs.listStarts();
595 is.check(
"Istream& operator>>(Istream&, Distribution<Type>&)");
608 os << static_cast<const List<List<scalar>>& >(d)
613 os.check(
"Ostream& operator<<(Ostream&, " "const Distribution&)");
633 rawDists[0] = d1.
raw();
634 rawDists[1] = d2.raw();
638 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
646 scalar valueToAdd = cmptRaw[rI].
first();
647 scalar cmptWeight = cmptRaw[rI].second();
663 cmptDistribution[listIndex] += cmptWeight;
label index(direction cmpt, label n)
Return the appropriate List index for the given bin index.
void write(const fileName &filePrefix) const
Write the distribution to file: key normalised raw.
#define forAll(list, i)
Loop across all elements in list.
~Distribution()
Destructor.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
A class for handling file names.
List< List< Pair< scalar > > > cumulativeNormalised() const
Return the cumulative normalised distribution and.
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Accumulating histogram of component values. Specified bin resolution, automatic generation of bins...
bool empty() const
Return true if the UList is empty (ie, size() is zero)
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
void size(const label)
Override size to be inconsistent with allocated storage.
const Type & second() const
Return second.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Traits class for primitives.
List< List< Pair< scalar > > > normalised() const
Return the normalised distribution (probability density)
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
const Type & first() const
Return first.
label k
Boltzmann constant.
T & first()
Return the first element of the list.
dimensionedScalar neg(const dimensionedScalar &ds)
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
Various functions to operate on Lists.
An ordered pair of two objects of type <T> with first() and second() elements.
const Type & binWidth() const
Return the bin width.
Distribution()
Construct null.
errorManip< error > abort(error &err)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
friend Ostream & operator(Ostream &, const Distribution< Type > &)
List< List< Pair< scalar > > > raw() const
Return the distribution of the total bin weights.
void clear()
Resets the Distribution by clearing the stored lists.
label size() const
Return the number of elements in the UList.
List< label > keys(direction cmpt) const
void setSize(const label)
Reset size of List.
Pair< label > validLimits(direction cmpt) const
Returns the indices of the first and last non-zero entries.
void add(const Type &valueToAdd, const Type &weight=pTraits< Type >::one)
Add a value to the distribution, optionally specifying a weight.
dimensioned< scalar > mag(const dimensioned< Type > &)
label & setComponent(label &l, const direction)
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
const List< label > & listStarts() const
Return the List start bin indices.
List< List< Pair< scalar > > > cumulativeRaw() const
Return the cumulative total bin weights and integration.
scalar totalWeight(direction cmpt) const
Sum the total weight added to the component in the.
A class representing the concept of 1 (scalar(1.0)) used to avoid unnecessary manipulations for objec...