37 listStarts_(
pTraits<Type>::nComponents, 0)
46 listStarts_(
pTraits<Type>::nComponents, 0)
82 scalar sumOfWeights = 0.0;
84 forAll(cmptDistribution, i)
86 sumOfWeights += cmptDistribution[i];
100 keys[
k] += listStarts_[cmpt];
116 if (cmptDistribution.
empty())
120 cmptDistribution.
setSize(2, 0.0);
122 listStarts_[cmpt] =
n;
127 label listIndex = -1;
129 label& listStart = listStarts_[cmpt];
131 label testIndex = n - listStart;
142 forAll(cmptDistribution, i)
144 newCmptDistribution[i + sOld] = cmptDistribution[i];
147 cmptDistribution = newCmptDistribution;
152 listIndex =
index(cmpt, n);
154 else if (testIndex > cmptDistribution.
size() - 1)
158 cmptDistribution.
setSize(2*cmptDistribution.
size(), 0.0);
162 listIndex =
index(cmpt, n);
166 listIndex = n - listStart;
185 forAll(cmptDistribution, i)
187 if (cmptDistribution[i] > 0.0)
189 if (limits.
first() == -1)
208 Type meanValue(
Zero);
210 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
237 Type medianValue(
Zero);
241 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
247 if (normDist.
size() == 1)
254 && normDist[0].second()*
component(binWidth_, cmpt) > 0.5
265 scalar Sk = (normDist[0].second())*
component(binWidth_, cmpt);
267 setComponent(medianValue, cmpt) = 0.5*(xk - xkm1)/(Sk) + xkm1;
271 label previousNonZeroIndex = 0;
273 scalar cumulative = 0.0;
280 + (normDist[nD].second()*
component(binWidth_, cmpt))
289 normDist[previousNonZeroIndex].
first()
294 + (normDist[nD].second()*
component(binWidth_, cmpt));
296 scalar Skm1 = cumulative;
299 (0.5 - Skm1)*(xk - xkm1)/(Sk - Skm1) + xkm1;
303 else if (
mag(normDist[nD].second()) > vSmall)
306 normDist[nD].second()*
component(binWidth_, cmpt);
308 previousNonZeroIndex = nD;
323 const Type& valueToAdd,
327 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
337 cmptDistribution[listIndex] +=
component(weight, cmpt);
348 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
352 if (cmptDistribution.
empty())
376 normDist[i].
first() =
377 (0.5 + scalar(key))*
component(binWidth_, cmpt);
379 normDist[i].second() =
386 return normDistribution;
396 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
400 if (cmptDistribution.
empty())
422 rawDist[i].
first() = (0.5 + scalar(key))*
component(binWidth_, cmpt);
424 rawDist[i].second() = cmptDistribution[
k];
428 return rawDistribution;
439 normalisedDistribution;
441 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
444 normalisedDistribution[cmpt];
447 cumulativeNormalisedDistribution[cmpt];
453 cumNormalisedCmpt[i].
first() =
454 normalisedCmpt[i].
first()
457 cumNormalisedCmpt[i].second() =
458 normalisedCmpt[i].second()*
component(binWidth_, cmpt) +
sum;
460 sum = cumNormalisedCmpt[i].second();
464 return cumulativeNormalisedDistribution;
476 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
486 cumRawCmpt[i].
first() =
490 cumRawCmpt[i].second() = rawCmpt[i].second() +
sum;
492 sum = cumRawCmpt[i].second();
496 return cumulativeRawDistribution;
503 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
505 (*this)[cmpt].clear();
507 listStarts_[cmpt] = 0;
519 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
528 os <<
"# key normalised raw" <<
endl;
532 os << normPairs[i].
first()
533 <<
' ' << normPairs[i].second()
534 <<
' ' << rawPairs[i].second()
543 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
554 os <<
"# key normalised raw" <<
endl;
558 os << normPairs[i].
first()
559 <<
' ' << normPairs[i].second()
560 <<
' ' << rawPairs[i].second()
570 void Foam::Distribution<Type>::operator=
579 <<
"Attempted assignment to self" 585 binWidth_ = rhs.binWidth();
587 listStarts_ = rhs.listStarts();
592 void Foam::Distribution<Type>::operator=
601 <<
"Attempted assignment to self" 607 binWidth_ = rhs.binWidth();
609 listStarts_ = move(rhs.listStarts());
627 is.check(
"Istream& operator>>(Istream&, Distribution<Type>&)");
640 os << static_cast<const List<List<scalar>>& >(d)
645 os.check(
"Ostream& operator<<(Ostream&, " "const Distribution&)");
665 rawDists[0] = d1.
raw();
666 rawDists[1] = d2.raw();
670 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
678 scalar valueToAdd = cmptRaw[rI].
first();
679 scalar cmptWeight = cmptRaw[rI].second();
695 cmptDistribution[listIndex] += cmptWeight;
label index(direction cmpt, label n)
Return the appropriate List index for the given bin index.
#define forAll(list, i)
Loop across all elements in list.
~Distribution()
Destructor.
bool empty() const
Return true if the UList is empty (ie, size() is zero)
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.
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...
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 & binWidth() const
Return the bin width.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Traits class for primitives.
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
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)
Pair< label > validLimits(direction cmpt) const
Returns the indices of the first and last non-zero entries.
Various functions to operate on Lists.
List< List< Pair< scalar > > > normalised() const
Return the normalised distribution (probability density)
const List< label > & listStarts() const
Return the List start bin indices.
An ordered pair of two objects of type <T> with first() and second() elements.
List< List< Pair< scalar > > > cumulativeNormalised() const
Return the cumulative normalised distribution and.
Distribution()
Construct null.
errorManip< error > abort(error &err)
List< List< Pair< scalar > > > cumulativeRaw() const
Return the cumulative total bin weights and integration.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
friend Ostream & operator(Ostream &, const Distribution< Type > &)
void clear()
Resets the Distribution by clearing the stored lists.
const Type & second() const
Return second.
void setSize(const label)
Reset size of List.
scalar totalWeight(direction cmpt) const
Sum the total weight added to the component in the.
List< List< Pair< scalar > > > raw() const
Return the distribution of the total bin weights.
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 > &)
void write(const fileName &filePrefix) const
Write the distribution to file: key normalised raw.
label & setComponent(label &l, const direction)
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
label size() const
Return the number of elements in the UList.
const Type & first() const
Return first.
List< label > keys(direction cmpt) const
A class representing the concept of 1 (scalar(1)) used to avoid unnecessary manipulations for objects...