48 os << pairs[i].first() <<
' ' << pairs[i].second() <<
nl;
86 label sumOfEntries = 0;
90 sumOfEntries += iter();
94 WarningIn(
"label distribution::totalEntries()")
95 <<
"Accumulated distribution values total has become negative: " 96 <<
"sumOfEntries = " << sumOfEntries
97 <<
". This is most likely to be because too many samples " 98 <<
"have been added to the bins and the label has 'rolled " 99 <<
"round'. Try distribution::approxTotalEntries which " 100 <<
"returns a scalar." <<
endl;
114 scalar sumOfEntries = 0;
118 sumOfEntries += scalar(iter());
127 scalar runningSum = 0;
140 *scalar((*
this)[key])
157 scalar runningSum = 0.0;
163 if (normDist.
size() == 1)
165 median = normDist[0].
first();
170 && normDist[0].second()*binWidth_ > 0.5
173 scalar xk = normDist[1].
first();
174 scalar xkm1 = normDist[0].
first();
176 (normDist[0].second() + normDist[1].second())*binWidth_;
177 scalar Skm1 = normDist[0].second()*binWidth_;
179 median = (0.5 - Skm1)*(xk - xkm1)/(Sk - Skm1) + xkm1;
183 label lastNonZeroIndex = 0;
187 if (runningSum + (normDist[nD].second()*binWidth_) > 0.5)
189 scalar xk = normDist[nD].
first();
190 scalar xkm1 = normDist[lastNonZeroIndex].
first();
191 scalar Sk = runningSum + (normDist[nD].second()*binWidth_);
192 scalar Skm1 = runningSum;
194 median = (0.5 - Skm1)*(xk - xkm1)/(Sk - Skm1) + xkm1;
198 else if (normDist[nD].second() > 0.0)
200 runningSum += normDist[nD].second()*binWidth_;
202 lastNonZeroIndex = nD;
220 if (iter == this->
end())
231 FatalErrorIn(
"distribution::add(const scalar valueToAdd)")
232 <<
"Accumulated distribution value has become negative: " 233 <<
"bin = " << (0.5 + scalar(n)) * binWidth_
234 <<
", value = " << (*
this)[
n]
235 <<
". This is most likely to be because too many samples " 236 <<
"have been added to a bin and the label has 'rolled round'" 244 add(scalar(valueToAdd));
262 if (iter == this->
end())
287 normDist[
k].
first() = (0.5 + scalar(key))*binWidth_;
289 normDist[
k].second() = scalar((*
this)[key])/totEnt/binWidth_;
294 Info<<
"totEnt: " << totEnt <<
endl;
318 oldDist[u].
first() -= shiftValue;
321 scalar lowestOldBin = oldDist[0].
first()/binWidth_ - 0.5;
325 lowestOldBin + 0.5*
sign(lowestOldBin)
328 scalar interpolationStartDirection =
329 sign(scalar(lowestNewKey) - lowestOldBin);
331 label newKey = lowestNewKey;
336 <<
nl << lowestOldBin
337 <<
nl << lowestNewKey
338 <<
nl << interpolationStartDirection
341 scalar checkNormalisation = 0;
345 checkNormalisation += oldDist[oD].second()*binWidth_;
348 Info<<
"Initial normalisation = " << checkNormalisation <<
endl;
353 newDist[u].first() = (0.5 + scalar(newKey)) * binWidth_;
355 if (interpolationStartDirection < 0)
359 newDist[u].second() =
360 (0.5 + scalar(newKey))*oldDist[u].second()
361 - oldDist[u].second()
362 *(oldDist[u].
first() - binWidth_)/ binWidth_;
366 newDist[u].second() =
367 (0.5 + scalar(newKey))
368 *(oldDist[u].second() - oldDist[u-1].second())
371 oldDist[u-1].second()*oldDist[u].
first()
372 - oldDist[u].second()*oldDist[u-1].
first()
379 if (u == oldDist.
size() - 1)
381 newDist[u].second() =
382 (0.5 + scalar(newKey))*-oldDist[u].second()
383 + oldDist[u].second()*(oldDist[u].
first() + binWidth_)
388 newDist[u].second() =
389 (0.5 + scalar(newKey))
390 *(oldDist[u+1].second() - oldDist[u].second())
393 oldDist[u].second()*oldDist[u+1].
first()
394 - oldDist[u+1].second()*oldDist[u].
first()
405 scalar checkNormalisation = 0;
409 checkNormalisation += newDist[nD].second()*binWidth_;
412 Info<<
"Shifted normalisation = " << checkNormalisation <<
endl;
433 rawDist[
k].
first() = (0.5 + scalar(key))*binWidth_;
435 rawDist[
k].second() = scalar((*
this)[key]);
449 FatalErrorIn(
"distribution::operator=(const distribution&)")
450 <<
"Attempted assignment to self" 470 "Ostream& operator<<(Ostream&, " 471 "const distribution&)"
static void write(const fileName &file, const List< Pair< scalar > > &pairs)
Write to file.
List< Pair< scalar > > normalisedShifted(scalar shiftValue)
An ordered pair of two objects of type <T> with first() and second() elements.
dimensionedScalar neg(const dimensionedScalar &ds)
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
An STL-conforming iterator.
T & last()
Return the last element of the list.
void operator=(const HashTable< T, label, Hash< label > > &)
Assignment.
A HashTable to objects of type <T> with a label key.
distribution()
Construct null.
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 size(const label)
Override size to be inconsistent with allocated storage.
void add(const scalar valueToAdd)
Add a value to the appropriate bin of the distribution.
dimensionedScalar sign(const dimensionedScalar &ds)
Accumulating histogram of values. Specified bin resolution automatic generation of bins...
Ostream & operator<<(Ostream &, const edgeMesh &)
T & first()
Return the first element of the list.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
scalar approxTotalEntries() const
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Ostream & endl(Ostream &os)
Add newline and flush stream.
#define WarningIn(functionName)
Report a warning using Foam::Warning.
label k
Boltzmann constant.
List< Pair< scalar > > normalised()
label size() const
Return number of elements in table.
List< Key > toc() const
Return the table of contents.
errorManip< error > abort(error &err)
List< Pair< scalar > > raw()
void operator=(const distribution &)
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
List< Pair< scalar > > normalisedMinusMean()
A class for handling file names.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
label totalEntries() const
iterator begin()
Iterator set to the beginning of the HashTable.
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
virtual ~distribution()
Destructor.
defineTypeNameAndDebug(combustionModel, 0)