Constant.C
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-2015 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 \*---------------------------------------------------------------------------*/
25 
26 #include "Constant.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class Type>
32 :
33  DataEntry<Type>(entryName),
34  value_(pTraits<Type>::zero),
35  dimensions_(dimless)
36 {
37  Istream& is(dict.lookup(entryName));
38  word entryType(is);
39  token firstToken(is);
40  if (firstToken.isWord())
41  {
42  token nextToken(is);
43  if (nextToken == token::BEGIN_SQR)
44  {
45  is.putBack(nextToken);
46  is >> dimensions_;
47  is >> value_;
48  }
49  }
50  else
51  {
52  is.putBack(firstToken);
53  is >> value_;
54  }
55 }
56 
57 
58 template<class Type>
60 (
61  const word& entryName,
62  const Type& value,
63  const dimensionSet& dimensions
64 )
65 :
66  DataEntry<Type>(entryName),
67  value_(value),
68  dimensions_(dimensions)
69 {}
70 
71 
72 template<class Type>
74 :
75  DataEntry<Type>(cnst),
76  value_(cnst.value_),
77  dimensions_(cnst.dimensions_)
78 {}
79 
80 
81 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
82 
83 template<class Type>
85 {}
86 
87 
88 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
89 
90 template<class Type>
91 Type Foam::Constant<Type>::value(const scalar x) const
92 {
93  return value_;
94 }
95 
96 
97 template<class Type>
98 Type Foam::Constant<Type>::integrate(const scalar x1, const scalar x2) const
99 {
100  return (x2 - x1)*value_;
101 }
102 
103 
104 template<class Type>
106 {
107  return dimensioned<Type>("dimensionedValue", dimensions_, value_);
108 }
109 
110 
111 template<class Type>
113 (
114  const scalar x1, const scalar x2
115 ) const
116 {
117  return dimensioned<Type>("dimensionedValue", dimensions_, (x2-x1)*value_);
118 }
119 
120 
121 // * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
122 
123 #include "ConstantIO.C"
124 
125 
126 // ************************************************************************* //
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
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
ConstantIO.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::token
A token holds items read from Istream.
Definition: token.H:67
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
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::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
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::token::isWord
bool isWord() const
Definition: tokenI.H:221
Foam::dimensioned< Type >
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:50
Foam::Constant::integrate
Type integrate(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: Constant.C:98
Foam::Istream::putBack
void putBack(const token &)
Put back token.
Definition: Istream.C:30
x
x
Definition: LISASMDCalcMethod2.H:52
Constant.H
Foam::token::BEGIN_SQR
@ BEGIN_SQR
Definition: token.H:102
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::zero
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:47