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 "dimensionedScalar.H"
28 #include "NamedEnum.H"
29 #include "OStringStream.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
36 }
37 
40  (
42  ({
43  "mass",
44  "length",
45  "time",
46  "temperature",
47  "moles",
48  "current",
49  "luminousIntensity"
50  })
51  );
52 
55 
56 const Foam::scalar Foam::dimensionSet::smallExponent = rootSmall;
57 
58 
59 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
60 
62 (
63  const scalar mass,
64  const scalar length,
65  const scalar time,
66  const scalar temperature,
67  const scalar moles,
68  const scalar current,
69  const scalar luminousIntensity
70 )
71 {
72  exponents_[MASS] = mass;
73  exponents_[LENGTH] = length;
74  exponents_[TIME] = time;
75  exponents_[TEMPERATURE] = temperature;
76  exponents_[MOLES] = moles;
77  exponents_[CURRENT] = current;
79 }
80 
81 
83 (
84  const scalar mass,
85  const scalar length,
86  const scalar time,
87  const scalar temperature,
88  const scalar moles
89 )
90 {
91  exponents_[MASS] = mass;
92  exponents_[LENGTH] = length;
93  exponents_[TIME] = time;
94  exponents_[TEMPERATURE] = temperature;
95  exponents_[MOLES] = moles;
96  exponents_[CURRENT] = 0;
97  exponents_[LUMINOUS_INTENSITY] = 0;
98 }
99 
100 
102 {
103  reset(ds);
104 }
105 
106 
107 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
108 
110 {
111  for (int Dimension=0; Dimension<nDimensions; ++Dimension)
112  {
113  // ie, mag(exponents_[Dimension]) > smallExponent
114  if
115  (
116  exponents_[Dimension] > smallExponent
117  || exponents_[Dimension] < -smallExponent
118  )
119  {
120  return false;
121  }
122  }
123 
124  return true;
125 }
126 
127 
129 {
130  for (int Dimension=0; Dimension<nDimensions; ++Dimension)
131  {
132  exponents_[Dimension] = ds.exponents_[Dimension];
133  }
134 }
135 
136 
137 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
138 
140 {
141  return exponents_[type];
142 }
143 
144 
146 {
147  return exponents_[type];
148 }
149 
150 
151 Foam::scalar Foam::dimensionSet::operator[](const label type) const
152 {
153  return exponents_[type];
154 }
155 
156 
158 {
159  return exponents_[type];
160 }
161 
162 
164 {
165  for (int Dimension=0; Dimension < nDimensions; ++Dimension)
166  {
167  if
168  (
169  mag(exponents_[Dimension] - ds.exponents_[Dimension])
170  > smallExponent
171  )
172  {
173  return false;
174  }
175  }
176 
177  return true;
178 }
179 
180 
182 {
183  return !(operator==(ds));
184 }
185 
186 
188 {
189  if (dimensionSet::debug && *this != ds)
190  {
192  << "Different dimensions for =" << endl
193  << " dimensions : " << info() << " = " << ds.info() << endl
194  << abort(FatalError);
195  }
196 
197  return true;
198 }
199 
200 
202 {
203  if (dimensionSet::debug && *this != ds)
204  {
206  << "Different dimensions for +=" << endl
207  << " dimensions : " << info() << " = " << ds.info() << endl
208  << abort(FatalError);
209  }
210 
211  return true;
212 }
213 
214 
216 {
217  if (dimensionSet::debug && *this != ds)
218  {
220  << "Different dimensions for -=" << endl
221  << " dimensions : " << info() << " = " << ds.info() << endl
222  << abort(FatalError);
223  }
224 
225  return true;
226 }
227 
228 
230 {
231  reset((*this)*ds);
232 
233  return true;
234 }
235 
236 
238 {
239  reset((*this)/ds);
240 
241  return true;
242 }
243 
244 
245 // * * * * * * * * * * * * * * * Friend functions * * * * * * * * * * * * * * //
246 
248 {
249  if (dimensionSet::debug && ds1 != ds2)
250  {
252  << "Arguments of max have different dimensions" << endl
253  << " dimensions : " << ds1.info() << " and " << ds2.info()
254  << endl << abort(FatalError);
255  }
256 
257  return ds1;
258 }
259 
260 
262 {
263  if (dimensionSet::debug && ds1 != ds2)
264  {
266  << "Arguments of min have different dimensions" << endl
267  << " dimensions : " << ds1.info() << " and " << ds2.info()
268  << endl << abort(FatalError);
269  }
270 
271  return ds1;
272 }
273 
274 
276 (
277  const dimensionSet& ds1,
278  const dimensionSet& ds2
279 )
280 {
281  return ds1*ds2;
282 }
283 
284 
286 (
287  const dimensionSet& ds1,
288  const dimensionSet& ds2
289 )
290 {
291  return ds1/ds2;
292 }
293 
294 
296 {
297  return ds;
298 }
299 
300 
301 Foam::dimensionSet Foam::pow(const dimensionSet& ds, const scalar p)
302 {
303  dimensionSet dimPow
304  (
305  ds[dimensionSet::MASS]*p,
307  ds[dimensionSet::TIME]*p,
312  );
313 
314  return dimPow;
315 }
316 
317 
319 (
320  const dimensionSet& ds,
321  const dimensionedScalar& dS
322 )
323 {
324  if (dimensionSet::debug && !dS.dimensions().dimensionless())
325  {
327  << "Exponent of pow is not dimensionless"
328  << abort(FatalError);
329  }
330 
331  dimensionSet dimPow
332  (
333  ds[dimensionSet::MASS]*dS.value(),
334  ds[dimensionSet::LENGTH]*dS.value(),
335  ds[dimensionSet::TIME]*dS.value(),
337  ds[dimensionSet::MOLES]*dS.value(),
338  ds[dimensionSet::CURRENT]*dS.value(),
340  );
341 
342  return dimPow;
343 }
344 
345 
347 (
348  const dimensionedScalar& dS,
349  const dimensionSet& ds
350 )
351 {
352  if
353  (
354  dimensionSet::debug
355  && !dS.dimensions().dimensionless()
356  && !ds.dimensionless()
357  )
358  {
360  << "Argument or exponent of pow not dimensionless" << endl
361  << abort(FatalError);
362  }
363 
364  return ds;
365 }
366 
367 
369 {
370  return pow(ds, 2);
371 }
372 
373 
375 {
376  return pow(ds, 3);
377 }
378 
379 
381 {
382  return pow(ds, 4);
383 }
384 
385 
387 {
388  return pow(ds, 5);
389 }
390 
391 
393 {
394  return pow(ds, 6);
395 }
396 
397 
399 {
400  return sqrt(sqrt(ds));
401 }
402 
403 
405 {
406  return pow(ds, 0.5);
407 }
408 
409 
411 {
412  return pow(ds, 1.0/3.0);
413 }
414 
415 
417 {
418  return pow(ds, 2);
419 }
420 
421 
423 {
424  return ds;
425 }
426 
427 
429 {
430  return dimless;
431 }
432 
433 
435 {
436  return dimless;
437 }
438 
439 
441 {
442  return dimless;
443 }
444 
445 
447 {
448  return dimless;
449 }
450 
451 
453 {
454  return dimless;
455 }
456 
457 
459 {
460  return ds;
461 }
462 
463 
465 {
466  return ds;
467 }
468 
469 
471 {
472  return dimless/ds;
473 }
474 
475 
477 {
478  if (dimensionSet::debug && !ds.dimensionless())
479  {
481  << "Argument of trancendental function not dimensionless"
482  << abort(FatalError);
483  }
484 
485  return ds;
486 }
487 
488 
490 {
491  if (dimensionSet::debug && ds1 != ds2)
492  {
494  << "Arguments of atan2 have different dimensions" << endl
495  << " dimensions : " << ds1.info() << " and " << ds2.info()
496  << endl << abort(FatalError);
497  }
498 
499  return dimless;
500 }
501 
502 
504 {
505  return ds;
506 }
507 
508 
510 {
511  return dimless;
512 }
513 
514 
516 {
517  return dimless;
518 }
519 
520 
521 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
522 
524 {
525  return ds;
526 }
527 
528 
529 Foam::dimensionSet Foam::operator+
530 (
531  const dimensionSet& ds1,
532  const dimensionSet& ds2
533 )
534 {
535  dimensionSet dimSum(ds1);
536 
537  if (dimensionSet::debug && ds1 != ds2)
538  {
540  << "LHS and RHS of + have different dimensions" << endl
541  << " dimensions : " << ds1.info() << " + " << ds2.info()
542  << endl << abort(FatalError);
543  }
544 
545  return dimSum;
546 }
547 
548 
549 Foam::dimensionSet Foam::operator-
550 (
551  const dimensionSet& ds1,
552  const dimensionSet& ds2
553 )
554 {
555  dimensionSet dimDifference(ds1);
556 
557  if (dimensionSet::debug && ds1 != ds2)
558  {
560  << "LHS and RHS of - have different dimensions" << endl
561  << " dimensions : " << ds1.info() << " - " << ds2.info()
562  << endl << abort(FatalError);
563  }
564 
565  return dimDifference;
566 }
567 
568 
569 Foam::dimensionSet Foam::operator*
570 (
571  const dimensionSet& ds1,
572  const dimensionSet& ds2
573 )
574 {
575  dimensionSet dimProduct(ds1);
576 
577  for (int Dimension=0; Dimension<dimensionSet::nDimensions; Dimension++)
578  {
579  dimProduct.exponents_[Dimension] += ds2.exponents_[Dimension];
580  }
581 
582  return dimProduct;
583 }
584 
585 
586 Foam::dimensionSet Foam::operator/
587 (
588  const dimensionSet& ds1,
589  const dimensionSet& ds2
590 )
591 {
592  dimensionSet dimQuotient(ds1);
593 
594  for (int Dimension=0; Dimension<dimensionSet::nDimensions; Dimension++)
595  {
596  dimQuotient.exponents_[Dimension] -= ds2.exponents_[Dimension];
597  }
598 
599  return dimQuotient;
600 }
601 
602 
603 Foam::dimensionSet Foam::operator&
604 (
605  const dimensionSet& ds1,
606  const dimensionSet& ds2
607 )
608 {
609  return ds1*ds2;
610 }
611 
612 
613 Foam::dimensionSet Foam::operator^
614 (
615  const dimensionSet& ds1,
616  const dimensionSet& ds2
617 )
618 {
619  return ds1*ds2;
620 }
621 
622 
623 Foam::dimensionSet Foam::operator&&
624 (
625  const dimensionSet& ds1,
626  const dimensionSet& ds2
627 )
628 {
629  return ds1*ds2;
630 }
631 
632 
633 // ************************************************************************* //
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:201
InfoProxy< dimensionSet > info() const
Return info proxy.
Definition: dimensionSet.H:245
bool operator==(const dimensionSet &) const
Definition: dimensionSet.C:163
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
bool operator/=(const dimensionSet &)
Definition: dimensionSet.C:237
bool operator-=(const dimensionSet &) const
Definition: dimensionSet.C:215
scalar operator[](const dimensionType) const
Definition: dimensionSet.C:139
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
bool dimensionless() const
Return true if it is dimensionless.
Definition: dimensionSet.C:109
dimensionType
Define an enumeration for the names of the dimension exponents.
Definition: dimensionSet.H:139
bool operator*=(const dimensionSet &)
Definition: dimensionSet.C:229
bool operator=(const dimensionSet &) const
Definition: dimensionSet.C:187
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.
const Foam::autoPtr< Foam::NamedEnum< Foam::dimensionSet::dimensionType, 7 > > dimensionTypeNamesPtr_(new Foam::NamedEnum< Foam::dimensionSet::dimensionType, 7 >({ "mass", "length", "time", "temperature", "moles", "current", "luminousIntensity" }))
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
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)
const dimensionSet & dimless
Definition: dimensions.C:138
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:509
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)
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:515
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:476
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