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

dimensionSet.H

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 Class
00026     Foam::dimensionSet
00027 
00028 Description
00029     Dimension set for the base types.
00030     This type may be used to implement rigorous dimension checking
00031     for algebraic manipulation.
00032 
00033 SourceFiles
00034     dimensionSet.C
00035     dimensionSetIO.C
00036     dimensionSets.C
00037 
00038 \*---------------------------------------------------------------------------*/
00039 
00040 #ifndef dimensionSet_H
00041 #define dimensionSet_H
00042 
00043 #include "scalar.H"
00044 #include "bool.H"
00045 #include "dimensionedScalarFwd.H"
00046 #include "className.H"
00047 
00048 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00049 
00050 namespace Foam
00051 {
00052 
00053 // Forward declaration of friend functions and operators
00054 
00055 class dimensionSet;
00056 
00057 // Friend functions
00058 
00059 dimensionSet max(const dimensionSet&, const dimensionSet&);
00060 dimensionSet min(const dimensionSet&, const dimensionSet&);
00061 dimensionSet cmptMultiply(const dimensionSet&, const dimensionSet&);
00062 dimensionSet cmptDivide(const dimensionSet&, const dimensionSet&);
00063 
00064 dimensionSet pow(const dimensionSet&, const scalar);
00065 dimensionSet pow(const dimensionSet&, const dimensionedScalar&);
00066 dimensionSet pow(const dimensionedScalar&, const dimensionSet&);
00067 
00068 dimensionSet sqr(const dimensionSet&);
00069 dimensionSet pow3(const dimensionSet&);
00070 dimensionSet pow4(const dimensionSet&);
00071 dimensionSet pow5(const dimensionSet&);
00072 dimensionSet pow6(const dimensionSet&);
00073 
00074 dimensionSet sqrt(const dimensionSet&);
00075 dimensionSet magSqr(const dimensionSet&);
00076 dimensionSet mag(const dimensionSet&);
00077 dimensionSet sign(const dimensionSet&);
00078 dimensionSet pos(const dimensionSet&);
00079 dimensionSet neg(const dimensionSet&);
00080 dimensionSet inv(const dimensionSet&);
00081 
00082 // Function to check the argument is dimensionless
00083 //  for transcendental functions
00084 dimensionSet trans(const dimensionSet&);
00085 
00086 // Return the argument; transformations do not change the dimensions
00087 dimensionSet transform(const dimensionSet&);
00088 
00089 // Friend operators
00090 
00091 dimensionSet operator-(const dimensionSet&);
00092 dimensionSet operator+(const dimensionSet&, const dimensionSet&);
00093 dimensionSet operator-(const dimensionSet&, const dimensionSet&);
00094 dimensionSet operator*(const dimensionSet&, const dimensionSet&);
00095 dimensionSet operator/(const dimensionSet&, const dimensionSet&);
00096 dimensionSet operator&(const dimensionSet&, const dimensionSet&);
00097 dimensionSet operator^(const dimensionSet&, const dimensionSet&);
00098 dimensionSet operator&&(const dimensionSet&, const dimensionSet&);
00099 
00100 // IOstream operators
00101 
00102 Istream& operator>>(Istream&, dimensionSet&);
00103 Ostream& operator<<(Ostream&, const dimensionSet&);
00104 
00105 
00106 /*---------------------------------------------------------------------------*\
00107                            Class dimensionSet Declaration
00108 \*---------------------------------------------------------------------------*/
00109 
00110 class dimensionSet
00111 {
00112 
00113 public:
00114 
00115     // Member constants
00116 
00117         enum
00118         {
00119             nDimensions = 7    // Number of dimensions in SI is 7
00120         };
00121 
00122         //- Define an enumeration for the names of the dimension exponents
00123         enum dimensionType
00124         {
00125             MASS,               // kilogram   kg
00126             LENGTH,             // metre      m
00127             TIME,               // second     s
00128             TEMPERATURE,        // Kelvin     K
00129             MOLES,              // mole       mol
00130             CURRENT,            // Ampere     A
00131             LUMINOUS_INTENSITY  // Candela    Cd
00132         };
00133 
00134 
00135     // Static data members
00136 
00137         static const scalar smallExponent;
00138 
00139 
00140 private:
00141 
00142     // private data
00143 
00144         // dimensionSet stored as an array of dimension exponents
00145         scalar exponents_[nDimensions];
00146 
00147 
00148 public:
00149 
00150     // Declare name of the class and its debug switch
00151     ClassName("dimensionSet");
00152 
00153 
00154     // Constructors
00155 
00156         //- Construct given individual dimension exponents for all
00157         //  seven dimensions
00158         dimensionSet
00159         (
00160             const scalar mass,
00161             const scalar length,
00162             const scalar time,
00163             const scalar temperature,
00164             const scalar moles,
00165             const scalar current,
00166             const scalar luminousIntensity
00167         );
00168 
00169         //- Construct given individual dimension exponents for first
00170         //  five dimensions
00171         dimensionSet
00172         (
00173             const scalar mass,
00174             const scalar length,
00175             const scalar time,
00176             const scalar temperature,
00177             const scalar moles
00178         );
00179 
00180         //- Construct from Istream
00181         dimensionSet(Istream&);
00182 
00183 
00184     // Member functions
00185 
00186         bool dimensionless() const;
00187         void reset(const dimensionSet&);
00188 
00189 
00190     // Member operators
00191 
00192         scalar operator[](const dimensionType) const;
00193         scalar& operator[](const dimensionType);
00194         bool operator==(const dimensionSet&) const;
00195         bool operator!=(const dimensionSet&) const;
00196 
00197         bool operator=(const dimensionSet&) const;
00198 
00199         bool operator+=(const dimensionSet&) const;
00200         bool operator-=(const dimensionSet&) const;
00201         bool operator*=(const dimensionSet&);
00202         bool operator/=(const dimensionSet&);
00203 
00204 
00205     // Friend functions
00206 
00207         friend dimensionSet max(const dimensionSet&, const dimensionSet&);
00208         friend dimensionSet min(const dimensionSet&, const dimensionSet&);
00209         friend dimensionSet cmptMultiply
00210         (
00211             const dimensionSet&,
00212             const dimensionSet&
00213         );
00214         friend dimensionSet cmptDivide
00215         (
00216             const dimensionSet&,
00217             const dimensionSet&
00218         );
00219 
00220         friend dimensionSet pow(const dimensionSet&, const scalar);
00221         friend dimensionSet pow(const dimensionSet&, const dimensionedScalar&);
00222         friend dimensionSet pow(const dimensionedScalar&, const dimensionSet&);
00223 
00224         friend dimensionSet sqr(const dimensionSet&);
00225         friend dimensionSet pow3(const dimensionSet&);
00226         friend dimensionSet pow4(const dimensionSet&);
00227         friend dimensionSet pow5(const dimensionSet&);
00228         friend dimensionSet pow6(const dimensionSet&);
00229 
00230         friend dimensionSet sqrt(const dimensionSet&);
00231         friend dimensionSet magSqr(const dimensionSet&);
00232         friend dimensionSet mag(const dimensionSet&);
00233         friend dimensionSet sign(const dimensionSet&);
00234         friend dimensionSet pos(const dimensionSet&);
00235         friend dimensionSet neg(const dimensionSet&);
00236         friend dimensionSet inv(const dimensionSet&);
00237 
00238         //- Function to check the argument is dimensionless
00239         //  for transcendental functions
00240         friend dimensionSet trans(const dimensionSet&);
00241 
00242         //- Return the argument; transformations do not change the dimensions
00243         friend dimensionSet transform(const dimensionSet&);
00244 
00245 
00246     // Friend operators
00247 
00248         friend dimensionSet operator-(const dimensionSet&);
00249 
00250         friend dimensionSet operator+
00251         (
00252             const dimensionSet&,
00253             const dimensionSet&
00254         );
00255 
00256         friend dimensionSet operator-
00257         (
00258             const dimensionSet&,
00259             const dimensionSet&
00260         );
00261 
00262         friend dimensionSet operator*
00263         (
00264             const dimensionSet&,
00265             const dimensionSet&
00266         );
00267 
00268         friend dimensionSet operator/
00269         (
00270             const dimensionSet&,
00271             const dimensionSet&
00272         );
00273 
00274         friend dimensionSet operator&
00275         (
00276             const dimensionSet&,
00277             const dimensionSet&
00278         );
00279 
00280         friend dimensionSet operator^
00281         (
00282             const dimensionSet&,
00283             const dimensionSet&
00284         );
00285 
00286         friend dimensionSet operator&&
00287         (
00288             const dimensionSet&,
00289             const dimensionSet&
00290         );
00291 
00292 
00293     // IOstream operators
00294 
00295         friend Istream& operator>>(Istream&, dimensionSet&);
00296         friend Ostream& operator<<(Ostream&, const dimensionSet&);
00297 };
00298 
00299 
00300 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00301 
00302 } // End namespace Foam
00303 
00304 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00305 
00306 #include "dimensionSets.H"
00307 
00308 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00309 
00310 #endif
00311 
00312 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd