distributionModel.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "distributionModel.H"
30
31// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32
33namespace Foam
34{
37}
38
39
40// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
41
43{
44 if (minValue() < 0)
45 {
47 << type() << "Distribution: "
48 << "Minimum value must be greater than zero." << nl
49 << "Supplied minValue = " << minValue()
50 << abort(FatalError);
51 }
52
53 if (maxValue() < minValue())
54 {
56 << type() << "Distribution: "
57 << "Maximum value cannot be smaller than minimum value" << nl
58 << " maxValue = " << maxValue()
59 << ", minValue = " << minValue()
60 << abort(FatalError);
61 }
62
63 if (maxValue() == minValue())
64 {
66 << type() << "Distribution: "
67 << "Maximum and minimum values are equal to each other" << nl
68 << " maxValue = " << maxValue()
69 << ", minValue = " << minValue()
70 << endl;
71 }
72}
73
74
75// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
76
78(
79 const word& name,
80 const dictionary& dict,
82)
83:
84 distributionModelDict_(dict),
85 rndGen_(rndGen),
86 minValue_(distributionModelDict_.getOrDefault<scalar>("minValue", GREAT)),
87 maxValue_(distributionModelDict_.getOrDefault<scalar>("maxValue", -GREAT))
88{}
89
90
92(
93 const distributionModel& p
94)
95:
96 distributionModelDict_(p.distributionModelDict_),
97 rndGen_(p.rndGen_),
98 minValue_(p.minValue_),
99 maxValue_(p.maxValue_)
100{}
101
102
103// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
104
106{
107 return minValue_;
108}
109
110
112{
113 return maxValue_;
114}
115
116
117// ************************************************************************* //
Random number generator.
Definition: Random.H:60
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A library of runtime-selectable doubly-truncated probability distribution models. Returns random samp...
virtual void check() const
Check that the distribution model is valid.
virtual scalar maxValue() const
Return the maximum of the distribution.
virtual scalar minValue() const
Return the minimum of the distribution.
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
volScalarField & p
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.
dictionary dict
Random rndGen
Definition: createFields.H:23