dimensionSet.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 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 pos0(const dimensionSet&);
85 dimensionSet neg(const dimensionSet&);
86 dimensionSet neg0(const dimensionSet&);
87 dimensionSet posPart(const dimensionSet&);
88 dimensionSet negPart(const dimensionSet&);
89 dimensionSet inv(const dimensionSet&);
90 
91 // Function to check the argument is dimensionless
92 // for transcendental functions
93 dimensionSet trans(const dimensionSet&);
94 
95 dimensionSet atan2(const dimensionSet&, const dimensionSet&);
96 
97 // Return the argument; transformations do not change the dimensions
98 dimensionSet transform(const dimensionSet&);
99 
100 // Friend operators
101 
102 dimensionSet operator-(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 dimensionSet operator^(const dimensionSet&, const dimensionSet&);
109 dimensionSet operator&&(const dimensionSet&, const dimensionSet&);
110 
111 // IOstream Operators
112 
113 Istream& operator>>(Istream&, dimensionSet&);
114 Ostream& operator<<(Ostream&, const dimensionSet&);
115 
116 
117 /*---------------------------------------------------------------------------*\
118  Class dimensionSet Declaration
119 \*---------------------------------------------------------------------------*/
121 class dimensionSet
122 {
123 
124 public:
125 
126  // Member constants
127 
128  enum
129  {
130  nDimensions = 7 // Number of dimensions in SI is 7
131  };
132 
133  //- Define an enumeration for the names of the dimension exponents
134  enum dimensionType
135  {
136  MASS, // kilogram kg
137  LENGTH, // metre m
138  TIME, // second s
139  TEMPERATURE, // Kelvin K
140  MOLES, // mole mol
141  CURRENT, // Ampere A
142  LUMINOUS_INTENSITY // Candela Cd
143  };
144 
145 
146  // Static Data Members
148  static const scalar smallExponent;
149 
150 
151 private:
152 
153  // Private classes
154 
155  class tokeniser
156  {
157  // Private Data
158 
159  Istream& is_;
160 
161  List<token> tokens_;
162 
163  label start_;
164 
165  label size_;
166 
167 
168  // Private Member Functions
169 
170  void push(const token&);
171 
172  token pop();
173 
174  void unpop(const token&);
175 
176  public:
177 
178  // Constructors
179 
180  tokeniser(Istream&);
181 
182 
183  // Member Functions
184 
185  Istream& stream()
186  {
187  return is_;
188  }
189 
190  bool hasToken() const;
191 
192  token nextToken();
193 
194  void putBack(const token&);
195 
196  void splitWord(const word&);
197 
198  static bool valid(char c);
199 
200  static label priority(const token& t);
201  };
202 
203 
204  //- Reset exponents to nearest integer if close to it. Used to
205  // handle reading with insufficient precision.
206  void round(const scalar tol);
207 
208  dimensionedScalar parse
209  (
210  const label lastPrior,
211  tokeniser& tis,
213  ) const;
214 
215 
216  // private data
217 
218  // dimensionSet stored as an array of dimension exponents
219  scalar exponents_[nDimensions];
220 
221 
222 public:
223 
224  // Declare name of the class and its debug switch
225  ClassName("dimensionSet");
226 
227 
228  // Constructors
229 
230  //- Construct given individual dimension exponents for all
231  // seven dimensions
233  (
234  const scalar mass,
235  const scalar length,
236  const scalar time,
237  const scalar temperature,
238  const scalar moles,
239  const scalar current,
240  const scalar luminousIntensity
241  );
242 
243  //- Construct given individual dimension exponents for first
244  // five dimensions
246  (
247  const scalar mass,
248  const scalar length,
249  const scalar time,
250  const scalar temperature,
251  const scalar moles
252  );
253 
254  //- Copy constructor
255  dimensionSet(const dimensionSet& ds);
256 
257  //- Construct and return a clone
259  {
260  return autoPtr<dimensionSet>(new dimensionSet(*this));
261  }
262 
263  //- Construct from Istream
265 
266 
267  // Member Functions
268 
269  //- Return true if it is dimensionless
270  bool dimensionless() const;
271 
272  void reset(const dimensionSet&);
273 
274 
275  // I/O
276 
277  //- Read using provided units. Used only in initial parsing
278  Istream& read
279  (
280  Istream& is,
281  scalar& multiplier,
282  const dictionary&
283  );
284 
285  //- Read using provided units
286  Istream& read
287  (
288  Istream& is,
289  scalar& multiplier,
291  );
292 
293  //- Read using system units
294  Istream& read
295  (
296  Istream& is,
297  scalar& multiplier
298  );
299 
300  //- Write using provided units
301  Ostream& write
302  (
303  Ostream& os,
304  scalar& multiplier,
305  const dimensionSets&
306  ) const;
307 
308  //- Write using system units
309  Ostream& write
310  (
311  Ostream& os,
312  scalar& multiplier
313  ) const;
314 
315 
316  // Member Operators
317 
318  scalar operator[](const dimensionType) const;
319  scalar& operator[](const dimensionType);
320 
321  scalar operator[](const label) const;
322  scalar& operator[](const label);
323 
324  bool operator==(const dimensionSet&) const;
325  bool operator!=(const dimensionSet&) const;
326 
327  bool operator=(const dimensionSet&) const;
328 
329  bool operator+=(const dimensionSet&) const;
330  bool operator-=(const dimensionSet&) const;
331  bool operator*=(const dimensionSet&);
332  bool operator/=(const dimensionSet&);
333 
334 
335  // Friend Functions
336 
337  friend dimensionSet max(const dimensionSet&, const dimensionSet&);
338  friend dimensionSet min(const dimensionSet&, const dimensionSet&);
339  friend dimensionSet cmptMultiply
340  (
341  const dimensionSet&,
342  const dimensionSet&
343  );
344  friend dimensionSet cmptDivide
345  (
346  const dimensionSet&,
347  const dimensionSet&
348  );
349 
350  friend dimensionSet pow(const dimensionSet&, const scalar);
351  friend dimensionSet pow(const dimensionSet&, const dimensionedScalar&);
352  friend dimensionSet pow(const dimensionedScalar&, const dimensionSet&);
353 
354  friend dimensionSet sqr(const dimensionSet&);
355  friend dimensionSet pow3(const dimensionSet&);
356  friend dimensionSet pow4(const dimensionSet&);
357  friend dimensionSet pow5(const dimensionSet&);
358  friend dimensionSet pow6(const dimensionSet&);
359  friend dimensionSet pow025(const dimensionSet&);
360 
361  friend dimensionSet sqrt(const dimensionSet&);
362  friend dimensionSet magSqr(const dimensionSet&);
363  friend dimensionSet mag(const dimensionSet&);
364  friend dimensionSet sign(const dimensionSet&);
365  friend dimensionSet pos0(const dimensionSet&);
366  friend dimensionSet neg(const dimensionSet&);
367  friend dimensionSet inv(const dimensionSet&);
368 
369  //- Function to check the argument is dimensionless
370  // for transcendental functions
371  friend dimensionSet trans(const dimensionSet&);
372 
373  friend dimensionSet atan2(const dimensionSet&, const dimensionSet&);
374 
375  //- Return the argument; transformations do not change the dimensions
376  friend dimensionSet transform(const dimensionSet&);
377 
378 
379  // Friend operators
380 
381  friend dimensionSet operator-(const dimensionSet&);
382 
383  friend dimensionSet operator+
384  (
385  const dimensionSet&,
386  const dimensionSet&
387  );
388 
389  friend dimensionSet operator-
390  (
391  const dimensionSet&,
392  const dimensionSet&
393  );
394 
395  friend dimensionSet operator*
396  (
397  const dimensionSet&,
398  const dimensionSet&
399  );
400 
401  friend dimensionSet operator/
402  (
403  const dimensionSet&,
404  const dimensionSet&
405  );
406 
407  friend dimensionSet operator&
408  (
409  const dimensionSet&,
410  const dimensionSet&
411  );
412 
413  friend dimensionSet operator^
414  (
415  const dimensionSet&,
416  const dimensionSet&
417  );
418 
419  friend dimensionSet operator&&
420  (
421  const dimensionSet&,
422  const dimensionSet&
423  );
424 
425 
426  // IOstream Operators
427 
428  friend Istream& operator>>(Istream&, dimensionSet&);
429  friend Ostream& operator<<(Ostream&, const dimensionSet&);
430 };
431 
432 
433 void writeEntry(Ostream& os, const dimensionSet& value);
434 
435 
436 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
437 
438 } // End namespace Foam
439 
440 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
441 
442 #include "dimensionSets.H"
443 
444 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
445 
446 #endif
447 
448 // ************************************************************************* //
dimensionedScalar sign(const dimensionedScalar &ds)
dimensionSet trans(const dimensionSet &)
Definition: dimensionSet.C:450
tmp< fvMatrix< Type > > operator*(const volScalarField::Internal &, const fvMatrix< Type > &)
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
autoPtr< dimensionSet > clone() const
Construct and return a clone.
Definition: dimensionSet.H:257
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:156
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 &)
friend dimensionSet pow025(const dimensionSet &)
A token holds items read from Istream.
Definition: token.H:72
bool operator-=(const dimensionSet &) const
Definition: dimensionSet.C:195
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensionedScalar pow025(const dimensionedScalar &ds)
friend dimensionSet pow4(const dimensionSet &)
bool operator=(const dimensionSet &) const
Definition: dimensionSet.C:167
ClassName("dimensionSet")
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 &)
tmp< fvMatrix< Type > > operator/(const fvMatrix< Type > &, const volScalarField::Internal &)
dimensionedScalar posPart(const dimensionedScalar &ds)
Ostream & write(Ostream &os, scalar &multiplier, const dimensionSets &) const
Write using provided units.
const dimensionedScalar c
Speed of light in a vacuum.
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
tmp< GeometricField< Type, fvPatchField, volMesh > > operator &(const fvMatrix< Type > &, const DimensionedField< Type, volMesh > &)
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:120
friend Ostream & operator<<(Ostream &, const dimensionSet &)
dimensionSet operator &&(const dimensionSet &, const dimensionSet &)
A class for handling words, derived from string.
Definition: word.H:59
Istream & operator>>(Istream &, directionInfo &)
dimensionedScalar cbrt(const dimensionedScalar &ds)
dimensionedScalar neg0(const dimensionedScalar &ds)
tmp< fvMatrix< Type > > operator-(const fvMatrix< Type > &)
bool operator+=(const dimensionSet &) const
Definition: dimensionSet.C:181
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 &)
bool operator!=(const dimensionSet &) const
Definition: dimensionSet.C:161
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:54
dimensionedScalar pos0(const dimensionedScalar &ds)
dimensionedScalar atan2(const dimensionedScalar &x, const dimensionedScalar &y)
friend dimensionSet min(const dimensionSet &, const dimensionSet &)
friend dimensionSet operator-(const dimensionSet &)
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
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)
scalar operator[](const dimensionType) const
Definition: dimensionSet.C:119
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Macro definitions for declaring ClassName(), NamespaceName(), etc.
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:133
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:52
Useful dimension sets.
friend dimensionSet sqr(const dimensionSet &)
friend dimensionSet pow5(const dimensionSet &)
friend dimensionSet pos0(const dimensionSet &)
bool operator==(const dimensionSet &) const
Definition: dimensionSet.C:143
static const scalar smallExponent
Definition: dimensionSet.H:147
bool dimensionless() const
Return true if it is dimensionless.
Definition: dimensionSet.C:89
friend dimensionSet inv(const dimensionSet &)
friend dimensionSet atan2(const dimensionSet &, const dimensionSet &)
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:477
friend dimensionSet sqrt(const dimensionSet &)