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-2026 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 "fieldTypes.H"
44 #include "className.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 unitSet;
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 a named dimensionSet given individual dimension exponents
197  // for all seven dimensions.
198  // The dimensionSet is added to the dimensions::table
200  (
201  const word& name,
202  const scalar mass,
203  const scalar length,
204  const scalar time,
205  const scalar temperature,
206  const scalar moles,
207  const scalar current,
208  const scalar luminousIntensity
209  );
210 
211  //- Construct given individual dimension exponents for first
212  // five dimensions
214  (
215  const scalar mass,
216  const scalar length,
217  const scalar time,
218  const scalar temperature,
219  const scalar moles
220  );
221 
222  //- Copy constructor
223  dimensionSet(const dimensionSet& ds);
224 
225  //- Named copy constructor
226  dimensionSet(const word& name, const dimensionSet& ds);
227 
228  //- Construct and return a clone
230  {
231  return autoPtr<dimensionSet>(new dimensionSet(*this));
232  }
233 
234  //- Construct from Istream
236 
237 
238  // Member Functions
239 
240  //- Return true if it is dimensionless
241  bool dimensionless() const;
242 
243  void reset(const dimensionSet&);
244 
245 
246  // I/O
247 
248  //- Read without the square brackets
250 
251  //- Read
252  Istream& read(Istream& is);
253 
254  //- Write without the square brackets
255  Ostream& writeNoBeginOrEnd(Ostream& os) const;
256 
257  //- Write
258  Ostream& write(Ostream& os) const;
259 
260  //- Write info without the square brackets
262 
263  //- Return info proxy
264  inline InfoProxy<dimensionSet> info() const
265  {
266  return *this;
267  }
268 
269 
270  // Member Operators
271 
272  scalar operator[](const dimensionType) const;
273  scalar& operator[](const dimensionType);
274 
275  scalar operator[](const label) const;
276  scalar& operator[](const label);
277 
278  bool operator==(const dimensionSet&) const;
279  bool operator!=(const dimensionSet&) const;
280 
281  bool operator=(const dimensionSet&) const;
282 
283  bool operator+=(const dimensionSet&) const;
284  bool operator-=(const dimensionSet&) const;
285  bool operator*=(const dimensionSet&);
286  bool operator/=(const dimensionSet&);
287 
288  template<class ... Args>
289  using typeForArgs = typename typeOfNcmpts<sizeof ... (Args)>::type;
290 
291  //- Return a dimensionedType with these dimensions
292  // and rank corresponding to the number of arguments
293  template<class ... Args>
294  dimensioned<typeForArgs<Args ...>> operator()
295  (
296  const Args& ... args
297  ) const
298  {
299  return dimensioned<typeForArgs<Args ...>>
300  (
301  *this,
302  typeForArgs<Args ...>(args ...)
303  );
304  }
305 
306  //- Return a named dimensionedType with these dimensions
307  // and rank corresponding to the number of arguments
308  template<class ... Args>
309  dimensioned<typeForArgs<Args ...>> operator()
310  (
311  const word& name,
312  const Args& ... args
313  ) const
314  {
315  return dimensioned<typeForArgs<Args ...>>
316  (
317  name,
318  *this,
319  typeForArgs<Args ...>(args ...)
320  );
321  }
322 
323 
324  // Friend Functions
325 
326  friend dimensionSet max(const dimensionSet&, const dimensionSet&);
327  friend dimensionSet min(const dimensionSet&, const dimensionSet&);
329  (
330  const dimensionSet&,
331  const dimensionSet&
332  );
333  friend dimensionSet cmptDivide
334  (
335  const dimensionSet&,
336  const dimensionSet&
337  );
338  friend dimensionSet cmptMag(const dimensionSet&);
339 
340  friend dimensionSet pow(const dimensionSet&, const scalar);
342  friend dimensionSet pow(const dimensionedScalar&, const dimensionSet&);
343 
344  friend dimensionSet sqr(const dimensionSet&);
349  friend dimensionSet pow025(const dimensionSet&);
350 
353  friend dimensionSet mag(const dimensionSet&);
356  friend dimensionSet neg(const dimensionSet&);
357  friend dimensionSet inv(const dimensionSet&);
358 
359  //- Function to check the argument is dimensionless
360  // for transcendental functions
361  friend dimensionSet trans(const dimensionSet&);
362 
363  friend dimensionSet atan2(const dimensionSet&, const dimensionSet&);
364 
365  friend dimensionSet transform(const dimensionSet&);
366 
368  friend dimensionSet perpendicular(const dimensionSet&);
369 
370 
371  // Friend Operators
372 
373  friend dimensionSet operator-(const dimensionSet&);
374 
375  friend dimensionSet operator+
376  (
377  const dimensionSet&,
378  const dimensionSet&
379  );
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 
418  // IOstream Operators
419 
423 };
424 
425 
426 void writeEntry(Ostream& os, const dimensionSet& value);
427 
428 
429 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
430 
431 } // End namespace Foam
432 
433 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
434 
435 #include "dimensions.H"
436 
437 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
438 
439 #endif
440 
441 // ************************************************************************* //
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
friend dimensionSet pow5(const dimensionSet &)
friend dimensionSet operator-(const dimensionSet &)
bool operator+=(const dimensionSet &) const
Definition: dimensionSet.C:236
friend dimensionSet pow(const dimensionSet &, const dimensionedScalar &)
InfoProxy< dimensionSet > info() const
Return info proxy.
Definition: dimensionSet.H:263
bool operator==(const dimensionSet &) const
Definition: dimensionSet.C:198
Ostream & writeInfoNoBeginOrEnd(Ostream &os) const
Write info without the square brackets.
friend dimensionSet transform(const dimensionSet &)
friend dimensionSet min(const dimensionSet &, const dimensionSet &)
bool operator!=(const dimensionSet &) const
Definition: dimensionSet.C:216
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 &)
friend dimensionSet sqr(const dimensionSet &)
friend dimensionSet pow025(const dimensionSet &)
friend dimensionSet atan2(const dimensionSet &, const dimensionSet &)
friend dimensionSet sqrt(const dimensionSet &)
Ostream & writeNoBeginOrEnd(Ostream &os) const
Write without the square brackets.
ClassName("dimensionSet")
bool operator/=(const dimensionSet &)
Definition: dimensionSet.C:272
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:250
friend dimensionSet pow4(const dimensionSet &)
scalar operator[](const dimensionType) const
Definition: dimensionSet.C:174
friend dimensionSet mag(const dimensionSet &)
void reset(const dimensionSet &)
Definition: dimensionSet.C:163
static const scalar smallExponent
A small exponent with which to perform inexact comparisons.
Definition: dimensionSet.H:156
friend dimensionSet pow3(const dimensionSet &)
friend dimensionSet sign(const dimensionSet &)
friend dimensionSet pow6(const dimensionSet &)
Istream & readNoBeginOrEnd(Istream &is)
Read without the square brackets.
bool dimensionless() const
Return true if it is dimensionless.
Definition: dimensionSet.C:144
friend dimensionSet normalised(const dimensionSet &)
autoPtr< dimensionSet > clone() const
Construct and return a clone.
Definition: dimensionSet.H:228
typename typeOfNcmpts< sizeof ...(Args)>::type typeForArgs
Definition: dimensionSet.H:288
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:264
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:222
Istream & read(Istream &is)
Read.
static const NamedEnum< dimensionType, 7 > & dimensionTypeNames_
Names of the dimensions.
Definition: dimensionSet.H:150
Generic dimensioned Type class.
A class for handling words, derived from string.
Definition: word.H:63
Macro definitions for declaring ClassName(), NamespaceName(), etc.
Predefined dimensions.
Include the header files for all the primitive types that Fields are instantiated for.
const dimensionSet time
const dimensionSet current
const dimensionSet temperature
const dimensionSet mass
const dimensionSet luminousIntensity
const dimensionSet length
const dimensionSet moles
Namespace for OpenFOAM.
dimensionedScalar pos(const dimensionedScalar &ds)
Istream & operator>>(Istream &, pointEdgeDist &)
Definition: pointEdgeDist.C:41
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
void transform(GeometricField< Type, GeoMesh > &rtf, const GeometricField< tensor, GeoMesh > &trf, const GeometricField< Type, GeoMesh > &tf)
tmp< DimensionedField< Type, GeoMesh, Field > > cmptMultiply(const DimensionedField< Type, GeoMesh, PrimitiveField1 > &df1, const DimensionedField< Type, GeoMesh, PrimitiveField2 > &df2)
void pow025(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
tmp< DimensionedField< Type, GeoMesh, Field > > operator/(const DimensionedField< Type, GeoMesh, PrimitiveField1 > &df1, const DimensionedField< scalar, GeoMesh, PrimitiveField2 > &df2)
tmp< DimensionedField< typename typeOfSum< Type1, Type2 >::type, GeoMesh, Field > > operator+(const DimensionedField< Type1, GeoMesh, PrimitiveField1 > &df1, const DimensionedField< Type2, GeoMesh, PrimitiveField2 > &df2)
tmp< DimensionedField< Type, GeoMesh, Field > > operator*(const DimensionedField< Type, GeoMesh, PrimitiveField1 > &df1, const DimensionedField< scalar, GeoMesh, PrimitiveField2 > &df2)
void pow4(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
void pow6(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
tmp< DimensionedField< typename outerProduct< Type, Type >::type, GeoMesh, Field >> sqr(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
dimensionedScalar negPart(const dimensionedScalar &ds)
tmp< DimensionedField< Type, GeoMesh, Field > > cmptDivide(const DimensionedField< Type, GeoMesh, PrimitiveField1 > &df1, const DimensionedField< Type, GeoMesh, PrimitiveField2 > &df2)
tmp< DimensionedField< Type, GeoMesh, Field > > operator-(const DimensionedField< Type, GeoMesh, PrimitiveField > &df1)
void inv(pointPatchField< tensor > &, const pointPatchField< tensor > &)
void pow5(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
dimensionSet normalised(const dimensionSet &)
Definition: dimensionSet.C:544
tmp< DimensionedField< typename scalarProduct< Type1, Type2 >::type, GeoMesh, Field > > operator&&(const DimensionedField< Type1, GeoMesh, PrimitiveField1 > &df1, const DimensionedField< Type2, GeoMesh, PrimitiveField2 > &df2)
dimensioned< Type > min(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
void pow3(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
dimensionedScalar neg(const dimensionedScalar &ds)
void cbrt(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
tmp< DimensionedField< typename crossProduct< Type1, Type2 >::type, GeoMesh, Field > > operator^(const DimensionedField< Type1, GeoMesh, PrimitiveField1 > &df1, const DimensionedField< Type2, GeoMesh, PrimitiveField2 > &df2)
tmp< DimensionedField< typename powProduct< Type, r >::type, GeoMesh, Field > > pow(const DimensionedField< Type, GeoMesh, PrimitiveField > &df, typename powProduct< Type, r >::type)
tmp< DimensionedField< scalar, GeoMesh, Field > > mag(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
tmp< DimensionedField< scalar, GeoMesh, Field > > atan2(const DimensionedField< scalar, GeoMesh, PrimitiveField1 > &dsf1, const DimensionedField< scalar, GeoMesh, PrimitiveField2 > &dsf2)
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
dimensionedScalar neg0(const dimensionedScalar &ds)
tmp< DimensionedField< Type, GeoMesh, Field > > cmptMag(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
dimensionSet perpendicular(const dimensionSet &)
Definition: dimensionSet.C:550
void sqrt(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
tmp< DimensionedField< scalar, GeoMesh, Field > > magSqr(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
dimensionSet trans(const dimensionSet &)
Definition: dimensionSet.C:511
void writeEntry(Ostream &os, const word &key, const DimensionedFieldFunction< DimensionedFieldType > &f)
tmp< DimensionedField< typename innerProduct< Type1, Type2 >::type, GeoMesh, Field > > operator&(const DimensionedField< Type1, GeoMesh, PrimitiveField1 > &df1, const DimensionedField< Type2, GeoMesh, PrimitiveField2 > &df2)
dimensionedScalar posPart(const dimensionedScalar &ds)
dimensioned< Type > max(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
Foam::argList args(argc, argv)