mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Merge remote branch 'OpenCFD/master' into olesenm
This commit is contained in:
@ -93,6 +93,8 @@ int main(int argc, char *argv[])
|
|||||||
kappa = (runTime.deltaT() + tc)/(runTime.deltaT()+tc+tk);
|
kappa = (runTime.deltaT() + tc)/(runTime.deltaT()+tc+tk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chemistrySh = kappa*chemistry.Sh()();
|
||||||
|
|
||||||
#include "rhoEqn.H"
|
#include "rhoEqn.H"
|
||||||
#include "UEqn.H"
|
#include "UEqn.H"
|
||||||
|
|
||||||
|
|||||||
@ -10,9 +10,32 @@
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
label nIntervals(readLabel(pdfDictionary.lookup("nIntervals")));
|
const label nIntervals(readLabel(pdfDictionary.lookup("nIntervals")));
|
||||||
|
|
||||||
label nSamples(readLabel(pdfDictionary.lookup("nSamples")));
|
const label nSamples(readLabel(pdfDictionary.lookup("nSamples")));
|
||||||
|
|
||||||
|
const bool writeData(readBool(pdfDictionary.lookup("writeData")));
|
||||||
|
|
||||||
|
|
||||||
|
const fileName pdfPath = runTime.path()/"pdf";
|
||||||
|
mkDir(pdfPath);
|
||||||
|
|
||||||
|
Random rndGen(label(0));
|
||||||
|
|
||||||
|
autoPtr<pdfs::pdf> p(pdfs::pdf::New(pdfDictionary, rndGen));
|
||||||
|
|
||||||
|
const scalar xMin = p->minValue();
|
||||||
|
const scalar xMax = p->maxValue();
|
||||||
|
|
||||||
|
autoPtr<OFstream> filePtr(NULL);
|
||||||
|
if (writeData)
|
||||||
|
{
|
||||||
|
fileName fName = pdfPath/(p->type() + ".data");
|
||||||
|
Info<< "Writing " << p->type() << " data samples to file:" << nl
|
||||||
|
<< fName << nl << endl;
|
||||||
|
|
||||||
|
filePtr.reset(new OFstream(fName));
|
||||||
|
}
|
||||||
|
|
||||||
scalarField samples(nIntervals, 0);
|
scalarField samples(nIntervals, 0);
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,10 @@ nSamples 10000;
|
|||||||
// Type of pdf
|
// Type of pdf
|
||||||
pdfType RosinRammler;
|
pdfType RosinRammler;
|
||||||
|
|
||||||
|
// Write data flag
|
||||||
|
writeData true;
|
||||||
|
|
||||||
|
// PDF model coefficients
|
||||||
RosinRammlerPDF
|
RosinRammlerPDF
|
||||||
{
|
{
|
||||||
minValue 1e-06;
|
minValue 1e-06;
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -29,6 +29,7 @@ Description
|
|||||||
#include "fvCFD.H"
|
#include "fvCFD.H"
|
||||||
#include "pdf.H"
|
#include "pdf.H"
|
||||||
#include "makeGraph.H"
|
#include "makeGraph.H"
|
||||||
|
#include "OFstream.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
// Main program:
|
// Main program:
|
||||||
@ -39,16 +40,6 @@ int main(int argc, char *argv[])
|
|||||||
#include "createTime.H"
|
#include "createTime.H"
|
||||||
#include "createFields.H"
|
#include "createFields.H"
|
||||||
|
|
||||||
fileName pdfPath = runTime.path()/"pdf";
|
|
||||||
mkDir(pdfPath);
|
|
||||||
|
|
||||||
Random rndGen(label(0));
|
|
||||||
|
|
||||||
autoPtr<pdf> p(pdf::New(pdfDictionary, rndGen));
|
|
||||||
|
|
||||||
scalar xMin = p->minValue();
|
|
||||||
scalar xMax = p->maxValue();
|
|
||||||
|
|
||||||
label iCheck = 100;
|
label iCheck = 100;
|
||||||
for (label i=1; i<=nSamples; i++)
|
for (label i=1; i<=nSamples; i++)
|
||||||
{
|
{
|
||||||
@ -56,6 +47,11 @@ int main(int argc, char *argv[])
|
|||||||
label n = label((ps - xMin)*nIntervals/(xMax - xMin));
|
label n = label((ps - xMin)*nIntervals/(xMax - xMin));
|
||||||
samples[n]++;
|
samples[n]++;
|
||||||
|
|
||||||
|
if (writeData)
|
||||||
|
{
|
||||||
|
filePtr() << ps << nl;
|
||||||
|
}
|
||||||
|
|
||||||
if (i % iCheck == 0)
|
if (i % iCheck == 0)
|
||||||
{
|
{
|
||||||
Info<< " processed " << i << " samples" << endl;
|
Info<< " processed " << i << " samples" << endl;
|
||||||
|
|||||||
@ -25,8 +25,8 @@ Class
|
|||||||
Foam::interpolationTable
|
Foam::interpolationTable
|
||||||
|
|
||||||
Description
|
Description
|
||||||
A list of times and values.
|
An interpolation/look-up table of scalar vs <Type> values.
|
||||||
The time values must be positive and monotonically increasing.
|
The reference scalar values must be positive and monotonically increasing.
|
||||||
|
|
||||||
The handling of out-of-bounds values depends on the current setting
|
The handling of out-of-bounds values depends on the current setting
|
||||||
of @a outOfBounds.
|
of @a outOfBounds.
|
||||||
|
|||||||
@ -54,7 +54,7 @@ Foam::ChomiakInjector::ChomiakInjector
|
|||||||
ChomiakDict_(dict.subDict(typeName + "Coeffs")),
|
ChomiakDict_(dict.subDict(typeName + "Coeffs")),
|
||||||
dropletPDF_
|
dropletPDF_
|
||||||
(
|
(
|
||||||
pdf::New
|
pdfs::pdf::New
|
||||||
(
|
(
|
||||||
ChomiakDict_.subDict("dropletPDF"),
|
ChomiakDict_.subDict("dropletPDF"),
|
||||||
sm.rndGen()
|
sm.rndGen()
|
||||||
|
|||||||
@ -63,7 +63,7 @@ private:
|
|||||||
|
|
||||||
dictionary ChomiakDict_;
|
dictionary ChomiakDict_;
|
||||||
|
|
||||||
autoPtr<pdf> dropletPDF_;
|
autoPtr<pdfs::pdf> dropletPDF_;
|
||||||
scalarList maxSprayAngle_;
|
scalarList maxSprayAngle_;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -54,7 +54,7 @@ Foam::definedHollowConeInjector::definedHollowConeInjector
|
|||||||
definedHollowConeDict_(dict.subDict(typeName + "Coeffs")),
|
definedHollowConeDict_(dict.subDict(typeName + "Coeffs")),
|
||||||
dropletPDF_
|
dropletPDF_
|
||||||
(
|
(
|
||||||
pdf::New
|
pdfs::pdf::New
|
||||||
(
|
(
|
||||||
definedHollowConeDict_.subDict("dropletPDF"),
|
definedHollowConeDict_.subDict("dropletPDF"),
|
||||||
sm.rndGen()
|
sm.rndGen()
|
||||||
|
|||||||
@ -60,7 +60,7 @@ private:
|
|||||||
typedef VectorSpace<Vector<scalar>, scalar, 2> pair;
|
typedef VectorSpace<Vector<scalar>, scalar, 2> pair;
|
||||||
|
|
||||||
dictionary definedHollowConeDict_;
|
dictionary definedHollowConeDict_;
|
||||||
autoPtr<pdf> dropletPDF_;
|
autoPtr<pdfs::pdf> dropletPDF_;
|
||||||
|
|
||||||
// inner and outer cone angle time histories
|
// inner and outer cone angle time histories
|
||||||
// 2 column vectors = (time, coneAngle)
|
// 2 column vectors = (time, coneAngle)
|
||||||
|
|||||||
@ -54,7 +54,7 @@ Foam::hollowConeInjector::hollowConeInjector
|
|||||||
hollowConeDict_(dict.subDict(typeName + "Coeffs")),
|
hollowConeDict_(dict.subDict(typeName + "Coeffs")),
|
||||||
dropletPDF_
|
dropletPDF_
|
||||||
(
|
(
|
||||||
pdf::New
|
pdfs::pdf::New
|
||||||
(
|
(
|
||||||
hollowConeDict_.subDict("dropletPDF"),
|
hollowConeDict_.subDict("dropletPDF"),
|
||||||
sm.rndGen()
|
sm.rndGen()
|
||||||
|
|||||||
@ -58,7 +58,7 @@ private:
|
|||||||
|
|
||||||
dictionary hollowConeDict_;
|
dictionary hollowConeDict_;
|
||||||
|
|
||||||
autoPtr<pdf> dropletPDF_;
|
autoPtr<pdfs::pdf> dropletPDF_;
|
||||||
scalarList innerAngle_;
|
scalarList innerAngle_;
|
||||||
scalarList outerAngle_;
|
scalarList outerAngle_;
|
||||||
|
|
||||||
|
|||||||
@ -119,7 +119,7 @@ Foam::ConeInjection<CloudType>::ConeInjection
|
|||||||
),
|
),
|
||||||
parcelPDF_
|
parcelPDF_
|
||||||
(
|
(
|
||||||
pdf::New
|
pdfs::pdf::New
|
||||||
(
|
(
|
||||||
this->coeffDict().subDict("parcelPDF"),
|
this->coeffDict().subDict("parcelPDF"),
|
||||||
owner.rndGen()
|
owner.rndGen()
|
||||||
|
|||||||
@ -96,7 +96,7 @@ class ConeInjection
|
|||||||
const autoPtr<DataEntry<scalar> > thetaOuter_;
|
const autoPtr<DataEntry<scalar> > thetaOuter_;
|
||||||
|
|
||||||
//- Parcel size PDF model
|
//- Parcel size PDF model
|
||||||
const autoPtr<pdf> parcelPDF_;
|
const autoPtr<pdfs::pdf> parcelPDF_;
|
||||||
|
|
||||||
|
|
||||||
// Tangential vectors to the direction vector
|
// Tangential vectors to the direction vector
|
||||||
|
|||||||
@ -150,7 +150,7 @@ Foam::ConeInjectionMP<CloudType>::ConeInjectionMP
|
|||||||
),
|
),
|
||||||
parcelPDF_
|
parcelPDF_
|
||||||
(
|
(
|
||||||
pdf::New
|
pdfs::pdf::New
|
||||||
(
|
(
|
||||||
this->coeffDict().subDict("parcelPDF"),
|
this->coeffDict().subDict("parcelPDF"),
|
||||||
owner.rndGen()
|
owner.rndGen()
|
||||||
|
|||||||
@ -103,7 +103,7 @@ class ConeInjectionMP
|
|||||||
const autoPtr<DataEntry<scalar> > thetaOuter_;
|
const autoPtr<DataEntry<scalar> > thetaOuter_;
|
||||||
|
|
||||||
//- Parcel size PDF model
|
//- Parcel size PDF model
|
||||||
const autoPtr<pdf> parcelPDF_;
|
const autoPtr<pdfs::pdf> parcelPDF_;
|
||||||
|
|
||||||
//- Number of parcels per injector already injected
|
//- Number of parcels per injector already injected
|
||||||
mutable label nInjected_;
|
mutable label nInjected_;
|
||||||
|
|||||||
@ -114,7 +114,7 @@ Foam::FieldActivatedInjection<CloudType>::FieldActivatedInjection
|
|||||||
diameters_(positions_.size()),
|
diameters_(positions_.size()),
|
||||||
parcelPDF_
|
parcelPDF_
|
||||||
(
|
(
|
||||||
pdf::New
|
pdfs::pdf::New
|
||||||
(
|
(
|
||||||
this->coeffDict().subDict("parcelPDF"),
|
this->coeffDict().subDict("parcelPDF"),
|
||||||
owner.rndGen()
|
owner.rndGen()
|
||||||
|
|||||||
@ -105,7 +105,7 @@ class FieldActivatedInjection
|
|||||||
scalarList diameters_;
|
scalarList diameters_;
|
||||||
|
|
||||||
//- Parcel size PDF model
|
//- Parcel size PDF model
|
||||||
const autoPtr<pdf> parcelPDF_;
|
const autoPtr<pdfs::pdf> parcelPDF_;
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@ -93,7 +93,7 @@ Foam::ManualInjection<CloudType>::ManualInjection
|
|||||||
U0_(this->coeffDict().lookup("U0")),
|
U0_(this->coeffDict().lookup("U0")),
|
||||||
parcelPDF_
|
parcelPDF_
|
||||||
(
|
(
|
||||||
pdf::New
|
pdfs::pdf::New
|
||||||
(
|
(
|
||||||
this->coeffDict().subDict("parcelPDF"),
|
this->coeffDict().subDict("parcelPDF"),
|
||||||
owner.rndGen()
|
owner.rndGen()
|
||||||
|
|||||||
@ -74,7 +74,7 @@ class ManualInjection
|
|||||||
const vector U0_;
|
const vector U0_;
|
||||||
|
|
||||||
//- Parcel size PDF model
|
//- Parcel size PDF model
|
||||||
const autoPtr<pdf> parcelPDF_;
|
const autoPtr<pdfs::pdf> parcelPDF_;
|
||||||
|
|
||||||
//- Number of particles represented by each parcel
|
//- Number of particles represented by each parcel
|
||||||
scalar nParticlesPerParcel_;
|
scalar nParticlesPerParcel_;
|
||||||
|
|||||||
@ -92,7 +92,7 @@ Foam::PatchInjection<CloudType>::PatchInjection
|
|||||||
),
|
),
|
||||||
parcelPDF_
|
parcelPDF_
|
||||||
(
|
(
|
||||||
pdf::New
|
pdfs::pdf::New
|
||||||
(
|
(
|
||||||
this->coeffDict().subDict("parcelPDF"),
|
this->coeffDict().subDict("parcelPDF"),
|
||||||
owner.rndGen()
|
owner.rndGen()
|
||||||
|
|||||||
@ -83,7 +83,7 @@ class PatchInjection
|
|||||||
const autoPtr<DataEntry<scalar> > volumeFlowRate_;
|
const autoPtr<DataEntry<scalar> > volumeFlowRate_;
|
||||||
|
|
||||||
//- Parcel size PDF model
|
//- Parcel size PDF model
|
||||||
const autoPtr<pdf> parcelPDF_;
|
const autoPtr<pdfs::pdf> parcelPDF_;
|
||||||
|
|
||||||
//- Cell owners
|
//- Cell owners
|
||||||
labelList cellOwners_;
|
labelList cellOwners_;
|
||||||
|
|||||||
@ -1,17 +1,12 @@
|
|||||||
pdf = pdf
|
pdf/pdf.C
|
||||||
uniform = uniform
|
pdf/newPdf.C
|
||||||
normal = normal
|
|
||||||
general = general
|
|
||||||
exponential = exponential
|
|
||||||
RosinRammler = RosinRammler
|
|
||||||
|
|
||||||
$(pdf)/pdf.C
|
exponential/exponential.C
|
||||||
$(pdf)/newPdf.C
|
fixedValue/fixedValue.C
|
||||||
|
general/general.C
|
||||||
$(uniform)/uniform.C
|
multiNormal/multiNormal.C
|
||||||
$(normal)/normal.C
|
normal/normal.C
|
||||||
$(general)/general.C
|
RosinRammler/RosinRammler.C
|
||||||
$(exponential)/exponential.C
|
uniform/uniform.C
|
||||||
$(RosinRammler)/RosinRammler.C
|
|
||||||
|
|
||||||
LIB = $(FOAM_LIBBIN)/libpdf
|
LIB = $(FOAM_LIBBIN)/libpdf
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -29,107 +29,53 @@ License
|
|||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace pdfs
|
||||||
{
|
{
|
||||||
defineTypeNameAndDebug(RosinRammler, 0);
|
defineTypeNameAndDebug(RosinRammler, 0);
|
||||||
|
|
||||||
addToRunTimeSelectionTable(pdf, RosinRammler, dictionary);
|
addToRunTimeSelectionTable(pdf, RosinRammler, dictionary);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::RosinRammler::RosinRammler(const dictionary& dict, Random& rndGen)
|
Foam::pdfs::RosinRammler::RosinRammler(const dictionary& dict, Random& rndGen)
|
||||||
:
|
:
|
||||||
pdf(dict, rndGen),
|
pdf(typeName, dict, rndGen),
|
||||||
pdfDict_(dict.subDict(typeName + "PDF")),
|
|
||||||
minValue_(readScalar(pdfDict_.lookup("minValue"))),
|
minValue_(readScalar(pdfDict_.lookup("minValue"))),
|
||||||
maxValue_(readScalar(pdfDict_.lookup("maxValue"))),
|
maxValue_(readScalar(pdfDict_.lookup("maxValue"))),
|
||||||
d_(pdfDict_.lookup("d")),
|
d_(readScalar(pdfDict_.lookup("d"))),
|
||||||
n_(pdfDict_.lookup("n")),
|
n_(readScalar(pdfDict_.lookup("n")))
|
||||||
ls_(d_),
|
|
||||||
range_(maxValue_ - minValue_)
|
|
||||||
{
|
{
|
||||||
if (minValue_<0)
|
check();
|
||||||
{
|
|
||||||
FatalErrorIn
|
|
||||||
(
|
|
||||||
"RosinRammler::RosinRammler(const dictionary& dict)"
|
|
||||||
) << " minValue = " << minValue_ << ", it must be >0." << nl
|
|
||||||
<< abort(FatalError);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (maxValue_<minValue_)
|
|
||||||
{
|
|
||||||
FatalErrorIn
|
|
||||||
(
|
|
||||||
"RosinRammler::RosinRammler(const dictionary& dict)"
|
|
||||||
) << " maxValue is smaller than minValue." << nl
|
|
||||||
<< abort(FatalError);
|
|
||||||
}
|
|
||||||
|
|
||||||
// find max value so that it can be normalized to 1.0
|
|
||||||
scalar sMax = 0;
|
|
||||||
label n = d_.size();
|
|
||||||
for (label i=0; i<n; i++)
|
|
||||||
{
|
|
||||||
scalar s = exp(-1.0);
|
|
||||||
for (label j=0; j<n; j++)
|
|
||||||
{
|
|
||||||
if (i!=j)
|
|
||||||
{
|
|
||||||
scalar xx = pow(d_[j]/d_[i], n_[j]);
|
|
||||||
scalar y = xx*exp(-xx);
|
|
||||||
s += y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sMax = max(sMax, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (label i=0; i<n; i++)
|
|
||||||
{
|
|
||||||
ls_[i] /= sMax;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::RosinRammler::~RosinRammler()
|
Foam::pdfs::RosinRammler::~RosinRammler()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::scalar Foam::RosinRammler::sample() const
|
Foam::scalar Foam::pdfs::RosinRammler::sample() const
|
||||||
{
|
{
|
||||||
scalar y = 0;
|
|
||||||
scalar x = 0;
|
|
||||||
scalar p = 0.0;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
x = minValue_ + range_*rndGen_.scalar01();
|
|
||||||
y = rndGen_.scalar01();
|
|
||||||
p = 0.0;
|
|
||||||
|
|
||||||
forAll(d_, i)
|
|
||||||
{
|
|
||||||
scalar xx = pow(x/d_[i], n_[i]);
|
|
||||||
p += ls_[i]*xx*exp(-xx);
|
|
||||||
}
|
|
||||||
} while (y>p);
|
|
||||||
|
|
||||||
|
scalar K = 1.0 - exp(-pow((maxValue_ - minValue_)/d_, n_));
|
||||||
|
scalar y = rndGen_.scalar01();
|
||||||
|
scalar x = minValue_ + d_*::pow(-log(1.0 - y*K), 1.0/n_);
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::scalar Foam::RosinRammler::minValue() const
|
Foam::scalar Foam::pdfs::RosinRammler::minValue() const
|
||||||
{
|
{
|
||||||
return minValue_;
|
return minValue_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::scalar Foam::RosinRammler::maxValue() const
|
Foam::scalar Foam::pdfs::RosinRammler::maxValue() const
|
||||||
{
|
{
|
||||||
return maxValue_;
|
return maxValue_;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -28,14 +28,12 @@ Description
|
|||||||
Rosin-Rammler pdf
|
Rosin-Rammler pdf
|
||||||
|
|
||||||
@f[
|
@f[
|
||||||
pdf = ( x/d )^n \exp ( -( x/d )^n )
|
cumulative pdf = (1.0 - exp( -((x - d0)/d)^n ) / (1.0 - exp( -((d1 - d0)/d)^n )
|
||||||
@f]
|
@f]
|
||||||
|
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
RosinRammlerI.H
|
|
||||||
RosinRammler.C
|
RosinRammler.C
|
||||||
RosinRammlerIO.C
|
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -48,6 +46,8 @@ SourceFiles
|
|||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
namespace pdfs
|
||||||
|
{
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class RosinRammler Declaration
|
Class RosinRammler Declaration
|
||||||
@ -59,17 +59,16 @@ class RosinRammler
|
|||||||
{
|
{
|
||||||
// Private data
|
// Private data
|
||||||
|
|
||||||
dictionary pdfDict_;
|
//- Distribution minimum
|
||||||
|
|
||||||
//- min and max values of the distribution
|
|
||||||
scalar minValue_;
|
scalar minValue_;
|
||||||
|
|
||||||
|
//- Distribution maximum
|
||||||
scalar maxValue_;
|
scalar maxValue_;
|
||||||
|
|
||||||
List<scalar> d_;
|
// Model coefficients
|
||||||
List<scalar> n_;
|
|
||||||
List<scalar> ls_;
|
|
||||||
|
|
||||||
scalar range_;
|
scalar d_;
|
||||||
|
scalar n_;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -107,6 +106,7 @@ public:
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace pdfs
|
||||||
} // End namespace Foam
|
} // End namespace Foam
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -23,100 +23,56 @@ License
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
#include "exponential.H"
|
#include "exponential.H"
|
||||||
#include "addToRunTimeSelectionTable.H"
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace pdfs
|
||||||
{
|
{
|
||||||
defineTypeNameAndDebug(exponential, 0);
|
defineTypeNameAndDebug(exponential, 0);
|
||||||
addToRunTimeSelectionTable(pdf, exponential, dictionary);
|
addToRunTimeSelectionTable(pdf, exponential, dictionary);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::exponential::exponential(const dictionary& dict, Random& rndGen)
|
Foam::pdfs::exponential::exponential(const dictionary& dict, Random& rndGen)
|
||||||
:
|
:
|
||||||
pdf(dict, rndGen),
|
pdf(typeName, dict, rndGen),
|
||||||
pdfDict_(dict.subDict(typeName + "PDF")),
|
|
||||||
minValue_(readScalar(pdfDict_.lookup("minValue"))),
|
minValue_(readScalar(pdfDict_.lookup("minValue"))),
|
||||||
maxValue_(readScalar(pdfDict_.lookup("maxValue"))),
|
maxValue_(readScalar(pdfDict_.lookup("maxValue"))),
|
||||||
lambda_(pdfDict_.lookup("lambda")),
|
lambda_(readScalar(pdfDict_.lookup("lambda")))
|
||||||
ls_(lambda_),
|
|
||||||
range_(maxValue_ - minValue_)
|
|
||||||
{
|
{
|
||||||
if (minValue_<0)
|
check();
|
||||||
{
|
|
||||||
FatalErrorIn
|
|
||||||
(
|
|
||||||
"exponential::exponential(const dictionary& dict)"
|
|
||||||
) << " minValue = " << minValue_ << ", it must be >0." << nl
|
|
||||||
<< abort(FatalError);
|
|
||||||
}
|
|
||||||
|
|
||||||
scalar sMax = 0;
|
|
||||||
label n = lambda_.size();
|
|
||||||
for (label i=0; i<n; i++)
|
|
||||||
{
|
|
||||||
scalar s = lambda_[i]*exp(-lambda_[i]*minValue_);
|
|
||||||
for (label j=0; j<n; j++)
|
|
||||||
{
|
|
||||||
if (i!=j)
|
|
||||||
{
|
|
||||||
scalar y = lambda_[j]*exp(-lambda_[j]*minValue_);
|
|
||||||
s += y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sMax = max(sMax, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (label i=0; i<n; i++)
|
|
||||||
{
|
|
||||||
ls_[i] /= sMax;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::exponential::~exponential()
|
Foam::pdfs::exponential::~exponential()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::scalar Foam::exponential::sample() const
|
Foam::scalar Foam::pdfs::exponential::sample() const
|
||||||
{
|
{
|
||||||
scalar y = 0.0;
|
scalar y = rndGen_.scalar01();
|
||||||
scalar x = 0.0;
|
scalar K = exp(-lambda_*maxValue_) - exp(-lambda_*minValue_);
|
||||||
scalar p = 0.0;
|
return -(1.0/lambda_)*log(exp(-lambda_*minValue_) + y*K);
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
x = minValue_ + range_*rndGen_.scalar01();
|
|
||||||
y = rndGen_.scalar01();
|
|
||||||
p = 0.0;
|
|
||||||
|
|
||||||
forAll(lambda_, i)
|
|
||||||
{
|
|
||||||
p += ls_[i]*exp(-lambda_[i]*x);
|
|
||||||
}
|
|
||||||
} while (p>y);
|
|
||||||
|
|
||||||
return x;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::scalar Foam::exponential::minValue() const
|
Foam::scalar Foam::pdfs::exponential::minValue() const
|
||||||
{
|
{
|
||||||
return minValue_;
|
return minValue_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::scalar Foam::exponential::maxValue() const
|
Foam::scalar Foam::pdfs::exponential::maxValue() const
|
||||||
{
|
{
|
||||||
return maxValue_;
|
return maxValue_;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -28,9 +28,7 @@ Description
|
|||||||
exponential pdf
|
exponential pdf
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
exponentialI.H
|
|
||||||
exponential.C
|
exponential.C
|
||||||
exponentialIO.C
|
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -43,6 +41,8 @@ SourceFiles
|
|||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
namespace pdfs
|
||||||
|
{
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class exponential Declaration
|
Class exponential Declaration
|
||||||
@ -54,16 +54,17 @@ class exponential
|
|||||||
{
|
{
|
||||||
// Private data
|
// Private data
|
||||||
|
|
||||||
dictionary pdfDict_;
|
//- Distribution minimum
|
||||||
|
|
||||||
//- min and max values of the distribution
|
|
||||||
scalar minValue_;
|
scalar minValue_;
|
||||||
|
|
||||||
|
//- Distribution maximum
|
||||||
scalar maxValue_;
|
scalar maxValue_;
|
||||||
|
|
||||||
List<scalar> lambda_;
|
|
||||||
List<scalar> ls_;
|
|
||||||
|
|
||||||
scalar range_;
|
// Model coefficients
|
||||||
|
|
||||||
|
scalar lambda_;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -100,14 +101,11 @@ public:
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace pdfs
|
||||||
} // End namespace Foam
|
} // End namespace Foam
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
//#include "exponentialI.H"
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
76
src/thermophysicalModels/pdfs/fixedValue/fixedValue.C
Normal file
76
src/thermophysicalModels/pdfs/fixedValue/fixedValue.C
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by the
|
||||||
|
Free Software Foundation; either version 2 of the License, or (at your
|
||||||
|
option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "fixedValue.H"
|
||||||
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace pdfs
|
||||||
|
{
|
||||||
|
defineTypeNameAndDebug(fixedValue, 0);
|
||||||
|
addToRunTimeSelectionTable(pdf, fixedValue, dictionary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::pdfs::fixedValue::fixedValue(const dictionary& dict, Random& rndGen)
|
||||||
|
:
|
||||||
|
pdf(typeName, dict, rndGen),
|
||||||
|
value_(readScalar(pdfDict_.lookup("value")))
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::pdfs::fixedValue::~fixedValue()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::scalar Foam::pdfs::fixedValue::fixedValue::sample() const
|
||||||
|
{
|
||||||
|
return value_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::scalar Foam::pdfs::fixedValue::fixedValue::minValue() const
|
||||||
|
{
|
||||||
|
return -VGREAT;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::scalar Foam::pdfs::fixedValue::fixedValue::maxValue() const
|
||||||
|
{
|
||||||
|
return VGREAT;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
103
src/thermophysicalModels/pdfs/fixedValue/fixedValue.H
Normal file
103
src/thermophysicalModels/pdfs/fixedValue/fixedValue.H
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by the
|
||||||
|
Free Software Foundation; either version 2 of the License, or (at your
|
||||||
|
option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::fixedValue
|
||||||
|
|
||||||
|
Description
|
||||||
|
Returns a fixed value
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
fixedValue.C
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef pdfFixedValue_H
|
||||||
|
#define pdfFixedValue_H
|
||||||
|
|
||||||
|
#include "pdf.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace pdfs
|
||||||
|
{
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class fixedValue Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
class fixedValue
|
||||||
|
:
|
||||||
|
public pdf
|
||||||
|
{
|
||||||
|
// Private data
|
||||||
|
|
||||||
|
//- Fixed value
|
||||||
|
scalar value_;
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//- Runtime type information
|
||||||
|
TypeName("fixedValue");
|
||||||
|
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct from components
|
||||||
|
fixedValue
|
||||||
|
(
|
||||||
|
const dictionary& dict,
|
||||||
|
Random& rndGen
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//- Destructor
|
||||||
|
virtual ~fixedValue();
|
||||||
|
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- Sample the pdf
|
||||||
|
virtual scalar sample() const;
|
||||||
|
|
||||||
|
//- Return the minimum value
|
||||||
|
virtual scalar minValue() const;
|
||||||
|
|
||||||
|
//- Return the maximum value
|
||||||
|
virtual scalar maxValue() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace pdfs
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -29,85 +29,110 @@ License
|
|||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace pdfs
|
||||||
{
|
{
|
||||||
defineTypeNameAndDebug(general, 0);
|
defineTypeNameAndDebug(general, 0);
|
||||||
addToRunTimeSelectionTable(pdf, general, dictionary);
|
addToRunTimeSelectionTable(pdf, general, dictionary);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::general::general(const dictionary& dict, Random& rndGen)
|
Foam::pdfs::general::general(const dictionary& dict, Random& rndGen)
|
||||||
:
|
:
|
||||||
pdf(dict, rndGen),
|
pdf(typeName, dict, rndGen),
|
||||||
pdfDict_(dict.subDict(typeName + "PDF")),
|
|
||||||
xy_(pdfDict_.lookup("distribution")),
|
xy_(pdfDict_.lookup("distribution")),
|
||||||
nEntries_(xy_.size()),
|
nEntries_(xy_.size()),
|
||||||
minValue_(xy_[0][0]),
|
minValue_(xy_[0][0]),
|
||||||
maxValue_(xy_[nEntries_-1][0]),
|
maxValue_(xy_[nEntries_-1][0]),
|
||||||
range_(maxValue_ - minValue_)
|
integral_(nEntries_)
|
||||||
{
|
{
|
||||||
// normalize the pdf
|
check();
|
||||||
scalar yMax = 0;
|
|
||||||
|
|
||||||
for (label i=0; i<nEntries_; i++)
|
// normalize the cumulative pdf
|
||||||
|
|
||||||
|
integral_[0] = 0.0;
|
||||||
|
for (label i=1; i<nEntries_; i++)
|
||||||
{
|
{
|
||||||
yMax = max(yMax, xy_[i][1]);
|
|
||||||
|
scalar k = (xy_[i][1] - xy_[i-1][1])/(xy_[i][0] - xy_[i-1][0]);
|
||||||
|
scalar d = xy_[i-1][1] - k*xy_[i-1][0];
|
||||||
|
scalar y1 = xy_[i][0]*(0.5*k*xy_[i][0] + d);
|
||||||
|
scalar y0 = xy_[i-1][0]*(0.5*k*xy_[i-1][0] + d);
|
||||||
|
scalar area = y1 - y0;
|
||||||
|
|
||||||
|
integral_[i] = area + integral_[i-1];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (label i=0; i<nEntries_; i++)
|
for (label i=0; i<nEntries_; i++)
|
||||||
{
|
{
|
||||||
xy_[i][1] /= yMax;
|
xy_[i][1] /= integral_[nEntries_-1];
|
||||||
|
integral_[i] /= integral_[nEntries_-1];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::general::~general()
|
Foam::pdfs::general::~general()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::scalar Foam::general::sample() const
|
Foam::scalar Foam::pdfs::general::sample() const
|
||||||
{
|
{
|
||||||
|
scalar y = rndGen_.scalar01();
|
||||||
|
|
||||||
|
// find the interval where y is in the table
|
||||||
|
label n=1;
|
||||||
|
while (integral_[n] <= y)
|
||||||
|
{
|
||||||
|
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];
|
||||||
|
|
||||||
|
scalar alpha = y + xy_[n-1][0]*(0.5*k*xy_[n-1][0] + d) - integral_[n-1];
|
||||||
scalar x = 0.0;
|
scalar x = 0.0;
|
||||||
scalar y = 0.0;
|
|
||||||
scalar p = 0.0;
|
|
||||||
|
|
||||||
do
|
// if k is small it's a linear equation, otherwise it's of second order
|
||||||
|
if (mag(k) > SMALL)
|
||||||
{
|
{
|
||||||
x = minValue_ + range_*rndGen_.scalar01();
|
scalar p = 2.0*d/k;
|
||||||
y = rndGen_.scalar01();
|
scalar q = -2.0*alpha/k;
|
||||||
|
scalar sqrtEr = sqrt(0.25*p*p - q);
|
||||||
|
|
||||||
bool intervalFound = false;
|
scalar x1 = -0.5*p + sqrtEr;
|
||||||
label i = -1;
|
scalar x2 = -0.5*p - sqrtEr;
|
||||||
while (!intervalFound)
|
if ((x1 >= xy_[n-1][0]) && (x1 <= xy_[n][0]))
|
||||||
{
|
{
|
||||||
i++;
|
x = x1;
|
||||||
if ((x>xy_[i][0]) && (x<xy_[i+1][0]))
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
intervalFound = true;
|
x = x2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
p = xy_[i][1]
|
{
|
||||||
+ (x - xy_[i][0])
|
x = alpha/d;
|
||||||
*(xy_[i+1][1] - xy_[i][1])
|
}
|
||||||
/(xy_[i+1][0] - xy_[i][0]);
|
|
||||||
} while (p>y);
|
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::scalar Foam::general::minValue() const
|
Foam::scalar Foam::pdfs::general::minValue() const
|
||||||
{
|
{
|
||||||
return minValue_;
|
return minValue_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::scalar Foam::general::maxValue() const
|
Foam::scalar Foam::pdfs::general::maxValue() const
|
||||||
{
|
{
|
||||||
return maxValue_;
|
return maxValue_;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -28,9 +28,7 @@ Description
|
|||||||
general pdf
|
general pdf
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
generalI.H
|
|
||||||
general.C
|
general.C
|
||||||
generalIO.C
|
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -43,6 +41,8 @@ SourceFiles
|
|||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
namespace pdfs
|
||||||
|
{
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class general Declaration
|
Class general Declaration
|
||||||
@ -54,8 +54,6 @@ class general
|
|||||||
{
|
{
|
||||||
// Private data
|
// Private data
|
||||||
|
|
||||||
dictionary pdfDict_;
|
|
||||||
|
|
||||||
typedef VectorSpace<Vector<scalar>, scalar, 2> pair;
|
typedef VectorSpace<Vector<scalar>, scalar, 2> pair;
|
||||||
|
|
||||||
List<pair> xy_;
|
List<pair> xy_;
|
||||||
@ -66,7 +64,7 @@ class general
|
|||||||
scalar minValue_;
|
scalar minValue_;
|
||||||
scalar maxValue_;
|
scalar maxValue_;
|
||||||
|
|
||||||
scalar range_;
|
List<scalar> integral_;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -104,6 +102,7 @@ public:
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace pdfs
|
||||||
} // End namespace Foam
|
} // End namespace Foam
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|||||||
133
src/thermophysicalModels/pdfs/multiNormal/multiNormal.C
Normal file
133
src/thermophysicalModels/pdfs/multiNormal/multiNormal.C
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by the
|
||||||
|
Free Software Foundation; either version 2 of the License, or (at your
|
||||||
|
option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "multiNormal.H"
|
||||||
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace pdfs
|
||||||
|
{
|
||||||
|
defineTypeNameAndDebug(multiNormal, 0);
|
||||||
|
addToRunTimeSelectionTable(pdf, multiNormal, dictionary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::pdfs::multiNormal::multiNormal(const dictionary& dict, Random& rndGen)
|
||||||
|
:
|
||||||
|
pdf(typeName, dict, rndGen),
|
||||||
|
minValue_(readScalar(pdfDict_.lookup("minValue"))),
|
||||||
|
maxValue_(readScalar(pdfDict_.lookup("maxValue"))),
|
||||||
|
range_(maxValue_ - minValue_),
|
||||||
|
expectation_(pdfDict_.lookup("expectation")),
|
||||||
|
variance_(pdfDict_.lookup("variance")),
|
||||||
|
strength_(pdfDict_.lookup("strength"))
|
||||||
|
{
|
||||||
|
check();
|
||||||
|
|
||||||
|
scalar sMax = 0;
|
||||||
|
label n = strength_.size();
|
||||||
|
for (label i=0; i<n; i++)
|
||||||
|
{
|
||||||
|
scalar x = expectation_[i];
|
||||||
|
scalar s = strength_[i];
|
||||||
|
for (label j=0; j<n; j++)
|
||||||
|
{
|
||||||
|
if (i!=j)
|
||||||
|
{
|
||||||
|
scalar x2 = (x - expectation_[j])/variance_[j];
|
||||||
|
scalar y = exp(-0.5*x2*x2);
|
||||||
|
s += strength_[j]*y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sMax = max(sMax, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (label i=0; i<n; i++)
|
||||||
|
{
|
||||||
|
strength_[i] /= sMax;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::pdfs::multiNormal::~multiNormal()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::scalar Foam::pdfs::multiNormal::sample() const
|
||||||
|
{
|
||||||
|
scalar y = 0;
|
||||||
|
scalar x = 0;
|
||||||
|
label n = expectation_.size();
|
||||||
|
bool success = false;
|
||||||
|
|
||||||
|
while (!success)
|
||||||
|
{
|
||||||
|
x = minValue_ + range_*rndGen_.scalar01();
|
||||||
|
y = rndGen_.scalar01();
|
||||||
|
scalar p = 0.0;
|
||||||
|
|
||||||
|
for (label i=0; i<n; i++)
|
||||||
|
{
|
||||||
|
scalar nu = expectation_[i];
|
||||||
|
scalar sigma = variance_[i];
|
||||||
|
scalar s = strength_[i];
|
||||||
|
scalar v = (x - nu)/sigma;
|
||||||
|
p += s*exp(-0.5*v*v);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y<p)
|
||||||
|
{
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::scalar Foam::pdfs::multiNormal::minValue() const
|
||||||
|
{
|
||||||
|
return minValue_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::scalar Foam::pdfs::multiNormal::maxValue() const
|
||||||
|
{
|
||||||
|
return maxValue_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
122
src/thermophysicalModels/pdfs/multiNormal/multiNormal.H
Normal file
122
src/thermophysicalModels/pdfs/multiNormal/multiNormal.H
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by the
|
||||||
|
Free Software Foundation; either version 2 of the License, or (at your
|
||||||
|
option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::multiNormal
|
||||||
|
|
||||||
|
Description
|
||||||
|
A multiNormal pdf
|
||||||
|
|
||||||
|
@verbatim
|
||||||
|
pdf = sum_i strength_i * exp(-0.5*((x - expectation_i)/variance_i)^2 )
|
||||||
|
@endverbatim
|
||||||
|
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
multiNormal.C
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef multiNormal_H
|
||||||
|
#define multiNormal_H
|
||||||
|
|
||||||
|
#include "pdf.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace pdfs
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class multiNormal Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
class multiNormal
|
||||||
|
:
|
||||||
|
public pdf
|
||||||
|
{
|
||||||
|
// Private data
|
||||||
|
|
||||||
|
//- Distribution minimum
|
||||||
|
scalar minValue_;
|
||||||
|
|
||||||
|
//- Distribution maximum
|
||||||
|
scalar maxValue_;
|
||||||
|
|
||||||
|
//- Distribution range
|
||||||
|
scalar range_;
|
||||||
|
|
||||||
|
|
||||||
|
// Model coefficients
|
||||||
|
|
||||||
|
List<scalar> expectation_;
|
||||||
|
List<scalar> variance_;
|
||||||
|
List<scalar> strength_;
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//- Runtime type information
|
||||||
|
TypeName("multiNormal");
|
||||||
|
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct from components
|
||||||
|
multiNormal
|
||||||
|
(
|
||||||
|
const dictionary& dict,
|
||||||
|
Random& rndGen
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//- Destructor
|
||||||
|
virtual ~multiNormal();
|
||||||
|
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- Sample the pdf
|
||||||
|
virtual scalar sample() const;
|
||||||
|
|
||||||
|
//- Return the minimum value
|
||||||
|
virtual scalar minValue() const;
|
||||||
|
|
||||||
|
//- Return the maximum value
|
||||||
|
virtual scalar maxValue() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace pdfs
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -25,98 +25,97 @@ License
|
|||||||
|
|
||||||
#include "normal.H"
|
#include "normal.H"
|
||||||
#include "addToRunTimeSelectionTable.H"
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
#include "mathematicalConstants.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace pdfs
|
||||||
{
|
{
|
||||||
defineTypeNameAndDebug(normal, 0);
|
defineTypeNameAndDebug(normal, 0);
|
||||||
addToRunTimeSelectionTable(pdf, normal, dictionary);
|
addToRunTimeSelectionTable(pdf, normal, dictionary);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::normal::normal(const dictionary& dict, Random& rndGen)
|
Foam::pdfs::normal::normal(const dictionary& dict, Random& rndGen)
|
||||||
:
|
:
|
||||||
pdf(dict, rndGen),
|
pdf(typeName, dict, rndGen),
|
||||||
pdfDict_(dict.subDict(typeName + "PDF")),
|
|
||||||
minValue_(readScalar(pdfDict_.lookup("minValue"))),
|
minValue_(readScalar(pdfDict_.lookup("minValue"))),
|
||||||
maxValue_(readScalar(pdfDict_.lookup("maxValue"))),
|
maxValue_(readScalar(pdfDict_.lookup("maxValue"))),
|
||||||
expectation_(pdfDict_.lookup("expectation")),
|
expectation_(readScalar(pdfDict_.lookup("expectation"))),
|
||||||
variance_(pdfDict_.lookup("variance")),
|
variance_(readScalar(pdfDict_.lookup("variance"))),
|
||||||
strength_(pdfDict_.lookup("strength")),
|
a_(0.147)
|
||||||
range_(maxValue_ - minValue_)
|
|
||||||
{
|
{
|
||||||
scalar sMax = 0;
|
if (minValue_ < 0)
|
||||||
label n = strength_.size();
|
|
||||||
for (label i=0; i<n; i++)
|
|
||||||
{
|
{
|
||||||
scalar x = expectation_[i];
|
FatalErrorIn("normal::normal(const dictionary&, Random&)")
|
||||||
scalar s = strength_[i];
|
<< "Minimum value must be greater than zero. "
|
||||||
for (label j=0; j<n; j++)
|
<< "Supplied minValue = " << minValue_
|
||||||
{
|
<< abort(FatalError);
|
||||||
if (i!=j)
|
|
||||||
{
|
|
||||||
scalar x2 = (x-expectation_[j])/variance_[j];
|
|
||||||
scalar y = exp(-0.5*x2*x2);
|
|
||||||
s += strength_[j]*y;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sMax = max(sMax, s);
|
if (maxValue_ < minValue_)
|
||||||
}
|
|
||||||
|
|
||||||
for (label i=0; i<n; i++)
|
|
||||||
{
|
{
|
||||||
strength_[i] /= sMax;
|
FatalErrorIn("normal::normal(const dictionary&, Random&)")
|
||||||
|
<< "Maximum value is smaller than the minimum value:"
|
||||||
|
<< " maxValue = " << maxValue_ << ", minValue = " << minValue_
|
||||||
|
<< abort(FatalError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::normal::~normal()
|
Foam::pdfs::normal::~normal()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::scalar Foam::normal::sample() const
|
Foam::scalar Foam::pdfs::normal::sample() const
|
||||||
{
|
{
|
||||||
scalar x = 0.0;
|
|
||||||
scalar y = 0.0;
|
|
||||||
scalar p = 0.0;
|
|
||||||
|
|
||||||
do
|
scalar a = erf((minValue_ - expectation_)/variance_);
|
||||||
{
|
scalar b = erf((maxValue_ - expectation_)/variance_);
|
||||||
x = minValue_ + range_*rndGen_.scalar01();
|
|
||||||
y = rndGen_.scalar01();
|
|
||||||
p = 0.0;
|
|
||||||
|
|
||||||
forAll(expectation_, i)
|
scalar y = rndGen_.scalar01();
|
||||||
{
|
scalar x = erfInv(y*(b - a) + a)*variance_ + expectation_;
|
||||||
scalar nu = expectation_[i];
|
|
||||||
scalar sigma = variance_[i];
|
// Note: numerical approximation of the inverse function yields slight
|
||||||
scalar s = strength_[i];
|
// inaccuracies
|
||||||
scalar v = (x - nu)/sigma;
|
|
||||||
p += s*exp(-0.5*v*v);
|
x = min(max(x, minValue_), maxValue_);
|
||||||
}
|
|
||||||
} while (p>y);
|
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::scalar Foam::normal::minValue() const
|
Foam::scalar Foam::pdfs::normal::minValue() const
|
||||||
{
|
{
|
||||||
return minValue_;
|
return minValue_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::scalar Foam::normal::maxValue() const
|
Foam::scalar Foam::pdfs::normal::maxValue() const
|
||||||
{
|
{
|
||||||
return maxValue_;
|
return maxValue_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::scalar Foam::pdfs::normal::erfInv(const scalar y) const
|
||||||
|
{
|
||||||
|
scalar k = 2.0/(constant::mathematical::pi*a_) + 0.5*log(1.0 - y*y);
|
||||||
|
scalar h = log(1.0 - y*y)/a_;
|
||||||
|
scalar x = sqrt(-k + sqrt(k*k - h));
|
||||||
|
if (y < 0.0)
|
||||||
|
{
|
||||||
|
x *= -1.0;
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -34,9 +34,7 @@ Description
|
|||||||
strength only has meaning if there's more than one pdf
|
strength only has meaning if there's more than one pdf
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
normalI.H
|
|
||||||
normal.C
|
normal.C
|
||||||
normalIO.C
|
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -49,6 +47,8 @@ SourceFiles
|
|||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
namespace pdfs
|
||||||
|
{
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class normal Declaration
|
Class normal Declaration
|
||||||
@ -60,17 +60,20 @@ class normal
|
|||||||
{
|
{
|
||||||
// Private data
|
// Private data
|
||||||
|
|
||||||
dictionary pdfDict_;
|
|
||||||
|
|
||||||
//- min and max values of the distribution
|
//- Distribution minimum
|
||||||
scalar minValue_;
|
scalar minValue_;
|
||||||
|
|
||||||
|
//- Distribution maximum
|
||||||
scalar maxValue_;
|
scalar maxValue_;
|
||||||
|
|
||||||
List<scalar> expectation_;
|
|
||||||
List<scalar> variance_;
|
|
||||||
List<scalar> strength_;
|
|
||||||
|
|
||||||
scalar range_;
|
// Model coefficients
|
||||||
|
|
||||||
|
scalar expectation_;
|
||||||
|
scalar variance_;
|
||||||
|
|
||||||
|
scalar a_;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -103,11 +106,14 @@ public:
|
|||||||
|
|
||||||
//- Return the maximum value
|
//- Return the maximum value
|
||||||
virtual scalar maxValue() const;
|
virtual scalar maxValue() const;
|
||||||
|
|
||||||
|
scalar erfInv(const scalar y) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace pdfs
|
||||||
} // End namespace Foam
|
} // End namespace Foam
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -27,7 +27,7 @@ License
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::autoPtr<Foam::pdf> Foam::pdf::New
|
Foam::autoPtr<Foam::pdfs::pdf> Foam::pdfs::pdf::New
|
||||||
(
|
(
|
||||||
const dictionary& dict,
|
const dictionary& dict,
|
||||||
Random& rndGen
|
Random& rndGen
|
||||||
@ -42,7 +42,7 @@ Foam::autoPtr<Foam::pdf> Foam::pdf::New
|
|||||||
|
|
||||||
if (cstrIter == dictionaryConstructorTablePtr_->end())
|
if (cstrIter == dictionaryConstructorTablePtr_->end())
|
||||||
{
|
{
|
||||||
FatalErrorIn("pdf::New(const dictionary&, Random&)")
|
FatalErrorIn("pdfs::pdf::New(const dictionary&, Random&)")
|
||||||
<< "unknown pdf type " << pdfType << nl << nl
|
<< "unknown pdf type " << pdfType << nl << nl
|
||||||
<< "Valid pdf types are:" << nl
|
<< "Valid pdf types are:" << nl
|
||||||
<< dictionaryConstructorTablePtr_->sortedToc()
|
<< dictionaryConstructorTablePtr_->sortedToc()
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -28,23 +28,49 @@ License
|
|||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace pdfs
|
||||||
{
|
{
|
||||||
defineTypeNameAndDebug(pdf, 0);
|
defineTypeNameAndDebug(pdf, 0);
|
||||||
defineRunTimeSelectionTable(pdf, dictionary);
|
defineRunTimeSelectionTable(pdf, dictionary);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
|
||||||
|
|
||||||
|
void Foam::pdfs::pdf::check() const
|
||||||
|
{
|
||||||
|
if (minValue() < 0)
|
||||||
|
{
|
||||||
|
FatalErrorIn("pdfs::pdf::check() const")
|
||||||
|
<< type() << "PDF: Minimum value must be greater than zero." << nl
|
||||||
|
<< "Supplied minValue = " << minValue()
|
||||||
|
<< abort(FatalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxValue() < minValue())
|
||||||
|
{
|
||||||
|
FatalErrorIn("pdfs::pdf::check() const")
|
||||||
|
<< type() << "PDF: Maximum value is smaller than the minimum value:"
|
||||||
|
<< nl << " maxValue = " << maxValue()
|
||||||
|
<< ", minValue = " << minValue()
|
||||||
|
<< abort(FatalError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::pdf::pdf(const dictionary& dict, Random& rndGen)
|
Foam::pdfs::pdf::pdf(const word& name, const dictionary& dict, Random& rndGen)
|
||||||
:
|
:
|
||||||
dict_(dict),
|
pdfDict_(dict.subDict(name + "PDF")),
|
||||||
rndGen_(rndGen)
|
rndGen_(rndGen)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::pdf::~pdf()
|
Foam::pdfs::pdf::~pdf()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -25,37 +25,27 @@ Class
|
|||||||
Foam::pdf
|
Foam::pdf
|
||||||
|
|
||||||
Description
|
Description
|
||||||
A library of runtime-selectable pdf's.
|
A library of runtime-selectable PDF's.
|
||||||
|
|
||||||
Returns a sampled value given the expectation (nu) and variance (sigma^2)
|
Returns a sampled value given the expectation (nu) and variance (sigma^2)
|
||||||
|
|
||||||
Sample of planned pdfs (beta p. 374-375):
|
Current PDF's include:
|
||||||
- binomial
|
|
||||||
- geometric
|
|
||||||
- Poisson
|
|
||||||
- hypergeometric
|
|
||||||
- Pascal
|
|
||||||
- uniform
|
|
||||||
- exponential
|
- exponential
|
||||||
|
- fixedValue
|
||||||
|
- general
|
||||||
|
- multi-normal
|
||||||
- normal
|
- normal
|
||||||
- Gamma
|
- Rosin-Rammler
|
||||||
- chi
|
- uniform
|
||||||
- t?
|
|
||||||
- F?
|
|
||||||
- beta
|
|
||||||
- Weibull
|
|
||||||
- Rayleigh
|
|
||||||
- Cauchy?
|
|
||||||
|
|
||||||
The pdf is tabulated in equidistant nPoints, in an interval.
|
The pdf is tabulated in equidistant nPoints, in an interval.
|
||||||
These values are integrated to obtain the cumulated pdf,
|
These values are integrated to obtain the cumulated PDF,
|
||||||
which is then used to change the distribution from unifrom to
|
which is then used to change the distribution from unifrom to
|
||||||
the actual pdf.
|
the actual pdf.
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
pdfI.H
|
|
||||||
pdf.C
|
pdf.C
|
||||||
pdfIO.C
|
newPdf.C
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -70,6 +60,8 @@ SourceFiles
|
|||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
namespace pdfs
|
||||||
|
{
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class pdf Declaration
|
Class pdf Declaration
|
||||||
@ -82,11 +74,19 @@ protected:
|
|||||||
|
|
||||||
// Protected data
|
// Protected data
|
||||||
|
|
||||||
const dictionary& dict_;
|
//- Coefficients dictionary
|
||||||
|
const dictionary pdfDict_;
|
||||||
|
|
||||||
|
//- Reference to the randmo number generator
|
||||||
Random& rndGen_;
|
Random& rndGen_;
|
||||||
|
|
||||||
|
|
||||||
|
// Protected member functions
|
||||||
|
|
||||||
|
//- Check that the PDF is valid
|
||||||
|
virtual void check() const;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//-Runtime type information
|
//-Runtime type information
|
||||||
@ -110,7 +110,7 @@ public:
|
|||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct from dictionary
|
//- Construct from dictionary
|
||||||
pdf(const dictionary& dict, Random& rndGen);
|
pdf(const word& name, const dictionary& dict, Random& rndGen);
|
||||||
|
|
||||||
|
|
||||||
//- Selector
|
//- Selector
|
||||||
@ -136,6 +136,7 @@ public:
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace pdfs
|
||||||
} // End namespace Foam
|
} // End namespace Foam
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -29,44 +29,48 @@ License
|
|||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace pdfs
|
||||||
{
|
{
|
||||||
defineTypeNameAndDebug(uniform, 0);
|
defineTypeNameAndDebug(uniform, 0);
|
||||||
addToRunTimeSelectionTable(pdf, uniform, dictionary);
|
addToRunTimeSelectionTable(pdf, uniform, dictionary);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::uniform::uniform(const dictionary& dict, Random& rndGen)
|
Foam::pdfs::uniform::uniform(const dictionary& dict, Random& rndGen)
|
||||||
:
|
:
|
||||||
pdf(dict, rndGen),
|
pdf(typeName, dict, rndGen),
|
||||||
pdfDict_(dict.subDict(typeName + "PDF")),
|
|
||||||
minValue_(readScalar(pdfDict_.lookup("minValue"))),
|
minValue_(readScalar(pdfDict_.lookup("minValue"))),
|
||||||
maxValue_(readScalar(pdfDict_.lookup("maxValue"))),
|
maxValue_(readScalar(pdfDict_.lookup("maxValue"))),
|
||||||
range_(maxValue_ - minValue_)
|
range_(maxValue_ - minValue_)
|
||||||
{}
|
{
|
||||||
|
check();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::uniform::~uniform()
|
Foam::pdfs::uniform::~uniform()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::scalar Foam::uniform::sample() const
|
Foam::scalar Foam::pdfs::uniform::sample() const
|
||||||
{
|
{
|
||||||
return (minValue_ + rndGen_.scalar01()*range_);
|
return (minValue_ + rndGen_.scalar01()*range_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::scalar Foam::uniform::minValue() const
|
Foam::scalar Foam::pdfs::uniform::minValue() const
|
||||||
{
|
{
|
||||||
return minValue_;
|
return minValue_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::scalar Foam::uniform::maxValue() const
|
Foam::scalar Foam::pdfs::uniform::maxValue() const
|
||||||
{
|
{
|
||||||
return maxValue_;
|
return maxValue_;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -28,9 +28,7 @@ Description
|
|||||||
uniform pdf
|
uniform pdf
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
uniformI.H
|
|
||||||
uniform.C
|
uniform.C
|
||||||
uniformIO.C
|
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -43,6 +41,8 @@ SourceFiles
|
|||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
namespace pdfs
|
||||||
|
{
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class uniform Declaration
|
Class uniform Declaration
|
||||||
@ -54,13 +54,13 @@ class uniform
|
|||||||
{
|
{
|
||||||
// Private data
|
// Private data
|
||||||
|
|
||||||
dictionary pdfDict_;
|
//- Distribution minimum
|
||||||
|
|
||||||
//- min and max values of the distribution
|
|
||||||
scalar minValue_;
|
scalar minValue_;
|
||||||
|
|
||||||
|
//- Distribution maximum
|
||||||
scalar maxValue_;
|
scalar maxValue_;
|
||||||
|
|
||||||
// help-variable to avoid always having to calculate max-min
|
//- Distribution range
|
||||||
scalar range_;
|
scalar range_;
|
||||||
|
|
||||||
|
|
||||||
@ -99,6 +99,7 @@ public:
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace pdfs
|
||||||
} // End namespace Foam
|
} // End namespace Foam
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|||||||
Reference in New Issue
Block a user