From 546fdb6207da5baca1f423e02929987e7d7ac5ca Mon Sep 17 00:00:00 2001 From: Andrew Heather <a.heather@opencfd.co.uk> Date: Tue, 20 Mar 2018 10:17:33 +0000 Subject: [PATCH] BUG: corrected 'binned' distribution model --- .../distributionModels/binned/binned.C | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/lagrangian/distributionModels/binned/binned.C b/src/lagrangian/distributionModels/binned/binned.C index 57530fa649c..a5cf7e1f2b6 100644 --- a/src/lagrangian/distributionModels/binned/binned.C +++ b/src/lagrangian/distributionModels/binned/binned.C @@ -47,10 +47,6 @@ const char* Foam::distributionModels::binned::header = void Foam::distributionModels::binned::initialise() { const label nSample(xy_.size()); - forAll(xy_, bini) - { - xy_[bini][1] /= scalar(nSample); - } // Convert values to integral values for (label bini = 1; bini < nSample; ++bini) @@ -58,6 +54,13 @@ void Foam::distributionModels::binned::initialise() xy_[bini][1] += xy_[bini - 1][1]; } + // Normalise + scalar sumProb = xy_.last()[1]; + forAll(xy_, bini) + { + xy_[bini][1] /= sumProb; + } + // Calculate the mean value label bini = 0; forAll(xy_, i) @@ -188,16 +191,7 @@ Foam::scalar Foam::distributionModels::binned::sample() const { if (xy_[i][1] > y) { - scalar d1 = y - xy_[i][1]; - scalar d2 = xy_[i+1][1] - y; - if (d1 < d2) - { - return xy_[i][0]; - } - else - { - return xy_[i+1][0]; - } + return xy_[i][0]; } } -- GitLab