dimensionSet.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-2016 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 Class
25  Foam::dimensionSet
26 
27 Description
28  Dimension set for the base types.
29 
30  This type may be used to implement rigorous dimension checking
31  for algebraic manipulation.
32 
33 SourceFiles
34  dimensionSet.C
35  dimensionSetIO.C
36  dimensionSets.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef dimensionSet_H
41 #define dimensionSet_H
42 
43 #include "bool.H"
44 #include "dimensionedScalarFwd.H"
45 #include "className.H"
46 #include "scalarField.H"
47 #include "PtrList.H"
48 #include "HashTable.H"
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 
55 // Forward declaration of friend functions and operators
56 
57 class dimensionSet;
58 class dimensionSets;
59 
60 // Friend functions
61 
62 dimensionSet max(const dimensionSet&, const dimensionSet&);
63 dimensionSet min(const dimensionSet&, const dimensionSet&);
64 dimensionSet cmptMultiply(const dimensionSet&, const dimensionSet&);
65 dimensionSet cmptDivide(const dimensionSet&, const dimensionSet&);
66 
67 dimensionSet pow(const dimensionSet&, const scalar);
68 dimensionSet pow(const dimensionSet&, const dimensionedScalar&);
69 dimensionSet pow(const dimensionedScalar&, const dimensionSet&);
70 
71 dimensionSet sqr(const dimensionSet&);
72 dimensionSet pow3(const dimensionSet&);
73 dimensionSet pow4(const dimensionSet&);
74 dimensionSet pow5(const dimensionSet&);
75 dimensionSet pow6(const dimensionSet&);
76 dimensionSet pow025(const dimensionSet&);
77 
78 dimensionSet sqrt(const dimensionSet&);
79 dimensionSet cbrt(const dimensionSet&);
80 dimensionSet magSqr(const dimensionSet&);
81 dimensionSet mag(const dimensionSet&);
82 dimensionSet sign(const dimensionSet&);
83 dimensionSet pos(const dimensionSet&);
84 dimensionSet neg(const dimensionSet&);
85 dimensionSet posPart(const dimensionSet&);
86 dimensionSet negPart(const dimensionSet&);
87 dimensionSet inv(const dimensionSet&);
88 
89 // Function to check the argument is dimensionless
90 // for transcendental functions
91 dimensionSet trans(const dimensionSet&);
92 
93 dimensionSet atan2(const dimensionSet&, const dimensionSet&);
94 
95 // Return the argument; transformations do not change the dimensions
96 dimensionSet transform(const dimensionSet&);
97 
98 // Friend operators
99 
100 dimensionSet operator-(const dimensionSet&);
101 dimensionSet operator+(const dimensionSet&, const dimensionSet&);
102 dimensionSet operator-(const dimensionSet&, const dimensionSet&);
103 dimensionSet operator*(const dimensionSet&, const dimensionSet&);
104 dimensionSet operator/(const dimensionSet&, const dimensionSet&);
105 dimensionSet operator&(const dimensionSet&, const dimensionSet&);
106 dimensionSet operator^(const dimensionSet&, const dimensionSet&);
107 dimensionSet operator&&(const dimensionSet&, const dimensionSet&);
108 
109 // IOstream operators
110 
111 Istream& operator>>(Istream&, dimensionSet&);
112 Ostream& operator<<(Ostream&, const dimensionSet&);
113 
114 
115 /*---------------------------------------------------------------------------*\
116  Class dimensionSet Declaration
117 \*---------------------------------------------------------------------------*/
119 class dimensionSet
120 {
121 
122 public:
123 
124  // Member constants
125 
126  enum
127  {
128  nDimensions = 7 // Number of dimensions in SI is 7
129  };
130 
131  //- Define an enumeration for the names of the dimension exponents
132  enum dimensionType
133  {
134  MASS, // kilogram kg
135  LENGTH, // metre m
136  TIME, // second s
137  TEMPERATURE, // Kelvin K
138  MOLES, // mole mol
139  CURRENT, // Ampere A
140  LUMINOUS_INTENSITY // Candela Cd
141  };
142 
143 
144  // Static data members
146  static const scalar smallExponent;
147 
148 
149 private:
150 
151  // Private classes
152 
153  class tokeniser
154  {
155  // Private data
156 
157  Istream& is_;
158 
159  List<token> tokens_;
160 
161  label start_;
162 
163  label size_;
164 
165 
166  // Private Member Functions
167 
168  void push(const token&);
169 
170  token pop();
171 
172  void unpop(const token&);
173 
174  public:
175 
176  // Constructors
177 
178  tokeniser(Istream&);
179 
180 
181  // Member Functions
182 
183  Istream& stream()
184  {
185  return is_;
186  }
187 
188  bool hasToken() const;
189 
190  token nextToken();
191 
192  void putBack(const token&);
193 
194  void splitWord(const word&);
195 
196  static bool valid(char c);
197 
198  static label priority(const token& t);
199  };
200 
201 
202  //- Reset exponents to nearest integer if close to it. Used to
203  // handle reading with insufficient precision.
204  void round(const scalar tol);
205 
206  dimensionedScalar parse
207  (
208  const label lastPrior,
209  tokeniser& tis,
211  ) const;
212 
213 
214  // private data
215 
216  // dimensionSet stored as an array of dimension exponents
217  scalar exponents_[nDimensions];
218 
219 
220 public:
221 
222  // Declare name of the class and its debug switch
223  ClassName("dimensionSet");
224 
225 
226  // Constructors
227 
228  //- Construct given individual dimension exponents for all
229  // seven dimensions
231  (
232  const scalar mass,
233  const scalar length,
234  const scalar time,
235  const scalar temperature,
236  const scalar moles,
237  const scalar current,
238  const scalar luminousIntensity
239  );
240 
241  //- Construct given individual dimension exponents for first
242  // five dimensions
244  (
245  const scalar mass,
246  const scalar length,
247  const scalar time,
248  const scalar temperature,
249  const scalar moles
250  );
251 
252  //- Copy constructor
253  dimensionSet(const dimensionSet& ds);
254 
255  //- Construct and return a clone
257  {
258  return autoPtr<dimensionSet>(new dimensionSet(*this));
259  }
260 
261  //- Construct from Istream
263 
264 
265  // Member functions
266 
267  //- Return true if it is dimensionless
268  bool dimensionless() const;
269 
270  void reset(const dimensionSet&);
271 
272 
273  // I/O
274 
275  //- Read using provided units. Used only in initial parsing
276  Istream& read
277  (
278  Istream& is,
279  scalar& multiplier,
280  const dictionary&
281  );
282 
283  //- Read using provided units
284  Istream& read
285  (
286  Istream& is,
287  scalar& multiplier,
289  );
290 
291  //- Read using system units
292  Istream& read
293  (
294  Istream& is,
295  scalar& multiplier
296  );
297 
298  //- Write using provided units
299  Ostream& write
300  (
301  Ostream& os,
302  scalar& multiplier,
303  const dimensionSets&
304  ) const;
305 
306  //- Write using system units
307  Ostream& write
308  (
309  Ostream& os,
310  scalar& multiplier
311  ) const;
312 
313 
314  // Member operators
315 
316  scalar operator[](const dimensionType) const;
317  scalar& operator[](const dimensionType);
318 
319  scalar operator[](const label) const;
320  scalar& operator[](const label);
321 
322  bool operator==(const dimensionSet&) const;
323  bool operator!=(const dimensionSet&) const;
324 
325  bool operator=(const dimensionSet&) const;
326 
327  bool operator+=(const dimensionSet&) const;
328  bool operator-=(const dimensionSet&) const;
329  bool operator*=(const dimensionSet&);
330  bool operator/=(const dimensionSet&);
331 
332 
333  // Friend functions
334 
335  friend dimensionSet max(const dimensionSet&, const dimensionSet&);
336  friend dimensionSet min(const dimensionSet&, const dimensionSet&);
337  friend dimensionSet cmptMultiply
338  (
339  const dimensionSet&,
340  const dimensionSet&
341  );
342  friend dimensionSet cmptDivide
343  (
344  const dimensionSet&,
345  const dimensionSet&
346  );
347 
348  friend dimensionSet pow(const dimensionSet&, const scalar);
349  friend dimensionSet pow(const dimensionSet&, const dimensionedScalar&);
350  friend dimensionSet pow(const dimensionedScalar&, const dimensionSet&);
351 
352  friend dimensionSet sqr(const dimensionSet&);
353  friend dimensionSet pow3(const dimensionSet&);
354  friend dimensionSet pow4(const dimensionSet&);
355  friend dimensionSet pow5(const dimensionSet&);
356  friend dimensionSet pow6(const dimensionSet&);
357  friend dimensionSet pow025(const dimensionSet&);
358 
359  friend dimensionSet sqrt(const dimensionSet&);
360  friend dimensionSet magSqr(const dimensionSet&);
361  friend dimensionSet mag(const dimensionSet&);
362  friend dimensionSet sign(const dimensionSet&);
363  friend dimensionSet pos(const dimensionSet&);
364  friend dimensionSet neg(const dimensionSet&);
365  friend dimensionSet inv(const dimensionSet&);
366 
367  //- Function to check the argument is dimensionless
368  // for transcendental functions
369  friend dimensionSet trans(const dimensionSet&);
370 
371  friend dimensionSet atan2(const dimensionSet&, const dimensionSet&);
372 
373  //- Return the argument; transformations do not change the dimensions
374  friend dimensionSet transform(const dimensionSet&);
375 
376 
377  // Friend operators
378 
379  friend dimensionSet operator-(const dimensionSet&);
380 
381  friend dimensionSet operator+
382  (
383  const dimensionSet&,
384  const dimensionSet&
385  );
386 
387  friend dimensionSet operator-
388  (
389  const dimensionSet&,
390  const dimensionSet&
391  );
392 
393  friend dimensionSet operator*
394  (
395  const dimensionSet&,
396  const dimensionSet&
397  );
398 
399  friend dimensionSet operator/
400  (
401  const dimensionSet&,
402  const dimensionSet&
403  );
404 
405  friend dimensionSet operator&
406  (
407  const dimensionSet&,
408  const dimensionSet&
409  );
410 
411  friend dimensionSet operator^
412  (
413  const dimensionSet&,
414  const dimensionSet&
415  );
416 
417  friend dimensionSet operator&&
418  (
419  const dimensionSet&,
420  const dimensionSet&
421  );
422 
423 
424  // IOstream operators
425 
426  friend Istream& operator>>(Istream&, dimensionSet&);
427  friend Ostream& operator<<(Ostream&, const dimensionSet&);
428 };
429 
430 
431 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
432 
433 } // End namespace Foam
434 
435 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
436 
437 #include "dimensionSets.H"
438 
439 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
440 
441 #endif
442 
443 // ************************************************************************* //
dimensionedScalar sign(const dimensionedScalar &ds)
dimensionSet trans(const dimensionSet &)
Definition: dimensionSet.C:438
bool operator-=(const dimensionSet &) const
Definition: dimensionSet.C:195
bool operator!=(const dimensionSet &) const
Definition: dimensionSet.C:161
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
bool operator/=(const dimensionSet &)
Definition: dimensionSet.C:217
friend dimensionSet pow(const dimensionSet &, const scalar)
HashSet< Key, Hash > operator^(const HashSet< Key, Hash > &hash1, const HashSet< Key, Hash > &hash2)
Create a HashSet that only contains unique entries (xor)
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
friend dimensionSet mag(const dimensionSet &)
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
dimensionedSymmTensor sqr(const dimensionedVector &dv)
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
friend dimensionSet neg(const dimensionSet &)
autoPtr< dimensionSet > clone() const
Construct and return a clone.
Definition: dimensionSet.H:255
friend dimensionSet pow025(const dimensionSet &)
A token holds items read from Istream.
Definition: token.H:69
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensionedScalar pow025(const dimensionedScalar &ds)
friend dimensionSet pow4(const dimensionSet &)
ClassName("dimensionSet")
bool operator=(const dimensionSet &) const
Definition: dimensionSet.C:167
dimensionSet(const scalar mass, const scalar length, const scalar time, const scalar temperature, const scalar moles, const scalar current, const scalar luminousIntensity)
Construct given individual dimension exponents for all.
Definition: dimensionSet.C:42
friend Istream & operator>>(Istream &, dimensionSet &)
dimensionedScalar operator/(const scalar s1, const dimensionedScalar &ds2)
bool operator==(const dimensionSet &) const
Definition: dimensionSet.C:143
tmp< fvMatrix< Type > > operator*(const DimensionedField< scalar, volMesh > &, const fvMatrix< Type > &)
dimensionedScalar posPart(const dimensionedScalar &ds)
dimensionedScalar neg(const dimensionedScalar &ds)
dimensionedScalar pow5(const dimensionedScalar &ds)
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
bool operator*=(const dimensionSet &)
Definition: dimensionSet.C:209
friend dimensionSet sign(const dimensionSet &)
dimensionedScalar pos(const dimensionedScalar &ds)
friend dimensionSet pow6(const dimensionSet &)
friend dimensionSet magSqr(const dimensionSet &)
Dimension set for the base types.
Definition: dimensionSet.H:118
friend Ostream & operator<<(Ostream &, const dimensionSet &)
friend dimensionSet pos(const dimensionSet &)
A class for handling words, derived from string.
Definition: word.H:59
Istream & operator>>(Istream &, directionInfo &)
dimensionedScalar cbrt(const dimensionedScalar &ds)
bool operator+=(const dimensionSet &) const
Definition: dimensionSet.C:181
tmp< fvMatrix< Type > > operator-(const fvMatrix< Type > &)
tmp< fvMatrix< Type > > operator+(const fvMatrix< Type > &, const fvMatrix< Type > &)
An STL-conforming hash table.
Definition: HashTable.H:61
friend dimensionSet max(const dimensionSet &, const dimensionSet &)
friend dimensionSet cmptDivide(const dimensionSet &, const dimensionSet &)
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
dimensioned< scalar > magSqr(const dimensioned< Type > &)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
dimensionedScalar atan2(const dimensionedScalar &x, const dimensionedScalar &y)
friend dimensionSet min(const dimensionSet &, const dimensionSet &)
friend dimensionSet operator-(const dimensionSet &)
friend dimensionSet pow3(const dimensionSet &)
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
friend dimensionSet cmptMultiply(const dimensionSet &, const dimensionSet &)
friend dimensionSet trans(const dimensionSet &)
Function to check the argument is dimensionless.
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
void reset(const dimensionSet &)
Definition: dimensionSet.C:108
dimensionedScalar pow3(const dimensionedScalar &ds)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
bool dimensionless() const
Return true if it is dimensionless.
Definition: dimensionSet.C:89
tmp< GeometricField< Type, fvPatchField, volMesh > > operator&(const fvMatrix< Type > &, const DimensionedField< Type, volMesh > &)
Macro definitions for declaring ClassName(), NamespaceName(), etc.
scalar operator[](const dimensionType) const
Definition: dimensionSet.C:119
const dimensionedScalar c
Speed of light in a vacuum.
Ostream & operator<<(Ostream &, const ensightPart &)
dimensionedScalar pow4(const dimensionedScalar &ds)
dimensionedScalar pow6(const dimensionedScalar &ds)
dimensionType
Define an enumeration for the names of the dimension exponents.
Definition: dimensionSet.H:131
dimensioned< scalar > mag(const dimensioned< Type > &)
friend dimensionSet transform(const dimensionSet &)
Return the argument; transformations do not change the dimensions.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:53
Useful dimension sets.
friend dimensionSet sqr(const dimensionSet &)
friend dimensionSet pow5(const dimensionSet &)
static const scalar smallExponent
Definition: dimensionSet.H:145
friend dimensionSet inv(const dimensionSet &)
Ostream & write(Ostream &os, scalar &multiplier, const dimensionSets &) const
Write using provided units.
friend dimensionSet atan2(const dimensionSet &, const dimensionSet &)
dimensioned< typename scalarProduct< Type1, Type2 >::type > operator&&(const dimensioned< Type1 > &, const dimensioned< Type2 > &)
Istream & read(Istream &is, scalar &multiplier, const dictionary &)
Read using provided units. Used only in initial parsing.
System bool.
Namespace for OpenFOAM.
dimensionedScalar negPart(const dimensionedScalar &ds)
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:465
friend dimensionSet sqrt(const dimensionSet &)