FreeFOAM The Cross-Platform CFD Toolkit
dimensionSet.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::dimensionSet
26 
27 Description
28  Dimension set for the base types.
29  This type may be used to implement rigorous dimension checking
30  for algebraic manipulation.
31 
32 SourceFiles
33  dimensionSet.C
34  dimensionSetIO.C
35  dimensionSets.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef dimensionSet_H
40 #define dimensionSet_H
41 
42 #include <OpenFOAM/scalar.H>
43 #include <OpenFOAM/bool.H>
45 #include <OpenFOAM/className.H>
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 // Forward declaration of friend functions and operators
53 
54 class dimensionSet;
55 
56 // Friend functions
57 
58 dimensionSet max(const dimensionSet&, const dimensionSet&);
59 dimensionSet min(const dimensionSet&, const dimensionSet&);
60 dimensionSet cmptMultiply(const dimensionSet&, const dimensionSet&);
61 dimensionSet cmptDivide(const dimensionSet&, const dimensionSet&);
62 
63 dimensionSet pow(const dimensionSet&, const scalar);
64 dimensionSet pow(const dimensionSet&, const dimensionedScalar&);
65 dimensionSet pow(const dimensionedScalar&, const dimensionSet&);
66 
67 dimensionSet sqr(const dimensionSet&);
68 dimensionSet pow3(const dimensionSet&);
69 dimensionSet pow4(const dimensionSet&);
70 dimensionSet pow5(const dimensionSet&);
71 dimensionSet pow6(const dimensionSet&);
72 
73 dimensionSet sqrt(const dimensionSet&);
74 dimensionSet magSqr(const dimensionSet&);
75 dimensionSet mag(const dimensionSet&);
76 dimensionSet sign(const dimensionSet&);
77 dimensionSet pos(const dimensionSet&);
78 dimensionSet neg(const dimensionSet&);
79 dimensionSet inv(const dimensionSet&);
80 
81 // Function to check the argument is dimensionless
82 // for transcendental functions
83 dimensionSet trans(const dimensionSet&);
84 
85 // Return the argument; transformations do not change the dimensions
86 dimensionSet transform(const dimensionSet&);
87 
88 // Friend operators
89 
90 dimensionSet operator-(const dimensionSet&);
91 dimensionSet operator+(const dimensionSet&, 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 
99 // IOstream operators
100 
101 Istream& operator>>(Istream&, dimensionSet&);
102 Ostream& operator<<(Ostream&, const dimensionSet&);
103 
104 
105 /*---------------------------------------------------------------------------*\
106  Class dimensionSet Declaration
107 \*---------------------------------------------------------------------------*/
108 
110 {
111 
112 public:
113 
114  // Member constants
115 
116  enum
117  {
118  nDimensions = 7 // Number of dimensions in SI is 7
119  };
120 
121  //- Define an enumeration for the names of the dimension exponents
123  {
124  MASS, // kilogram kg
125  LENGTH, // metre m
126  TIME, // second s
127  TEMPERATURE, // Kelvin K
128  MOLES, // mole mol
129  CURRENT, // Ampere A
130  LUMINOUS_INTENSITY // Candela Cd
131  };
132 
133 
134  // Static data members
135 
136  static const scalar smallExponent;
137 
138 
139 private:
140 
141  // private data
142 
143  // dimensionSet stored as an array of dimension exponents
144  scalar exponents_[nDimensions];
145 
146 
147 public:
148 
149  // Declare name of the class and its debug switch
150  ClassName("dimensionSet");
151 
152 
153  // Constructors
154 
155  //- Construct given individual dimension exponents for all
156  // seven dimensions
158  (
159  const scalar mass,
160  const scalar length,
161  const scalar time,
162  const scalar temperature,
163  const scalar moles,
164  const scalar current,
165  const scalar luminousIntensity
166  );
167 
168  //- Construct given individual dimension exponents for first
169  // five dimensions
171  (
172  const scalar mass,
173  const scalar length,
174  const scalar time,
175  const scalar temperature,
176  const scalar moles
177  );
178 
179  //- Construct from Istream
181 
182 
183  // Member functions
184 
185  bool dimensionless() const;
186  void reset(const dimensionSet&);
187 
188 
189  // Member operators
190 
191  scalar operator[](const dimensionType) const;
192  scalar& operator[](const dimensionType);
193  bool operator==(const dimensionSet&) const;
194  bool operator!=(const dimensionSet&) const;
195 
196  bool operator=(const dimensionSet&) const;
197 
198  bool operator+=(const dimensionSet&) const;
199  bool operator-=(const dimensionSet&) const;
200  bool operator*=(const dimensionSet&);
201  bool operator/=(const dimensionSet&);
202 
203 
204  // Friend functions
205 
206  friend dimensionSet max(const dimensionSet&, const dimensionSet&);
207  friend dimensionSet min(const dimensionSet&, const dimensionSet&);
209  (
210  const dimensionSet&,
211  const dimensionSet&
212  );
213  friend dimensionSet cmptDivide
214  (
215  const dimensionSet&,
216  const dimensionSet&
217  );
218 
219  friend dimensionSet pow(const dimensionSet&, const scalar);
220  friend dimensionSet pow(const dimensionSet&, const dimensionedScalar&);
221  friend dimensionSet pow(const dimensionedScalar&, const dimensionSet&);
222 
223  friend dimensionSet sqr(const dimensionSet&);
224  friend dimensionSet pow3(const dimensionSet&);
225  friend dimensionSet pow4(const dimensionSet&);
226  friend dimensionSet pow5(const dimensionSet&);
227  friend dimensionSet pow6(const dimensionSet&);
228 
229  friend dimensionSet sqrt(const dimensionSet&);
230  friend dimensionSet magSqr(const dimensionSet&);
231  friend dimensionSet mag(const dimensionSet&);
232  friend dimensionSet sign(const dimensionSet&);
233  friend dimensionSet pos(const dimensionSet&);
234  friend dimensionSet neg(const dimensionSet&);
235  friend dimensionSet inv(const dimensionSet&);
236 
237  //- Function to check the argument is dimensionless
238  // for transcendental functions
239  friend dimensionSet trans(const dimensionSet&);
240 
241  //- Return the argument; transformations do not change the dimensions
242  friend dimensionSet transform(const dimensionSet&);
243 
244 
245  // Friend operators
246 
247  friend dimensionSet operator-(const dimensionSet&);
248 
249  friend dimensionSet operator+
250  (
251  const dimensionSet&,
252  const dimensionSet&
253  );
254 
255  friend dimensionSet operator-
256  (
257  const dimensionSet&,
258  const dimensionSet&
259  );
260 
261  friend dimensionSet operator*
262  (
263  const dimensionSet&,
264  const dimensionSet&
265  );
266 
267  friend dimensionSet operator/
268  (
269  const dimensionSet&,
270  const dimensionSet&
271  );
272 
273  friend dimensionSet operator&
274  (
275  const dimensionSet&,
276  const dimensionSet&
277  );
278 
279  friend dimensionSet operator^
280  (
281  const dimensionSet&,
282  const dimensionSet&
283  );
284 
285  friend dimensionSet operator&&
286  (
287  const dimensionSet&,
288  const dimensionSet&
289  );
290 
291 
292  // IOstream operators
293 
295  friend Ostream& operator<<(Ostream&, const dimensionSet&);
296 };
297 
298 
299 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
300 
301 } // End namespace Foam
302 
303 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
304 
305 #include <OpenFOAM/dimensionSets.H>
306 
307 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
308 
309 #endif
310 
311 // ************************ vim: set sw=4 sts=4 et: ************************ //