FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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