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-2020 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 - for entry <name> returning the value <value>:
31  \verbatim
32  <name> constant <value>
33  \endverbatim
34 
35 SourceFiles
36  Constant.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef Constant_H
41 #define Constant_H
42 
43 #include "Function1.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 namespace Function1s
50 {
51 
52 /*---------------------------------------------------------------------------*\
53  Class Constant Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 template<class Type>
57 class Constant
58 :
59  public FieldFunction1<Type, Constant<Type>>
60 {
61  // Private Data
62 
63  //- Constant value
64  Type value_;
65 
66 
67 public:
68 
69  // Runtime type information
70  TypeName("constant");
71 
72 
73  // Constructors
74 
75  //- Construct from name and value
76  Constant(const word& name, const Type& val);
77 
78  //- Construct from name and dictionary
79  Constant(const word& name, const dictionary& dict);
80 
81  //- Construct from name and Istream
82  // Reads the constant value without the Function1 type
83  // for backward compatibility
84  Constant(const word& name, Istream& is);
85 
86  //- Copy constructor
87  Constant(const Constant<Type>& cnst);
88 
89  //- Construct and return a clone
90  virtual tmp<Function1<Type>> clone() const
91  {
92  return tmp<Function1<Type>>(new Constant<Type>(*this));
93  }
94 
95 
96  //- Destructor
97  virtual ~Constant();
98 
99 
100  // Member Functions
101 
102  //- Return constant value
103  virtual inline Type value(const scalar) const;
104 
105  //- Integrate between two values
106  virtual inline Type integral(const scalar x1, const scalar x2) const;
107 
108  //- Write in dictionary format
109  virtual void write(Ostream& os) const;
110 
111 
112  // Member Operators
113 
114  //- Disallow default bitwise assignment
115  void operator=(const Constant<Type>&) = delete;
116 };
117 
118 
119 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
120 
121 } // End namespace Function1s
122 } // End namespace Foam
123 
124 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
125 
126 #include "ConstantI.H"
127 
128 #ifdef NoRepository
129  #include "Constant.C"
130  #include "Function1New.C"
131 #endif
132 
133 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
134 
135 #endif
136 
137 // ************************************************************************* //
Constant(const word &name, const Type &val)
Construct from name and value.
Definition: Constant.C:32
const word const dictionary & dict
Definition: Function1.H:84
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
const word & name() const
Return the name of the entry.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
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:56
virtual tmp< Function1< Type > > clone() const
Construct and return a clone.
Definition: Constant.H:89
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.