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