FreeFOAM The Cross-Platform CFD Toolkit
dimensionedType.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::dimensioned
26 
27 Description
28  Generic dimensioned Type class
29 
30 SourceFiles
31  dimensionedType.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef dimensionedType_H
36 #define dimensionedType_H
37 
38 #include <OpenFOAM/word.H>
39 #include <OpenFOAM/direction.H>
40 #include <OpenFOAM/dimensionSet.H>
41 #include <OpenFOAM/VectorSpace.H>
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 // Forward declaration of friend functions and operators
49 
50 template<class Type> class dimensioned;
51 
52 template<class Type>
53 Istream& operator>>(Istream&, dimensioned<Type>&);
54 
55 template<class Type>
56 Ostream& operator<<(Ostream&, const dimensioned<Type>&);
57 
58 class dictionary;
59 
60 /*---------------------------------------------------------------------------*\
61  Class dimensioned Declaration
62 \*---------------------------------------------------------------------------*/
63 
64 template <class Type>
66 {
67  // private data
68 
69  //- Variable name
70  word name_;
71 
72  //- The dimension set
73  dimensionSet dimensions_;
74 
75  //- The data value
76  Type value_;
77 
78 
79 public:
80 
81  //- Component type
83 
84 
85  // Constructors
86 
87  //- Construct given a name, a value and its dimensionSet.
88  dimensioned(const word&, const dimensionSet&, const Type);
89 
90  //- Construct from a dimensioned<Type> changing the name.
91  dimensioned(const word&, const dimensioned<Type>&);
92 
93  //- Construct given a value (creates dimensionless value).
94  dimensioned(const Type& t)
95  :
96  name_(::Foam::name(t)),
97  dimensions_(dimless),
98  value_(t)
99  {}
100 
101  //- Construct from Istream.
103 
104  //- Construct from an Istream with a given name
105  dimensioned(const word&, Istream&);
106 
107  //- Construct from an Istream with a given name and dimensions
108  dimensioned(const word&, const dimensionSet&, Istream&);
109 
110  //- Construct from dictionary, with default value.
112  (
113  const word&,
114  const dictionary&,
115  const Type& defaultValue = pTraits<Type>::zero,
116  const dimensionSet& dims = dimless
117  );
118 
119  //- Construct from dictionary, with default value.
120  // If the value is not found, it is added into the dictionary.
122  (
123  const word&,
124  dictionary&,
125  const Type& defaultValue = pTraits<Type>::zero,
126  const dimensionSet& dims = dimless
127  );
128 
129 
130  // Member functions
131 
132  //- Return const reference to name.
133  const word& name() const;
134 
135  //- Return non-const reference to name.
136  word& name();
137 
138  //- Return const reference to dimensions.
139  const dimensionSet& dimensions() const;
140 
141  //- Return non-const reference to dimensions.
143 
144  //- Return const reference to value.
145  const Type& value() const;
146 
147  //- Return non-const reference to value.
148  Type& value();
149 
150  //- Return a component as a dimensioned<cmptType>
152 
153  //- Return a component with a dimensioned<cmptType>
154  void replace(const direction, const dimensioned<cmptType>&);
155 
156  //- Return transpose.
157  dimensioned<Type> T() const;
158 
159  //- Update the value of dimensioned<Type> if found in the dictionary.
160  bool readIfPresent(const dictionary&);
161 
162 
163  // Member operators
164 
165  //- Return a component as a dimensioned<cmptType>
167 
168  void operator+=(const dimensioned<Type>&);
169  void operator-=(const dimensioned<Type>&);
170  void operator*=(const scalar);
171  void operator/=(const scalar);
172 
173 
174  // IOstream operators
175 
176  friend Istream& operator>> <Type>
178 
179  friend Ostream& operator<< <Type>
180  (Ostream&, const dimensioned<Type>&);
181 };
182 
183 
184 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
185 
186 template<class Type, int r>
188 pow
189 (
190  const dimensioned<Type>&,
192  = pTraits<typename powProduct<Type, r>::type>::zero
193 );
194 
195 template<class Type>
197 sqr(const dimensioned<Type>&);
198 
199 template<class Type>
200 dimensioned<scalar> magSqr(const dimensioned<Type>&);
201 
202 template<class Type>
203 dimensioned<scalar> mag(const dimensioned<Type>&);
204 
205 template<class Type>
206 dimensioned<Type> cmptMultiply
207 (
208  const dimensioned<Type>&,
209  const dimensioned<Type>&
210 );
211 
212 template<class Type>
213 dimensioned<Type> cmptDivide
214 (
215  const dimensioned<Type>&,
216  const dimensioned<Type>&
217 );
218 
219 template<class Type>
220 dimensioned<Type> max(const dimensioned<Type>&, const dimensioned<Type>&);
221 
222 template<class Type>
223 dimensioned<Type> min(const dimensioned<Type>&, const dimensioned<Type>&);
224 
225 template<class Type>
226 bool operator>(const dimensioned<Type>&, const dimensioned<Type>&);
227 
228 template<class Type>
229 bool operator<(const dimensioned<Type>&, const dimensioned<Type>&);
230 
231 template<class Type>
232 dimensioned<Type> operator+(const dimensioned<Type>&, const dimensioned<Type>&);
233 
234 template<class Type>
235 dimensioned<Type> operator-(const dimensioned<Type>&);
236 
237 template<class Type>
238 dimensioned<Type> operator-(const dimensioned<Type>&, const dimensioned<Type>&);
239 
240 template<class Type>
241 dimensioned<Type> operator*
242 (
243  const dimensioned<scalar>&,
244  const dimensioned<Type>&
245 );
246 
247 template<class Type>
248 dimensioned<Type> operator/
249 (
250  const dimensioned<Type>&,
251  const dimensioned<scalar>&
252 );
253 
254 
255 // Products
256 // ~~~~~~~~
257 
258 #define PRODUCT_OPERATOR(product, op, opFunc) \
259  \
260 template<class Type1, class Type2> \
261 dimensioned<typename product<Type1, Type2>::type> \
262 operator op(const dimensioned<Type1>&, const dimensioned<Type2>&); \
263  \
264 template<class Type, class Form, class Cmpt, int nCmpt> \
265 dimensioned<typename product<Type, Form>::type> \
266 operator op \
267 ( \
268  const dimensioned<Type>&, \
269  const VectorSpace<Form,Cmpt,nCmpt>& \
270 ); \
271  \
272 template<class Type, class Form, class Cmpt, int nCmpt> \
273 dimensioned<typename product<Form, Type>::type> \
274 operator op \
275 ( \
276  const VectorSpace<Form,Cmpt,nCmpt>&, \
277  const dimensioned<Type>& \
278 );
279 
280 PRODUCT_OPERATOR(outerProduct, *, outer)
281 PRODUCT_OPERATOR(crossProduct, ^, cross)
282 PRODUCT_OPERATOR(innerProduct, &, dot)
283 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
284 
285 #undef PRODUCT_OPERATOR
286 
287 
288 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
289 
290 } // End namespace Foam
291 
292 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
293 
294 #ifdef NoRepository
295 # include <OpenFOAM/dimensionedType.C>
296 #endif
297 
298 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
299 
300 #endif
301 
302 // ************************ vim: set sw=4 sts=4 et: ************************ //