Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Development
openfoam
Commits
bece1133
Commit
bece1133
authored
Oct 20, 2010
by
Andrew Heather
Browse files
ENH: Updated pdfs to employ cachedRandom class
parent
610ae314
Changes
17
Hide whitespace changes
Inline
Side-by-side
src/thermophysicalModels/pdfs/RosinRammler/RosinRammler.C
View file @
bece1133
...
...
@@ -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_
.
scalar
01
();
scalar
y
=
rndGen_
.
sample01
<
scalar
>
();
scalar
x
=
minValue_
+
d_
*::
pow
(
-
log
(
1
.
0
-
y
*
K
),
1
.
0
/
n_
);
return
x
;
}
...
...
src/thermophysicalModels/pdfs/RosinRammler/RosinRammler.H
View file @
bece1133
...
...
@@ -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
...
...
src/thermophysicalModels/pdfs/exponential/exponential.C
View file @
bece1133
...
...
@@ -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_
.
scalar
01
();
scalar
y
=
rndGen_
.
sample01
<
scalar
>
();
scalar
K
=
exp
(
-
lambda_
*
maxValue_
)
-
exp
(
-
lambda_
*
minValue_
);
return
-
(
1
.
0
/
lambda_
)
*
log
(
exp
(
-
lambda_
*
minValue_
)
+
y
*
K
);
}
...
...
src/thermophysicalModels/pdfs/exponential/exponential.H
View file @
bece1133
...
...
@@ -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
...
...
src/thermophysicalModels/pdfs/fixedValue/fixedValue.C
View file @
bece1133
...
...
@@ -39,13 +39,20 @@ namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam
::
pdfs
::
fixedValue
::
fixedValue
(
const
dictionary
&
dict
,
Random
&
rndGen
)
Foam
::
pdfs
::
fixedValue
::
fixedValue
(
const
dictionary
&
dict
,
cached
Random
&
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
()
...
...
src/thermophysicalModels/pdfs/fixedValue/fixedValue.H
View file @
bece1133
...
...
@@ -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
...
...
src/thermophysicalModels/pdfs/general/general.C
View file @
bece1133
...
...
@@ -39,7 +39,7 @@ namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam
::
pdfs
::
general
::
general
(
const
dictionary
&
dict
,
Random
&
rndGen
)
Foam
::
pdfs
::
general
::
general
(
const
dictionary
&
dict
,
cached
Random
&
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_
.
scalar
01
();
scalar
y
=
rndGen_
.
sample01
<
scalar
>
();
// find the interval where y is in the table
label
n
=
1
;
...
...
src/thermophysicalModels/pdfs/general/general.H
View file @
bece1133
...
...
@@ -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
...
...
src/thermophysicalModels/pdfs/multiNormal/multiNormal.C
View file @
bece1133
...
...
@@ -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_
.
scalar
01
();
y
=
rndGen_
.
scalar
01
();
x
=
minValue_
+
range_
*
rndGen_
.
sample01
<
scalar
>
();
y
=
rndGen_
.
sample01
<
scalar
>
();
scalar
p
=
0
.
0
;
for
(
label
i
=
0
;
i
<
n
;
i
++
)
...
...
src/thermophysicalModels/pdfs/multiNormal/multiNormal.H
View file @
bece1133
...
...
@@ -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
...
...
src/thermophysicalModels/pdfs/normal/normal.C
View file @
bece1133
...
...
@@ -40,7 +40,7 @@ namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam
::
pdfs
::
normal
::
normal
(
const
dictionary
&
dict
,
Random
&
rndGen
)
Foam
::
pdfs
::
normal
::
normal
(
const
dictionary
&
dict
,
cached
Random
&
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_
.
scalar
01
();
scalar
y
=
rndGen_
.
sample01
<
scalar
>
();
scalar
x
=
erfInv
(
y
*
(
b
-
a
)
+
a
)
*
variance_
+
expectation_
;
// Note: numerical approximation of the inverse function yields slight
...
...
src/thermophysicalModels/pdfs/normal/normal.H
View file @
bece1133
...
...
@@ -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
;
};
...
...
src/thermophysicalModels/pdfs/pdf/pdf.C
View file @
bece1133
...
...
@@ -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
;
}
// ************************************************************************* //
src/thermophysicalModels/pdfs/pdf/pdf.H
View file @
bece1133
...
...
@@ -54,7 +54,7 @@ SourceFiles
#include
"IOdictionary.H"
#include
"autoPtr.H"
#include
"Random.H"
#include
"
cached
Random.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
...
...
@@ -78,7 +78,7 @@ protected:
const
dictionary
pdfDict_
;
//- Reference to the random number generator
Random
&
rndGen_
;
cached
Random
&
rndGen_
;
// Protected Member Functions
...
...
@@ -101,7 +101,7 @@ public:
dictionary
,
(
const
dictionary
&
dict
,
Random
&
rndGen
cached
Random
&
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
,
cached
Random
&
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
;
};
...
...
src/thermophysicalModels/pdfs/pdf/pdfNew.C
View file @
bece1133
...
...
@@ -30,7 +30,7 @@ License
Foam
::
autoPtr
<
Foam
::
pdfs
::
pdf
>
Foam
::
pdfs
::
pdf
::
New
(
const
dictionary
&
dict
,
Random
&
rndGen
cached
Random
&
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&,
cached
Random&)"
)
<<
"Unknown pdf type "
<<
modelType
<<
nl
<<
nl
<<
"Valid pdf types are:"
<<
nl
<<
dictionaryConstructorTablePtr_
->
sortedToc
()
...
...
src/thermophysicalModels/pdfs/uniform/uniform.C
View file @
bece1133
...
...
@@ -39,7 +39,7 @@ namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam
::
pdfs
::
uniform
::
uniform
(
const
dictionary
&
dict
,
Random
&
rndGen
)
Foam
::
pdfs
::
uniform
::
uniform
(
const
dictionary
&
dict
,
cached
Random
&
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
()
*
rang
e_
);
return
rndGen_
.
position
<
scalar
>
(
minValue_
,
maxValu
e_
);
}
...
...
src/thermophysicalModels/pdfs/uniform/uniform.H
View file @
bece1133
...
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment