CompatibilityConstant.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-2012 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 "CompatibilityConstant.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class Type>
32 (
33  const word& entryName,
34  const dictionary& dict
35 )
36 :
37  DataEntry<Type>(entryName),
38  value_(pTraits<Type>::zero),
39  dimensions_(dimless)
40 {
41  Istream& is(dict.lookup(entryName));
42 
43  token firstToken(is);
44  if (firstToken.isWord())
45  {
46  token nextToken(is);
47  if (nextToken == token::BEGIN_SQR)
48  {
49  is.putBack(nextToken);
50  is >> dimensions_;
51  is >> value_;
52  }
53  }
54  else
55  {
56  is.putBack(firstToken);
57  is >> value_;
58  }
59 }
60 
61 
62 template<class Type>
64 (
65  const CompatibilityConstant<Type>& cnst
66 )
67 :
68  DataEntry<Type>(cnst),
69  value_(cnst.value_),
70  dimensions_(cnst.dimensions_)
71 {}
72 
73 
74 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
75 
76 template<class Type>
78 {}
79 
80 
81 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
82 
83 template<class Type>
85 {
86  return value_;
87 }
88 
89 
90 template<class Type>
92 (
93  const scalar x1,
94  const scalar x2
95 ) const
96 {
97  return (x2 - x1)*value_;
98 }
99 
100 
101 template<class Type>
103 dimValue(const scalar x) const
104 {
105  return dimensioned<Type>("dimensionedValue", dimensions_, value_);
106 }
107 
108 
109 template<class Type>
111 (
112  const scalar x1, const scalar x2
113 ) const
114 {
115  return dimensioned<Type>("dimensionedValue", dimensions_, (x2-x1)*value_);
116 }
117 
118 // * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
119 
120 #include "CompatibilityConstantIO.C"
121 
122 
123 // ************************************************************************* //
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::CompatibilityConstant::integrate
Type integrate(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: CompatibilityConstant.C:92
Foam::token
A token holds items read from Istream.
Definition: token.H:67
Foam::CompatibilityConstant::~CompatibilityConstant
virtual ~CompatibilityConstant()
Destructor.
Definition: CompatibilityConstant.C:77
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::CompatibilityConstant::value_
Type value_
Constant value.
Definition: CompatibilityConstant.H:69
Foam::CompatibilityConstant
Templated basic entry that holds a constant value for backwards compatibility (when DataEntry type is...
Definition: CompatibilityConstant.H:52
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::CompatibilityConstant::CompatibilityConstant
CompatibilityConstant(const word &entryName, const dictionary &dict)
Construct from entry name and Istream.
Definition: CompatibilityConstant.C:32
CompatibilityConstant.H
Foam::CompatibilityConstant::value
Type value(const scalar) const
Return constant value.
Definition: CompatibilityConstant.C:84
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:50
Foam::Istream::putBack
void putBack(const token &)
Put back token.
Definition: Istream.C:30
x
x
Definition: LISASMDCalcMethod2.H:52
CompatibilityConstantIO.C
Foam::CompatibilityConstant::dimIntegrate
dimensioned< Type > dimIntegrate(const scalar x1, const scalar x2) const
Integrate between two values and return dimensioned type.
Definition: CompatibilityConstant.C:111
Foam::CompatibilityConstant::dimValue
dimensioned< Type > dimValue(const scalar) const
Return dimensioned constant value.
Definition: CompatibilityConstant.C:103
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::CompatibilityConstant::dimensions_
dimensionSet dimensions_
The dimension set.
Definition: CompatibilityConstant.H:72