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();
134 List<label> keys =
toc();
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;
217 iterator iter(this->
begin());
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();
273 List<Pair<scalar>> normDist(size());
279 normDist[
k].first() = (0.5 + scalar(
key))*binWidth_;
281 normDist[
k].second() = scalar((*
this)[
key])/totEnt/binWidth_;
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;
416 List<Pair<scalar>> rawDist(size());
422 rawDist[
k].first() = (0.5 + scalar(
key))*binWidth_;
424 rawDist[
k].second() = scalar((*
this)[
key]);
451 <<
static_cast<const Map<label>&
>(d);
distribution()
Construct null.
scalar approxTotalEntries() const
dimensionedScalar sign(const dimensionedScalar &ds)
label find(const ListType &input, const UnaryPredicate &pred, const label start=0)
Same as ListOps::find_if.
void size(const label n)
Older name for setAddressableSize.
A class for handling file names.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
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...
srcOptions insert("case", fileName(rootDirSource/caseDirSource))
Output to file stream, using an OSstream.
constexpr char nl
The newline '\n' character (0x0a)
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.
quaternion normalised(const quaternion &q)
Return the normalised (unit) quaternion of the given quaternion.
dimensionedScalar neg(const dimensionedScalar &ds)
#define forAll(list, i)
Loop across all elements in list.
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...
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
int debug
Static debugging option.
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
OBJstream os(runTime.globalPath()/outputName)
defineTypeNameAndDebug(combustionModel, 0)
static void write(const fileName &file, const List< Pair< scalar >> &pairs)
Write to file.
T & last()
Access last element of the list, position [size()-1].
List< Pair< scalar > > normalised()
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
List< Pair< scalar > > normalisedMinusMean()
#define WarningInFunction
Report a warning using Foam::Warning.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
List< Pair< scalar > > normalisedShifted(scalar shiftValue)
void operator=(const distribution &)
List< label > sortedToc(const UList< bool > &bools)
Return the (sorted) values corresponding to 'true' entries.
label totalEntries() const
messageStream Info
Information stream (stdout output on master, null elsewhere)
List< Pair< scalar > > raw()
constexpr auto begin(C &c) -> decltype(c.begin())
Return iterator to the beginning of the container c.
List< label > toc(const UList< bool > &bools)
Return the (sorted) values corresponding to 'true' entries.
void operator=(const this_type &rhs)
Copy assignment.
forAllConstIters(mixture.phases(), phase)
A HashTable to objects of type <T> with a label key.