OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

dimensionSet.C

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