RosinRammler.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "RosinRammler.H"
00028 #include "addToRunTimeSelectionTable.H"
00029
00030
00031
00032 namespace Foam
00033 {
00034 defineTypeNameAndDebug(RosinRammler, 0);
00035
00036 addToRunTimeSelectionTable(pdf, RosinRammler, dictionary);
00037 }
00038
00039
00040
00041 Foam::RosinRammler::RosinRammler(const dictionary& dict, Random& rndGen)
00042 :
00043 pdf(dict, rndGen),
00044 pdfDict_(dict.subDict(typeName + "PDF")),
00045 minValue_(readScalar(pdfDict_.lookup("minValue"))),
00046 maxValue_(readScalar(pdfDict_.lookup("maxValue"))),
00047 d_(pdfDict_.lookup("d")),
00048 n_(pdfDict_.lookup("n")),
00049 ls_(d_),
00050 range_(maxValue_-minValue_)
00051 {
00052 if (minValue_<0)
00053 {
00054 FatalErrorIn
00055 (
00056 "RosinRammler::RosinRammler(const dictionary& dict)"
00057 ) << " minValue = " << minValue_ << ", it must be >0." << abort(FatalError);
00058 }
00059
00060 if (maxValue_<minValue_)
00061 {
00062 FatalErrorIn
00063 (
00064 "RosinRammler::RosinRammler(const dictionary& dict)"
00065 ) << " maxValue is smaller than minValue." << abort(FatalError);
00066 }
00067
00068
00069 scalar sMax = 0;
00070 label n = d_.size();
00071 for (label i=0; i<n; i++)
00072 {
00073 scalar s = exp(-1.0);
00074 for (label j=0; j<n; j++)
00075 {
00076 if (i!=j)
00077 {
00078 scalar xx = pow(d_[j]/d_[i], n_[j]);
00079 scalar y = xx*exp(-xx);
00080 s += y;
00081 }
00082 }
00083
00084 sMax = max(sMax, s);
00085 }
00086
00087 for (label i=0; i<n; i++)
00088 {
00089 ls_[i] /= sMax;
00090 }
00091 }
00092
00093
00094
00095
00096 Foam::RosinRammler::~RosinRammler()
00097 {}
00098
00099
00100
00101
00102 Foam::scalar Foam::RosinRammler::sample() const
00103 {
00104 scalar y = 0;
00105 scalar x = 0;
00106 label n = d_.size();
00107 bool success = false;
00108
00109 while (!success)
00110 {
00111 x = minValue_ + range_*rndGen_.scalar01();
00112 y = rndGen_.scalar01();
00113 scalar p = 0.0;
00114
00115 for (label i=0; i<n; i++)
00116 {
00117 scalar xx = pow(x/d_[i], n_[i]);
00118 p += ls_[i]*xx*exp(-xx);
00119 }
00120
00121 if (y<p)
00122 {
00123 success = true;
00124 }
00125 }
00126
00127 return x;
00128 }
00129
00130
00131 Foam::scalar Foam::RosinRammler::minValue() const
00132 {
00133 return minValue_;
00134 }
00135
00136
00137 Foam::scalar Foam::RosinRammler::maxValue() const
00138 {
00139 return maxValue_;
00140 }
00141
00142
00143
Copyright © 2000-2009 OpenCFD Ltd