1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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 "exponential.H"
29 #include "addToRunTimeSelectionTable.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 defineTypeNameAndDebug(exponential, 0);
36 addToRunTimeSelectionTable(pdf, exponential, dictionary);
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 Foam::exponential::exponential(const dictionary& dict, Random& rndGen)
44 pdfDict_(dict.subDict(typeName + "PDF")),
45 minValue_(readScalar(pdfDict_.lookup("minValue"))),
46 maxValue_(readScalar(pdfDict_.lookup("maxValue"))),
47 lambda_(pdfDict_.lookup("lambda")),
49 range_(maxValue_-minValue_)
55 "exponential::exponential(const dictionary& dict)"
56 ) << " minValue = " << minValue_ << ", it must be >0." << abort(FatalError);
60 label n = lambda_.size();
61 for (label i=0; i<n; i++)
63 scalar s = lambda_[i]*exp(-lambda_[i]*minValue_);
64 for (label j=0; j<n; j++)
68 scalar y = lambda_[j]*exp(-lambda_[j]*minValue_);
76 for(label i=0; i<n; i++)
83 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
85 Foam::exponential::~exponential()
89 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
91 Foam::scalar Foam::exponential::sample() const
95 label n = lambda_.size();
100 x = minValue_ + range_*rndGen_.scalar01();
101 y = rndGen_.scalar01();
104 for(label i=0; i<n; i++)
106 p += ls_[i]*exp(-lambda_[i]*x);
119 Foam::scalar Foam::exponential::minValue() const
125 Foam::scalar Foam::exponential::maxValue() const
131 // ************************************************************************* //