OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

RosinRammler.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "RosinRammler.H"
00028 #include "addToRunTimeSelectionTable.H"
00029 
00030 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00031 
00032 namespace Foam
00033 {
00034     defineTypeNameAndDebug(RosinRammler, 0);
00035 
00036     addToRunTimeSelectionTable(pdf, RosinRammler, dictionary);
00037 }
00038 
00039 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
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     // find max value so that it can be normalized to 1.0
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 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00095 
00096 Foam::RosinRammler::~RosinRammler()
00097 {}
00098 
00099 
00100 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
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