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,
49 )
50 :
52  (
53  -labelMax,
54  -labelMax,
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  Ostream& os,
107  const unitConversion& units
108 ) const
109 {
111 
112  writeEntry(os, "value", units, value_);
113 }
114 
115 
118 {
119  const scalar d = 0.1*mag(value_);
120 
121  tmp<scalarField> tResult(new scalarField(5));
122  scalarField& result = tResult.ref();
123 
124  result[0] = value_ - d;
125  result[1] = value_*(1 - sign(value_)*rootVSmall);
126  result[2] = value_;
127  result[3] = value_*(1 + sign(value_)*rootVSmall);
128  result[4] = value_ + d;
129 
130  return tResult;
131 }
132 
133 
136 {
137  tmp<scalarField> tResult(new scalarField(5, 0));
138  scalarField& result = tResult.ref();
139 
140  result[2] = 1/rootVSmall;
141 
142  return tResult;
143 }
144 
145 
146 // ************************************************************************* //
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 keyword definitions, which are a keyword followed by any number of values (e....
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 scalar min() const
Return the minimum value.
Definition: fixedValue.C:86
virtual scalar sample() const
Sample the distribution.
Definition: fixedValue.C:80
virtual tmp< scalarField > PDF(const scalarField &x) const
Return the distribution probability density function.
Definition: fixedValue.C:135
virtual ~fixedValue()
Destructor.
Definition: fixedValue.C:74
virtual tmp< scalarField > x(const label n) const
Return coordinates to plot across the range of the distribution.
Definition: fixedValue.C:117
virtual void write(Ostream &os, const unitConversion &units) const
Write to a stream.
Definition: fixedValue.C:105
virtual scalar max() const
Return the maximum value.
Definition: fixedValue.C:92
virtual scalar mean() const
Return the mean value.
Definition: fixedValue.C:98
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:181
Unit conversion structure. Contains the associated dimensions and the multiplier with which to conver...
defineTypeNameAndDebug(exponential, 0)
addToRunTimeSelectionTable(distribution, exponential, dictionary)
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
Namespace for OpenFOAM.
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
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
dimensioned< scalar > mag(const dimensioned< Type > &)
static const label labelMax
Definition: label.H:62
dictionary dict
randomGenerator rndGen(653213)