40 listStarts_(
pTraits<Type>::nComponents, 0)
49 listStarts_(
pTraits<Type>::nComponents, 0)
56 List<List<scalar>>(static_cast<const List<List<scalar>>&>(d)),
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;
125 List<scalar> newCmptDistribution(2*cmptDistribution.
size(),
Zero);
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++)
199 const List<scalar>& cmptDistribution = (*this)[cmpt];
201 scalar totalCmptWeight = totalWeight(cmpt);
203 List<label> theKeys = keys(cmpt);
207 label
key = theKeys[
k];
224 Type medianValue(
Zero);
226 List<List<Pair<scalar>>> normDistribution =
normalised();
228 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
230 List<Pair<scalar>>& normDist = normDistribution[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);
333 List<List<Pair<scalar>>> normDistribution(pTraits<Type>::nComponents);
335 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
337 const List<scalar>& cmptDistribution = (*this)[cmpt];
339 if (cmptDistribution.empty())
344 scalar totalCmptWeight = totalWeight(cmpt);
346 List<label> cmptKeys = keys(cmpt);
348 List<Pair<scalar>>& normDist = normDistribution[cmpt];
350 Pair<label> limits = validLimits(cmpt);
352 normDist.setSize(limits.second() - limits.first() + 1);
356 label
k = limits.first(), i = 0;
357 k <= limits.second();
361 label
key = cmptKeys[
k];
363 normDist[i].first() =
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];
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;
502 List<List<Pair<scalar>>> rawDistribution = raw();
504 List<List<Pair<scalar>>> normDistribution =
normalised();
506 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
508 const List<Pair<scalar>>& rawPairs = rawDistribution[cmpt];
510 const List<Pair<scalar>>& normPairs = normDistribution[cmpt];
512 OFstream
os(filePrefix +
'_' + pTraits<Type>::componentNames[cmpt]);
514 os <<
"# key normalised raw" <<
endl;
518 os << normPairs[i].first()
519 <<
' ' << normPairs[i].second()
520 <<
' ' << rawPairs[i].second()
525 List<List<Pair<scalar>>> rawCumDist = cumulativeRaw();
527 List<List<Pair<scalar>>> normCumDist = cumulativeNormalised();
529 for (
direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
531 const List<Pair<scalar>>& rawPairs = rawCumDist[cmpt];
533 const List<Pair<scalar>>& normPairs = normCumDist[cmpt];
537 filePrefix +
"_cumulative_" + pTraits<Type>::componentNames[cmpt]
540 os <<
"# key normalised raw" <<
endl;
544 os << normPairs[i].first()
545 <<
' ' << normPairs[i].second()
546 <<
' ' << rawPairs[i].second()
566 List<List<scalar>>::operator=(rhs);
570 listStarts_ = rhs.listStarts();
580 Distribution<Type>& d
583 is >>
static_cast<List<List<scalar>
>&>(d)
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);
label index(direction cmpt, label n)
Return the appropriate List index for the given bin index.
const T & first() const noexcept
Access the first element.
void size(const label n)
Older name for setAddressableSize.
~Distribution()
Destructor.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &f1)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
virtual bool check(const char *operation) const
Check IOstream status for given operation.
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...
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
constexpr char nl
The newline '\n' character (0x0a)
bool empty() const noexcept
True if List is empty (ie, size() is zero)
const Type & binWidth() const
Return the bin width.
T & first()
Access first element of the list, position [0].
Ostream & endl(Ostream &os)
Add newline and flush stream.
A traits class, which is primarily used for primitives.
label k
Boltzmann constant.
quaternion normalised(const quaternion &q)
Return the normalised (unit) quaternion of the given quaternion.
dimensionedScalar neg(const dimensionedScalar &ds)
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)
#define forAll(list, i)
Loop across all elements in list.
void setSize(const label n)
Alias for resize()
An ordered pair of two objects of type <T> with first() and second() elements.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
List< List< Pair< scalar > > > cumulativeNormalised() const
Return the cumulative normalised distribution and.
Distribution()
Construct null.
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...
OBJstream os(runTime.globalPath()/outputName)
void clear()
Resets the Distribution by clearing the stored lists.
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.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
void add(const Type &valueToAdd, const Type &weight=pTraits< Type >::one)
Add a value to the distribution, optionally specifying a weight.
const T & second() const noexcept
Access the second element.
void write(const fileName &filePrefix) const
Write the distribution to file: key normalised raw.
label & setComponent(label &val, const direction) noexcept
Non-const access to integer-type (has no components)
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
List< label > keys(direction cmpt) const
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
static constexpr const zero Zero
Global zero (0)