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)
201 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
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=
570 "Foam::Distribution<Type>::operator=" 571 "(const Foam::Distribution<Type>&)" 572 ) <<
"Attempted assignment to self" 578 binWidth_ = rhs.binWidth();
580 listStarts_ = rhs.listStarts();
598 is.check(
"Istream& operator>>(Istream&, Distribution<Type>&)");
611 os << static_cast<const List< List<scalar> >& >(d)
616 os.check(
"Ostream& operator<<(Ostream&, " "const Distribution&)");
636 rawDists[0] = d1.
raw();
637 rawDists[1] = d2.raw();
641 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
649 scalar valueToAdd = cmptRaw[rI].
first();
650 scalar cmptWeight = cmptRaw[rI].second();
666 cmptDistribution[listIndex] += cmptWeight;
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...
List< List< Pair< scalar > > > cumulativeNormalised() const
Return the cumulative normalised distribution and.
~Distribution()
Destructor.
An ordered pair of two objects of type <T> with first() and second() elements.
dimensionedScalar neg(const dimensionedScalar &ds)
dimensioned< scalar > mag(const dimensioned< Type > &)
bool empty() const
Return true if the UList is empty (ie, size() is zero).
List< label > keys(direction cmpt) const
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Pair< label > validLimits(direction cmpt) const
Returns the indices of the first and last non-zero entries.
label & setComponent(label &l, const direction)
const Type & second() const
Return second.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
void write(const fileName &filePrefix) const
Write the distribution to file: key normalised raw.
void size(const label)
Override size to be inconsistent with allocated storage.
Various functions to operate on Lists.
void add(const Type &valueToAdd, const Type &weight=pTraits< Type >::one)
Add a value to the distribution, optionally specifying a weight.
List< List< Pair< scalar > > > raw() const
Return the distribution of the total bin weights.
T & first()
Return the first element of the list.
List< List< Pair< scalar > > > normalised() const
Return the normalised distribution (probability density)
friend Ostream & operator(Ostream &, const Distribution< Type > &)
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Distribution()
Construct null.
void setSize(const label)
Reset size of List.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
label k
Boltzmann constant.
const Type & binWidth() const
Return the bin width.
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
errorManip< error > abort(error &err)
void clear()
Resets the Distribution by clearing the stored lists.
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Accumulating histogram of component values. Specified bin resolution, automatic generation of bins...
Traits class for primitives.
A class for handling file names.
const Type & first() const
Return first.
label size() const
Return the number of elements in the UList.
const List< label > & listStarts() const
Return the List start bin indices.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
label index(direction cmpt, label n)
Return the appropriate List index for the given bin index.
List< List< Pair< scalar > > > cumulativeRaw() const
Return the cumulative total bin weights and integration.