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-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::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  Type value_;
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(const word& name, const dictionary& dict);
87 
88  //- Construct from name and Istream
89  // Reads the constant value without the Function2 type
90  // for backward compatibility
91  Constant(const word& name, Istream& is);
92 
93  //- Copy constructor
94  Constant(const Constant<Type>& cnst);
95 
96  //- Construct and return a clone
97  virtual tmp<Function2<Type>> clone() const
98  {
99  return tmp<Function2<Type>>(new Constant<Type>(*this));
100  }
101 
102 
103  //- Destructor
104  virtual ~Constant();
105 
106 
107  // Member Functions
108 
109  //- Return constant
110  virtual inline Type value(const scalar x, const scalar y) const;
111 
112  //- Return constant field
113  virtual inline tmp<Field<Type>> value
114  (
115  const scalarField& x,
116  const scalarField& y
117  ) const;
118 
119  //- Write in dictionary format
120  virtual void write(Ostream& os) const;
121 
122 
123  // Member Operators
124 
125  //- Disallow default bitwise assignment
126  void operator=(const Constant<Type>&) = delete;
127 };
128 
129 
130 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
131 
132 } // End namespace Function2s
133 } // End namespace Foam
134 
135 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
136 
137 #include "Constant2I.H"
138 
139 #ifdef NoRepository
140  #include "Constant2.C"
141  #include "Function2New.C"
142 #endif
143 
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 
146 #endif
147 
148 // ************************************************************************* //
scalar y
const word & name() const
Return the name of the entry.
Definition: Function2.C:81
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:32
virtual tmp< Function2< Type > > clone() const
Construct and return a clone.
Definition: Constant2.H:96
virtual void write(Ostream &os) const
Write in dictionary format.
Definition: Constant2.C:102
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:95
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:160
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.
dictionary dict