dimensionSet.C
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 \*---------------------------------------------------------------------------*/
25 
26 #include "dimensionSet.H"
27 #include "dimensions.H"
28 #include "dimensionedScalar.H"
29 #include "NamedEnum.H"
30 #include "OStringStream.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
37 }
38 
41  (
43  {
44  "mass",
45  "length",
46  "time",
47  "temperature",
48  "moles",
49  "current",
50  "luminousIntensity"
51  }
52  );
53 
56 
57 const Foam::scalar Foam::dimensionSet::smallExponent = rootSmall;
58 
59 
60 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
61 
63 (
64  const scalar mass,
65  const scalar length,
66  const scalar time,
67  const scalar temperature,
68  const scalar moles,
69  const scalar current,
70  const scalar luminousIntensity
71 )
72 {
73  exponents_[MASS] = mass;
74  exponents_[LENGTH] = length;
75  exponents_[TIME] = time;
76  exponents_[TEMPERATURE] = temperature;
77  exponents_[MOLES] = moles;
78  exponents_[CURRENT] = current;
80 }
81 
82 
84 (
85  const word& name,
86  const scalar mass,
87  const scalar length,
88  const scalar time,
89  const scalar temperature,
90  const scalar moles,
91  const scalar current,
92  const scalar luminousIntensity
93 )
94 :
96  (
97  mass,
98  length,
99  time,
100  temperature,
101  moles,
102  current,
104  )
105 {
106  dimensions::table.insert(name, *this);
107 }
108 
109 
111 (
112  const scalar mass,
113  const scalar length,
114  const scalar time,
115  const scalar temperature,
116  const scalar moles
117 )
118 {
119  exponents_[MASS] = mass;
120  exponents_[LENGTH] = length;
121  exponents_[TIME] = time;
122  exponents_[TEMPERATURE] = temperature;
123  exponents_[MOLES] = moles;
124  exponents_[CURRENT] = 0;
125  exponents_[LUMINOUS_INTENSITY] = 0;
126 }
127 
128 
130 {
131  reset(ds);
132 }
133 
134 
136 {
137  reset(ds);
138  dimensions::table.insert(name, *this);
139 }
140 
141 
142 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
143 
145 {
146  for (int Dimension=0; Dimension<nDimensions; ++Dimension)
147  {
148  // ie, mag(exponents_[Dimension]) > smallExponent
149  if
150  (
151  exponents_[Dimension] > smallExponent
152  || exponents_[Dimension] < -smallExponent
153  )
154  {
155  return false;
156  }
157  }
158 
159  return true;
160 }
161 
162 
164 {
165  for (int Dimension=0; Dimension<nDimensions; ++Dimension)
166  {
167  exponents_[Dimension] = ds.exponents_[Dimension];
168  }
169 }
170 
171 
172 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
173 
175 {
176  return exponents_[type];
177 }
178 
179 
181 {
182  return exponents_[type];
183 }
184 
185 
186 Foam::scalar Foam::dimensionSet::operator[](const label type) const
187 {
188  return exponents_[type];
189 }
190 
191 
193 {
194  return exponents_[type];
195 }
196 
197 
199 {
200  for (int Dimension=0; Dimension < nDimensions; ++Dimension)
201  {
202  if
203  (
204  mag(exponents_[Dimension] - ds.exponents_[Dimension])
205  > smallExponent
206  )
207  {
208  return false;
209  }
210  }
211 
212  return true;
213 }
214 
215 
217 {
218  return !(operator==(ds));
219 }
220 
221 
223 {
224  if (dimensionSet::debug && *this != ds)
225  {
227  << "Different dimensions for =" << endl
228  << " dimensions : " << info() << " = " << ds.info() << endl
229  << abort(FatalError);
230  }
231 
232  return true;
233 }
234 
235 
237 {
238  if (dimensionSet::debug && *this != ds)
239  {
241  << "Different dimensions for +=" << endl
242  << " dimensions : " << info() << " = " << ds.info() << endl
243  << abort(FatalError);
244  }
245 
246  return true;
247 }
248 
249 
251 {
252  if (dimensionSet::debug && *this != ds)
253  {
255  << "Different dimensions for -=" << endl
256  << " dimensions : " << info() << " = " << ds.info() << endl
257  << abort(FatalError);
258  }
259 
260  return true;
261 }
262 
263 
265 {
266  reset((*this)*ds);
267 
268  return true;
269 }
270 
271 
273 {
274  reset((*this)/ds);
275 
276  return true;
277 }
278 
279 
280 // * * * * * * * * * * * * * * * Friend functions * * * * * * * * * * * * * * //
281 
283 {
284  if (dimensionSet::debug && ds1 != ds2)
285  {
287  << "Arguments of max have different dimensions" << endl
288  << " dimensions : " << ds1.info() << " and " << ds2.info()
289  << endl << abort(FatalError);
290  }
291 
292  return ds1;
293 }
294 
295 
297 {
298  if (dimensionSet::debug && ds1 != ds2)
299  {
301  << "Arguments of min have different dimensions" << endl
302  << " dimensions : " << ds1.info() << " and " << ds2.info()
303  << endl << abort(FatalError);
304  }
305 
306  return ds1;
307 }
308 
309 
311 (
312  const dimensionSet& ds1,
313  const dimensionSet& ds2
314 )
315 {
316  return ds1*ds2;
317 }
318 
319 
321 (
322  const dimensionSet& ds1,
323  const dimensionSet& ds2
324 )
325 {
326  return ds1/ds2;
327 }
328 
329 
331 {
332  return ds;
333 }
334 
335 
336 Foam::dimensionSet Foam::pow(const dimensionSet& ds, const scalar p)
337 {
338  dimensionSet dimPow
339  (
340  ds[dimensionSet::MASS]*p,
342  ds[dimensionSet::TIME]*p,
347  );
348 
349  return dimPow;
350 }
351 
352 
354 (
355  const dimensionSet& ds,
356  const dimensionedScalar& dS
357 )
358 {
359  if (dimensionSet::debug && !dS.dimensions().dimensionless())
360  {
362  << "Exponent of pow is not dimensionless"
363  << abort(FatalError);
364  }
365 
366  dimensionSet dimPow
367  (
368  ds[dimensionSet::MASS]*dS.value(),
369  ds[dimensionSet::LENGTH]*dS.value(),
370  ds[dimensionSet::TIME]*dS.value(),
372  ds[dimensionSet::MOLES]*dS.value(),
373  ds[dimensionSet::CURRENT]*dS.value(),
375  );
376 
377  return dimPow;
378 }
379 
380 
382 (
383  const dimensionedScalar& dS,
384  const dimensionSet& ds
385 )
386 {
387  if
388  (
389  dimensionSet::debug
390  && !dS.dimensions().dimensionless()
391  && !ds.dimensionless()
392  )
393  {
395  << "Argument or exponent of pow not dimensionless" << endl
396  << abort(FatalError);
397  }
398 
399  return ds;
400 }
401 
402 
404 {
405  return pow(ds, 2);
406 }
407 
408 
410 {
411  return pow(ds, 3);
412 }
413 
414 
416 {
417  return pow(ds, 4);
418 }
419 
420 
422 {
423  return pow(ds, 5);
424 }
425 
426 
428 {
429  return pow(ds, 6);
430 }
431 
432 
434 {
435  return sqrt(sqrt(ds));
436 }
437 
438 
440 {
441  return pow(ds, 0.5);
442 }
443 
444 
446 {
447  return pow(ds, 1.0/3.0);
448 }
449 
450 
452 {
453  return pow(ds, 2);
454 }
455 
456 
458 {
459  return ds;
460 }
461 
462 
464 {
465  return dimless;
466 }
467 
468 
470 {
471  return dimless;
472 }
473 
474 
476 {
477  return dimless;
478 }
479 
480 
482 {
483  return dimless;
484 }
485 
486 
488 {
489  return dimless;
490 }
491 
492 
494 {
495  return ds;
496 }
497 
498 
500 {
501  return ds;
502 }
503 
504 
506 {
507  return dimless/ds;
508 }
509 
510 
512 {
513  if (dimensionSet::debug && !ds.dimensionless())
514  {
516  << "Argument of trancendental function not dimensionless"
517  << abort(FatalError);
518  }
519 
520  return ds;
521 }
522 
523 
525 {
526  if (dimensionSet::debug && ds1 != ds2)
527  {
529  << "Arguments of atan2 have different dimensions" << endl
530  << " dimensions : " << ds1.info() << " and " << ds2.info()
531  << endl << abort(FatalError);
532  }
533 
534  return dimless;
535 }
536 
537 
539 {
540  return ds;
541 }
542 
543 
545 {
546  return dimless;
547 }
548 
549 
551 {
552  return dimless;
553 }
554 
555 
556 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
557 
559 {
560  return ds;
561 }
562 
563 
564 Foam::dimensionSet Foam::operator+
565 (
566  const dimensionSet& ds1,
567  const dimensionSet& ds2
568 )
569 {
570  dimensionSet dimSum(ds1);
571 
572  if (dimensionSet::debug && ds1 != ds2)
573  {
575  << "LHS and RHS of + have different dimensions" << endl
576  << " dimensions : " << ds1.info() << " + " << ds2.info()
577  << endl << abort(FatalError);
578  }
579 
580  return dimSum;
581 }
582 
583 
584 Foam::dimensionSet Foam::operator-
585 (
586  const dimensionSet& ds1,
587  const dimensionSet& ds2
588 )
589 {
590  dimensionSet dimDifference(ds1);
591 
592  if (dimensionSet::debug && ds1 != ds2)
593  {
595  << "LHS and RHS of - have different dimensions" << endl
596  << " dimensions : " << ds1.info() << " - " << ds2.info()
597  << endl << abort(FatalError);
598  }
599 
600  return dimDifference;
601 }
602 
603 
604 Foam::dimensionSet Foam::operator*
605 (
606  const dimensionSet& ds1,
607  const dimensionSet& ds2
608 )
609 {
610  dimensionSet dimProduct(ds1);
611 
612  for (int Dimension=0; Dimension<dimensionSet::nDimensions; Dimension++)
613  {
614  dimProduct.exponents_[Dimension] += ds2.exponents_[Dimension];
615  }
616 
617  return dimProduct;
618 }
619 
620 
621 Foam::dimensionSet Foam::operator/
622 (
623  const dimensionSet& ds1,
624  const dimensionSet& ds2
625 )
626 {
627  dimensionSet dimQuotient(ds1);
628 
629  for (int Dimension=0; Dimension<dimensionSet::nDimensions; Dimension++)
630  {
631  dimQuotient.exponents_[Dimension] -= ds2.exponents_[Dimension];
632  }
633 
634  return dimQuotient;
635 }
636 
637 
638 Foam::dimensionSet Foam::operator&
639 (
640  const dimensionSet& ds1,
641  const dimensionSet& ds2
642 )
643 {
644  return ds1*ds2;
645 }
646 
647 
648 Foam::dimensionSet Foam::operator^
649 (
650  const dimensionSet& ds1,
651  const dimensionSet& ds2
652 )
653 {
654  return ds1*ds2;
655 }
656 
657 
658 Foam::dimensionSet Foam::operator&&
659 (
660  const dimensionSet& ds1,
661  const dimensionSet& ds2
662 )
663 {
664  return ds1*ds2;
665 }
666 
667 
668 // ************************************************************************* //
InfoProxy< IOstream > info() const
Return info proxy.
Definition: IOstream.H:552
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:55
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
bool operator+=(const dimensionSet &) const
Definition: dimensionSet.C:236
InfoProxy< dimensionSet > info() const
Return info proxy.
Definition: dimensionSet.H:263
bool operator==(const dimensionSet &) const
Definition: dimensionSet.C:198
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
bool operator/=(const dimensionSet &)
Definition: dimensionSet.C:272
bool operator-=(const dimensionSet &) const
Definition: dimensionSet.C:250
scalar operator[](const dimensionType) const
Definition: dimensionSet.C:174
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
bool dimensionless() const
Return true if it is dimensionless.
Definition: dimensionSet.C:144
dimensionType
Define an enumeration for the names of the dimension exponents.
Definition: dimensionSet.H:139
bool operator*=(const dimensionSet &)
Definition: dimensionSet.C:264
bool operator=(const dimensionSet &) const
Definition: dimensionSet.C:222
static const NamedEnum< dimensionType, 7 > & dimensionTypeNames_
Names of the dimensions.
Definition: dimensionSet.H:150
const dimensionSet & dimensions() const
Return const reference to dimensions.
const Type & value() const
Return const reference to value.
A class for handling words, derived from string.
Definition: word.H:63
const Foam::autoPtr< Foam::NamedEnum< Foam::dimensionSet::dimensionType, 7 > > dimensionTypeNamesPtr_(new Foam::NamedEnum< Foam::dimensionSet::dimensionType, 7 > { "mass", "length", "time", "temperature", "moles", "current", "luminousIntensity" })
Predefined dimensions.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
HashTable< dimensionSet > table
Table of dimensions.
Definition: dimensions.C:38
const dimensionSet dimless
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)
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
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
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)
errorManip< error > abort(error &err)
Definition: errorManip.H:131
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
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 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)
error FatalError
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)
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)
dimensionSet trans(const dimensionSet &)
Definition: dimensionSet.C:511
dimensionedScalar posPart(const dimensionedScalar &ds)
dimensioned< Type > max(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
volScalarField & p