Commit 0a4ba61e authored by Andrew Heather's avatar Andrew Heather
Browse files

BUG: corrected 'binned' distribution model

parent bf182b18
...@@ -47,10 +47,6 @@ const char* Foam::distributionModels::binned::header = ...@@ -47,10 +47,6 @@ const char* Foam::distributionModels::binned::header =
void Foam::distributionModels::binned::initialise() void Foam::distributionModels::binned::initialise()
{ {
const label nSample(xy_.size()); const label nSample(xy_.size());
forAll(xy_, bini)
{
xy_[bini][1] /= scalar(nSample);
}
// Convert values to integral values // Convert values to integral values
for (label bini = 1; bini < nSample; ++bini) for (label bini = 1; bini < nSample; ++bini)
...@@ -58,6 +54,13 @@ void Foam::distributionModels::binned::initialise() ...@@ -58,6 +54,13 @@ void Foam::distributionModels::binned::initialise()
xy_[bini][1] += xy_[bini - 1][1]; xy_[bini][1] += xy_[bini - 1][1];
} }
// Normalise
scalar sumProb = xy_.last()[1];
forAll(xy_, bini)
{
xy_[bini][1] /= sumProb;
}
// Calculate the mean value // Calculate the mean value
label bini = 0; label bini = 0;
forAll(xy_, i) forAll(xy_, i)
...@@ -188,16 +191,7 @@ Foam::scalar Foam::distributionModels::binned::sample() const ...@@ -188,16 +191,7 @@ Foam::scalar Foam::distributionModels::binned::sample() const
{ {
if (xy_[i][1] > y) if (xy_[i][1] > y)
{ {
scalar d1 = y - xy_[i][1]; return xy_[i][0];
scalar d2 = xy_[i+1][1] - y;
if (d1 < d2)
{
return xy_[i][0];
}
else
{
return xy_[i+1][0];
}
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment