All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Constant.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) 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 Class
25  Foam::Function1s::Constant
26 
27 Description
28  Templated function 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 SourceFiles
37  Constant.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef Constant_H
42 #define Constant_H
43 
44 #include "Function1.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 namespace Function1s
51 {
52 
53 /*---------------------------------------------------------------------------*\
54  Class Constant Declaration
55 \*---------------------------------------------------------------------------*/
56 
57 template<class Type>
58 class Constant
59 :
60  public FieldFunction1<Type, Constant<Type>>
61 {
62  // Private Data
63 
64  //- Constant value
65  const Type value_;
66 
67 
68  // Private Member Functions
69 
70  //- Read the value
71  static Type readValue(const unitConversions& units, Istream& is);
72 
73 
74 public:
75 
76  // Runtime type information
77  TypeName("constant");
78 
79 
80  // Constructors
81 
82  //- Construct from name and value
83  Constant(const word& name, const Type& val);
84 
85  //- Construct from name and dictionary
86  Constant
87  (
88  const word& name,
89  const unitConversions& units,
90  const dictionary& dict
91  );
92 
93  //- Construct from name and Istream
94  Constant(const word& name, const unitConversions& units, Istream& is);
95 
96  //- Copy constructor
97  Constant(const Constant<Type>& cnst);
98 
99  //- Construct and return a clone
100  virtual tmp<Function1<Type>> clone() const
101  {
102  return tmp<Function1<Type>>(new Constant<Type>(*this));
103  }
104 
105 
106  //- Destructor
107  virtual ~Constant();
108 
109 
110  // Member Functions
111 
112  //- Return constant value
113  virtual inline Type value(const scalar) const;
114 
115  //- Integrate between two values
116  virtual inline Type integral(const scalar x1, const scalar x2) const;
117 
118  //- Is this function guaranteed to be constant?
119  virtual inline bool constant() const;
120 
121  //- Write in dictionary format
122  virtual void write(Ostream& os, const unitConversions& units) const;
123 
124 
125  // Member Operators
126 
127  //- Disallow default bitwise assignment
128  void operator=(const Constant<Type>&) = delete;
129 };
130 
131 
132 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
133 
134 } // End namespace Function1s
135 } // End namespace Foam
136 
137 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
138 
139 #include "ConstantI.H"
140 
141 #ifdef NoRepository
142  #include "Constant.C"
143  #include "Function1New.C"
144 #endif
145 
146 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
147 
148 #endif
149 
150 // ************************************************************************* //
const word & name() const
Return the name of the entry.
Definition: Function1.C:78
Templated function that returns a constant value.
Definition: Constant.H:60
Constant(const word &name, const Type &val)
Construct from name and value.
Definition: Constant.C:59
virtual Type integral(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: ConstantI.H:39
virtual void write(Ostream &os, const unitConversions &units) const
Write in dictionary format.
Definition: Constant.C:114
virtual Type value(const scalar) const
Return constant value.
Definition: ConstantI.H:31
void operator=(const Constant< Type > &)=delete
Disallow default bitwise assignment.
virtual bool constant() const
Is this function guaranteed to be constant?
Definition: ConstantI.H:49
virtual ~Constant()
Destructor.
Definition: Constant.C:106
virtual tmp< Function1< Type > > clone() const
Construct and return a clone.
Definition: Constant.H:99
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