STYLE: distributionModels: modernise code style

This commit is contained in:
Kutalmis Bercin
2021-08-24 09:08:54 +01:00
parent 0feb0e4d7b
commit 89289b0716
20 changed files with 132 additions and 164 deletions

View File

@ -84,12 +84,6 @@ Foam::distributionModels::RosinRammler::RosinRammler(const RosinRammler& p)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::distributionModels::RosinRammler::~RosinRammler()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::scalar Foam::distributionModels::RosinRammler::sample() const

View File

@ -83,7 +83,7 @@ public:
//- Construct from components
RosinRammler(const dictionary& dict, Random& rndGen);
//- Construct copy
//- Copy construct
RosinRammler(const RosinRammler& p);
//- Construct and return a clone
@ -92,17 +92,20 @@ public:
return autoPtr<distributionModel>(new RosinRammler(*this));
}
//- No copy assignment
void operator=(const RosinRammler&) = delete;
//- Destructor
virtual ~RosinRammler();
virtual ~RosinRammler() = default;
// Member Functions
//- Sample the distributionModel
//- Sample the distribution
virtual scalar sample() const;
//- Return the mean value
//- Return the theoretical mean of the distribution
virtual scalar meanValue() const;
};

View File

@ -32,11 +32,11 @@ License
namespace Foam
{
namespace distributionModels
{
defineTypeNameAndDebug(binned, 0);
addToRunTimeSelectionTable(distributionModel, binned, dictionary);
}
namespace distributionModels
{
defineTypeNameAndDebug(binned, 0);
addToRunTimeSelectionTable(distributionModel, binned, dictionary);
}
}
@ -183,27 +183,21 @@ Foam::distributionModels::binned::binned(const binned& p)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::distributionModels::binned::~binned()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::scalar Foam::distributionModels::binned::sample() const
{
scalar y = rndGen_.sample01<scalar>();
const scalar u = rndGen_.sample01<scalar>();
for (label i = 0; i < xy_.size() - 1; ++i)
{
if (xy_[i][1] > y)
if (xy_[i][1] > u)
{
return xy_[i][0];
}
}
return xy_.last()[0];
return maxValue_;
}

View File

@ -70,18 +70,18 @@ class binned
:
public distributionModel
{
// Private data
typedef VectorSpace<Vector<scalar>, scalar, 2> pair;
typedef VectorSpace<Vector<scalar>, scalar, 2> pair;
// Private Data
// List of (bin probability)
// List of (bin probability) pairs
List<pair> xy_;
//- Distribution mean value
//- Mean of the distribution
scalar meanValue_;
// Private member functions
// Private Member Functions
//- Initialise the distribution parameters
void initialise();
@ -101,6 +101,7 @@ public:
binned(const dictionary& dict, Random& rndGen);
//- Construct from components
// Allows negative entries
binned
(
const UList<scalar>& sampleData,
@ -108,7 +109,7 @@ public:
Random& rndGen
);
//- Construct copy
//- Copy construct
binned(const binned& p);
//- Construct and return a clone
@ -117,17 +118,20 @@ public:
return autoPtr<distributionModel>(new binned(*this));
}
//- No copy assignment
void operator=(const binned&) = delete;
//- Destructor
virtual ~binned();
virtual ~binned() = default;
// Member Functions
//- Sample the distributionModel
//- Sample the distribution
virtual scalar sample() const;
//- Return the mean value
//- Return the arithmetic mean of the distribution data
virtual scalar meanValue() const;
//- Write data to stream

View File

@ -100,12 +100,6 @@ Foam::distributionModel::distributionModel
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::distributionModel::~distributionModel()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::scalar Foam::distributionModel::minValue() const

View File

@ -71,10 +71,9 @@ namespace Foam
class distributionModel
{
protected:
// Protected data
// Protected Data
//- Coefficients dictionary
const dictionary distributionModelDict_;
@ -125,7 +124,7 @@ public:
Random& rndGen
);
//- Construct copy
//- Copy construct
distributionModel(const distributionModel& p);
//- Construct and return a clone
@ -141,12 +140,12 @@ public:
//- Destructor
virtual ~distributionModel();
virtual ~distributionModel() = default;
// Member Functions
//- Sample the distributionModel
//- Sample the distribution
virtual scalar sample() const = 0;
//- Return the minimum of the distribution
@ -155,7 +154,8 @@ public:
//- Return the maximum of the distribution
virtual scalar maxValue() const;
//- Return the maximum value
//- Return the theoretical mean of the distribution, or
//- the arithmetic mean of the distribution data
virtual scalar meanValue() const = 0;
};

