initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / dimensionSet / dimensionSet.H
blobe61d3ec4df03d416bec6e57905516119aae3caba
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::dimensionSet
28 Description
29     Dimension set for the base types.
30     This type may be used to implement rigorous dimension checking
31     for algebraic manipulation.
33 SourceFiles
34     dimensionSet.C
35     dimensionSetIO.C
36     dimensionSets.C
38 \*---------------------------------------------------------------------------*/
40 #ifndef dimensionSet_H
41 #define dimensionSet_H
43 #include "scalar.H"
44 #include "bool.H"
45 #include "dimensionedScalarFwd.H"
46 #include "className.H"
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 namespace Foam
53 // Forward declaration of friend functions and operators
55 class dimensionSet;
57 // Friend functions
59 dimensionSet max(const dimensionSet&, const dimensionSet&);
60 dimensionSet min(const dimensionSet&, const dimensionSet&);
61 dimensionSet cmptMultiply(const dimensionSet&, const dimensionSet&);
62 dimensionSet cmptDivide(const dimensionSet&, const dimensionSet&);
64 dimensionSet pow(const dimensionSet&, const scalar);
65 dimensionSet pow(const dimensionSet&, const dimensionedScalar&);
66 dimensionSet pow(const dimensionedScalar&, const dimensionSet&);
68 dimensionSet sqr(const dimensionSet&);
69 dimensionSet pow3(const dimensionSet&);
70 dimensionSet pow4(const dimensionSet&);
71 dimensionSet pow5(const dimensionSet&);
72 dimensionSet pow6(const dimensionSet&);
74 dimensionSet sqrt(const dimensionSet&);
75 dimensionSet magSqr(const dimensionSet&);
76 dimensionSet mag(const dimensionSet&);
77 dimensionSet sign(const dimensionSet&);
78 dimensionSet pos(const dimensionSet&);
79 dimensionSet neg(const dimensionSet&);
80 dimensionSet inv(const dimensionSet&);
82 // Function to check the argument is dimensionless
83 //  for transcendental functions
84 dimensionSet trans(const dimensionSet&);
86 // Return the argument; transformations do not change the dimensions
87 dimensionSet transform(const dimensionSet&);
89 // Friend operators
91 dimensionSet operator-(const dimensionSet&);
92 dimensionSet operator+(const dimensionSet&, const dimensionSet&);
93 dimensionSet operator-(const dimensionSet&, const dimensionSet&);
94 dimensionSet operator*(const dimensionSet&, const dimensionSet&);
95 dimensionSet operator/(const dimensionSet&, const dimensionSet&);
96 dimensionSet operator&(const dimensionSet&, const dimensionSet&);
97 dimensionSet operator^(const dimensionSet&, const dimensionSet&);
98 dimensionSet operator&&(const dimensionSet&, const dimensionSet&);
100 // IOstream operators
102 Istream& operator>>(Istream&, dimensionSet&);
103 Ostream& operator<<(Ostream&, const dimensionSet&);
106 /*---------------------------------------------------------------------------*\
107                            Class dimensionSet Declaration
108 \*---------------------------------------------------------------------------*/
110 class dimensionSet
113 public:
115     // Member constants
117         enum
118         {
119             nDimensions = 7    // Number of dimensions in SI is 7
120         };
122         //- Define an enumeration for the names of the dimension exponents
123         enum dimensionType
124         {
125             MASS,               // kilogram   kg
126             LENGTH,             // metre      m
127             TIME,               // second     s
128             TEMPERATURE,        // Kelvin     K
129             MOLES,              // mole       mol
130             CURRENT,            // Ampere     A
131             LUMINOUS_INTENSITY  // Candela    Cd
132         };
135     // Static data members
137         static const scalar smallExponent;
140 private:
142     // private data
144         // dimensionSet stored as an array of dimension exponents
145         scalar exponents_[nDimensions];
148 public:
150     // Declare name of the class and its debug switch
151     ClassName("dimensionSet");
154     // Constructors
156         //- Construct given individual dimension exponents for all
157         //  seven dimensions
158         dimensionSet
159         (
160             const scalar mass,
161             const scalar length,
162             const scalar time,
163             const scalar temperature,
164             const scalar moles,
165             const scalar current,
166             const scalar luminousIntensity
167         );
169         //- Construct given individual dimension exponents for first
170         //  five dimensions
171         dimensionSet
172         (
173             const scalar mass,
174             const scalar length,
175             const scalar time,
176             const scalar temperature,
177             const scalar moles
178         );
180         //- Construct from Istream
181         dimensionSet(Istream&);
184     // Member functions
186         bool dimensionless() const;
187         void reset(const dimensionSet&);
190     // Member operators
192         scalar operator[](const dimensionType) const;
193         scalar& operator[](const dimensionType);
194         bool operator==(const dimensionSet&) const;
195         bool operator!=(const dimensionSet&) const;
197         bool operator=(const dimensionSet&) const;
199         bool operator+=(const dimensionSet&) const;
200         bool operator-=(const dimensionSet&) const;
201         bool operator*=(const dimensionSet&);
202         bool operator/=(const dimensionSet&);
205     // Friend functions
207         friend dimensionSet max(const dimensionSet&, const dimensionSet&);
208         friend dimensionSet min(const dimensionSet&, const dimensionSet&);
209         friend dimensionSet cmptMultiply
210         (
211             const dimensionSet&,
212             const dimensionSet&
213         );
214         friend dimensionSet cmptDivide
215         (
216             const dimensionSet&,
217             const dimensionSet&
218         );
220         friend dimensionSet pow(const dimensionSet&, const scalar);
221         friend dimensionSet pow(const dimensionSet&, const dimensionedScalar&);
222         friend dimensionSet pow(const dimensionedScalar&, const dimensionSet&);
224         friend dimensionSet sqr(const dimensionSet&);
225         friend dimensionSet pow3(const dimensionSet&);
226         friend dimensionSet pow4(const dimensionSet&);
227         friend dimensionSet pow5(const dimensionSet&);
228         friend dimensionSet pow6(const dimensionSet&);
230         friend dimensionSet sqrt(const dimensionSet&);
231         friend dimensionSet magSqr(const dimensionSet&);
232         friend dimensionSet mag(const dimensionSet&);
233         friend dimensionSet sign(const dimensionSet&);
234         friend dimensionSet pos(const dimensionSet&);
235         friend dimensionSet neg(const dimensionSet&);
236         friend dimensionSet inv(const dimensionSet&);
238         //- Function to check the argument is dimensionless
239         //  for transcendental functions
240         friend dimensionSet trans(const dimensionSet&);
242         //- Return the argument; transformations do not change the dimensions
243         friend dimensionSet transform(const dimensionSet&);
246     // Friend operators
248         friend dimensionSet operator-(const dimensionSet&);
250         friend dimensionSet operator+
251         (
252             const dimensionSet&,
253             const dimensionSet&
254         );
256         friend dimensionSet operator-
257         (
258             const dimensionSet&,
259             const dimensionSet&
260         );
262         friend dimensionSet operator*
263         (
264             const dimensionSet&,
265             const dimensionSet&
266         );
268         friend dimensionSet operator/
269         (
270             const dimensionSet&,
271             const dimensionSet&
272         );
274         friend dimensionSet operator&
275         (
276             const dimensionSet&,
277             const dimensionSet&
278         );
280         friend dimensionSet operator^
281         (
282             const dimensionSet&,
283             const dimensionSet&
284         );
286         friend dimensionSet operator&&
287         (
288             const dimensionSet&,
289             const dimensionSet&
290         );
293     // IOstream operators
295         friend Istream& operator>>(Istream&, dimensionSet&);
296         friend Ostream& operator<<(Ostream&, const dimensionSet&);
300 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
302 } // End namespace Foam
304 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
306 #include "dimensionSets.H"
308 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
310 #endif
312 // ************************************************************************* //