fixedValue.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-2024 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 "fixedValue.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 namespace distributions
34 {
37 }
38 }
39 
40 
41 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 
44 (
45  const unitConversion& units,
46  const dictionary& dict,
47  const label sampleQ,
49 )
50 :
52  (
53  -labelMax,
54  sampleQ,
55  std::move(rndGen)
56  ),
57  value_(dict.lookup<scalar>("value", units))
58 {}
59 
60 
62 (
63  const fixedValue& d,
64  const label sampleQ
65 )
66 :
68  value_(d.value_)
69 {}
70 
71 
72 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
73 
75 {}
76 
77 
78 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
79 
81 {
82  return value_;
83 }
84 
85 
87 {
88  return value_;
89 }
90 
91 
93 {
94  return value_;
95 }
96 
97 
99 {
100  return value_;
101 }
102 
103 
105 (
106  const scalarField& x,
107  const label e,
108  const bool
109 ) const
110 {
111  return pos(x - value_)*integerPow(value_, e);
112 }
113 
114 
116 (
117  Ostream& os,
118  const unitConversion& units
119 ) const
120 {
121  writeEntry(os, "type", type());
122  writeEntry(os, "value", units, value_);
123 }
124 
125 
128 {
129  const scalar d = 0.1*mag(value_);
130 
131  tmp<scalarField> tResult(new scalarField(5));
132  scalarField& result = tResult.ref();
133 
134  result[0] = value_ - d;
135  result[1] = value_*(1 - sign(value_)*rootVSmall);
136  result[2] = value_;
137  result[3] = value_*(1 + sign(value_)*rootVSmall);
138  result[4] = value_ + d;
139 
140  return tResult;
141 }
142 
143 
146 {
147  tmp<scalarField> tResult(new scalarField(5, 0));
148  scalarField& result = tResult.ref();
149 
150  result[2] = 1/rootVSmall;
151 
152  return tResult;
153 }
154 
155 
156 // ************************************************************************* //
label n
Macros for easy insertion into run-time selection tables.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Base class for statistical distributions.
Definition: distribution.H:76
Distribution which always takes a specified fixed value.
Definition: fixedValue.H:65
fixedValue(const unitConversion &units, const dictionary &dict, const label sampleQ, randomGenerator &&rndGen)
Construct from a dictionary.
Definition: fixedValue.C:44
virtual tmp< scalarField > integralPDFxPow(const scalarField &x, const label e, const bool consistent=false) const
Return the integral of the PDF multiplied by an integer power of x.
Definition: fixedValue.C:105
virtual scalar min() const
Return the minimum value.
Definition: fixedValue.C:86
virtual scalar sample() const
Sample the distribution.
Definition: fixedValue.C:80
virtual ~fixedValue()
Destructor.
Definition: fixedValue.C:74
virtual tmp< scalarField > plotPDF(const scalarField &x) const
Return values to plot the probability density function.
Definition: fixedValue.C:145
virtual void write(Ostream &os, const unitConversion &units) const
Write to a stream.
Definition: fixedValue.C:116
virtual scalar max() const
Return the maximum value.
Definition: fixedValue.C:92
virtual scalar mean() const
Return the mean value.
Definition: fixedValue.C:98
virtual tmp< scalarField > plotX(const label n) const
Return coordinates to plot across the range of the distribution.
Definition: fixedValue.C:127
Random number generator.
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:197
Unit conversion structure. Contains the associated dimensions and the multiplier with which to conver...
defineTypeNameAndDebug(exponential, 0)
addToRunTimeSelectionTable(distribution, exponential, dictionary)
Namespace for OpenFOAM.
dimensionedScalar pos(const dimensionedScalar &ds)
const doubleScalar e
Definition: doubleScalar.H:106
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
scalar integerPow(const scalar x, const label e)
Compute the power of the number x to the integer e.
Definition: scalarI.H:30
void mag(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
const HashTable< unitConversion > & units()
Get the table of unit conversions.
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
static const label labelMax
Definition: label.H:62
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
dictionary dict
randomGenerator rndGen(653213)