All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dimensionedConstants.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) 2011-2019 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 Global
25  dimensionedConstants
26 
27 Description
28  Dictionary reading and supplying the dimensioned constants used within
29  OpenFOAM, particularly for thermodynamics.
30 
31  The values are read from the OpenFOAM etc/controlDict and should be
32  changed to run with a different set of units from the default SI units.
33 
34 SourceFiles
35  dimensionedConstants.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef dimensionedConstants_H
40 #define dimensionedConstants_H
41 
42 #include "dictionary.H"
43 #include "dimensionedScalar.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
53 
54 
56 :
57  public simpleRegIOobject,
58  public dimensionedScalar
59 {
60  const word& group_;
61 
62  //- Lookup the dimensionedConstant from the registry
63  void lookup();
64 
65 
66 public:
67 
69  (
70  const word& group,
71  const char* name,
73  )
74  :
76  dimensionedScalar(name, dimensions, 0),
77  group_(group)
78  {
79  lookup();
80  }
81 
83  {}
84 
85  virtual void readData(Istream& is)
86  {
87  lookup();
88  }
89 
90  virtual void writeData(Ostream& os) const
91  {
92  os << static_cast<const dimensionedScalar&>(*this);
93  }
94 };
95 
96 
97 //- Defined and register a dimensioned constant
98 #define defineDimensionedConstant(Group, Name, Dimensions) \
99  registerDimensionedConstant register##Name##DimensionedConstant_ \
100  ( \
101  Group::group, \
102  #Name, \
103  Dimensions \
104  ); \
105  const Foam::dimensionedScalar& Group::Name \
106  ( \
107  register##Name##DimensionedConstant_ \
108  );
109 
110 
112 :
113  public simpleRegIOobject,
114  public dimensionedScalar
115 {
116  const word& group_;
117  const dimensionedScalar default_;
118 
119  //- Lookup the dimensionedConstant from the registry
120  void lookup();
121 
122 
123 public:
124 
126  (
127  const word& group,
128  const char* name,
129  const dimensionedScalar& value
130  )
131  :
133  dimensionedScalar(name, value),
134  group_(group),
135  default_(name, value)
136  {
137  lookup();
138  }
139 
141  {}
142 
143  virtual void readData(Istream& is)
144  {
145  lookup();
146  }
147 
148  virtual void writeData(Ostream& os) const
149  {
150  os << static_cast<const dimensionedScalar&>(*this);
151  }
152 };
154 
155 //- Defined and register a dimensioned constant with default
156 #define defineDimensionedConstantWithDefault(Group, Name, DefaultExpr) \
157  registerDimensionedConstantWithDefault \
158  register##Name##DimensionedConstant_ \
159  ( \
160  Group::group, \
161  #Name, \
162  DefaultExpr \
163  ); \
164  \
165  const Foam::dimensionedScalar& Group::Name \
166  ( \
167  register##Name##DimensionedConstant_ \
168  );
169 
170 
171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
172 
173 } // End namespace Foam
174 
175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176 
177 #endif
178 
179 // ************************************************************************* //
const char *const group
Group name for atomic constants.
Abstract base class for registered object with I/O. Used in debug symbol registration.
virtual void writeData(Ostream &os) const
Write.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
dictionary & dimensionedConstants()
void addDimensionedConstantObject(const char *name, simpleRegIOobject *)
Register DimensionedConstant read/write object.
Definition: debug.C:311
Dimension set for the base types.
Definition: dimensionSet.H:120
A class for handling words, derived from string.
Definition: word.H:59
const Type & value() const
Return const reference to value.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
registerDimensionedConstant(const word &group, const char *name, const dimensionSet &dimensions)
const word & name() const
Return const reference to name.
virtual void readData(Istream &is)
Read.
const dimensionSet & dimensions() const
Return const reference to dimensions.
Namespace for OpenFOAM.