View File

@ -70,25 +70,20 @@ Foam::distributionModels::exponential::exponential(const exponential& p)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::distributionModels::exponential::~exponential()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::scalar Foam::distributionModels::exponential::sample() const
{
scalar y = rndGen_.sample01<scalar>();
scalar K = exp(-lambda_*maxValue_) - exp(-lambda_*minValue_);
return -(1.0/lambda_)*log(exp(-lambda_*minValue_) + y*K);
const scalar u = rndGen_.sample01<scalar>();
const scalar qMin = exp(-lambda_*minValue_);
const scalar qMax = exp(-lambda_*maxValue_);
return -(scalar(1)/lambda_)*log(qMin + u*(qMax - qMin));
}
Foam::scalar Foam::distributionModels::exponential::meanValue() const
{
return 1.0/lambda_;
return scalar(1)/lambda_;
}

View File

@ -55,11 +55,10 @@ class exponential
:
public distributionModel
{
// Private data
// Private Data
// Model coefficients
scalar lambda_;
//- Rate parameter
scalar lambda_;
public:
@ -73,7 +72,7 @@ public:
//- Construct from components
exponential(const dictionary& dict, Random& rndGen);
//- Construct copy
//- Copy construct
exponential(const exponential& p);
//- Construct and return a clone
@ -82,17 +81,20 @@ public:
return autoPtr<distributionModel>(new exponential(*this));
}
//- No copy assignment
void operator=(const exponential&) = delete;
//- Destructor
virtual ~exponential();
virtual ~exponential() = default;
// Member Functions
//- Sample the distributionModel
//- Sample the distribution
virtual scalar sample() const;
//- Return the mean value
//- Return the theoretical mean of the distribution
virtual scalar meanValue() const;
};

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -67,12 +68,6 @@ Foam::distributionModels::fixedValue::fixedValue(const fixedValue& p)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::distributionModels::fixedValue::~fixedValue()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::scalar Foam::distributionModels::fixedValue::fixedValue::sample() const

View File

@ -53,9 +53,9 @@ class fixedValue
:
public distributionModel
{
// Private data
// Private Data
//- Fixed value
//- Fixed value for size
scalar value_;
@ -70,7 +70,7 @@ public:
//- Construct from components
fixedValue(const dictionary& dict, Random& rndGen);
//- Construct copy
//- Copy construct
fixedValue(const fixedValue& p);
//- Construct and return a clone
@ -79,23 +79,26 @@ public:
return autoPtr<distributionModel>(new fixedValue(*this));
}
//- No copy assignment
void operator=(const fixedValue&) = delete;
//- Destructor
virtual ~fixedValue();
virtual ~fixedValue() = default;
// Member Functions
//- Sample the distributionModel
//- Sample the distribution
virtual scalar sample() const;
//- Return the minimum value
//- Return the minimum of the distribution
virtual scalar minValue() const;
//- Return the maximum value
//- Return the maximum of the distribution
virtual scalar maxValue() const;
//- Return the mean value
//- Return the theoretical mean of the distribution
virtual scalar meanValue() const;
};

View File

