1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "dimensionSet.H"
28 #include "dimensionedScalar.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 defineTypeNameAndDebug(Foam::dimensionSet, 1);
33 const Foam::scalar Foam::dimensionSet::smallExponent = SMALL;
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 Foam::dimensionSet::dimensionSet
43 const scalar temperature,
46 const scalar luminousIntensity
49 exponents_[MASS] = mass;
50 exponents_[LENGTH] = length;
51 exponents_[TIME] = time;
52 exponents_[TEMPERATURE] = temperature;
53 exponents_[MOLES] = moles;
54 exponents_[CURRENT] = current;
55 exponents_[LUMINOUS_INTENSITY] = luminousIntensity;
59 Foam::dimensionSet::dimensionSet
64 const scalar temperature,
68 exponents_[MASS] = mass;
69 exponents_[LENGTH] = length;
70 exponents_[TIME] = time;
71 exponents_[TEMPERATURE] = temperature;
72 exponents_[MOLES] = moles;
73 exponents_[CURRENT] = 0;
74 exponents_[LUMINOUS_INTENSITY] = 0;
78 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
80 bool Foam::dimensionSet::dimensionless() const
82 bool Dimensionless = true;
84 for (int Dimension=0; Dimension<nDimensions; Dimension++)
86 Dimensionless = Dimensionless &&
88 exponents_[Dimension] < smallExponent
89 && exponents_[Dimension] > -smallExponent
97 void Foam::dimensionSet::reset(const dimensionSet& ds)
99 for (int Dimension=0; Dimension<nDimensions; Dimension++)
101 exponents_[Dimension] = ds.exponents_[Dimension];
106 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
108 Foam::scalar Foam::dimensionSet::operator[](const dimensionType type) const
110 return exponents_[type];
113 Foam::scalar& Foam::dimensionSet::operator[](const dimensionType type)
115 return exponents_[type];
119 bool Foam::dimensionSet::operator==(const dimensionSet& ds) const
123 for (int Dimension=0; Dimension<nDimensions; Dimension++)
126 (mag(exponents_[Dimension] - ds.exponents_[Dimension])
133 bool Foam::dimensionSet::operator!=(const dimensionSet& ds) const
135 return !(operator==(ds));
139 bool Foam::dimensionSet::operator=(const dimensionSet& ds) const
141 if (dimensionSet::debug && *this != ds)
143 FatalErrorIn("dimensionSet::operator=(const dimensionSet& ds) const")
144 << "Different dimensions for =" << endl
145 << " dimensions : " << *this << " = " << ds << endl
146 << abort(FatalError);
153 bool Foam::dimensionSet::operator+=(const dimensionSet& ds) const
155 if (dimensionSet::debug && *this != ds)
157 FatalErrorIn("dimensionSet::operator+=(const dimensionSet& ds) const")
158 << "Different dimensions for +=" << endl
159 << " dimensions : " << *this << " = " << ds << endl
160 << abort(FatalError);
166 bool Foam::dimensionSet::operator-=(const dimensionSet& ds) const
168 if (dimensionSet::debug && *this != ds)
170 FatalErrorIn("dimensionSet::operator-=(const dimensionSet& ds) const")
171 << "Different dimensions for -=" << endl
172 << " dimensions : " << *this << " = " << ds << endl
173 << abort(FatalError);
179 bool Foam::dimensionSet::operator*=(const dimensionSet& ds)
186 bool Foam::dimensionSet::operator/=(const dimensionSet& ds)
194 // * * * * * * * * * * * * * * * Friend functions * * * * * * * * * * * * * * //
196 Foam::dimensionSet Foam::max(const dimensionSet& ds1, const dimensionSet& ds2)
198 if (dimensionSet::debug && ds1 != ds2)
200 FatalErrorIn("max(const dimensionSet& ds1, const dimensionSet& ds2)")
201 << "Arguments of max have different dimensions" << endl
202 << " dimensions : " << ds1 << " and " << ds2 << endl
203 << abort(FatalError);
209 Foam::dimensionSet Foam::min(const dimensionSet& ds1, const dimensionSet& ds2)
211 if (dimensionSet::debug && ds1 != ds2)
213 FatalErrorIn("min(const dimensionSet& ds1, const dimensionSet& ds2)")
214 << "Arguments of min have different dimensions" << endl
215 << " dimensions : " << ds1 << " and " << ds2 << endl
216 << abort(FatalError);
223 Foam::dimensionSet Foam::cmptMultiply
225 const dimensionSet& ds1,
226 const dimensionSet& ds2
233 Foam::dimensionSet Foam::cmptDivide
235 const dimensionSet& ds1,
236 const dimensionSet& ds2
243 Foam::dimensionSet Foam::pow(const dimensionSet& ds, const scalar p)
247 ds[dimensionSet::MASS]*p,
248 ds[dimensionSet::LENGTH]*p,
249 ds[dimensionSet::TIME]*p,
250 ds[dimensionSet::TEMPERATURE]*p,
251 ds[dimensionSet::MOLES]*p,
252 ds[dimensionSet::CURRENT]*p,
253 ds[dimensionSet::LUMINOUS_INTENSITY]*p
259 Foam::dimensionSet Foam::pow
261 const dimensionSet& ds,
262 const dimensionedScalar& dS
265 if (dimensionSet::debug && !dS.dimensions().dimensionless())
267 FatalErrorIn("pow(const dimensionSet& ds, const dimensionedScalar& dS)")
268 << "Exponent of pow are not dimensionless"
269 << abort(FatalError);
274 ds[dimensionSet::MASS]*dS.value(),
275 ds[dimensionSet::LENGTH]*dS.value(),
276 ds[dimensionSet::TIME]*dS.value(),
277 ds[dimensionSet::TEMPERATURE]*dS.value(),
278 ds[dimensionSet::MOLES]*dS.value(),
279 ds[dimensionSet::CURRENT]*dS.value(),
280 ds[dimensionSet::LUMINOUS_INTENSITY]*dS.value()
286 Foam::dimensionSet Foam::pow
288 const dimensionedScalar& dS,
289 const dimensionSet& ds
295 && !dS.dimensions().dimensionless()
296 && !ds.dimensionless())
298 FatalErrorIn("pow(const dimensionedScalar& dS, const dimensionSet& ds)")
299 << "Argument or exponent of pow not dimensionless" << endl
300 << abort(FatalError);
307 Foam::dimensionSet Foam::sqr(const dimensionSet& ds)
312 Foam::dimensionSet Foam::pow3(const dimensionSet& ds)
317 Foam::dimensionSet Foam::pow4(const dimensionSet& ds)
322 Foam::dimensionSet Foam::pow5(const dimensionSet& ds)
327 Foam::dimensionSet Foam::pow6(const dimensionSet& ds)
332 Foam::dimensionSet Foam::sqrt(const dimensionSet& ds)
337 Foam::dimensionSet Foam::magSqr(const dimensionSet& ds)
342 Foam::dimensionSet Foam::mag(const dimensionSet& ds)
347 Foam::dimensionSet Foam::sign(const dimensionSet&)
352 Foam::dimensionSet Foam::pos(const dimensionSet&)
357 Foam::dimensionSet Foam::neg(const dimensionSet&)
362 Foam::dimensionSet Foam::inv(const dimensionSet& ds)
367 Foam::dimensionSet Foam::hinv(const dimensionSet& ds)
372 Foam::dimensionSet Foam::trans(const dimensionSet& ds)
374 if (dimensionSet::debug && !ds.dimensionless())
376 FatalErrorIn("trans(const dimensionSet& ds)")
377 << "Argument of trancendental function not dimensionless"
378 << abort(FatalError);
384 Foam::dimensionSet Foam::transform(const dimensionSet& ds)
390 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
392 Foam::dimensionSet Foam::operator-(const dimensionSet& ds)
397 Foam::dimensionSet Foam::operator+
399 const dimensionSet& ds1,
400 const dimensionSet& ds2
403 dimensionSet dimSum(ds1);
405 if (dimensionSet::debug && ds1 != ds2)
408 ("operator+(const dimensionSet& ds1, const dimensionSet& ds2)")
409 << "LHS and RHS of + have different dimensions" << endl
410 << " dimensions : " << ds1 << " + " << ds2 << endl
411 << abort(FatalError);
417 Foam::dimensionSet Foam::operator-
419 const dimensionSet& ds1,
420 const dimensionSet& ds2
423 dimensionSet dimDifference(ds1);
425 if (dimensionSet::debug && ds1 != ds2)
428 ("operator-(const dimensionSet& ds1, const dimensionSet& ds2)")
429 << "LHS and RHS of - have different dimensions" << endl
430 << " dimensions : " << ds1 << " - " << ds2 << endl
431 << abort(FatalError);
434 return dimDifference;
437 Foam::dimensionSet Foam::operator*
439 const dimensionSet& ds1,
440 const dimensionSet& ds2
443 dimensionSet dimProduct(ds1);
445 for (int Dimension=0; Dimension<dimensionSet::nDimensions; Dimension++)
447 dimProduct.exponents_[Dimension] += ds2.exponents_[Dimension];
453 Foam::dimensionSet Foam::operator/
455 const dimensionSet& ds1,
456 const dimensionSet& ds2
459 dimensionSet dimQuotient(ds1);
461 for (int Dimension=0; Dimension<dimensionSet::nDimensions; Dimension++)
463 dimQuotient.exponents_[Dimension] -= ds2.exponents_[Dimension];
470 Foam::dimensionSet Foam::operator&
472 const dimensionSet& ds1,
473 const dimensionSet& ds2
479 Foam::dimensionSet Foam::operator^
481 const dimensionSet& ds1,
482 const dimensionSet& ds2
488 Foam::dimensionSet Foam::operator&&
490 const dimensionSet& ds1,
491 const dimensionSet& ds2
498 // ************************************************************************* //