1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "dimensionSet.H"
27 #include "dimensionedScalar.H"
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 defineTypeNameAndDebug(Foam::dimensionSet, 1);
32 const Foam::scalar Foam::dimensionSet::smallExponent = SMALL;
35 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37 Foam::dimensionSet::dimensionSet
42 const scalar temperature,
45 const scalar luminousIntensity
48 exponents_[MASS] = mass;
49 exponents_[LENGTH] = length;
50 exponents_[TIME] = time;
51 exponents_[TEMPERATURE] = temperature;
52 exponents_[MOLES] = moles;
53 exponents_[CURRENT] = current;
54 exponents_[LUMINOUS_INTENSITY] = luminousIntensity;
58 Foam::dimensionSet::dimensionSet
63 const scalar temperature,
67 exponents_[MASS] = mass;
68 exponents_[LENGTH] = length;
69 exponents_[TIME] = time;
70 exponents_[TEMPERATURE] = temperature;
71 exponents_[MOLES] = moles;
72 exponents_[CURRENT] = 0;
73 exponents_[LUMINOUS_INTENSITY] = 0;
77 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
79 bool Foam::dimensionSet::dimensionless() const
81 bool Dimensionless = true;
83 for (int Dimension=0; Dimension<nDimensions; Dimension++)
85 Dimensionless = Dimensionless &&
87 exponents_[Dimension] < smallExponent
88 && exponents_[Dimension] > -smallExponent
96 void Foam::dimensionSet::reset(const dimensionSet& ds)
98 for (int Dimension=0; Dimension<nDimensions; Dimension++)
100 exponents_[Dimension] = ds.exponents_[Dimension];
105 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
107 Foam::scalar Foam::dimensionSet::operator[](const dimensionType type) const
109 return exponents_[type];
112 Foam::scalar& Foam::dimensionSet::operator[](const dimensionType type)
114 return exponents_[type];
118 bool Foam::dimensionSet::operator==(const dimensionSet& ds) const
122 for (int Dimension=0; Dimension<nDimensions; Dimension++)
125 (mag(exponents_[Dimension] - ds.exponents_[Dimension])
132 bool Foam::dimensionSet::operator!=(const dimensionSet& ds) const
134 return !(operator==(ds));
138 bool Foam::dimensionSet::operator=(const dimensionSet& ds) const
140 if (dimensionSet::debug && *this != ds)
142 FatalErrorIn("dimensionSet::operator=(const dimensionSet& ds) const")
143 << "Different dimensions for =" << endl
144 << " dimensions : " << *this << " = " << ds << endl
145 << abort(FatalError);
152 bool Foam::dimensionSet::operator+=(const dimensionSet& ds) const
154 if (dimensionSet::debug && *this != ds)
156 FatalErrorIn("dimensionSet::operator+=(const dimensionSet& ds) const")
157 << "Different dimensions for +=" << endl
158 << " dimensions : " << *this << " = " << ds << endl
159 << abort(FatalError);
165 bool Foam::dimensionSet::operator-=(const dimensionSet& ds) const
167 if (dimensionSet::debug && *this != ds)
169 FatalErrorIn("dimensionSet::operator-=(const dimensionSet& ds) const")
170 << "Different dimensions for -=" << endl
171 << " dimensions : " << *this << " = " << ds << endl
172 << abort(FatalError);
178 bool Foam::dimensionSet::operator*=(const dimensionSet& ds)
185 bool Foam::dimensionSet::operator/=(const dimensionSet& ds)
193 // * * * * * * * * * * * * * * * Friend functions * * * * * * * * * * * * * * //
195 Foam::dimensionSet Foam::max(const dimensionSet& ds1, const dimensionSet& ds2)
197 if (dimensionSet::debug && ds1 != ds2)
199 FatalErrorIn("max(const dimensionSet& ds1, const dimensionSet& ds2)")
200 << "Arguments of max have different dimensions" << endl
201 << " dimensions : " << ds1 << " and " << ds2 << endl
202 << abort(FatalError);
208 Foam::dimensionSet Foam::min(const dimensionSet& ds1, const dimensionSet& ds2)
210 if (dimensionSet::debug && ds1 != ds2)
212 FatalErrorIn("min(const dimensionSet& ds1, const dimensionSet& ds2)")
213 << "Arguments of min have different dimensions" << endl
214 << " dimensions : " << ds1 << " and " << ds2 << endl
215 << abort(FatalError);
222 Foam::dimensionSet Foam::cmptMultiply
224 const dimensionSet& ds1,
225 const dimensionSet& ds2
232 Foam::dimensionSet Foam::cmptDivide
234 const dimensionSet& ds1,
235 const dimensionSet& ds2
242 Foam::dimensionSet Foam::pow(const dimensionSet& ds, const scalar p)
246 ds[dimensionSet::MASS]*p,
247 ds[dimensionSet::LENGTH]*p,
248 ds[dimensionSet::TIME]*p,
249 ds[dimensionSet::TEMPERATURE]*p,
250 ds[dimensionSet::MOLES]*p,
251 ds[dimensionSet::CURRENT]*p,
252 ds[dimensionSet::LUMINOUS_INTENSITY]*p
258 Foam::dimensionSet Foam::pow
260 const dimensionSet& ds,
261 const dimensionedScalar& dS
264 if (dimensionSet::debug && !dS.dimensions().dimensionless())
266 FatalErrorIn("pow(const dimensionSet& ds, const dimensionedScalar& dS)")
267 << "Exponent of pow are not dimensionless"
268 << abort(FatalError);
273 ds[dimensionSet::MASS]*dS.value(),
274 ds[dimensionSet::LENGTH]*dS.value(),
275 ds[dimensionSet::TIME]*dS.value(),
276 ds[dimensionSet::TEMPERATURE]*dS.value(),
277 ds[dimensionSet::MOLES]*dS.value(),
278 ds[dimensionSet::CURRENT]*dS.value(),
279 ds[dimensionSet::LUMINOUS_INTENSITY]*dS.value()
285 Foam::dimensionSet Foam::pow
287 const dimensionedScalar& dS,
288 const dimensionSet& ds
294 && !dS.dimensions().dimensionless()
295 && !ds.dimensionless())
297 FatalErrorIn("pow(const dimensionedScalar& dS, const dimensionSet& ds)")
298 << "Argument or exponent of pow not dimensionless" << endl
299 << abort(FatalError);
306 Foam::dimensionSet Foam::sqr(const dimensionSet& ds)
311 Foam::dimensionSet Foam::pow3(const dimensionSet& ds)
316 Foam::dimensionSet Foam::pow4(const dimensionSet& ds)
321 Foam::dimensionSet Foam::pow5(const dimensionSet& ds)
326 Foam::dimensionSet Foam::pow6(const dimensionSet& ds)
331 Foam::dimensionSet Foam::sqrt(const dimensionSet& ds)
336 Foam::dimensionSet Foam::magSqr(const dimensionSet& ds)
341 Foam::dimensionSet Foam::mag(const dimensionSet& ds)
346 Foam::dimensionSet Foam::sign(const dimensionSet&)
351 Foam::dimensionSet Foam::pos(const dimensionSet&)
356 Foam::dimensionSet Foam::neg(const dimensionSet&)
361 Foam::dimensionSet Foam::inv(const dimensionSet& ds)
366 Foam::dimensionSet Foam::hinv(const dimensionSet& ds)
371 Foam::dimensionSet Foam::trans(const dimensionSet& ds)
373 if (dimensionSet::debug && !ds.dimensionless())
375 FatalErrorIn("trans(const dimensionSet& ds)")
376 << "Argument of trancendental function not dimensionless"
377 << abort(FatalError);
383 Foam::dimensionSet Foam::transform(const dimensionSet& ds)
389 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
391 Foam::dimensionSet Foam::operator-(const dimensionSet& ds)
396 Foam::dimensionSet Foam::operator+
398 const dimensionSet& ds1,
399 const dimensionSet& ds2
402 dimensionSet dimSum(ds1);
404 if (dimensionSet::debug && ds1 != ds2)
407 ("operator+(const dimensionSet& ds1, const dimensionSet& ds2)")
408 << "LHS and RHS of + have different dimensions" << endl
409 << " dimensions : " << ds1 << " + " << ds2 << endl
410 << abort(FatalError);
416 Foam::dimensionSet Foam::operator-
418 const dimensionSet& ds1,
419 const dimensionSet& ds2
422 dimensionSet dimDifference(ds1);
424 if (dimensionSet::debug && ds1 != ds2)
427 ("operator-(const dimensionSet& ds1, const dimensionSet& ds2)")
428 << "LHS and RHS of - have different dimensions" << endl
429 << " dimensions : " << ds1 << " - " << ds2 << endl
430 << abort(FatalError);
433 return dimDifference;
436 Foam::dimensionSet Foam::operator*
438 const dimensionSet& ds1,
439 const dimensionSet& ds2
442 dimensionSet dimProduct(ds1);
444 for (int Dimension=0; Dimension<dimensionSet::nDimensions; Dimension++)
446 dimProduct.exponents_[Dimension] += ds2.exponents_[Dimension];
452 Foam::dimensionSet Foam::operator/
454 const dimensionSet& ds1,
455 const dimensionSet& ds2
458 dimensionSet dimQuotient(ds1);
460 for (int Dimension=0; Dimension<dimensionSet::nDimensions; Dimension++)
462 dimQuotient.exponents_[Dimension] -= ds2.exponents_[Dimension];
469 Foam::dimensionSet Foam::operator&
471 const dimensionSet& ds1,
472 const dimensionSet& ds2
478 Foam::dimensionSet Foam::operator^
480 const dimensionSet& ds1,
481 const dimensionSet& ds2
487 Foam::dimensionSet Foam::operator&&
489 const dimensionSet& ds1,
490 const dimensionSet& ds2
497 // ************************************************************************* //