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-2026 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  Type value_;
66 
67 
68 public:
69 
70  // Runtime type information
71  TypeName("constant");
72 
73 
74  // Constructors
75 
76  //- Construct from name and value
77  Constant(const word& name, const Type& val);
78 
79  //- Construct from name and dictionary
80  Constant
81  (
82  const word& name,
83  const unitSets& units,
84  const dictionary& dict
85  );
86 
87  //- Construct from name and Istream
88  Constant(const word& name, const unitSets& units, Istream& is);
89 
90  //- Copy constructor
91  Constant(const Constant<Type>& cnst);
92 
93  //- Construct and return a clone
94  virtual tmp<Function1<Type>> clone() const
95  {
96  return tmp<Function1<Type>>(new Constant<Type>(*this));
97  }
98 
99 
100  //- Destructor
101  virtual ~Constant();
102 
103 
104  // Member Functions
105 
106  //- Return constant value
107  virtual inline Type value(const scalar) const;
108 
109  //- Integrate between two values
110  virtual inline Type integral(const scalar x1, const scalar x2) const;
111 
112  //- Is this function guaranteed to be constant?
113  virtual inline bool constant() const;
114 
115  //- Write in dictionary format
116  virtual void write(Ostream& os, const unitSets& units) const;
117 
118 
119  // Member Operators
120 
121  //- Copy assignment
122  void operator=(const Constant<Type>&);
123 };
124 
125 
126 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
127 
128 } // End namespace Function1s
129 } // End namespace Foam
130 
131 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
132 
133 #include "ConstantI.H"
134 
135 #ifdef NoRepository
136  #include "Constant.C"
137  #include "Function1New.C"
138 #endif
139 
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
141 
142 #endif
143 
144 // ************************************************************************* //
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:33
virtual Type integral(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: ConstantI.H:39
void operator=(const Constant< Type > &)
Copy assignment.
Definition: Constant.C:100
virtual void write(Ostream &os, const unitSets &units) const
Write in dictionary format.
Definition: Constant.C:88
virtual Type value(const scalar) const
Return constant value.
Definition: ConstantI.H:31
virtual bool constant() const
Is this function guaranteed to be constant?
Definition: ConstantI.H:49
virtual ~Constant()
Destructor.
Definition: Constant.C:80
virtual tmp< Function1< Type > > clone() const
Construct and return a clone.
Definition: Constant.H:93
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 keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
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:63
Namespace for OpenFOAM.
dictionary dict
Struct containing two unitSets for use in converting both the argument and the value of a Function1.