@ -162,55 +162,45 @@ Foam::distributionModels::general::general(const general& p)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::distributionModels::general::~general()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::scalar Foam::distributionModels::general::sample() const
{
scalar y = rndGen_.sample01<scalar>();
const scalar u = rndGen_.sample01<scalar>();
// Find the interval where y is in the table
// Find the interval where u is in the table
label n = 1;
while (integral_[n] <= y)
while (integral_[n] <= u)
{
n++;
}
scalar k = (xy_[n][1] - xy_[n-1][1])/(xy_[n][0] - xy_[n-1][0]);
scalar d = xy_[n-1][1] - k*xy_[n-1][0];
const scalar k = (xy_[n][1] - xy_[n-1][1])/(xy_[n][0] - xy_[n-1][0]);
const scalar d = xy_[n-1][1] - k*xy_[n-1][0];
scalar alpha = y + xy_[n-1][0]*(0.5*k*xy_[n-1][0] + d) - integral_[n-1];
scalar x = 0.0;
const scalar alpha =
u + xy_[n-1][0]*(0.5*k*xy_[n-1][0] + d) - integral_[n-1];
// If k is small it is a linear equation, otherwise it is of second order
if (mag(k) > SMALL)
{
scalar p = 2.0*d/k;
scalar q = -2.0*alpha/k;
scalar sqrtEr = sqrt(0.25*p*p - q);
const scalar p = 2.0*d/k;
const scalar q = -2.0*alpha/k;
const scalar sqrtEr = sqrt(0.25*p*p - q);
scalar x1 = -0.5*p + sqrtEr;
scalar x2 = -0.5*p - sqrtEr;
const scalar x1 = -0.5*p + sqrtEr;
const scalar x2 = -0.5*p - sqrtEr;
if ((x1 >= xy_[n-1][0]) && (x1 <= xy_[n][0]))
{
x = x1;
return x1;
}
else
{
x = x2;
return x2;
}
}
else
{
x = alpha/d;
}
return x;
return alpha/d;
}
@ -269,11 +259,11 @@ void Foam::distributionModels::general::readDict(const dictionary& dict)
Foam::tmp<Foam::Field<Foam::scalar>>
Foam::distributionModels::general::x() const
{
tmp<Field<scalar>> tx(new Field<scalar>(xy_.size()));
scalarField& xi = tx.ref();
auto tx = tmp<scalarField>::New(xy_.size());
auto& x = tx.ref();
forAll(xy_, i)
{
xi[i] = xy_[i][0];
x[i] = xy_[i][0];
}
return tx;
@ -283,11 +273,11 @@ Foam::distributionModels::general::x() const
Foam::tmp<Foam::Field<Foam::scalar>>
Foam::distributionModels::general::y() const
{
tmp<Field<scalar>> ty(new Field<scalar>(xy_.size()));
scalarField& yi = ty.ref();
auto ty = tmp<scalarField>::New(xy_.size());
auto& y = ty.ref();
forAll(xy_, i)
{
yi[i] = xy_[i][1];
y[i] = xy_[i][1];
}
return ty;

View File

@ -65,26 +65,29 @@ namespace distributionModels
{
/*---------------------------------------------------------------------------*\
Class general Declaration
Class general Declaration
\*---------------------------------------------------------------------------*/
class general
:
public distributionModel
{
// Private data
typedef VectorSpace<Vector<scalar>, scalar, 2> pair;
typedef VectorSpace<Vector<scalar>, scalar, 2> pair;
// Private Data
// List of (bin probability)
//- List of (x, y=f(x)) pairs
List<pair> xy_;
//- Mean of the distribution
scalar meanValue_;
//- Values of cumulative distribution function
List<scalar> integral_;
// Private member functions
// Private Member Functions
//- Initialise the distribution parameters
void initialise();
@ -102,6 +105,7 @@ public:
general(const dictionary& dict, Random& rndGen);
//- Construct from components
// Allows negative entries
general
(
const UList<scalar>& sampleData,
@ -109,7 +113,7 @@ public:
Random& rndGen
);
//- Construct copy
//- Copy construct
general(const general& p);
//- Construct and return a clone
@ -118,23 +122,26 @@ public:
return autoPtr<distributionModel>(new general(*this));
}
//- No copy assignment
void operator=(const general&) = delete;
//- Destructor
virtual ~general();
virtual ~general() = default;
// Member Functions
//- Bin boundaries
virtual tmp<Field<scalar>> x() const;
virtual tmp<scalarField> x() const;
//- Probabilities
virtual tmp<Field<scalar>> y() const;
virtual tmp<scalarField> y() const;
//- Sample the distributionModel
//- Sample the distribution
virtual scalar sample() const;
//- Return the mean value
//- Return the arithmetic mean of the distribution data
virtual scalar meanValue() const;
//- Write data to stream

View File

@ -77,12 +77,6 @@ Foam::distributionModels::massRosinRammler::massRosinRammler
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::distributionModels::massRosinRammler::~massRosinRammler()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::scalar Foam::distributionModels::massRosinRammler::sample() const

View File

@ -71,13 +71,12 @@ class massRosinRammler
:
public distributionModel
{
// Private data
// Private Data
//- Characteristic droplet size
//- Scale parameter
scalar d_;
//- Empirical dimensionless constant to specify the distribution width,
// sometimes referred to as the dispersion coefficient
//- Shape parameter
scalar n_;
@ -92,7 +91,7 @@ public:
//- Construct from components
massRosinRammler(const dictionary& dict, Random& rndGen);
//- Construct copy
//- Copy construct
massRosinRammler(const massRosinRammler& p);
//- Construct and return a clone
@ -101,17 +100,20 @@ public:
return autoPtr<distributionModel>(new massRosinRammler(*this));
}
//- No copy assignment
void operator=(const massRosinRammler&) = delete;
//- Destructor
virtual ~massRosinRammler();
virtual ~massRosinRammler() = default;
// Member Functions
//- Sample the distributionModel
//- Sample the distribution
virtual scalar sample() const;
//- Return the mean value
//- Return the theoretical mean of the distribution
virtual scalar meanValue() const;
};

View File

@ -92,12 +92,6 @@ Foam::distributionModels::multiNormal::multiNormal(const multiNormal& p)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::distributionModels::multiNormal::~multiNormal()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::scalar Foam::distributionModels::multiNormal::sample() const

View File

@ -60,7 +60,7 @@ class multiNormal
:
public distributionModel
{
// Private data
// Private Data
//- Distribution range
scalar range_;
@ -84,7 +84,7 @@ public:
//- Construct from components
multiNormal(const dictionary& dict, Random& rndGen);
//- Construct copy
//- Copy construct
multiNormal(const multiNormal& p);
//- Construct and return a clone
@ -93,17 +93,20 @@ public:
return autoPtr<distributionModel>(new multiNormal(*this));
}
//- No copy assignment
void operator=(const multiNormal&) = delete;
//- Destructor
virtual ~multiNormal();
virtual ~multiNormal() = default;
// Member Functions
//- Sample the distributionModel
//- Sample the distribution
virtual scalar sample() const;
//- Return the mean value
//- Return the theoretical mean of the distribution
virtual scalar meanValue() const;
};

View File

@ -75,12 +75,6 @@ Foam::distributionModels::normal::normal(const normal& p)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::distributionModels::normal::~normal()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::scalar Foam::distributionModels::normal::sample() const

View File

@ -82,7 +82,7 @@ public:
//- Construct from components
normal(const dictionary& dict, Random& rndGen);
//- Construct copy
//- Copy construct
normal(const normal& p);
//- Construct and return a clone
@ -91,17 +91,20 @@ public:
return autoPtr<distributionModel>(new normal(*this));
}
//- No copy assignment
void operator=(const normal&) = delete;
//- Destructor
virtual ~normal();
virtual ~normal() = default;
// Member Functions
//- Sample the distributionModel
//- Sample the distribution
virtual scalar sample() const;
//- Return the mean value
//- Return the theoretical mean of the distribution
virtual scalar meanValue() const;
};

View File

@ -60,12 +60,6 @@ Foam::distributionModels::uniform::uniform(const uniform& p)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::distributionModels::uniform::~uniform()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::scalar Foam::distributionModels::uniform::sample() const

View File

@ -66,7 +66,7 @@ public:
//- Construct from components
uniform(const dictionary& dict, Random& rndGen);
//- Construct copy
//- Copy construct
uniform(const uniform& p);
//- Construct and return a clone
@ -75,17 +75,20 @@ public:
return autoPtr<distributionModel>(new uniform(*this));
}
//- No copy assignment
void operator=(const uniform&) = delete;
//- Destructor
virtual ~uniform();
virtual ~uniform() = default;
// Member Functions
//- Sample the distributionModel
//- Sample the distribution
virtual scalar sample() const;
//- Return the mean value
//- Return the theoretical mean of the distribution
virtual scalar meanValue() const;
};