initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / thermophysicalModels / pdfs / RosinRammler / RosinRammler.C
blobbd9fb04fad62e86c0a1a95138c61663dfc2f0edb
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
28 #include "RosinRammler.H"
29 #include "addToRunTimeSelectionTable.H"
31 namespace Foam
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(RosinRammler, 0);
38 addToRunTimeSelectionTable
40     pdf,
41     RosinRammler,
42     dictionary
45 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
48 // Construct from components
49 RosinRammler::RosinRammler
51     const dictionary& dict,
52     Random& rndGen
55     pdf(dict, rndGen),
56     pdfDict_(dict.subDict(typeName + "PDF")),
57     minValue_(readScalar(pdfDict_.lookup("minValue"))),
58     maxValue_(readScalar(pdfDict_.lookup("maxValue"))),
59     d_(pdfDict_.lookup("d")),
60     n_(pdfDict_.lookup("n")),
61     ls_(d_),
62     range_(maxValue_-minValue_)
64     if (minValue_<0)
65     {
66         FatalErrorIn
67         (
68             "RosinRammler::RosinRammler(const dictionary& dict)"
69         ) << " minValue = " << minValue_ << ", it must be >0." << abort(FatalError);
70     }
72     if (maxValue_<minValue_)
73     {
74         FatalErrorIn
75         (
76             "RosinRammler::RosinRammler(const dictionary& dict)"
77         ) << " maxValue is smaller than minValue." << abort(FatalError);
78     }
80     // find max value so that it can be normalized to 1.0
81     scalar sMax = 0;
82     label n = d_.size();
83     for(label i=0; i<n; i++)
84     {
85         scalar s = exp(-1.0);
86         for(label j=0; j<n; j++)
87         {
88             if (i!=j)
89             {
90                 scalar xx = pow(d_[j]/d_[i], n_[j]);
91                 scalar y = xx*exp(-xx);
92                 s += y;
93             }
94         }
96         sMax = max(sMax, s);
97     }
99     for(label i=0; i<n; i++)
100     {
101         ls_[i] /= sMax;
102     }
107 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
109 Foam::RosinRammler::~RosinRammler()
113 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
115 scalar RosinRammler::sample() const
117     scalar y = 0;
118     scalar x = 0;
119     label n = d_.size();
120     bool success = false;
122     while(!success)
123     {
124         x = minValue_ + range_*rndGen_.scalar01();
125         y = rndGen_.scalar01();
126         scalar p = 0.0;
128         for(label i=0; i<n; i++)
129         {
130             scalar xx = pow(x/d_[i], n_[i]);
131             p += ls_[i]*xx*exp(-xx);
132         }
134         if (y<p)
135         {
136             success = true;
137         }
138     }
140     return x;
143 scalar RosinRammler::minValue() const
145     return minValue_;
148 scalar RosinRammler::maxValue() const
150     return maxValue_;
153 // ************************************************************************* //