Tidying up and comments

This commit is contained in:
graham
2009-11-23 22:44:58 +00:00
parent a700e27f79
commit 08cb452916
2 changed files with 18 additions and 42 deletions

View File

@ -45,17 +45,6 @@ Foam::Distribution<Type>::Distribution(const Type& binWidth)
{} {}
// template<class Type>
// Foam::Distribution<Type>::Distribution
// (
// const cmptType& binWidth
// )
// :
// List< Map<scalar> >(pTraits<Type>::nComponents),
// binWidth_(binWidth*pTraits<Type>::one)
// {}
template<class Type> template<class Type>
Foam::Distribution<Type>::Distribution(const Distribution<Type>& d) Foam::Distribution<Type>::Distribution(const Distribution<Type>& d)
: :
@ -71,10 +60,6 @@ Foam::Distribution<Type>::~Distribution()
{} {}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
template<class Type> template<class Type>
@ -131,9 +116,7 @@ inline Type Foam::Distribution<Type>::median()
for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++) for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
{ {
List<Pair<scalar> >& normDist = normDistribution[cmpt]; List< Pair<scalar> >& normDist = normDistribution[cmpt];
scalar cumulative = 0.0;
if (normDist.size()) if (normDist.size())
{ {
@ -164,6 +147,8 @@ inline Type Foam::Distribution<Type>::median()
{ {
label lastNonZeroIndex = 0; label lastNonZeroIndex = 0;
scalar cumulative = 0.0;
forAll(normDist,nD) forAll(normDist,nD)
{ {
if if
@ -188,7 +173,7 @@ inline Type Foam::Distribution<Type>::median()
break; break;
} }
else if (normDist[nD].second() > 0.0) else if (mag(normDist[nD].second()) > VSMALL)
{ {
cumulative += cumulative +=
normDist[nD].second()*component(binWidth_, cmpt); normDist[nD].second()*component(binWidth_, cmpt);
@ -232,17 +217,6 @@ void Foam::Distribution<Type>::add
{ {
cmptDistribution[n] += component(weight, cmpt); cmptDistribution[n] += component(weight, cmpt);
} }
// if (cmptDistribution[n] < 0)
// {
// FatalErrorIn("Distribution::add(const scalar valueToAdd)")
// << "Accumulated Distribution value has become negative: "
// << "bin = " << (0.5 + scalar(n))*component(binWidth_, cmpt)
// << ", value = " << cmptDistribution[n]
// << ". This is most likely to be because too many samples "
// << "have been added to a bin and the weight has 'rolled round'"
// << abort(FatalError);
// }
} }
} }
@ -290,7 +264,7 @@ Distribution<Type>::normalised()
List<label> keys = cmptDistribution.sortedToc(); List<label> keys = cmptDistribution.sortedToc();
List<Pair<scalar> >& normDist = normDistribution[cmpt]; List< Pair<scalar> >& normDist = normDistribution[cmpt];
normDist.setSize(keys.size()); normDist.setSize(keys.size());
@ -326,7 +300,7 @@ Distribution<Type>::raw()
List<label> keys = cmptDistribution.sortedToc(); List<label> keys = cmptDistribution.sortedToc();
List<Pair<scalar> >& rawDist = rawDistribution[cmpt]; List< Pair<scalar> >& rawDist = rawDistribution[cmpt];
rawDist.setSize(keys.size()); rawDist.setSize(keys.size());
@ -348,7 +322,7 @@ template<class Type>
void Foam::Distribution<Type>::write void Foam::Distribution<Type>::write
( (
const fileName& filePrefix, const fileName& filePrefix,
const List< List<Pair<scalar> > >& pairs const List< List< Pair<scalar> > >& pairs
) const ) const
{ {
if (pairs.size() != pTraits<Type>::nComponents) if (pairs.size() != pTraits<Type>::nComponents)
@ -358,7 +332,7 @@ void Foam::Distribution<Type>::write
"Distribution::write" "Distribution::write"
"(" "("
"const fileName& filePrefix," "const fileName& filePrefix,"
"const List< List<Pair<scalar> > >& pairs" "const List< List< Pair<scalar> > >& pairs"
")" ")"
) )
<< "List of pairs (" << pairs.size() << "List of pairs (" << pairs.size()
@ -369,7 +343,7 @@ void Foam::Distribution<Type>::write
for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++) for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
{ {
const List<Pair<scalar> >& cmptPairs = pairs[cmpt]; const List< Pair<scalar> >& cmptPairs = pairs[cmpt];
OFstream os(filePrefix + '_' + pTraits<Type>::componentNames[cmpt]); OFstream os(filePrefix + '_' + pTraits<Type>::componentNames[cmpt]);

View File

@ -81,9 +81,6 @@ public:
//- Construct from separate binWidth for each component //- Construct from separate binWidth for each component
Distribution(const Type& binWidth); Distribution(const Type& binWidth);
//- Construct from single binWidth for each component
// Distribution(const cmptType& binWidth);
//- Construct as copy //- Construct as copy
Distribution(const Distribution& d); Distribution(const Distribution& d);
@ -93,6 +90,8 @@ public:
// Member Functions // Member Functions
//- Sum the total weight added to the component in the
// argument
scalar totalWeight(direction cmpt) const; scalar totalWeight(direction cmpt) const;
Type mean() const; Type mean() const;
@ -102,28 +101,31 @@ public:
// variable where the cumulative Distribution = 0.5. // variable where the cumulative Distribution = 0.5.
Type median(); Type median();
//- Add a value to the distribution, optionally specifying a weight
void add void add
( (
const Type& valueToAdd, const Type& valueToAdd,
const Type& weight = pTraits<Type>::one const Type& weight = pTraits<Type>::one
); );
//- Add the missing keys to the Maps to fill any gaps
void insertMissingKeys(); void insertMissingKeys();
//- Return the normalised distribution and bins
List< List<Pair<scalar> > > normalised(); List< List<Pair<scalar> > > normalised();
// List<Pair<scalar> > normalisedMinusMean(); //- Return the distribution of the total bin weights
// List<Pair<scalar> > normalisedShifted(scalar shift Value);
List< List < Pair<scalar> > > raw(); List< List < Pair<scalar> > > raw();
// Access // Access
//- Return the bin width
inline const Type& binWidth() const; inline const Type& binWidth() const;
// Write // Write
//- Write the distribution to file. Produces a separate file
// for each component.
void write void write
( (
const fileName& filePrefix, const fileName& filePrefix,