48 os << pairs[i].first() <<
' ' << pairs[i].second() <<
nl;
86 label sumOfEntries = 0;
90 sumOfEntries += iter();
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())
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())
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())
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]);
450 <<
"Attempted assignment to self" 470 "Ostream& operator<<(Ostream&, " 471 "const distribution&)" distribution()
Construct null.
scalar approxTotalEntries() const
dimensionedScalar sign(const dimensionedScalar &ds)
#define forAll(list, i)
Loop across all elements in list.
FvWallInfoData< WallInfo, label > 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.
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void size(const label)
Override size to be inconsistent with allocated storage.
Ostream & endl(Ostream &os)
Add newline and flush stream.
virtual ~distribution()
Destructor.
void add(const scalar valueToAdd)
Add a value to the appropriate bin of the distribution.
label k
Boltzmann constant.
T & first()
Return the first element of the list.
dimensionedScalar neg(const dimensionedScalar &ds)
label size() const
Return number of elements in table.
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
An STL-conforming iterator.
iterator begin()
Iterator set to the beginning of the HashTable.
Accumulating histogram of values. Specified bin resolution automatic generation of bins...
errorManip< error > abort(error &err)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
defineTypeNameAndDebug(combustionModel, 0)
static void write(const fileName &file, const List< Pair< scalar >> &pairs)
Write to file.
List< Pair< scalar > > normalised()
labelList second(const UList< labelPair > &p)
List< Pair< scalar > > normalisedMinusMean()
#define WarningInFunction
Report a warning using Foam::Warning.
List< Pair< scalar > > normalisedShifted(scalar shiftValue)
Ostream & operator<<(Ostream &, const ensightPart &)
void operator=(const distribution &)
label totalEntries() const
List< Pair< scalar > > raw()
List< Key > toc() const
Return the table of contents.
T & last()
Return the last element of the list.
void operator=(const Map< T > &map)
A HashTable to objects of type <T> with a label key.