All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Constant2.H
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) 2020-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 Class
25  Foam::Function2s::Constant
26 
27 Description
28  Templated function of two variables that returns a constant value.
29 
30 Usage
31  For entry <name> returning the value <value>:
32  \verbatim
33  <name> constant <value>;
34  \endverbatim
35 
36  or simply
37 
38  \verbatim
39  <name> <value>;
40  \endverbatim
41 
42 SourceFiles
43  Constant.C
44 
45 \*---------------------------------------------------------------------------*/
46 
47 #ifndef Constant2_H
48 #define Constant2_H
49 
50 #include "Function2.H"
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 namespace Function2s
57 {
58 
59 /*---------------------------------------------------------------------------*\
60  Class Constant Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 template<class Type>
64 class Constant
65 :
66  public FieldFunction2<Type, Constant<Type>>
67 {
68  // Private Data
69 
70  //- Constant value
71  const Type value_;
72 
73 
74  // Private Member Functions
75 
76  //- Read the value
77  static Type readValue(const unitConversions& units, Istream& is);
78 
79 
80 public:
81 
82  // Runtime type information
83  TypeName("constant");
84 
85 
86  // Constructors
87 
88  //- Construct from name and value
89  Constant(const word& name, const Type& val);
90 
91  //- Construct from name and dictionary
92  Constant
93  (
94  const word& name,
95  const unitConversions& units,
96  const dictionary& dict
97  );
98 
99  //- Construct from name and Istream
100  // Reads the constant value without the Function2 type
101  // for backward compatibility
102  Constant(const word& name, const unitConversions& units, Istream& is);
103 
104  //- Copy constructor
105  Constant(const Constant<Type>& cnst);
106 
107  //- Construct and return a clone
108  virtual tmp<Function2<Type>> clone() const
109  {
110  return tmp<Function2<Type>>(new Constant<Type>(*this));
111  }
112 
113 
114  //- Destructor
115  virtual ~Constant();
116 
117 
118  // Member Functions
119 
120  //- Return constant
121  virtual inline Type value(const scalar x, const scalar y) const;
122 
123  //- Return constant field
124  virtual inline tmp<Field<Type>> value
125  (
126  const scalarField& x,
127  const scalarField& y
128  ) const;
129 
130  //- Write in dictionary format
131  virtual void write(Ostream& os, const unitConversions& units) const;
132 
133 
134  // Member Operators
135 
136  //- Disallow default bitwise assignment
137  void operator=(const Constant<Type>&) = delete;
138 };
139 
140 
141 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
142 
143 } // End namespace Function2s
144 } // End namespace Foam
145 
146 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
147 
148 #include "Constant2I.H"
149 
150 #ifdef NoRepository
151  #include "Constant2.C"
152  #include "Function2New.C"
153 #endif
154 
155 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156 
157 #endif
158 
159 // ************************************************************************* //
scalar y
const word & name() const
Return the name of the entry.
Definition: Function2.C:78
Templated function of two variables that returns a constant value.
Definition: Constant2.H:66
Constant(const word &name, const Type &val)
Construct from name and value.
Definition: Constant2.C:59
virtual tmp< Function2< Type > > clone() const
Construct and return a clone.
Definition: Constant2.H:107
virtual void write(Ostream &os, const unitConversions &units) const
Write in dictionary format.
Definition: Constant2.C:114
void operator=(const Constant< Type > &)=delete
Disallow default bitwise assignment.
virtual Type value(const scalar x, const scalar y) const
Return constant.
Definition: Constant2I.H:32
virtual ~Constant()
Destructor.
Definition: Constant2.C:106
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
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
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
const HashTable< unitConversion > & units()
Get the table of unit conversions.
dictionary dict