40 listStarts_(
pTraits<Type>::nComponents, 0)
49 listStarts_(
pTraits<Type>::nComponents, 0)
57 binWidth_(d.binWidth()),
58 listStarts_(d.listStarts())
76 scalar sumOfWeights = 0.0;
78 forAll(cmptDistribution, i)
80 sumOfWeights += cmptDistribution[i];
90 return identity((*
this)[cmpt].size(), listStarts_[cmpt]);
103 if (cmptDistribution.
empty())
107 cmptDistribution.
setSize(2, 0.0);
109 listStarts_[cmpt] =
n;
114 label listIndex = -1;
116 label& listStart = listStarts_[cmpt];
118 label testIndex =
n - listStart;
127 label sOld = cmptDistribution.
size();
129 forAll(cmptDistribution, i)
131 newCmptDistribution[i + sOld] = cmptDistribution[i];
134 cmptDistribution = newCmptDistribution;
139 listIndex = index(cmpt,
n);
141 else if (testIndex > cmptDistribution.
size() - 1)
145 cmptDistribution.
setSize(2*cmptDistribution.
size(), 0.0);
149 listIndex = index(cmpt,
n);
153 listIndex =
n - listStart;
172 forAll(cmptDistribution, i)
174 if (cmptDistribution[i] > 0.0)
176 if (limits.
first() == -1)
195 Type meanValue(
Zero);
197 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
201 scalar totalCmptWeight = totalWeight(cmpt);
207 label key = theKeys[
k];
224 Type medianValue(
Zero);
228 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
234 if (normDist.
size() == 1)
241 && normDist[0].second()*
component(binWidth_, cmpt) > 0.5
252 scalar Sk = (normDist[0].second())*
component(binWidth_, cmpt);
254 setComponent(medianValue, cmpt) = 0.5*(xk - xkm1)/(Sk) + xkm1;
258 label previousNonZeroIndex = 0;
260 scalar cumulative = 0.0;
267 + (normDist[nD].second()*
component(binWidth_, cmpt))
276 normDist[previousNonZeroIndex].
first()
281 + (normDist[nD].second()*
component(binWidth_, cmpt));
283 scalar Skm1 = cumulative;
286 (0.5 - Skm1)*(xk - xkm1)/(Sk - Skm1) + xkm1;
290 else if (
mag(normDist[nD].second()) > VSMALL)
293 normDist[nD].second()*
component(binWidth_, cmpt);
295 previousNonZeroIndex = nD;
310 const Type& valueToAdd,
314 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
322 label listIndex = index(cmpt,
n);
324 cmptDistribution[listIndex] +=
component(weight, cmpt);
335 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
339 if (cmptDistribution.
empty())
344 scalar totalCmptWeight = totalWeight(cmpt);
356 label
k = limits.
first(), i = 0;
361 label key = cmptKeys[
k];
363 normDist[i].
first() =
364 (0.5 + scalar(key))*
component(binWidth_, cmpt);
366 normDist[i].second() =
373 return normDistribution;
383 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
387 if (cmptDistribution.
empty())
402 label
k = limits.
first(), i = 0;
407 label key = cmptKeys[
k];
409 rawDist[i].
first() = (0.5 + scalar(key))*
component(binWidth_, cmpt);
411 rawDist[i].second() = cmptDistribution[
k];
415 return rawDistribution;
426 normalisedDistribution;
428 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
431 normalisedDistribution[cmpt];
434 cumulativeNormalisedDistribution[cmpt];
440 cumNormalisedCmpt[i].
first() =
441 normalisedCmpt[i].
first()
444 cumNormalisedCmpt[i].second() =
445 normalisedCmpt[i].second()*
component(binWidth_, cmpt) +
sum;
447 sum = cumNormalisedCmpt[i].second();
451 return cumulativeNormalisedDistribution;
463 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
473 cumRawCmpt[i].
first() =
477 cumRawCmpt[i].second() = rawCmpt[i].second() +
sum;
479 sum = cumRawCmpt[i].second();
483 return cumulativeRawDistribution;
490 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
492 (*this)[cmpt].clear();
494 listStarts_[cmpt] = 0;
506 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
514 os <<
"# key normalised raw" <<
endl;
519 <<
' ' << normPairs[i].second()
520 <<
' ' << rawPairs[i].second()
529 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
540 os <<
"# key normalised raw" <<
endl;
545 <<
' ' << normPairs[i].second()
546 <<
' ' << rawPairs[i].second()
568 binWidth_ = rhs.binWidth();
570 listStarts_ = rhs.listStarts();
596 const Distribution<Type>& d
599 os << static_cast<const List<List<scalar>>&>(d)
613 const Distribution<Type>& d1,
614 const Distribution<Type>& d2
618 Distribution<Type> d(
max(d1.
binWidth(), d2.binWidth()));
620 List<List<List<Pair<scalar>>>> rawDists(2);
622 rawDists[0] = d1.
raw();
623 rawDists[1] = d2.raw();
627 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
629 List<scalar>& cmptDistribution = d[cmpt];
631 const List<Pair<scalar>>& cmptRaw = rawDists[rDI][cmpt];
635 scalar valueToAdd = cmptRaw[rI].first();
636 scalar cmptWeight = cmptRaw[rI].second();
650 label listIndex = d.index(cmpt,
n);
652 cmptDistribution[listIndex] += cmptWeight;
657 return Distribution<Type>(d);
Various functions to operate on Lists.
Accumulating histogram of component values. Specified bin resolution, automatic generation of bins.
List< List< Pair< scalar > > > cumulativeNormalised() const
Return the cumulative normalised distribution and.
~Distribution()
Destructor.
Distribution()
Construct null.
scalar totalWeight(direction cmpt) const
Sum the total weight added to the component in the.
void clear()
Resets the Distribution by clearing the stored lists.
Pair< label > validLimits(direction cmpt) const
Returns the indices of the first and last non-zero entries.
const Type & binWidth() const
Return the bin width.
List< List< Pair< scalar > > > cumulativeRaw() const
Return the cumulative total bin weights and integration.
List< List< Pair< scalar > > > raw() const
Return the distribution of the total bin weights.
List< List< Pair< scalar > > > normalised() const
Return the normalised distribution (probability density)
T & first() noexcept
The first element of the list, position [0].
const_iterator_pair< const_key_iterator, this_type > keys() const
A const iterator begin/end pair for iterating over keys.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void setSize(const label n)
Alias for resize()
Output to file stream, using an OSstream.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
An ordered pair of two objects of type <T> with first() and second() elements.
const T & second() const noexcept
Return second element, which is also the last element.
T & first()
Return the first element of the list.
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
void size(const label n)
Older name for setAddressableSize.
A class for handling file names.
virtual bool write()
Write the output fields.
Sums a given list of (at least two or more) fields and outputs the result into a new field,...
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
A traits class, which is primarily used for primitives.
OBJstream os(runTime.globalPath()/outputName)
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
quaternion normalised(const quaternion &q)
Return the normalised (unit) quaternion of the given quaternion.
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
label & setComponent(label &val, const direction) noexcept
Non-const access to integer-type (has no components)
Ostream & endl(Ostream &os)
Add newline and flush stream.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
dimensionedScalar neg(const dimensionedScalar &ds)
static constexpr const zero Zero
Global zero (0)
constexpr char nl
The newline '\n' character (0x0a)
#define forAll(list, i)
Loop across all elements in list.