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-2024 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 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef dimensionSet_H
40 #define dimensionSet_H
41 
42 #include "bool.H"
43 #include "className.H"
44 #include "NamedEnum.H"
45 #include "InfoProxy.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 // Forward declaration of friend functions and operators
53 
54 class dimensionSet;
55 class unitConversion;
56 template<class Type> class dimensioned;
57 typedef dimensioned<scalar> dimensionedScalar;
58 
59 // Friend Functions
60 
61 dimensionSet max(const dimensionSet&, const dimensionSet&);
62 dimensionSet min(const dimensionSet&, const dimensionSet&);
63 dimensionSet cmptMultiply(const dimensionSet&, const dimensionSet&);
64 dimensionSet cmptDivide(const dimensionSet&, const dimensionSet&);
65 dimensionSet cmptMag(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 dimensionSet normalised(const dimensionSet&);
101 dimensionSet perpendicular(const dimensionSet&);
102 
103 // Friend operators
104 
105 dimensionSet operator-(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 dimensionSet operator&(const dimensionSet&, const dimensionSet&);
111 dimensionSet operator^(const dimensionSet&, const dimensionSet&);
112 dimensionSet operator&&(const dimensionSet&, const dimensionSet&);
113 
114 // IOstream Operators
115 
116 Istream& operator>>(Istream&, dimensionSet&);
117 Ostream& operator<<(Ostream&, const dimensionSet&);
118 Ostream& operator<<(Ostream&, const InfoProxy<dimensionSet>&);
119 
120 
121 /*---------------------------------------------------------------------------*\
122  Class dimensionSet Declaration
123 \*---------------------------------------------------------------------------*/
124 
125 class dimensionSet
126 {
127 
128 public:
129 
130  // Member constants
131 
132  //- Define an enumeration for the number of dimensions
133  enum
134  {
135  nDimensions = 7 // Number of dimensions in SI is 7
136  };
137 
138  //- Define an enumeration for the names of the dimension exponents
139  enum dimensionType
140  {
141  MASS, // kilogram kg
142  LENGTH, // metre m
143  TIME, // second s
144  TEMPERATURE, // Kelvin K
145  MOLES, // kilomole kmol
146  CURRENT, // Ampere A
147  LUMINOUS_INTENSITY // Candela Cd
148  };
149 
150  //- Names of the dimensions
152 
153 
154  // Static Data Members
155 
156  //- A small exponent with which to perform inexact comparisons
157  static const scalar smallExponent;
158 
159 
160 private:
161 
162  // Private Data
163 
164  //- Array of dimension exponents
165  scalar exponents_[nDimensions];
166 
167 
168  // Private Member Functions
169 
170  //- Reset exponents to nearest integer if close to it. Used to
171  // handle reading with insufficient precision.
172  void round(const scalar tol);
173 
174 
175 public:
176 
177  // Declare name of the class and its debug switch
178  ClassName("dimensionSet");
179 
180 
181  // Constructors
182 
183  //- Construct given individual dimension exponents for all
184  // seven dimensions
186  (
187  const scalar mass,
188  const scalar length,
189  const scalar time,
190  const scalar temperature,
191  const scalar moles,
192  const scalar current,
193  const scalar luminousIntensity
194  );
195 
196  //- Construct given individual dimension exponents for first
197  // five dimensions
199  (
200  const scalar mass,
201  const scalar length,
202  const scalar time,
203  const scalar temperature,
204  const scalar moles
205  );
206 
207  //- Copy constructor
208  dimensionSet(const dimensionSet& ds);
209 
210  //- Construct and return a clone
212  {
213  return autoPtr<dimensionSet>(new dimensionSet(*this));
214  }
215 
216  //- Construct from Istream
218 
219 
220  // Member Functions
221 
222  //- Return true if it is dimensionless
223  bool dimensionless() const;
224 
225  void reset(const dimensionSet&);
226 
227 
228  // I/O
229 
230  //- Read, assuming the '[' has already been read
232 
233  //- Read
234  Istream& read(Istream& is);
235 
236  //- Write
237  Ostream& write(Ostream& os) const;
238 
239  //- Return info proxy
240  inline InfoProxy<dimensionSet> info() const
241  {
242  return *this;
243  }
244 
245 
246  // Member Operators
247 
248  scalar operator[](const dimensionType) const;
249  scalar& operator[](const dimensionType);
250 
251  scalar operator[](const label) const;
252  scalar& operator[](const label);
253 
254  bool operator==(const dimensionSet&) const;
255  bool operator!=(const dimensionSet&) const;
256 
257  bool operator=(const dimensionSet&) const;
258 
259  bool operator+=(const dimensionSet&) const;
260  bool operator-=(const dimensionSet&) const;
261  bool operator*=(const dimensionSet&);
262  bool operator/=(const dimensionSet&);
263 
264 
265  // Friend Functions
266 
267  friend dimensionSet max(const dimensionSet&, const dimensionSet&);
268  friend dimensionSet min(const dimensionSet&, const dimensionSet&);
270  (
271  const dimensionSet&,
272  const dimensionSet&
273  );
274  friend dimensionSet cmptDivide
275  (
276  const dimensionSet&,
277  const dimensionSet&
278  );
279  friend dimensionSet cmptMag(const dimensionSet&);
280 
281  friend dimensionSet pow(const dimensionSet&, const scalar);
283  friend dimensionSet pow(const dimensionedScalar&, const dimensionSet&);
284 
285  friend dimensionSet sqr(const dimensionSet&);
290  friend dimensionSet pow025(const dimensionSet&);
291 
294  friend dimensionSet mag(const dimensionSet&);
297  friend dimensionSet neg(const dimensionSet&);
298  friend dimensionSet inv(const dimensionSet&);
299 
300  //- Function to check the argument is dimensionless
301  // for transcendental functions
302  friend dimensionSet trans(const dimensionSet&);
303 
304  friend dimensionSet atan2(const dimensionSet&, const dimensionSet&);
305 
306  friend dimensionSet transform(const dimensionSet&);
307 
309  friend dimensionSet perpendicular(const dimensionSet&);
310 
311 
312  // Friend Operators
313 
314  friend dimensionSet operator-(const dimensionSet&);
315 
316  friend dimensionSet operator+
317  (
318  const dimensionSet&,
319  const dimensionSet&
320  );
321 
322  friend dimensionSet operator-
323  (
324  const dimensionSet&,
325  const dimensionSet&
326  );
327 
328  friend dimensionSet operator*
329  (
330  const dimensionSet&,
331  const dimensionSet&
332  );
333 
334  friend dimensionSet operator/
335  (
336  const dimensionSet&,
337  const dimensionSet&
338  );
339 
340  friend dimensionSet operator&
341  (
342  const dimensionSet&,
343  const dimensionSet&
344  );
345 
346  friend dimensionSet operator^
347  (
348  const dimensionSet&,
349  const dimensionSet&
350  );
351 
352  friend dimensionSet operator&&
353  (
354  const dimensionSet&,
355  const dimensionSet&
356  );
357 
358 
359  // IOstream Operators
360 
364 };
365 
366 
367 void writeEntry(Ostream& os, const dimensionSet& value);
368 
369 
370 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
371 
372 } // End namespace Foam
373 
374 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
375 
376 #include "dimensionSets.H"
377 
378 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
379 
380 #endif
381 
382 // ************************************************************************* //
System bool.
A helper class for outputting values to Ostream.
Definition: InfoProxy.H:50
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
Dimension set for the base types.
Definition: dimensionSet.H:125
Istream & readNoBegin(Istream &is)
Read, assuming the '[' has already been read.
friend dimensionSet pow5(const dimensionSet &)
friend dimensionSet operator-(const dimensionSet &)
bool operator+=(const dimensionSet &) const
Definition: dimensionSet.C:202
friend dimensionSet pow(const dimensionSet &, const dimensionedScalar &)
InfoProxy< dimensionSet > info() const
Return info proxy.
Definition: dimensionSet.H:239
bool operator==(const dimensionSet &) const
Definition: dimensionSet.C:164
friend dimensionSet transform(const dimensionSet &)
friend dimensionSet min(const dimensionSet &, const dimensionSet &)
bool operator!=(const dimensionSet &) const
Definition: dimensionSet.C:182
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:63
friend dimensionSet magSqr(const dimensionSet &)
friend dimensionSet pos0(const dimensionSet &)
friend dimensionSet neg(const dimensionSet &)
static const scalar smallExponent
A small exponent with which to perform inexact comparisons.
Definition: dimensionSet.H:156
friend dimensionSet sqr(const dimensionSet &)
friend dimensionSet pow025(const dimensionSet &)
friend dimensionSet atan2(const dimensionSet &, const dimensionSet &)
friend dimensionSet sqrt(const dimensionSet &)
ClassName("dimensionSet")
bool operator/=(const dimensionSet &)
Definition: dimensionSet.C:238
friend dimensionSet cmptMag(const dimensionSet &)
Ostream & write(Ostream &os) const
Write.
friend Istream & operator>>(Istream &, dimensionSet &)
friend Ostream & operator<<(Ostream &, const dimensionSet &)
friend Ostream & operator<<(Ostream &, const InfoProxy< dimensionSet > &)
friend dimensionSet cmptMultiply(const dimensionSet &, const dimensionSet &)
bool operator-=(const dimensionSet &) const
Definition: dimensionSet.C:216
friend dimensionSet pow4(const dimensionSet &)
scalar operator[](const dimensionType) const
Definition: dimensionSet.C:140
friend dimensionSet mag(const dimensionSet &)
void reset(const dimensionSet &)
Definition: dimensionSet.C:129
friend dimensionSet pow3(const dimensionSet &)
friend dimensionSet sign(const dimensionSet &)
friend dimensionSet pow6(const dimensionSet &)
static const NamedEnum< dimensionType, 7 > dimensionTypeNames_
Names of the dimensions.
Definition: dimensionSet.H:150
bool dimensionless() const
Return true if it is dimensionless.
Definition: dimensionSet.C:110
friend dimensionSet normalised(const dimensionSet &)
autoPtr< dimensionSet > clone() const
Construct and return a clone.
Definition: dimensionSet.H:210
friend dimensionSet pow(const dimensionSet &, const scalar)
dimensionType
Define an enumeration for the names of the dimension exponents.
Definition: dimensionSet.H:139
bool operator*=(const dimensionSet &)
Definition: dimensionSet.C:230
friend dimensionSet trans(const dimensionSet &)
Function to check the argument is dimensionless.
friend dimensionSet cmptDivide(const dimensionSet &, const dimensionSet &)
friend dimensionSet inv(const dimensionSet &)
friend dimensionSet perpendicular(const dimensionSet &)
friend dimensionSet pow(const dimensionedScalar &, const dimensionSet &)
friend dimensionSet max(const dimensionSet &, const dimensionSet &)
bool operator=(const dimensionSet &) const
Definition: dimensionSet.C:188
Istream & read(Istream &is)
Read.
Macro definitions for declaring ClassName(), NamespaceName(), etc.
Useful dimension sets.
Namespace for OpenFOAM.
dimensionedScalar pow6(const dimensionedScalar &ds)
dimensionedScalar pos(const dimensionedScalar &ds)
dimensionedScalar pow5(const dimensionedScalar &ds)
dimensionedScalar pos0(const dimensionedScalar &ds)
dimensionedScalar sign(const dimensionedScalar &ds)
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
dimensionedSymmTensor sqr(const dimensionedVector &dv)
dimensionedScalar pow3(const dimensionedScalar &ds)
HashSet< Key, Hash > operator^(const HashSet< Key, Hash > &hash1, const HashSet< Key, Hash > &hash2)
Create a HashSet that only contains unique entries (xor)
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
dimensionedScalar atan2(const dimensionedScalar &x, const dimensionedScalar &y)
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
dimensionedScalar negPart(const dimensionedScalar &ds)
dimensionedScalar sqrt(const dimensionedScalar &ds)
Istream & operator>>(Istream &, pistonPointEdgeData &)
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:504
dimensionSet normalised(const dimensionSet &)
Definition: dimensionSet.C:510
dimensioned< scalar > mag(const dimensioned< Type > &)
dimensionedScalar pow4(const dimensionedScalar &ds)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
dimensionedScalar neg(const dimensionedScalar &ds)
dimensionSet cmptMag(const dimensionSet &)
Definition: dimensionSet.C:296
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
tmp< VolField< Type > > operator&(const fvMatrix< Type > &, const DimensionedField< Type, volMesh > &)
tmp< fvMatrix< Type > > operator*(const volScalarField::Internal &, const fvMatrix< Type > &)
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
tmp< fvMatrix< Type > > operator+(const fvMatrix< Type > &, const fvMatrix< Type > &)
dimensionedScalar neg0(const dimensionedScalar &ds)
dimensionedScalar cbrt(const dimensionedScalar &ds)
dimensionSet perpendicular(const dimensionSet &)
Definition: dimensionSet.C:516
tmp< fvMatrix< Type > > operator-(const fvMatrix< Type > &)
dimensionSet trans(const dimensionSet &)
Definition: dimensionSet.C:477
dimensioned< scalar > magSqr(const dimensioned< Type > &)
dimensionedScalar posPart(const dimensionedScalar &ds)
tmp< fvMatrix< Type > > operator/(const fvMatrix< Type > &, const volScalarField::Internal &)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
dimensionedScalar pow025(const dimensionedScalar &ds)
dimensioned< typename scalarProduct< Type1, Type2 >::type > operator&&(const dimensioned< Type1 > &, const dimensioned< Type2 > &)