diff --git a/applications/test/Distribution/DistributionTest.C b/applications/test/Distribution/DistributionTest.C index 687d5746ac..e59cb1af1e 100644 --- a/applications/test/Distribution/DistributionTest.C +++ b/applications/test/Distribution/DistributionTest.C @@ -34,7 +34,7 @@ Description normalDistribution(mean, sigma, x) = \ sqrt(1.0/(2.0*pi*sigma**2))*exp(-(x - mean)**2.0/(2.0*sigma**2)) - plot normalDistribution(8.5, 2.5, x) + plot normalDistribution(8.5, 2.5, x), "Distribution_scalar_test_x" w p @endverbatim \*---------------------------------------------------------------------------*/ diff --git a/src/OpenFOAM/containers/HashTables/Map/Distribution/Distribution.C b/src/OpenFOAM/containers/Lists/Distribution/Distribution.C similarity index 62% rename from src/OpenFOAM/containers/HashTables/Map/Distribution/Distribution.C rename to src/OpenFOAM/containers/Lists/Distribution/Distribution.C index 93edcef5dc..263853428d 100644 --- a/src/OpenFOAM/containers/HashTables/Map/Distribution/Distribution.C +++ b/src/OpenFOAM/containers/Lists/Distribution/Distribution.C @@ -26,30 +26,134 @@ License #include "Distribution.H" #include "OFstream.H" +#include "ListOps.H" + +// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // + +template +Foam::label Foam::Distribution::index +( + direction cmpt, + label n +) +{ + List& cmptDistribution = (*this)[cmpt]; + + if (cmptDistribution.empty()) + { + // Initialise this list with this value + + cmptDistribution.setSize(2, 0.0); + + listStarts_[cmpt] = n; + + return 0; + } + + label listIndex = -1; + + label& listStart = listStarts_[cmpt]; + + label testIndex = n - listStart; + + if (testIndex < 0) + { + // Underflow of this List, storage increase and remapping + // required + + List newCmptDistribution(2*cmptDistribution.size(), 0.0); + + label sOld = cmptDistribution.size(); + + forAll(cmptDistribution, i) + { + newCmptDistribution[i + sOld] = cmptDistribution[i]; + } + + cmptDistribution = newCmptDistribution; + + listStart -= sOld; + + // Recursively call this function in case another remap is required. + listIndex = index(cmpt, n); + } + else if (testIndex > cmptDistribution.size() - 1) + { + // Overflow of this List, storage increase required + + cmptDistribution.setSize(2*cmptDistribution.size(), 0.0); + + // Recursively call this function in case another storage + // alteration is required. + listIndex = index(cmpt, n); + } + else + { + listIndex = n - listStart; + } + + return listIndex; +} + + +template +Foam::Pair Foam::Distribution::validLimits +( + direction cmpt +) const +{ + const List& cmptDistribution = (*this)[cmpt]; + + // limits.first(): lower bound, i.e. the first non-zero entry + // limits.second(): upper bound, i.e. the last non-zero entry + Pair