Constant.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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::Constant
26 
27 Description
28  Templated basic entry that holds a constant value.
29 
30  Usage - for entry <entryName> having the value <value>:
31  \verbatim
32  <entryName> constant <value>
33  \endverbatim
34 
35 SourceFiles
36  Constant.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef Constant_H
41 #define Constant_H
42 
43 #include "DataEntry.H"
44 #include "dimensionSet.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 template<class Type>
52 class Constant;
53 
54 template<class Type>
56 
57 /*---------------------------------------------------------------------------*\
58  Class Constant Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 template<class Type>
62 class Constant
63 :
64  public DataEntry<Type>
65 {
66  // Private data
67 
68  //- Constant value
69  Type value_;
70 
71  //- The dimension set
73 
74 
75  // Private Member Functions
76 
77  //- Disallow default bitwise assignment
78  void operator=(const Constant<Type>&);
79 
80 
81 public:
82 
83  // Runtime type information
84  TypeName("constant");
85 
86 
87  // Constructors
88 
89  //- Construct from components
90  Constant
91  (
92  const word& entryName,
93  const Type& value,
94  const dimensionSet& dimensions = dimless
95  );
96 
97  //- Construct from entry name and dictionary
98  Constant(const word& entryName, const dictionary& dict);
99 
100  //- Copy constructor
101  Constant(const Constant<Type>& cnst);
102 
103  //- Construct and return a clone
104  virtual tmp<DataEntry<Type> > clone() const
105  {
106  return tmp<DataEntry<Type> >(new Constant<Type>(*this));
107  }
108 
109 
110  //- Destructor
111  virtual ~Constant();
112 
113 
114  // Member Functions
115 
116  //- Return constant value
117  Type value(const scalar) const;
118 
119  //- Integrate between two values
120  Type integrate(const scalar x1, const scalar x2) const;
121 
122  //- Return dimensioned constant value
123  dimensioned<Type> dimValue(const scalar) const;
124 
125  //- Integrate between two values and return dimensioned type
127  (
128  const scalar x1,
129  const scalar x2
130  ) const;
131 
132 
133  // I/O
134 
135  //- Ostream Operator
136  friend Ostream& operator<< <Type>
137  (
138  Ostream& os,
139  const Constant<Type>& cnst
140  );
141 
142  //- Write in dictionary format
143  virtual void writeData(Ostream& os) const;
144 };
145 
146 
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
148 
149 } // End namespace Foam
150 
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 
153 #ifdef NoRepository
154 # include "Constant.C"
155 #endif
156 
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158 
159 #endif
160 
161 // ************************************************************************* //
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
Foam::Constant::operator=
void operator=(const Constant< Type > &)
Disallow default bitwise assignment.
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::Constant::value_
Type value_
Constant value.
Definition: Constant.H:68
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Constant.C
Foam::Constant::~Constant
virtual ~Constant()
Destructor.
Definition: Constant.C:84
Foam::Constant::Constant
Constant(const word &entryName, const Type &value, const dimensionSet &dimensions=dimless)
Construct from components.
Foam::dimensionSet
Dimension set for the base types.
Definition: dimensionSet.H:116
Foam::Constant::dimensions_
dimensionSet dimensions_
The dimension set.
Definition: Constant.H:71
Foam::Constant
Templated basic entry that holds a constant value.
Definition: Constant.H:51
Foam::Constant::dimValue
dimensioned< Type > dimValue(const scalar) const
Return dimensioned constant value.
Definition: Constant.C:105
Foam::Constant::value
Type value(const scalar) const
Return constant value.
Definition: Constant.C:91
DataEntry.H
Foam::Constant::dimIntegrate
dimensioned< Type > dimIntegrate(const scalar x1, const scalar x2) const
Integrate between two values and return dimensioned type.
Definition: Constant.C:113
Foam::operator<<
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:130
dimensionSet.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::dimensioned< Type >
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::Constant::clone
virtual tmp< DataEntry< Type > > clone() const
Construct and return a clone.
Definition: Constant.H:103
Foam::Constant::integrate
Type integrate(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: Constant.C:98
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::DataEntry
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: DataEntry.H:52
Foam::Constant::TypeName
TypeName("constant")
Foam::Constant::writeData
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: ConstantIO.C:63