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-2021 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 "OStringStream.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(dimensionSet, 1);
35  const scalar dimensionSet::smallExponent = small;
36 }
37 
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
42 (
43  const scalar mass,
44  const scalar length,
45  const scalar time,
46  const scalar temperature,
47  const scalar moles,
48  const scalar current,
49  const scalar luminousIntensity
50 )
51 {
52  exponents_[MASS] = mass;
53  exponents_[LENGTH] = length;
54  exponents_[TIME] = time;
55  exponents_[TEMPERATURE] = temperature;
56  exponents_[MOLES] = moles;
57  exponents_[CURRENT] = current;
58  exponents_[LUMINOUS_INTENSITY] = luminousIntensity;
59 }
60 
61 
63 (
64  const scalar mass,
65  const scalar length,
66  const scalar time,
67  const scalar temperature,
68  const scalar moles
69 )
70 {
71  exponents_[MASS] = mass;
72  exponents_[LENGTH] = length;
73  exponents_[TIME] = time;
74  exponents_[TEMPERATURE] = temperature;
75  exponents_[MOLES] = moles;
76  exponents_[CURRENT] = 0;
77  exponents_[LUMINOUS_INTENSITY] = 0;
78 }
79 
80 
82 {
83  reset(ds);
84 }
85 
86 
87 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
88 
90 {
91  for (int Dimension=0; Dimension<nDimensions; ++Dimension)
92  {
93  // ie, mag(exponents_[Dimension]) > smallExponent
94  if
95  (
96  exponents_[Dimension] > smallExponent
97  || exponents_[Dimension] < -smallExponent
98  )
99  {
100  return false;
101  }
102  }
103 
104  return true;
105 }
106 
107 
109 {
110  for (int Dimension=0; Dimension<nDimensions; ++Dimension)
111  {
112  exponents_[Dimension] = ds.exponents_[Dimension];
113  }
114 }
115 
116 
117 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
118 
120 {
121  return exponents_[type];
122 }
123 
124 
126 {
127  return exponents_[type];
128 }
129 
130 
131 Foam::scalar Foam::dimensionSet::operator[](const label type) const
132 {
133  return exponents_[type];
134 }
135 
136 
138 {
139  return exponents_[type];
140 }
141 
142 
144 {
145  for (int Dimension=0; Dimension < nDimensions; ++Dimension)
146  {
147  if
148  (
149  mag(exponents_[Dimension] - ds.exponents_[Dimension])
150  > smallExponent
151  )
152  {
153  return false;
154  }
155  }
156 
157  return true;
158 }
159 
160 
162 {
163  return !(operator==(ds));
164 }
165 
166 
168 {
169  if (dimensionSet::debug && *this != ds)
170  {
172  << "Different dimensions for =" << endl
173  << " dimensions : " << *this << " = " << ds << endl
174  << abort(FatalError);
175  }
176 
177  return true;
178 }
179 
180 
182 {
183  if (dimensionSet::debug && *this != ds)
184  {
186  << "Different dimensions for +=" << endl
187  << " dimensions : " << *this << " = " << ds << endl
188  << abort(FatalError);
189  }
190 
191  return true;
192 }
193 
194 
196 {
197  if (dimensionSet::debug && *this != ds)
198  {
200  << "Different dimensions for -=" << endl
201  << " dimensions : " << *this << " = " << ds << endl
202  << abort(FatalError);
203  }
204 
205  return true;
206 }
207 
208 
210 {
211  reset((*this)*ds);
212 
213  return true;
214 }
215 
216 
218 {
219  reset((*this)/ds);
220 
221  return true;
222 }
223 
224 
225 // * * * * * * * * * * * * * * * Friend functions * * * * * * * * * * * * * * //
226 
228 {
229  if (dimensionSet::debug && ds1 != ds2)
230  {
232  << "Arguments of max have different dimensions" << endl
233  << " dimensions : " << ds1 << " and " << ds2 << endl
234  << abort(FatalError);
235  }
236 
237  return ds1;
238 }
239 
240 
242 {
243  if (dimensionSet::debug && ds1 != ds2)
244  {
246  << "Arguments of min have different dimensions" << endl
247  << " dimensions : " << ds1 << " and " << ds2 << endl
248  << abort(FatalError);
249  }
250 
251  return ds1;
252 }
253 
254 
256 (
257  const dimensionSet& ds1,
258  const dimensionSet& ds2
259 )
260 {
261  return ds1*ds2;
262 }
263 
264 
266 (
267  const dimensionSet& ds1,
268  const dimensionSet& ds2
269 )
270 {
271  return ds1/ds2;
272 }
273 
274 
276 {
277  return ds;
278 }
279 
280 
281 Foam::dimensionSet Foam::pow(const dimensionSet& ds, const scalar p)
282 {
283  dimensionSet dimPow
284  (
285  ds[dimensionSet::MASS]*p,
286  ds[dimensionSet::LENGTH]*p,
287  ds[dimensionSet::TIME]*p,
289  ds[dimensionSet::MOLES]*p,
290  ds[dimensionSet::CURRENT]*p,
292  );
293 
294  return dimPow;
295 }
296 
297 
299 (
300  const dimensionSet& ds,
301  const dimensionedScalar& dS
302 )
303 {
304  if (dimensionSet::debug && !dS.dimensions().dimensionless())
305  {
307  << "Exponent of pow is not dimensionless"
308  << abort(FatalError);
309  }
310 
311  dimensionSet dimPow
312  (
313  ds[dimensionSet::MASS]*dS.value(),
314  ds[dimensionSet::LENGTH]*dS.value(),
315  ds[dimensionSet::TIME]*dS.value(),
317  ds[dimensionSet::MOLES]*dS.value(),
318  ds[dimensionSet::CURRENT]*dS.value(),
320  );
321 
322  return dimPow;
323 }
324 
325 
327 (
328  const dimensionedScalar& dS,
329  const dimensionSet& ds
330 )
331 {
332  if
333  (
334  dimensionSet::debug
335  && !dS.dimensions().dimensionless()
336  && !ds.dimensionless()
337  )
338  {
340  << "Argument or exponent of pow not dimensionless" << endl
341  << abort(FatalError);
342  }
343 
344  return ds;
345 }
346 
347 
349 {
350  return pow(ds, 2);
351 }
352 
353 
355 {
356  return pow(ds, 3);
357 }
358 
359 
361 {
362  return pow(ds, 4);
363 }
364 
365 
367 {
368  return pow(ds, 5);
369 }
370 
371 
373 {
374  return pow(ds, 6);
375 }
376 
377 
379 {
380  return sqrt(sqrt(ds));
381 }
382 
383 
385 {
386  return pow(ds, 0.5);
387 }
388 
389 
391 {
392  return pow(ds, 1.0/3.0);
393 }
394 
395 
397 {
398  return pow(ds, 2);
399 }
400 
401 
403 {
404  return ds;
405 }
406 
407 
409 {
410  return dimless;
411 }
412 
413 
415 {
416  return dimless;
417 }
418 
419 
421 {
422  return dimless;
423 }
424 
425 
427 {
428  return dimless;
429 }
430 
431 
433 {
434  return dimless;
435 }
436 
437 
439 {
440  return ds;
441 }
442 
443 
445 {
446  return ds;
447 }
448 
449 
451 {
452  return dimless/ds;
453 }
454 
455 
457 {
458  if (dimensionSet::debug && !ds.dimensionless())
459  {
461  << "Argument of trancendental function not dimensionless"
462  << abort(FatalError);
463  }
464 
465  return ds;
466 }
467 
468 
470 {
471  if (dimensionSet::debug && ds1 != ds2)
472  {
474  << "Arguments of atan2 have different dimensions" << endl
475  << " dimensions : " << ds1 << " and " << ds2 << endl
476  << abort(FatalError);
477  }
478 
479  return dimless;
480 }
481 
482 
484 {
485  return ds;
486 }
487 
488 
489 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
490 
492 {
493  return ds;
494 }
495 
496 
497 Foam::dimensionSet Foam::operator+
498 (
499  const dimensionSet& ds1,
500  const dimensionSet& ds2
501 )
502 {
503  dimensionSet dimSum(ds1);
504 
505  if (dimensionSet::debug && ds1 != ds2)
506  {
508  << "LHS and RHS of + have different dimensions" << endl
509  << " dimensions : " << ds1 << " + " << ds2 << endl
510  << abort(FatalError);
511  }
512 
513  return dimSum;
514 }
515 
516 
517 Foam::dimensionSet Foam::operator-
518 (
519  const dimensionSet& ds1,
520  const dimensionSet& ds2
521 )
522 {
523  dimensionSet dimDifference(ds1);
524 
525  if (dimensionSet::debug && ds1 != ds2)
526  {
528  << "LHS and RHS of - have different dimensions" << endl
529  << " dimensions : " << ds1 << " - " << ds2 << endl
530  << abort(FatalError);
531  }
532 
533  return dimDifference;
534 }
535 
536 
537 Foam::dimensionSet Foam::operator*
538 (
539  const dimensionSet& ds1,
540  const dimensionSet& ds2
541 )
542 {
543  dimensionSet dimProduct(ds1);
544 
545  for (int Dimension=0; Dimension<dimensionSet::nDimensions; Dimension++)
546  {
547  dimProduct.exponents_[Dimension] += ds2.exponents_[Dimension];
548  }
549 
550  return dimProduct;
551 }
552 
553 
554 Foam::dimensionSet Foam::operator/
555 (
556  const dimensionSet& ds1,
557  const dimensionSet& ds2
558 )
559 {
560  dimensionSet dimQuotient(ds1);
561 
562  for (int Dimension=0; Dimension<dimensionSet::nDimensions; Dimension++)
563  {
564  dimQuotient.exponents_[Dimension] -= ds2.exponents_[Dimension];
565  }
566 
567  return dimQuotient;
568 }
569 
570 
571 Foam::dimensionSet Foam::operator&
572 (
573  const dimensionSet& ds1,
574  const dimensionSet& ds2
575 )
576 {
577  return ds1*ds2;
578 }
579 
580 
581 Foam::dimensionSet Foam::operator^
582 (
583  const dimensionSet& ds1,
584  const dimensionSet& ds2
585 )
586 {
587  return ds1*ds2;
588 }
589 
590 
591 Foam::dimensionSet Foam::operator&&
592 (
593  const dimensionSet& ds1,
594  const dimensionSet& ds2
595 )
596 {
597  return ds1*ds2;
598 }
599 
600 
601 // ************************************************************************* //
dimensionedScalar sign(const dimensionedScalar &ds)
dimensionSet trans(const dimensionSet &)
Definition: dimensionSet.C:456
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
bool operator/=(const dimensionSet &)
Definition: dimensionSet.C:217
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
dimensionedSymmTensor sqr(const dimensionedVector &dv)
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
bool operator-=(const dimensionSet &) const
Definition: dimensionSet.C:195
dimensionedScalar sqrt(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
dimensionedScalar pow025(const dimensionedScalar &ds)
bool operator=(const dimensionSet &) const
Definition: dimensionSet.C:167
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:42
const dimensionSet dimless
dimensionedScalar posPart(const dimensionedScalar &ds)
dimensionedScalar neg(const dimensionedScalar &ds)
dimensionedScalar pow5(const dimensionedScalar &ds)
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
bool operator*=(const dimensionSet &)
Definition: dimensionSet.C:209
dimensionedScalar pos(const dimensionedScalar &ds)
Dimension set for the base types.
Definition: dimensionSet.H:121
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
dimensionedScalar cbrt(const dimensionedScalar &ds)
dimensionedScalar neg0(const dimensionedScalar &ds)
dimensionSet cmptMag(const dimensionSet &)
Definition: dimensionSet.C:275
const Type & value() const
Return const reference to value.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
tmp< fvMatrix< Type > > operator-(const fvMatrix< Type > &)
bool operator+=(const dimensionSet &) const
Definition: dimensionSet.C:181
errorManip< error > abort(error &err)
Definition: errorManip.H:131
bool operator!=(const dimensionSet &) const
Definition: dimensionSet.C:161
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
dimensioned< scalar > magSqr(const dimensioned< Type > &)
dimensionedScalar pos0(const dimensionedScalar &ds)
dimensionedScalar atan2(const dimensionedScalar &x, const dimensionedScalar &y)
defineTypeNameAndDebug(combustionModel, 0)
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
void reset(const dimensionSet &)
Definition: dimensionSet.C:108
dimensionedScalar pow3(const dimensionedScalar &ds)
scalar operator[](const dimensionType) const
Definition: dimensionSet.C:119
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
dimensionedScalar pow4(const dimensionedScalar &ds)
const dimensionSet & dimensions() const
Return const reference to dimensions.
dimensionedScalar pow6(const dimensionedScalar &ds)
dimensionType
Define an enumeration for the names of the dimension exponents.
Definition: dimensionSet.H:134
dimensioned< scalar > mag(const dimensioned< Type > &)
volScalarField & p
bool operator==(const dimensionSet &) const
Definition: dimensionSet.C:143
static const scalar smallExponent
Definition: dimensionSet.H:148
bool dimensionless() const
Return true if it is dimensionless.
Definition: dimensionSet.C:89
Namespace for OpenFOAM.
dimensionedScalar negPart(const dimensionedScalar &ds)
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:483