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 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 without the square brackets
232 
233  //- Read
234  Istream& read(Istream& is);
235 
236  //- Write without the square brackets
237  Ostream& writeNoBeginOrEnd(Ostream& os) const;
238 
239  //- Write
240  Ostream& write(Ostream& os) const;
241 
242  //- Write info without the square brackets
244 
245  //- Return info proxy
246  inline InfoProxy<dimensionSet> info() const
247  {
248  return *this;
249  }
250 
251 
252  // Member Operators
253 
254  scalar operator[](const dimensionType) const;
255  scalar& operator[](const dimensionType);
256 
257  scalar operator[](const label) const;
258  scalar& operator[](const label);
259 
260  bool operator==(const dimensionSet&) const;
261  bool operator!=(const dimensionSet&) const;
262 
263  bool operator=(const dimensionSet&) const;
264 
265  bool operator+=(const dimensionSet&) const;
266  bool operator-=(const dimensionSet&) const;
267  bool operator*=(const dimensionSet&);
268  bool operator/=(const dimensionSet&);
269 
270  template<class ... Args>
271  using typeForArgs = typename typeOfNcmpts<sizeof ... (Args)>::type;
272 
273  //- Return a dimensionedType with these dimensions
274  // and rank corresponding to the number of arguments
275  template<class ... Args>
276  dimensioned<typeForArgs<Args ...>> operator()
277  (
278  const Args& ... args
279  ) const
280  {
281  return dimensioned<typeForArgs<Args ...>>
282  (
283  *this,
284  typeForArgs<Args ...>(args ...)
285  );
286  }
287 
288  //- Return a named dimensionedType with these dimensions
289  // and rank corresponding to the number of arguments
290  template<class ... Args>
291  dimensioned<typeForArgs<Args ...>> operator()
292  (
293  const word& name,
294  const Args& ... args
295  ) const
296  {
297  return dimensioned<typeForArgs<Args ...>>
298  (
299  name,
300  *this,
301  typeForArgs<Args ...>(args ...)
302  );
303  }
304 
305 
306  // Friend Functions
307 
308  friend dimensionSet max(const dimensionSet&, const dimensionSet&);
309  friend dimensionSet min(const dimensionSet&, const dimensionSet&);
311  (
312  const dimensionSet&,
313  const dimensionSet&
314  );
315  friend dimensionSet cmptDivide
316  (
317  const dimensionSet&,
318  const dimensionSet&
319  );
320  friend dimensionSet cmptMag(const dimensionSet&);
321 
322  friend dimensionSet pow(const dimensionSet&, const scalar);
324  friend dimensionSet pow(const dimensionedScalar&, const dimensionSet&);
325 
326  friend dimensionSet sqr(const dimensionSet&);
331  friend dimensionSet pow025(const dimensionSet&);
332 
335  friend dimensionSet mag(const dimensionSet&);
338  friend dimensionSet neg(const dimensionSet&);
339  friend dimensionSet inv(const dimensionSet&);
340 
341  //- Function to check the argument is dimensionless
342  // for transcendental functions
343  friend dimensionSet trans(const dimensionSet&);
344 
345  friend dimensionSet atan2(const dimensionSet&, const dimensionSet&);
346 
347  friend dimensionSet transform(const dimensionSet&);
348 
350  friend dimensionSet perpendicular(const dimensionSet&);
351 
352 
353  // Friend Operators
354 
355  friend dimensionSet operator-(const dimensionSet&);
356 
357  friend dimensionSet operator+
358  (
359  const dimensionSet&,
360  const dimensionSet&
361  );
362 
363  friend dimensionSet operator-
364  (
365  const dimensionSet&,
366  const dimensionSet&
367  );
368 
369  friend dimensionSet operator*
370  (
371  const dimensionSet&,
372  const dimensionSet&
373  );
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 
400  // IOstream Operators
401 
405 };
406 
407 
408 void writeEntry(Ostream& os, const dimensionSet& value);
409 
410 
411 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
412 
413 } // End namespace Foam
414 
415 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
416 
417 #include "dimensions.H"
418 
419 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
420 
421 #endif
422 
423 // ************************************************************************* //
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:201
friend dimensionSet pow(const dimensionSet &, const dimensionedScalar &)
InfoProxy< dimensionSet > info() const
Return info proxy.
Definition: dimensionSet.H:245
bool operator==(const dimensionSet &) const
Definition: dimensionSet.C:163
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:181
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:62
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:237
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:215
friend dimensionSet pow4(const dimensionSet &)
scalar operator[](const dimensionType) const
Definition: dimensionSet.C:139
friend dimensionSet mag(const dimensionSet &)
void reset(const dimensionSet &)
Definition: dimensionSet.C:128
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:109
friend dimensionSet normalised(const dimensionSet &)
autoPtr< dimensionSet > clone() const
Construct and return a clone.
Definition: dimensionSet.H:210
typename typeOfNcmpts< sizeof ...(Args)>::type typeForArgs
Definition: dimensionSet.H:270
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:229
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:187
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:509
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:515
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:476
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)