OpenFOAM logo
Open Source CFD Toolkit

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-2005 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     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 /*---------------------------------------------------------------------------*\
00054                            Class dimensionSet Declaration
00055 \*---------------------------------------------------------------------------*/
00056 
00057 class dimensionSet
00058 {
00059 
00060 public:
00061 
00062     // Member constants
00063 
00064         enum
00065         {
00066             nDimensions = 7    // Number of dimensions in SI is 7
00067         };
00068 
00069         //- Define an enumeration for the names of the dimension exponents
00070         enum dimensionType
00071         {
00072             MASS,               // kilogram   kg
00073             LENGTH,             // meter      m
00074             TIME,               // second     s
00075             TEMPERATURE,        // Kelvin     K
00076             MOLES,              // mole       mol
00077             CURRENT,            // Ampere     A
00078             LUMINOUS_INTENSITY  // Candela    Cd
00079         };
00080 
00081 
00082     // Static data members
00083 
00084         static const scalar smallExponent;
00085 
00086 
00087 private:
00088 
00089     // private data
00090 
00091         // dimensionSet stored as an array of dimension exponents
00092         scalar exponents_[nDimensions];
00093 
00094 
00095 public:
00096 
00097     // Declare name of the class and it's debug switch
00098     ClassName("dimensionSet");
00099 
00100 
00101     // Constructors
00102 
00103         //- Construct given individual dimension exponents for all
00104         //  seven dimensions
00105         dimensionSet
00106         (
00107             const scalar mass,
00108             const scalar length,
00109             const scalar time,
00110             const scalar temperature,
00111             const scalar moles,
00112             const scalar current,
00113             const scalar luminousIntensity
00114         );
00115 
00116         //- Construct given individual dimension exponents for first
00117         //  five dimensions
00118         dimensionSet
00119         (
00120             const scalar mass,
00121             const scalar length,
00122             const scalar time,
00123             const scalar temperature,
00124             const scalar moles
00125         );
00126 
00127         //- Construct from Istream
00128         dimensionSet(Istream&);
00129 
00130 
00131     // Member functions
00132 
00133         bool dimensionless() const;
00134         void reset(const dimensionSet&);
00135 
00136 
00137     // Member operators
00138 
00139         scalar operator[](const dimensionType) const;
00140         scalar& operator[](const dimensionType);
00141         bool operator==(const dimensionSet&) const;
00142         bool operator!=(const dimensionSet&) const;
00143 
00144         bool operator=(const dimensionSet&) const;
00145 
00146         bool operator+=(const dimensionSet&) const;
00147         bool operator-=(const dimensionSet&) const;
00148         bool operator*=(const dimensionSet&);
00149         bool operator/=(const dimensionSet&);
00150 
00151 
00152     // Friend functions
00153 
00154         friend dimensionSet max(const dimensionSet&, const dimensionSet&);
00155         friend dimensionSet min(const dimensionSet&, const dimensionSet&);
00156         friend dimensionSet scale(const dimensionSet&, const dimensionSet&);
00157 
00158         friend dimensionSet pow(const dimensionSet&, const scalar);
00159         friend dimensionSet pow(const dimensionSet&, const dimensionedScalar&);
00160         friend dimensionSet pow(const dimensionedScalar&, const dimensionSet&);
00161 
00162         friend dimensionSet sqr(const dimensionSet&);
00163         friend dimensionSet pow3(const dimensionSet&);
00164         friend dimensionSet pow4(const dimensionSet&);
00165 
00166         friend dimensionSet sqrt(const dimensionSet&);
00167         friend dimensionSet magSqr(const dimensionSet&);
00168         friend dimensionSet mag(const dimensionSet&);
00169         friend dimensionSet sign(const dimensionSet&);
00170         friend dimensionSet pos(const dimensionSet&);
00171         friend dimensionSet neg(const dimensionSet&);
00172 
00173 
00174     // Friend operators
00175 
00176         friend dimensionSet operator-(const dimensionSet&);
00177 
00178         friend dimensionSet operator+
00179         (
00180             const dimensionSet&,
00181             const dimensionSet&
00182         );
00183 
00184         friend dimensionSet operator-
00185         (
00186             const dimensionSet&,
00187             const dimensionSet&
00188         );
00189 
00190         friend dimensionSet operator*
00191         (
00192             const dimensionSet&,
00193             const dimensionSet&
00194         );
00195 
00196         friend dimensionSet operator/
00197         (
00198             const dimensionSet&,
00199             const dimensionSet&
00200         );
00201 
00202         friend dimensionSet operator&
00203         (
00204             const dimensionSet&,
00205             const dimensionSet&
00206         );
00207 
00208         friend dimensionSet operator^
00209         (
00210             const dimensionSet&,
00211             const dimensionSet&
00212         );
00213 
00214         friend dimensionSet operator&&
00215         (
00216             const dimensionSet&,
00217             const dimensionSet&
00218         );
00219 
00220 
00221     // IOstream operators
00222 
00223         friend Istream& operator>>(Istream&, dimensionSet&);
00224         friend Ostream& operator<<(Ostream&, const dimensionSet&);
00225 };
00226 
00227 
00228 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00229 
00230 } // End namespace Foam
00231 
00232 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00233 
00234 #include "dimensionSets.H"
00235 
00236 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00237 
00238 #endif
00239 
00240 // ************************************************************************* //
For further information go to www.openfoam.org