From 867f4197318fc73e1f0dab07e7ae4f6fe400c7b0 Mon Sep 17 00:00:00 2001 From: graham Date: Wed, 10 Feb 2010 17:50:31 +0000 Subject: [PATCH] ENH: Distribution. Basing the Distribution class on a List instead of a Map. Resizing by doubling and mapping data when a new entry is added that is outside of the current bounds. Trimming the output (normalised or raw) to only the entries that contain data. Overriding List clear method to enable the Distribution to be reset, but retaining the correct number of components. --- .../test/Distribution/DistributionTest.C | 2 +- .../Map => Lists}/Distribution/Distribution.C | 272 +++++++++++++----- .../Map => Lists}/Distribution/Distribution.H | 30 +- .../Distribution/DistributionI.H | 7 + .../oldDistribution/oldDistribution.C | 0 .../oldDistribution/oldDistribution.H | 0 .../oldDistribution/oldDistributionI.H | 0 7 files changed, 226 insertions(+), 85 deletions(-) rename src/OpenFOAM/containers/{HashTables/Map => Lists}/Distribution/Distribution.C (62%) rename src/OpenFOAM/containers/{HashTables/Map => Lists}/Distribution/Distribution.H (84%) rename src/OpenFOAM/containers/{HashTables/Map => Lists}/Distribution/DistributionI.H (92%) rename src/OpenFOAM/containers/{HashTables/Map => Lists}/Distribution/oldDistribution/oldDistribution.C (100%) rename src/OpenFOAM/containers/{HashTables/Map => Lists}/Distribution/oldDistribution/oldDistribution.H (100%) rename src/OpenFOAM/containers/{HashTables/Map => Lists}/Distribution/oldDistribution/oldDistributionI.H (100%) 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