mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: Updated pdfs to employ cachedRandom class
This commit is contained in:
@ -39,7 +39,11 @@ namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::pdfs::RosinRammler::RosinRammler(const dictionary& dict, Random& rndGen)
|
||||
Foam::pdfs::RosinRammler::RosinRammler
|
||||
(
|
||||
const dictionary& dict,
|
||||
cachedRandom& rndGen
|
||||
)
|
||||
:
|
||||
pdf(typeName, dict, rndGen),
|
||||
minValue_(readScalar(pdfDict_.lookup("minValue"))),
|
||||
@ -51,6 +55,16 @@ Foam::pdfs::RosinRammler::RosinRammler(const dictionary& dict, Random& rndGen)
|
||||
}
|
||||
|
||||
|
||||
Foam::pdfs::RosinRammler::RosinRammler(const RosinRammler& p)
|
||||
:
|
||||
pdf(p),
|
||||
minValue_(p.minValue_),
|
||||
maxValue_(p.maxValue_),
|
||||
d_(p.d_),
|
||||
n_(p.n_)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::pdfs::RosinRammler::~RosinRammler()
|
||||
@ -61,9 +75,8 @@ Foam::pdfs::RosinRammler::~RosinRammler()
|
||||
|
||||
Foam::scalar Foam::pdfs::RosinRammler::sample() const
|
||||
{
|
||||
|
||||
scalar K = 1.0 - exp(-pow((maxValue_ - minValue_)/d_, n_));
|
||||
scalar y = rndGen_.scalar01();
|
||||
scalar y = rndGen_.sample01<scalar>();
|
||||
scalar x = minValue_ + d_*::pow(-log(1.0 - y*K), 1.0/n_);
|
||||
return x;
|
||||
}
|
||||
|
||||
@ -82,11 +82,16 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct from components
|
||||
RosinRammler
|
||||
(
|
||||
const dictionary& dict,
|
||||
Random& rndGen
|
||||
);
|
||||
RosinRammler(const dictionary& dict, cachedRandom& rndGen);
|
||||
|
||||
//- Construct copy
|
||||
RosinRammler(const RosinRammler& p);
|
||||
|
||||
//- Construct and return a clone
|
||||
virtual autoPtr<pdf> clone() const
|
||||
{
|
||||
return autoPtr<pdf>(new RosinRammler(*this));
|
||||
}
|
||||
|
||||
|
||||
//- Destructor
|
||||
|
||||
@ -39,7 +39,11 @@ namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::pdfs::exponential::exponential(const dictionary& dict, Random& rndGen)
|
||||
Foam::pdfs::exponential::exponential
|
||||
(
|
||||
const dictionary& dict,
|
||||
cachedRandom& rndGen
|
||||
)
|
||||
:
|
||||
pdf(typeName, dict, rndGen),
|
||||
minValue_(readScalar(pdfDict_.lookup("minValue"))),
|
||||
@ -50,6 +54,15 @@ Foam::pdfs::exponential::exponential(const dictionary& dict, Random& rndGen)
|
||||
}
|
||||
|
||||
|
||||
Foam::pdfs::exponential::exponential(const exponential& p)
|
||||
:
|
||||
pdf(p),
|
||||
minValue_(p.minValue_),
|
||||
maxValue_(p.maxValue_),
|
||||
lambda_(p.lambda_)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::pdfs::exponential::~exponential()
|
||||
@ -60,7 +73,7 @@ Foam::pdfs::exponential::~exponential()
|
||||
|
||||
Foam::scalar Foam::pdfs::exponential::sample() const
|
||||
{
|
||||
scalar y = rndGen_.scalar01();
|
||||
scalar y = rndGen_.sample01<scalar>();
|
||||
scalar K = exp(-lambda_*maxValue_) - exp(-lambda_*minValue_);
|
||||
return -(1.0/lambda_)*log(exp(-lambda_*minValue_) + y*K);
|
||||
}
|
||||
|
||||
@ -75,11 +75,16 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct from components
|
||||
exponential
|
||||
(
|
||||
const dictionary& dict,
|
||||
Random& rndGen
|
||||
);
|
||||
exponential(const dictionary& dict, cachedRandom& rndGen);
|
||||
|
||||
//- Construct copy
|
||||
exponential(const exponential& p);
|
||||
|
||||
//- Construct and return a clone
|
||||
virtual autoPtr<pdf> clone() const
|
||||
{
|
||||
return autoPtr<pdf>(new exponential(*this));
|
||||
}
|
||||
|
||||
|
||||
//- Destructor
|
||||
|
||||
@ -39,13 +39,20 @@ namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::pdfs::fixedValue::fixedValue(const dictionary& dict, Random& rndGen)
|
||||
Foam::pdfs::fixedValue::fixedValue(const dictionary& dict, cachedRandom& rndGen)
|
||||
:
|
||||
pdf(typeName, dict, rndGen),
|
||||
value_(readScalar(pdfDict_.lookup("value")))
|
||||
{}
|
||||
|
||||
|
||||
Foam::pdfs::fixedValue::fixedValue(const fixedValue& p)
|
||||
:
|
||||
pdf(p),
|
||||
value_(p.value_)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::pdfs::fixedValue::~fixedValue()
|
||||
|
||||
@ -66,11 +66,16 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct from components
|
||||
fixedValue
|
||||
(
|
||||
const dictionary& dict,
|
||||
Random& rndGen
|
||||
);
|
||||
fixedValue(const dictionary& dict, cachedRandom& rndGen);
|
||||
|
||||
//- Construct copy
|
||||
fixedValue(const fixedValue& p);
|
||||
|
||||
//- Construct and return a clone
|
||||
virtual autoPtr<pdf> clone() const
|
||||
{
|
||||
return autoPtr<pdf>(new fixedValue(*this));
|
||||
}
|
||||
|
||||
|
||||
//- Destructor
|
||||
|
||||
@ -39,7 +39,7 @@ namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::pdfs::general::general(const dictionary& dict, Random& rndGen)
|
||||
Foam::pdfs::general::general(const dictionary& dict, cachedRandom& rndGen)
|
||||
:
|
||||
pdf(typeName, dict, rndGen),
|
||||
xy_(pdfDict_.lookup("distribution")),
|
||||
@ -74,6 +74,17 @@ Foam::pdfs::general::general(const dictionary& dict, Random& rndGen)
|
||||
}
|
||||
|
||||
|
||||
Foam::pdfs::general::general(const general& p)
|
||||
:
|
||||
pdf(p),
|
||||
xy_(p.xy_),
|
||||
nEntries_(p.nEntries_),
|
||||
minValue_(p.minValue_),
|
||||
maxValue_(p.maxValue_),
|
||||
integral_(p.integral_)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::pdfs::general::~general()
|
||||
@ -84,7 +95,7 @@ Foam::pdfs::general::~general()
|
||||
|
||||
Foam::scalar Foam::pdfs::general::sample() const
|
||||
{
|
||||
scalar y = rndGen_.scalar01();
|
||||
scalar y = rndGen_.sample01<scalar>();
|
||||
|
||||
// find the interval where y is in the table
|
||||
label n=1;
|
||||
|
||||
@ -36,6 +36,8 @@ SourceFiles
|
||||
#define general_H
|
||||
|
||||
#include "pdf.H"
|
||||
#include "Vector.H"
|
||||
#include "VectorSpace.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -76,11 +78,16 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct from components
|
||||
general
|
||||
(
|
||||
const dictionary& dict,
|
||||
Random& rndGen
|
||||
);
|
||||
general(const dictionary& dict, cachedRandom& rndGen);
|
||||
|
||||
//- Construct copy
|
||||
general(const general& p);
|
||||
|
||||
//- Construct and return a clone
|
||||
virtual autoPtr<pdf> clone() const
|
||||
{
|
||||
return autoPtr<pdf>(new general(*this));
|
||||
}
|
||||
|
||||
|
||||
//- Destructor
|
||||
|
||||
@ -39,7 +39,11 @@ namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::pdfs::multiNormal::multiNormal(const dictionary& dict, Random& rndGen)
|
||||
Foam::pdfs::multiNormal::multiNormal
|
||||
(
|
||||
const dictionary& dict,
|
||||
cachedRandom& rndGen
|
||||
)
|
||||
:
|
||||
pdf(typeName, dict, rndGen),
|
||||
minValue_(readScalar(pdfDict_.lookup("minValue"))),
|
||||
@ -77,6 +81,18 @@ Foam::pdfs::multiNormal::multiNormal(const dictionary& dict, Random& rndGen)
|
||||
}
|
||||
|
||||
|
||||
Foam::pdfs::multiNormal::multiNormal(const multiNormal& p)
|
||||
:
|
||||
pdf(p),
|
||||
minValue_(p.minValue_),
|
||||
maxValue_(p.maxValue_),
|
||||
range_(p.range_),
|
||||
expectation_(p.expectation_),
|
||||
variance_(p.variance_),
|
||||
strength_(p.strength_)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::pdfs::multiNormal::~multiNormal()
|
||||
@ -94,8 +110,8 @@ Foam::scalar Foam::pdfs::multiNormal::sample() const
|
||||
|
||||
while (!success)
|
||||
{
|
||||
x = minValue_ + range_*rndGen_.scalar01();
|
||||
y = rndGen_.scalar01();
|
||||
x = minValue_ + range_*rndGen_.sample01<scalar>();
|
||||
y = rndGen_.sample01<scalar>();
|
||||
scalar p = 0.0;
|
||||
|
||||
for (label i=0; i<n; i++)
|
||||
|
||||
@ -85,11 +85,16 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct from components
|
||||
multiNormal
|
||||
(
|
||||
const dictionary& dict,
|
||||
Random& rndGen
|
||||
);
|
||||
multiNormal(const dictionary& dict, cachedRandom& rndGen);
|
||||
|
||||
//- Construct copy
|
||||
multiNormal(const multiNormal& p);
|
||||
|
||||
//- Construct and return a clone
|
||||
virtual autoPtr<pdf> clone() const
|
||||
{
|
||||
return autoPtr<pdf>(new multiNormal(*this));
|
||||
}
|
||||
|
||||
|
||||
//- Destructor
|
||||
|
||||
@ -40,7 +40,7 @@ namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::pdfs::normal::normal(const dictionary& dict, Random& rndGen)
|
||||
Foam::pdfs::normal::normal(const dictionary& dict, cachedRandom& rndGen)
|
||||
:
|
||||
pdf(typeName, dict, rndGen),
|
||||
minValue_(readScalar(pdfDict_.lookup("minValue"))),
|
||||
@ -67,6 +67,17 @@ Foam::pdfs::normal::normal(const dictionary& dict, Random& rndGen)
|
||||
}
|
||||
|
||||
|
||||
Foam::pdfs::normal::normal(const normal& p)
|
||||
:
|
||||
pdf(p),
|
||||
minValue_(p.minValue_),
|
||||
maxValue_(p.maxValue_),
|
||||
expectation_(p.expectation_),
|
||||
variance_(p.variance_),
|
||||
a_(p.a_)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::pdfs::normal::~normal()
|
||||
@ -81,7 +92,7 @@ Foam::scalar Foam::pdfs::normal::sample() const
|
||||
scalar a = erf((minValue_ - expectation_)/variance_);
|
||||
scalar b = erf((maxValue_ - expectation_)/variance_);
|
||||
|
||||
scalar y = rndGen_.scalar01();
|
||||
scalar y = rndGen_.sample01<scalar>();
|
||||
scalar x = erfInv(y*(b - a) + a)*variance_ + expectation_;
|
||||
|
||||
// Note: numerical approximation of the inverse function yields slight
|
||||
|
||||
@ -85,11 +85,16 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct from components
|
||||
normal
|
||||
(
|
||||
const dictionary& dict,
|
||||
Random& rndGen
|
||||
);
|
||||
normal(const dictionary& dict, cachedRandom& rndGen);
|
||||
|
||||
//- Construct copy
|
||||
normal(const normal& p);
|
||||
|
||||
//- Construct and return a clone
|
||||
virtual autoPtr<pdf> clone() const
|
||||
{
|
||||
return autoPtr<pdf>(new normal(*this));
|
||||
}
|
||||
|
||||
|
||||
//- Destructor
|
||||
@ -107,7 +112,7 @@ public:
|
||||
//- Return the maximum value
|
||||
virtual scalar maxValue() const;
|
||||
|
||||
scalar erfInv(const scalar y) const;
|
||||
virtual scalar erfInv(const scalar y) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -61,17 +61,52 @@ void Foam::pdfs::pdf::check() const
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::pdfs::pdf::pdf(const word& name, const dictionary& dict, Random& rndGen)
|
||||
Foam::pdfs::pdf::pdf
|
||||
(
|
||||
const word& name,
|
||||
const dictionary& dict,
|
||||
cachedRandom& rndGen
|
||||
)
|
||||
:
|
||||
pdfDict_(dict.subDict(name + "PDF")),
|
||||
rndGen_(rndGen)
|
||||
{}
|
||||
|
||||
|
||||
Foam::pdfs::pdf::pdf(const pdf& p)
|
||||
:
|
||||
pdfDict_(p.pdfDict_),
|
||||
rndGen_(p.rndGen_)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::pdfs::pdf::~pdf()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
Foam::scalar Foam::pdfs::pdf::sample() const
|
||||
{
|
||||
notImplemented("Foam::scalar Foam::pdfs::pdf::sample() const");
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
|
||||
Foam::scalar Foam::pdfs::pdf::minValue() const
|
||||
{
|
||||
notImplemented("Foam::scalar Foam::pdfs::pdf::minValue() const");
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
|
||||
Foam::scalar Foam::pdfs::pdf::maxValue() const
|
||||
{
|
||||
notImplemented("Foam::scalar Foam::pdfs::pdf::maxValue() const");
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -54,7 +54,7 @@ SourceFiles
|
||||
|
||||
#include "IOdictionary.H"
|
||||
#include "autoPtr.H"
|
||||
#include "Random.H"
|
||||
#include "cachedRandom.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -78,7 +78,7 @@ protected:
|
||||
const dictionary pdfDict_;
|
||||
|
||||
//- Reference to the random number generator
|
||||
Random& rndGen_;
|
||||
cachedRandom& rndGen_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
@ -101,7 +101,7 @@ public:
|
||||
dictionary,
|
||||
(
|
||||
const dictionary& dict,
|
||||
Random& rndGen
|
||||
cachedRandom& rndGen
|
||||
),
|
||||
(dict, rndGen)
|
||||
);
|
||||
@ -110,11 +110,20 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
pdf(const word& name, const dictionary& dict, Random& rndGen);
|
||||
pdf(const word& name, const dictionary& dict, cachedRandom& rndGen);
|
||||
|
||||
//- Construct copy
|
||||
pdf(const pdf& p);
|
||||
|
||||
//- Construct and return a clone
|
||||
virtual autoPtr<pdf> clone() const
|
||||
{
|
||||
return autoPtr<pdf>(new pdf(*this));
|
||||
}
|
||||
|
||||
|
||||
//- Selector
|
||||
static autoPtr<pdf> New(const dictionary& dict, Random& rndGen);
|
||||
static autoPtr<pdf> New(const dictionary& dict, cachedRandom& rndGen);
|
||||
|
||||
|
||||
//- Destructor
|
||||
@ -124,13 +133,13 @@ public:
|
||||
// Member Functions
|
||||
|
||||
//- Sample the pdf
|
||||
virtual scalar sample() const = 0;
|
||||
virtual scalar sample() const;
|
||||
|
||||
//- Return the minimum value
|
||||
virtual scalar minValue() const = 0;
|
||||
virtual scalar minValue() const;
|
||||
|
||||
//- Return the maximum value
|
||||
virtual scalar maxValue() const = 0;
|
||||
virtual scalar maxValue() const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ License
|
||||
Foam::autoPtr<Foam::pdfs::pdf> Foam::pdfs::pdf::New
|
||||
(
|
||||
const dictionary& dict,
|
||||
Random& rndGen
|
||||
cachedRandom& rndGen
|
||||
)
|
||||
{
|
||||
const word modelType(dict.lookup("pdfType"));
|
||||
@ -42,7 +42,7 @@ Foam::autoPtr<Foam::pdfs::pdf> Foam::pdfs::pdf::New
|
||||
|
||||
if (cstrIter == dictionaryConstructorTablePtr_->end())
|
||||
{
|
||||
FatalErrorIn("pdfs::pdf::New(const dictionary&, Random&)")
|
||||
FatalErrorIn("pdfs::pdf::New(const dictionary&, cachedRandom&)")
|
||||
<< "Unknown pdf type " << modelType << nl << nl
|
||||
<< "Valid pdf types are:" << nl
|
||||
<< dictionaryConstructorTablePtr_->sortedToc()
|
||||
|
||||
@ -39,7 +39,7 @@ namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::pdfs::uniform::uniform(const dictionary& dict, Random& rndGen)
|
||||
Foam::pdfs::uniform::uniform(const dictionary& dict, cachedRandom& rndGen)
|
||||
:
|
||||
pdf(typeName, dict, rndGen),
|
||||
minValue_(readScalar(pdfDict_.lookup("minValue"))),
|
||||
@ -50,6 +50,14 @@ Foam::pdfs::uniform::uniform(const dictionary& dict, Random& rndGen)
|
||||
}
|
||||
|
||||
|
||||
Foam::pdfs::uniform::uniform(const uniform& p)
|
||||
:
|
||||
pdf(p),
|
||||
minValue_(p.minValue_),
|
||||
maxValue_(p.maxValue_)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::pdfs::uniform::~uniform()
|
||||
@ -60,7 +68,7 @@ Foam::pdfs::uniform::~uniform()
|
||||
|
||||
Foam::scalar Foam::pdfs::uniform::sample() const
|
||||
{
|
||||
return (minValue_ + rndGen_.scalar01()*range_);
|
||||
return rndGen_.position<scalar>(minValue_, maxValue_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -73,11 +73,16 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct from components
|
||||
uniform
|
||||
(
|
||||
const dictionary& dict,
|
||||
Random& rndGen
|
||||
);
|
||||
uniform(const dictionary& dict, cachedRandom& rndGen);
|
||||
|
||||
//- Construct copy
|
||||
uniform(const uniform& p);
|
||||
|
||||
//- Construct and return a clone
|
||||
virtual autoPtr<pdf> clone() const
|
||||
{
|
||||
return autoPtr<pdf>(new uniform(*this));
|
||||
}
|
||||
|
||||
|
||||
//- Destructor
|
||||
|
||||
Reference in New Issue
Block a user