00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "dimensionSet.H"
00027 #include <OpenFOAM/dimensionedScalar.H>
00028
00029
00030
00031 defineTypeNameAndDebug(Foam::dimensionSet, 1);
00032 const Foam::scalar Foam::dimensionSet::smallExponent = SMALL;
00033
00034
00035
00036
00037 Foam::dimensionSet::dimensionSet
00038 (
00039 const scalar mass,
00040 const scalar length,
00041 const scalar time,
00042 const scalar temperature,
00043 const scalar moles,
00044 const scalar current,
00045 const scalar luminousIntensity
00046 )
00047 {
00048 exponents_[MASS] = mass;
00049 exponents_[LENGTH] = length;
00050 exponents_[TIME] = time;
00051 exponents_[TEMPERATURE] = temperature;
00052 exponents_[MOLES] = moles;
00053 exponents_[CURRENT] = current;
00054 exponents_[LUMINOUS_INTENSITY] = luminousIntensity;
00055 }
00056
00057
00058 Foam::dimensionSet::dimensionSet
00059 (
00060 const scalar mass,
00061 const scalar length,
00062 const scalar time,
00063 const scalar temperature,
00064 const scalar moles
00065 )
00066 {
00067 exponents_[MASS] = mass;
00068 exponents_[LENGTH] = length;
00069 exponents_[TIME] = time;
00070 exponents_[TEMPERATURE] = temperature;
00071 exponents_[MOLES] = moles;
00072 exponents_[CURRENT] = 0;
00073 exponents_[LUMINOUS_INTENSITY] = 0;
00074 }
00075
00076
00077
00078
00079 bool Foam::dimensionSet::dimensionless() const
00080 {
00081 bool Dimensionless = true;
00082
00083 for (int Dimension=0; Dimension<nDimensions; Dimension++)
00084 {
00085 Dimensionless = Dimensionless &&
00086 (
00087 exponents_[Dimension] < smallExponent
00088 && exponents_[Dimension] > -smallExponent
00089 );
00090 }
00091
00092 return Dimensionless;
00093 }
00094
00095
00096 void Foam::dimensionSet::reset(const dimensionSet& ds)
00097 {
00098 for (int Dimension=0; Dimension<nDimensions; Dimension++)
00099 {
00100 exponents_[Dimension] = ds.exponents_[Dimension];
00101 }
00102 }
00103
00104
00105
00106
00107 Foam::scalar Foam::dimensionSet::operator[](const dimensionType type) const
00108 {
00109 return exponents_[type];
00110 }
00111
00112 Foam::scalar& Foam::dimensionSet::operator[](const dimensionType type)
00113 {
00114 return exponents_[type];
00115 }
00116
00117
00118 bool Foam::dimensionSet::operator==(const dimensionSet& ds) const
00119 {
00120 bool equall = true;
00121
00122 for (int Dimension=0; Dimension<nDimensions; Dimension++)
00123 {
00124 equall = equall &&
00125 (mag(exponents_[Dimension] - ds.exponents_[Dimension])
00126 < smallExponent);
00127 }
00128
00129 return equall;
00130 }
00131
00132 bool Foam::dimensionSet::operator!=(const dimensionSet& ds) const
00133 {
00134 return !(operator==(ds));
00135 }
00136
00137
00138 bool Foam::dimensionSet::operator=(const dimensionSet& ds) const
00139 {
00140 if (dimensionSet::debug && *this != ds)
00141 {
00142 FatalErrorIn("dimensionSet::operator=(const dimensionSet& ds) const")
00143 << "Different dimensions for =" << endl
00144 << " dimensions : " << *this << " = " << ds << endl
00145 << abort(FatalError);
00146 }
00147
00148 return true;
00149 }
00150
00151
00152 bool Foam::dimensionSet::operator+=(const dimensionSet& ds) const
00153 {
00154 if (dimensionSet::debug && *this != ds)
00155 {
00156 FatalErrorIn("dimensionSet::operator+=(const dimensionSet& ds) const")
00157 << "Different dimensions for +=" << endl
00158 << " dimensions : " << *this << " = " << ds << endl
00159 << abort(FatalError);
00160 }
00161
00162 return true;
00163 }
00164
00165 bool Foam::dimensionSet::operator-=(const dimensionSet& ds) const
00166 {
00167 if (dimensionSet::debug && *this != ds)
00168 {
00169 FatalErrorIn("dimensionSet::operator-=(const dimensionSet& ds) const")
00170 << "Different dimensions for -=" << endl
00171 << " dimensions : " << *this << " = " << ds << endl
00172 << abort(FatalError);
00173 }
00174
00175 return true;
00176 }
00177
00178 bool Foam::dimensionSet::operator*=(const dimensionSet& ds)
00179 {
00180 reset((*this)*ds);
00181
00182 return true;
00183 }
00184
00185 bool Foam::dimensionSet::operator/=(const dimensionSet& ds)
00186 {
00187 reset((*this)/ds);
00188
00189 return true;
00190 }
00191
00192
00193
00194
00195 Foam::dimensionSet Foam::max(const dimensionSet& ds1, const dimensionSet& ds2)
00196 {
00197 if (dimensionSet::debug && ds1 != ds2)
00198 {
00199 FatalErrorIn("max(const dimensionSet& ds1, const dimensionSet& ds2)")
00200 << "Arguments of max have different dimensions" << endl
00201 << " dimensions : " << ds1 << " and " << ds2 << endl
00202 << abort(FatalError);
00203 }
00204
00205 return ds1;
00206 }
00207
00208 Foam::dimensionSet Foam::min(const dimensionSet& ds1, const dimensionSet& ds2)
00209 {
00210 if (dimensionSet::debug && ds1 != ds2)
00211 {
00212 FatalErrorIn("min(const dimensionSet& ds1, const dimensionSet& ds2)")
00213 << "Arguments of min have different dimensions" << endl
00214 << " dimensions : " << ds1 << " and " << ds2 << endl
00215 << abort(FatalError);
00216 }
00217
00218 return ds1;
00219 }
00220
00221
00222 Foam::dimensionSet Foam::cmptMultiply
00223 (
00224 const dimensionSet& ds1,
00225 const dimensionSet& ds2
00226 )
00227 {
00228 return ds1*ds2;
00229 }
00230
00231
00232 Foam::dimensionSet Foam::cmptDivide
00233 (
00234 const dimensionSet& ds1,
00235 const dimensionSet& ds2
00236 )
00237 {
00238 return ds1/ds2;
00239 }
00240
00241
00242 Foam::dimensionSet Foam::pow(const dimensionSet& ds, const scalar p)
00243 {
00244 dimensionSet dimPow
00245 (
00246 ds[dimensionSet::MASS]*p,
00247 ds[dimensionSet::LENGTH]*p,
00248 ds[dimensionSet::TIME]*p,
00249 ds[dimensionSet::TEMPERATURE]*p,
00250 ds[dimensionSet::MOLES]*p,
00251 ds[dimensionSet::CURRENT]*p,
00252 ds[dimensionSet::LUMINOUS_INTENSITY]*p
00253 );
00254
00255 return dimPow;
00256 }
00257
00258 Foam::dimensionSet Foam::pow
00259 (
00260 const dimensionSet& ds,
00261 const dimensionedScalar& dS
00262 )
00263 {
00264 if (dimensionSet::debug && !dS.dimensions().dimensionless())
00265 {
00266 FatalErrorIn("pow(const dimensionSet& ds, const dimensionedScalar& dS)")
00267 << "Exponent of pow are not dimensionless"
00268 << abort(FatalError);
00269 }
00270
00271 dimensionSet dimPow
00272 (
00273 ds[dimensionSet::MASS]*dS.value(),
00274 ds[dimensionSet::LENGTH]*dS.value(),
00275 ds[dimensionSet::TIME]*dS.value(),
00276 ds[dimensionSet::TEMPERATURE]*dS.value(),
00277 ds[dimensionSet::MOLES]*dS.value(),
00278 ds[dimensionSet::CURRENT]*dS.value(),
00279 ds[dimensionSet::LUMINOUS_INTENSITY]*dS.value()
00280 );
00281
00282 return dimPow;
00283 }
00284
00285 Foam::dimensionSet Foam::pow
00286 (
00287 const dimensionedScalar& dS,
00288 const dimensionSet& ds
00289 )
00290 {
00291 if
00292 (
00293 dimensionSet::debug
00294 && !dS.dimensions().dimensionless()
00295 && !ds.dimensionless())
00296 {
00297 FatalErrorIn("pow(const dimensionedScalar& dS, const dimensionSet& ds)")
00298 << "Argument or exponent of pow not dimensionless" << endl
00299 << abort(FatalError);
00300 }
00301
00302 return ds;
00303 }
00304
00305
00306 Foam::dimensionSet Foam::sqr(const dimensionSet& ds)
00307 {
00308 return pow(ds, 2);
00309 }
00310
00311 Foam::dimensionSet Foam::pow3(const dimensionSet& ds)
00312 {
00313 return pow(ds, 3);
00314 }
00315
00316 Foam::dimensionSet Foam::pow4(const dimensionSet& ds)
00317 {
00318 return pow(ds, 4);
00319 }
00320
00321 Foam::dimensionSet Foam::pow5(const dimensionSet& ds)
00322 {
00323 return pow(ds, 5);
00324 }
00325
00326 Foam::dimensionSet Foam::pow6(const dimensionSet& ds)
00327 {
00328 return pow(ds, 6);
00329 }
00330
00331 Foam::dimensionSet Foam::sqrt(const dimensionSet& ds)
00332 {
00333 return pow(ds, 0.5);
00334 }
00335
00336 Foam::dimensionSet Foam::magSqr(const dimensionSet& ds)
00337 {
00338 return pow(ds, 2);
00339 }
00340
00341 Foam::dimensionSet Foam::mag(const dimensionSet& ds)
00342 {
00343 return ds;
00344 }
00345
00346 Foam::dimensionSet Foam::sign(const dimensionSet&)
00347 {
00348 return dimless;
00349 }
00350
00351 Foam::dimensionSet Foam::pos(const dimensionSet&)
00352 {
00353 return dimless;
00354 }
00355
00356 Foam::dimensionSet Foam::neg(const dimensionSet&)
00357 {
00358 return dimless;
00359 }
00360
00361 Foam::dimensionSet Foam::inv(const dimensionSet& ds)
00362 {
00363 return dimless/ds;
00364 }
00365
00366 Foam::dimensionSet Foam::trans(const dimensionSet& ds)
00367 {
00368 if (dimensionSet::debug && !ds.dimensionless())
00369 {
00370 FatalErrorIn("trans(const dimensionSet& ds)")
00371 << "Argument of trancendental function not dimensionless"
00372 << abort(FatalError);
00373 }
00374
00375 return ds;
00376 }
00377
00378 Foam::dimensionSet Foam::transform(const dimensionSet& ds)
00379 {
00380 return ds;
00381 }
00382
00383
00384
00385
00386 Foam::dimensionSet Foam::operator-(const dimensionSet& ds)
00387 {
00388 return ds;
00389 }
00390
00391 Foam::dimensionSet Foam::operator+
00392 (
00393 const dimensionSet& ds1,
00394 const dimensionSet& ds2
00395 )
00396 {
00397 dimensionSet dimSum(ds1);
00398
00399 if (dimensionSet::debug && ds1 != ds2)
00400 {
00401 FatalErrorIn
00402 ("operator+(const dimensionSet& ds1, const dimensionSet& ds2)")
00403 << "LHS and RHS of + have different dimensions" << endl
00404 << " dimensions : " << ds1 << " + " << ds2 << endl
00405 << abort(FatalError);
00406 }
00407
00408 return dimSum;
00409 }
00410
00411 Foam::dimensionSet Foam::operator-
00412 (
00413 const dimensionSet& ds1,
00414 const dimensionSet& ds2
00415 )
00416 {
00417 dimensionSet dimDifference(ds1);
00418
00419 if (dimensionSet::debug && ds1 != ds2)
00420 {
00421 FatalErrorIn
00422 ("operator-(const dimensionSet& ds1, const dimensionSet& ds2)")
00423 << "LHS and RHS of - have different dimensions" << endl
00424 << " dimensions : " << ds1 << " - " << ds2 << endl
00425 << abort(FatalError);
00426 }
00427
00428 return dimDifference;
00429 }
00430
00431 Foam::dimensionSet Foam::operator*
00432 (
00433 const dimensionSet& ds1,
00434 const dimensionSet& ds2
00435 )
00436 {
00437 dimensionSet dimProduct(ds1);
00438
00439 for (int Dimension=0; Dimension<dimensionSet::nDimensions; Dimension++)
00440 {
00441 dimProduct.exponents_[Dimension] += ds2.exponents_[Dimension];
00442 }
00443
00444 return dimProduct;
00445 }
00446
00447 Foam::dimensionSet Foam::operator/
00448 (
00449 const dimensionSet& ds1,
00450 const dimensionSet& ds2
00451 )
00452 {
00453 dimensionSet dimQuotient(ds1);
00454
00455 for (int Dimension=0; Dimension<dimensionSet::nDimensions; Dimension++)
00456 {
00457 dimQuotient.exponents_[Dimension] -= ds2.exponents_[Dimension];
00458 }
00459
00460 return dimQuotient;
00461 }
00462
00463
00464 Foam::dimensionSet Foam::operator&
00465 (
00466 const dimensionSet& ds1,
00467 const dimensionSet& ds2
00468 )
00469 {
00470 return ds1*ds2;
00471 }
00472
00473 Foam::dimensionSet Foam::operator^
00474 (
00475 const dimensionSet& ds1,
00476 const dimensionSet& ds2
00477 )
00478 {
00479 return ds1*ds2;
00480 }
00481
00482 Foam::dimensionSet Foam::operator&&
00483 (
00484 const dimensionSet& ds1,
00485 const dimensionSet& ds2
00486 )
00487 {
00488 return ds1*ds2;
00489 }
00490
00491
00492