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 |
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  DataEntry<Type>(cnst),
62  value_(cnst.value_),
63  dimensions_(cnst.dimensions_)
64 {}
65 
66 
67 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
68 
69 template<class Type>
71 {}
72 
73 
74 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
75 
76 template<class Type>
77 Type Foam::Constant<Type>::value(const scalar x) const
78 {
79  return value_;
80 }
81 
82 
83 template<class Type>
84 Type Foam::Constant<Type>::integrate(const scalar x1, const scalar x2) const
85 {
86  return (x2 - x1)*value_;
87 }
88 
89 
90 template<class Type>
92 {
93  return dimensioned<Type>("dimensionedValue", dimensions_, value_);
94 }
95 
96 
97 template<class Type>
99 (
100  const scalar x1, const scalar x2
101 ) const
102 {
103  return dimensioned<Type>("dimensionedValue", dimensions_, (x2-x1)*value_);
104 }
105 
106 
107 // * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
108 
109 #include "ConstantIO.C"
110 
111 
112 // ************************************************************************* //
bool isWord() const
Definition: tokenI.H:221
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A class for handling words, derived from string.
Definition: word.H:59
virtual ~Constant()
Destructor.
Definition: Constant.C:70
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
dictionary dict
Generic dimensioned Type class.
Constant(const word &entryName, const dictionary &dict)
Construct from entry name and Istream.
Definition: Constant.C:31
Templated basic entry that holds a constant value.
Definition: Constant.H:51
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:47
A token holds items read from Istream.
Definition: token.H:67
Type integrate(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: Constant.C:84
Type value(const scalar) const
Return constant value.
Definition: Constant.C:77
dimensioned< Type > dimValue(const scalar) const
Return dimensioned constant value.
Definition: Constant.C:91
Traits class for primitives.
Definition: pTraits.H:50
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
dimensioned< Type > dimIntegrate(const scalar x1, const scalar x2) const
Integrate between two values and return dimensioned type.
Definition: Constant.C:99
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: DataEntry.H:52