diff --git a/src/thermophysicalModels/pdfs/RosinRammler/RosinRammler.C b/src/thermophysicalModels/pdfs/RosinRammler/RosinRammler.C index f634d252640c00a528a35264a3b5db8a087ec824..ee4207b07880055d80817fe08c59e14d49ce1736 100644 --- a/src/thermophysicalModels/pdfs/RosinRammler/RosinRammler.C +++ b/src/thermophysicalModels/pdfs/RosinRammler/RosinRammler.C @@ -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; } diff --git a/src/thermophysicalModels/pdfs/RosinRammler/RosinRammler.H b/src/thermophysicalModels/pdfs/RosinRammler/RosinRammler.H index 4a5a3d379f874d09c446604f5ee4f654204525b7..9a37742340e28dc3871b5610b585fb3a1bc9a295 100644 --- a/src/thermophysicalModels/pdfs/RosinRammler/RosinRammler.H +++ b/src/thermophysicalModels/pdfs/RosinRammler/RosinRammler.H @@ -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 diff --git a/src/thermophysicalModels/pdfs/exponential/exponential.C b/src/thermophysicalModels/pdfs/exponential/exponential.C index 6255ca18276c9fca06556f064e36c08bb24e5702..b4162a27a32fdb43863b6f2282bb53dcb7cc28b4 100644 --- a/src/thermophysicalModels/pdfs/exponential/exponential.C +++ b/src/thermophysicalModels/pdfs/exponential/exponential.C @@ -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); } diff --git a/src/thermophysicalModels/pdfs/exponential/exponential.H b/src/thermophysicalModels/pdfs/exponential/exponential.H index 9a28455480ef75192f0ecfd85ec4d2fcfef104ef..655db25c1e9e6c5e269af8d5238d8f120a3d4bda 100644 --- a/src/thermophysicalModels/pdfs/exponential/exponential.H +++ b/src/thermophysicalModels/pdfs/exponential/exponential.H @@ -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 diff --git a/src/thermophysicalModels/pdfs/fixedValue/fixedValue.C b/src/thermophysicalModels/pdfs/fixedValue/fixedValue.C index b8afd67303645161d3941828b6bfd41dc1e8ff38..5808c5dbb523a05c6101fa7922d52c5e1c5710d3 100644 --- a/src/thermophysicalModels/pdfs/fixedValue/fixedValue.C +++ b/src/thermophysicalModels/pdfs/fixedValue/fixedValue.C @@ -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() diff --git a/src/thermophysicalModels/pdfs/fixedValue/fixedValue.H b/src/thermophysicalModels/pdfs/fixedValue/fixedValue.H index 97fd3c4a4e21f05708c0db7b2c441a2634b1ac6d..c2905114286ed4f61287701b1c3d8451c368eaf6 100644 --- a/src/thermophysicalModels/pdfs/fixedValue/fixedValue.H +++ b/src/thermophysicalModels/pdfs/fixedValue/fixedValue.H @@ -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 diff --git a/src/thermophysicalModels/pdfs/general/general.C b/src/thermophysicalModels/pdfs/general/general.C index da674ee2ad69393f96081a116bd4fb6108e761bf..7361892850517b0c07c3d99129860cf429f1bd23 100644 --- a/src/thermophysicalModels/pdfs/general/general.C +++ b/src/thermophysicalModels/pdfs/general/general.C @@ -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; diff --git a/src/thermophysicalModels/pdfs/general/general.H b/src/thermophysicalModels/pdfs/general/general.H index 5c178443a628ef480a45a8817d33b9b1ba84ff23..dcc81459eb562f8d5e8c4ead3f3f0ea552572a32 100644 --- a/src/thermophysicalModels/pdfs/general/general.H +++ b/src/thermophysicalModels/pdfs/general/general.H @@ -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 diff --git a/src/thermophysicalModels/pdfs/multiNormal/multiNormal.C b/src/thermophysicalModels/pdfs/multiNormal/multiNormal.C index 21b7c8fb2a1a1a573710580cd5e36da5c2fb3b69..554063bdbf2a6e889af5fa82a07a83a90b3c4184 100644 --- a/src/thermophysicalModels/pdfs/multiNormal/multiNormal.C +++ b/src/thermophysicalModels/pdfs/multiNormal/multiNormal.C @@ -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++) diff --git a/src/thermophysicalModels/pdfs/multiNormal/multiNormal.H b/src/thermophysicalModels/pdfs/multiNormal/multiNormal.H index 70947604f3b6ce9b51c569cf4ba3080c87b6d3f6..4b8a9dc731b0a89873bec515197993bae6f16377 100644 --- a/src/thermophysicalModels/pdfs/multiNormal/multiNormal.H +++ b/src/thermophysicalModels/pdfs/multiNormal/multiNormal.H @@ -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 diff --git a/src/thermophysicalModels/pdfs/normal/normal.C b/src/thermophysicalModels/pdfs/normal/normal.C index ed2308cb5b144f0d6224cdd70741e3c734f1b429..56c4a0460d2a23f4a59c6fac80dc3fabad0bb887 100644 --- a/src/thermophysicalModels/pdfs/normal/normal.C +++ b/src/thermophysicalModels/pdfs/normal/normal.C @@ -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 diff --git a/src/thermophysicalModels/pdfs/normal/normal.H b/src/thermophysicalModels/pdfs/normal/normal.H index 44aae0f7b0b6186e9c4b8f584439a98be2b0ab82..e7dde44aa20491a95543d5d55338c664fd3e1bd5 100644 --- a/src/thermophysicalModels/pdfs/normal/normal.H +++ b/src/thermophysicalModels/pdfs/normal/normal.H @@ -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; }; diff --git a/src/thermophysicalModels/pdfs/pdf/pdf.C b/src/thermophysicalModels/pdfs/pdf/pdf.C index 5d6e5693b7bb57fc39a02517377f7680572657ea..822311de7fbaa6ae252446c636160393bc0090c4 100644 --- a/src/thermophysicalModels/pdfs/pdf/pdf.C +++ b/src/thermophysicalModels/pdfs/pdf/pdf.C @@ -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; +} + + // ************************************************************************* // diff --git a/src/thermophysicalModels/pdfs/pdf/pdf.H b/src/thermophysicalModels/pdfs/pdf/pdf.H index d6dbf8fb90fc3c41c9a20c3bd653850866bb3e51..ddf006c072671be4a0b33c314ade0a866bd6ea84 100644 --- a/src/thermophysicalModels/pdfs/pdf/pdf.H +++ b/src/thermophysicalModels/pdfs/pdf/pdf.H @@ -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; }; diff --git a/src/thermophysicalModels/pdfs/pdf/pdfNew.C b/src/thermophysicalModels/pdfs/pdf/pdfNew.C index c4144ee5630a465e55beb861d6476c7584ae9b48..d903726ac7a2dc8ae868ee35138b60f799632b1a 100644 --- a/src/thermophysicalModels/pdfs/pdf/pdfNew.C +++ b/src/thermophysicalModels/pdfs/pdf/pdfNew.C @@ -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() diff --git a/src/thermophysicalModels/pdfs/uniform/uniform.C b/src/thermophysicalModels/pdfs/uniform/uniform.C index 1aa0e3d14533c102ab06666cd64f853f47577403..3a5fa5d564d6f008b9db957098a132088846d32a 100644 --- a/src/thermophysicalModels/pdfs/uniform/uniform.C +++ b/src/thermophysicalModels/pdfs/uniform/uniform.C @@ -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_); } diff --git a/src/thermophysicalModels/pdfs/uniform/uniform.H b/src/thermophysicalModels/pdfs/uniform/uniform.H index a4cc6e32c68a8ffbabcae779ae0031e212dc4baf..a56f24933af5213d2132a171137e2cfc010312aa 100644 --- a/src/thermophysicalModels/pdfs/uniform/uniform.H +++ b/src/thermophysicalModels/pdfs/uniform/uniform.H @@ -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