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-2022 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(const word& name, const dictionary& dict);
81 
82  //- Construct from name and Istream
83  // Reads the constant value without the Function1 type
84  // for backward compatibility
85  Constant(const word& name, Istream& is);
86 
87  //- Copy constructor
88  Constant(const Constant<Type>& cnst);
89 
90  //- Construct and return a clone
91  virtual tmp<Function1<Type>> clone() const
92  {
93  return tmp<Function1<Type>>(new Constant<Type>(*this));
94  }
95 
96 
97  //- Destructor
98  virtual ~Constant();
99 
100 
101  // Member Functions
102 
103  //- Return constant value
104  virtual inline Type value(const scalar) const;
105 
106  //- Integrate between two values
107  virtual inline Type integral(const scalar x1, const scalar x2) const;
108 
109  //- Write in dictionary format
110  virtual void write(Ostream& os) const;
111 
112 
113  // Member Operators
114 
115  //- Disallow default bitwise assignment
116  void operator=(const Constant<Type>&) = delete;
117 };
118 
119 
120 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
121 
122 } // End namespace Function1s
123 } // End namespace Foam
124 
125 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
126 
127 #include "ConstantI.H"
128 
129 #ifdef NoRepository
130  #include "Constant.C"
131  #include "Function1New.C"
132 #endif
133 
134 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
135 
136 #endif
137 
138 // ************************************************************************* //
dictionary dict
Constant(const word &name, const Type &val)
Construct from name and value.
Definition: Constant.C:32
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
const word & name() const
Return the name of the entry.
Definition: Function1.C:82
virtual Type integral(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: ConstantI.H:39
A class for handling words, derived from string.
Definition: word.H:59
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
virtual void write(Ostream &os) const
Write in dictionary format.
Definition: Constant.C:103
virtual ~Constant()
Destructor.
Definition: Constant.C:96
Templated function that returns a constant value.
Definition: Constant.H:57
virtual tmp< Function1< Type > > clone() const
Construct and return a clone.
Definition: Constant.H:90
A class for managing temporary objects.
Definition: PtrList.H:53
virtual Type value(const scalar) const
Return constant value.
Definition: ConstantI.H:31
void operator=(const Constant< Type > &)=delete
Disallow default bitwise assignment.
Namespace for OpenFOAM.