Commit b3bf8309 authored by Andrew Heather's avatar Andrew Heather
Browse files

ENH: Updates to thermo/pdfs library

- added Niklas' update to Rosin-Rammler
- new fixedValue type
- code clean-up
parent cb7fd508
pdf = pdf
uniform = uniform
normal = normal
general = general
exponential = exponential
RosinRammler = RosinRammler
pdf/pdf.C
pdf/newPdf.C
$(pdf)/pdf.C
$(pdf)/newPdf.C
$(uniform)/uniform.C
$(normal)/normal.C
$(general)/general.C
$(exponential)/exponential.C
$(RosinRammler)/RosinRammler.C
exponential/exponential.C
fixedValue/fixedValue.C
general/general.C
multiNormal/multiNormal.C
normal/normal.C
RosinRammler/RosinRammler.C
uniform/uniform.C
LIB = $(FOAM_LIBBIN)/libpdf
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -31,106 +31,52 @@ License
namespace Foam
{
defineTypeNameAndDebug(RosinRammler, 0);
addToRunTimeSelectionTable(pdf, RosinRammler, dictionary);
namespace pdfs
{
defineTypeNameAndDebug(RosinRammler, 0);
addToRunTimeSelectionTable(pdf, RosinRammler, dictionary);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::RosinRammler::RosinRammler(const dictionary& dict, Random& rndGen)
Foam::pdfs::RosinRammler::RosinRammler(const dictionary& dict, Random& rndGen)
:
pdf(dict, rndGen),
pdfDict_(dict.subDict(typeName + "PDF")),
pdf(typeName, dict, rndGen),
minValue_(readScalar(pdfDict_.lookup("minValue"))),
maxValue_(readScalar(pdfDict_.lookup("maxValue"))),
d_(pdfDict_.lookup("d")),
n_(pdfDict_.lookup("n")),
ls_(d_),
range_(maxValue_ - minValue_)
d_(readScalar(pdfDict_.lookup("d"))),
n_(readScalar(pdfDict_.lookup("n")))
{
if (minValue_<0)
{
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;
}
check();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::RosinRammler::~RosinRammler()
Foam::pdfs::RosinRammler::~RosinRammler()
{}
// * * * * * * * * * * * * * * * 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;
}
Foam::scalar Foam::RosinRammler::minValue() const
Foam::scalar Foam::pdfs::RosinRammler::minValue() const
{
return minValue_;
}
Foam::scalar Foam::RosinRammler::maxValue() const
Foam::scalar Foam::pdfs::RosinRammler::maxValue() const
{
return maxValue_;
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -29,14 +29,12 @@ Description
Rosin-Rammler pdf
@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]
SourceFiles
RosinRammlerI.H
RosinRammler.C
RosinRammlerIO.C
\*---------------------------------------------------------------------------*/
......@@ -49,9 +47,11 @@ SourceFiles
namespace Foam
{
namespace pdfs
{
/*---------------------------------------------------------------------------*\
Class RosinRammler Declaration
Class RosinRammler Declaration
\*---------------------------------------------------------------------------*/
class RosinRammler
......@@ -60,17 +60,16 @@ class RosinRammler
{
// Private data
dictionary pdfDict_;
//- min and max values of the distribution
//- Distribution minimum
scalar minValue_;
//- Distribution maximum
scalar maxValue_;
List<scalar> d_;
List<scalar> n_;
List<scalar> ls_;
// Model coefficients
scalar range_;
scalar d_;
scalar n_;
public:
......@@ -108,6 +107,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace pdfs
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -24,7 +24,6 @@ License
\*---------------------------------------------------------------------------*/
#include "exponential.H"
#include "addToRunTimeSelectionTable.H"
......@@ -32,92 +31,49 @@ License
namespace Foam
{
defineTypeNameAndDebug(exponential, 0);
addToRunTimeSelectionTable(pdf, exponential, dictionary);
namespace pdfs
{
defineTypeNameAndDebug(exponential, 0);
addToRunTimeSelectionTable(pdf, exponential, dictionary);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::exponential::exponential(const dictionary& dict, Random& rndGen)
Foam::pdfs::exponential::exponential(const dictionary& dict, Random& rndGen)
:
pdf(dict, rndGen),
pdfDict_(dict.subDict(typeName + "PDF")),
pdf(typeName, dict, rndGen),
minValue_(readScalar(pdfDict_.lookup("minValue"))),
maxValue_(readScalar(pdfDict_.lookup("maxValue"))),
lambda_(pdfDict_.lookup("lambda")),
ls_(lambda_),
range_(maxValue_ - minValue_)
lambda_(readScalar(pdfDict_.lookup("lambda")))
{
if (minValue_<0)
{
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;
}
check();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::exponential::~exponential()
Foam::pdfs::exponential::~exponential()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::scalar Foam::exponential::sample() const
Foam::scalar Foam::pdfs::exponential::sample() const
{
scalar y = 0.0;
scalar x = 0.0;
scalar p = 0.0;
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;
scalar y = rndGen_.scalar01();
scalar K = exp(-lambda_*maxValue_) - exp(-lambda_*minValue_);
return -(1.0/lambda_)*log(exp(-lambda_*minValue_) + y*K);
}
Foam::scalar Foam::exponential::minValue() const
Foam::scalar Foam::pdfs::exponential::minValue() const
{
return minValue_;
}
Foam::scalar Foam::exponential::maxValue() const
Foam::scalar Foam::pdfs::exponential::maxValue() const
{
return maxValue_;
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -29,9 +29,7 @@ Description
exponential pdf
SourceFiles
exponentialI.H
exponential.C
exponentialIO.C
\*---------------------------------------------------------------------------*/
......@@ -44,6 +42,8 @@ SourceFiles
namespace Foam
{
namespace pdfs
{
/*---------------------------------------------------------------------------*\
Class exponential Declaration
......@@ -55,16 +55,17 @@ class exponential
{
// Private data
dictionary pdfDict_;
//- min and max values of the distribution
//- Distribution minimum
scalar minValue_;
//- Distribution maximum
scalar maxValue_;
List<scalar> lambda_;
List<scalar> ls_;
scalar range_;
// Model coefficients
scalar lambda_;
public:
......@@ -101,14 +102,11 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace pdfs
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//#include "exponentialI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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;
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -31,84 +31,109 @@ License