51 os << pairs[i].first() <<
' ' << pairs[i].second() <<
nl;
74 Map<label>(static_cast<
Map<label>>(d)),
75 binWidth_(d.binWidth())
89 label sumOfEntries = 0;
93 sumOfEntries += iter.val();
98 <<
"Accumulated distribution values total has become negative: "
99 <<
"sumOfEntries = " << sumOfEntries
100 <<
". This is most likely to be because too many samples "
101 <<
"have been added to the bins and the label has 'rolled "
102 <<
"round'. Try distribution::approxTotalEntries which "
103 <<
"returns a scalar." <<
endl;
117 scalar sumOfEntries = 0;
121 sumOfEntries += scalar(iter.val());
130 scalar runningSum = 0;
132 scalar totEnt = approxTotalEntries();
143 *scalar((*
this)[key])
160 scalar runningSum = 0.0;
166 if (normDist.
size() == 1)
168 median = normDist[0].
first();
173 && normDist[0].second()*binWidth_ > 0.5
176 scalar xk = normDist[1].
first();
177 scalar xkm1 = normDist[0].
first();
179 (normDist[0].second() + normDist[1].second())*binWidth_;
180 scalar Skm1 = normDist[0].second()*binWidth_;
182 median = (0.5 - Skm1)*(xk - xkm1)/(Sk - Skm1) + xkm1;
186 label lastNonZeroIndex = 0;
190 if (runningSum + (normDist[nD].second()*binWidth_) > 0.5)
192 scalar xk = normDist[nD].
first();
193 scalar xkm1 = normDist[lastNonZeroIndex].
first();
194 scalar Sk = runningSum + (normDist[nD].second()*binWidth_);
195 scalar Skm1 = runningSum;
197 median = (0.5 - Skm1)*(xk - xkm1)/(Sk - Skm1) + xkm1;
201 else if (normDist[nD].second() > 0.0)
203 runningSum += normDist[nD].second()*binWidth_;
205 lastNonZeroIndex = nD;
219 label
n = label(valueToAdd/binWidth_) - label(
neg(valueToAdd/binWidth_));
223 if (iter == this->end())
235 <<
"Accumulated distribution value has become negative: "
236 <<
"bin = " << (0.5 + scalar(
n)) * binWidth_
237 <<
", value = " << (*
this)[
n]
238 <<
". This is most likely to be because too many samples "
239 <<
"have been added to a bin and the label has 'rolled round'"
247 add(scalar(valueToAdd));
257 for (label
k = keys[1];
k < keys.
last();
k++)
268 scalar totEnt = approxTotalEntries();
279 normDist[
k].
first() = (0.5 + scalar(key))*binWidth_;
281 normDist[
k].second() = scalar((*
this)[key])/totEnt/binWidth_;
286 Info<<
"totEnt: " << totEnt <<
endl;
295 return normalisedShifted(mean());
310 oldDist[u].
first() -= shiftValue;
313 scalar lowestOldBin = oldDist[0].
first()/binWidth_ - 0.5;
315 label lowestNewKey = label
317 lowestOldBin + 0.5*
sign(lowestOldBin)
320 scalar interpolationStartDirection =
321 sign(scalar(lowestNewKey) - lowestOldBin);
323 label newKey = lowestNewKey;
328 <<
nl << lowestOldBin
329 <<
nl << lowestNewKey
330 <<
nl << interpolationStartDirection
333 scalar checkNormalisation = 0;
337 checkNormalisation += oldDist[oD].second()*binWidth_;
340 Info<<
"Initial normalisation = " << checkNormalisation <<
endl;
345 newDist[u].
first() = (0.5 + scalar(newKey)) * binWidth_;
347 if (interpolationStartDirection < 0)
351 newDist[u].second() =
352 (0.5 + scalar(newKey))*oldDist[u].second()
353 - oldDist[u].second()
354 *(oldDist[u].
first() - binWidth_)/ binWidth_;
358 newDist[u].second() =
359 (0.5 + scalar(newKey))
360 *(oldDist[u].second() - oldDist[u-1].second())
363 oldDist[u-1].second()*oldDist[u].
first()
364 - oldDist[u].second()*oldDist[u-1].
first()
371 if (u == oldDist.
size() - 1)
373 newDist[u].second() =
374 (0.5 + scalar(newKey))*-oldDist[u].second()
375 + oldDist[u].second()*(oldDist[u].
first() + binWidth_)
380 newDist[u].second() =
381 (0.5 + scalar(newKey))
382 *(oldDist[u+1].second() - oldDist[u].second())
385 oldDist[u].second()*oldDist[u+1].
first()
386 - oldDist[u+1].second()*oldDist[u].
first()
397 scalar checkNormalisation = 0;
401 checkNormalisation += newDist[nD].second()*binWidth_;
404 Info<<
"Shifted normalisation = " << checkNormalisation <<
endl;
422 rawDist[
k].
first() = (0.5 + scalar(key))*binWidth_;
424 rawDist[
k].second() = scalar((*
this)[key]);
Forward iterator with non-const access.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
A HashTable to objects of type <T> with a label key.
void operator=(const this_type &rhs)
Copy assignment.
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.
T & first()
Return the first element of the list.
void size(const label n)
Older name for setAddressableSize.
T & last()
Return the last element of the list.
Accumulating histogram of values. Specified bin resolution automatic generation of bins.
void operator=(const distribution &)
List< Pair< scalar > > normalisedMinusMean()
List< Pair< scalar > > raw()
virtual ~distribution()
Destructor.
List< Pair< scalar > > normalised()
List< Pair< scalar > > normalisedShifted(scalar shiftValue)
label totalEntries() const
scalar approxTotalEntries() const
distribution()
Construct null.
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,...
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
#define WarningInFunction
Report a warning using Foam::Warning.
dimensionedScalar sign(const dimensionedScalar &ds)
quaternion normalised(const quaternion &q)
Return the normalised (unit) quaternion of the given quaternion.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Ostream & endl(Ostream &os)
Add newline and flush stream.
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
errorManip< error > abort(error &err)
dimensionedScalar neg(const dimensionedScalar &ds)
constexpr char nl
The newline '\n' character (0x0a)
srcOptions insert("case", fileName(rootDirSource/caseDirSource))
#define forAll(list, i)
Loop across all elements in list.
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.