distribution.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "distribution.H"
27 
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32  defineTypeNameAndDebug(distribution, 0);
34 }
35 
36 
37 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
38 
40 {
41  if (max() < min())
42  {
44  << type() << ": The maximum value is smaller than the minimum "
45  << "value:" << nl << " max = " << max() << ", min = "
46  << min() << abort(FatalIOError);
47  }
48 }
49 
50 
52 {
53  if (min() < 0)
54  {
56  << type() << ": The minimum value must be greater than "
57  << "zero." << nl << " min = " << min()
58  << abort(FatalIOError);
59  }
60 }
61 
62 
65 (
66  const scalarField& x,
67  const tmp<scalarField>& pdf
68 ) const
69 {
70  return pos0(x - min())*pos0(max() - x)*pdf;
71 }
72 
73 
74 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
75 
77 (
78  const word& name,
79  const dictionary& dict,
80  Random& rndGen,
81  const label sampleQ
82 )
83 :
84  rndGen_(rndGen),
85  Q_(dict.lookup<scalar>("Q")),
86  sampleQ_(sampleQ)
87 {
88  if (Q_ < 0)
89  {
91  << name << ": Size exponent cannot be negative" << nl
92  << " Q = " << Q_ << abort(FatalIOError);
93  }
94 
95  if (sampleQ_ < 0)
96  {
98  << name << ": Sampling size exponent cannot be negative" << nl
99  << " sampleQ = " << sampleQ_ << abort(FatalError);
100  }
101 }
102 
103 
105 (
106  Random& rndGen,
107  const label Q,
108  const label sampleQ
109 )
110 :
111  rndGen_(rndGen),
112  Q_(Q),
113  sampleQ_(sampleQ)
114 {}
115 
116 
118 :
119  rndGen_(d.rndGen_),
120  Q_(d.Q_),
121  sampleQ_(sampleQ)
122 {}
123 
124 
125 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
126 
128 {}
129 
130 
131 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
132 
134 {
135  Info<< indent << "min/average/max value = " << min() << '/' << mean()
136  << '/' << max() << endl;
137 }
138 
139 
141 {
142  const scalar x0 = min(), x1 = max(), d = 0.1*(x1 - x0);
143 
144  tmp<scalarField> tResult(new scalarField(n));
145  scalarField& result = tResult.ref();
146 
147  result[0] = x0 - d;
148  result[1] = x0*(1 - sign(x0)*small);
149  result[2] = x0*(1 + sign(x0)*small);
150 
151  for (label i = 3; i < n - 3; ++ i)
152  {
153  const scalar f = scalar(i - 2)/(n - 5);
154 
155  result[i] = (1 - f)*x0 + f*x1;
156  }
157 
158  result[n - 3] = x1*(1 - sign(x1)*small);
159  result[n - 2] = x1*(1 + sign(x1)*small);
160  result[n - 1] = x1 + d;
161 
162  return tResult;
163 }
164 
165 
166 // ************************************************************************* //
label n
Random number generator.
Definition: Random.H:58
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
Accumulating histogram of values. Specified bin resolution automatic generation of bins.
Definition: distribution.H:61
void report() const
Report.
Definition: distribution.C:133
virtual scalar max() const =0
Return the maximum value.
virtual void validatePositive(const dictionary &dict) const
Validate that the lower bound is positive.
Definition: distribution.C:51
tmp< scalarField > clipPDF(const scalarField &x, const tmp< scalarField > &pdf) const
Clip the PDF values to zero outside the bounds.
Definition: distribution.C:65
const label Q_
Distribution size exponent.
Definition: distribution.H:84
virtual ~distribution()
Destructor.
Definition: distribution.C:78
virtual tmp< scalarField > x(const label n) const
Return coordinates to plot across the range of the distribution.
Definition: distribution.C:140
const label sampleQ_
Sample size exponent.
Definition: distribution.H:87
virtual void validateBounds(const dictionary &dict) const
Validate that the bounds are monotonic.
Definition: distribution.C:39
distribution()
Construct null.
Definition: distribution.C:55
virtual scalar min() const =0
Return the minimum value.
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
A class for handling words, derived from string.
Definition: word.H:62
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:318
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
Namespace for OpenFOAM.
dimensionedScalar pos0(const dimensionedScalar &ds)
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
dimensionedScalar sign(const dimensionedScalar &ds)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
errorManip< error > abort(error &err)
Definition: errorManip.H:131
messageStream Info
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
defineTypeNameAndDebug(combustionModel, 0)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
IOerror FatalIOError
error FatalError
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:221
static const char nl
Definition: Ostream.H:260
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
labelList f(nPoints)
dictionary dict
Random rndGen(label(0))