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) 2011-2015 OpenFOAM Foundation
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 "word.H"
39 #include "direction.H"
40 #include "dimensionSet.H"
41 #include "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>
65 class dimensioned
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  // Private member functions
80 
81  //- Initialize from Istream
82  // Helper-function for constructors
83  void initialize(Istream& is);
84 
85 
86 public:
87 
88  //- Component type
89  typedef typename pTraits<Type>::cmptType cmptType;
90 
91 
92  // Constructors
93 
94  //- Construct given a name, a value and its dimensionSet.
95  dimensioned(const word&, const dimensionSet&, const Type);
96 
97  //- Construct from a dimensioned<Type> changing the name.
98  dimensioned(const word&, const dimensioned<Type>&);
99 
100  //- Construct given a value (creates dimensionless value).
101  dimensioned(const Type& t)
102  :
103  name_(::Foam::name(t)),
104  dimensions_(dimless),
105  value_(t)
106  {}
107 
108  //- Construct from Istream.
110 
111  //- Construct from an Istream with a given name
112  dimensioned(const word&, Istream&);
113 
114  //- Construct from an Istream with a given name and dimensions
115  dimensioned(const word&, const dimensionSet&, Istream&);
116 
117  //- Construct from dictionary lookup with a given name and dimensions
118  dimensioned(const word&, const dimensionSet&, const dictionary&);
119 
120  //- Null constructor
121  dimensioned();
122 
123 
124  // Static member functions
125 
126  //- Construct from dictionary, with default dimensions and value.
128  (
129  const word&,
130  const dictionary&,
131  const dimensionSet& dims = dimless,
132  const Type& defaultValue = pTraits<Type>::zero
133  );
134 
135  //- Construct from dictionary dimensionless with value.
137  (
138  const word&,
139  const dictionary&,
140  const Type& defaultValue = pTraits<Type>::zero
141  );
142 
143  //- Construct from dictionary, with default value.
144  // If the value is not found, it is added into the dictionary.
146  (
147  const word&,
148  dictionary&,
149  const dimensionSet& dims = dimless,
150  const Type& defaultValue = pTraits<Type>::zero
151  );
152 
153  //- Construct from dictionary, dimensionless with default value.
154  // If the value is not found, it is added into the dictionary.
156  (
157  const word&,
158  dictionary&,
159  const Type& defaultValue = pTraits<Type>::zero
160  );
161 
162 
163  // Member functions
164 
165  //- Return const reference to name.
166  const word& name() const;
167 
168  //- Return non-const reference to name.
169  word& name();
170 
171  //- Return const reference to dimensions.
172  const dimensionSet& dimensions() const;
173 
174  //- Return non-const reference to dimensions.
176 
177  //- Return const reference to value.
178  const Type& value() const;
179 
180  //- Return non-const reference to value.
181  Type& value();
182 
183  //- Return a component as a dimensioned<cmptType>
185 
186  //- Return a component with a dimensioned<cmptType>
187  void replace(const direction, const dimensioned<cmptType>&);
188 
189  //- Return transpose.
190  dimensioned<Type> T() const;
191 
192  //- Update the value of dimensioned<Type>
193  void read(const dictionary&);
194 
195  //- Update the value of dimensioned<Type> if found in the dictionary.
196  bool readIfPresent(const dictionary&);
197 
198 
199  // I/O
200 
201  //- Read value from stream and units from dictionary
202  Istream& read(Istream& is, const dictionary&);
203 
204  //- Read value from stream and units from table
206 
207  //- Read value from stream and units from system table
208  Istream& read(Istream& is);
209 
210 
211  // Member operators
212 
213  //- Return a component as a dimensioned<cmptType>
215 
216  void operator+=(const dimensioned<Type>&);
217  void operator-=(const dimensioned<Type>&);
218  void operator*=(const scalar);
219  void operator/=(const scalar);
220 
221 
222  // IOstream operators
223 
224  friend Istream& operator>> <Type>
226 
227  friend Ostream& operator<< <Type>
228  (Ostream&, const dimensioned<Type>&);
229 };
230 
231 
232 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
233 
234 template<class Type, int r>
236 pow
237 (
238  const dimensioned<Type>&,
241 );
242 
243 template<class Type>
245 sqr(const dimensioned<Type>&);
246 
247 template<class Type>
248 dimensioned<scalar> magSqr(const dimensioned<Type>&);
249 
250 template<class Type>
251 dimensioned<scalar> mag(const dimensioned<Type>&);
252 
253 template<class Type>
255 (
256  const dimensioned<Type>&,
257  const dimensioned<Type>&
258 );
259 
260 template<class Type>
262 (
263  const dimensioned<Type>&,
264  const dimensioned<Type>&
265 );
266 
267 template<class Type>
269 
270 template<class Type>
272 
273 template<class Type>
274 bool operator>(const dimensioned<Type>&, const dimensioned<Type>&);
275 
276 template<class Type>
277 bool operator<(const dimensioned<Type>&, const dimensioned<Type>&);
278 
279 template<class Type>
281 
282 template<class Type>
284 
285 template<class Type>
287 
288 template<class Type>
289 dimensioned<Type> operator*
290 (
291  const dimensioned<scalar>&,
292  const dimensioned<Type>&
293 );
294 
295 template<class Type>
296 dimensioned<Type> operator/
297 (
298  const dimensioned<Type>&,
299  const dimensioned<scalar>&
300 );
301 
302 
303 // Products
304 // ~~~~~~~~
306 #define PRODUCT_OPERATOR(product, op, opFunc) \
307  \
308 template<class Type1, class Type2> \
309 dimensioned<typename product<Type1, Type2>::type> \
310 operator op(const dimensioned<Type1>&, const dimensioned<Type2>&); \
311  \
312 template<class Type, class Form, class Cmpt, int nCmpt> \
313 dimensioned<typename product<Type, Form>::type> \
314 operator op \
315 ( \
316  const dimensioned<Type>&, \
317  const VectorSpace<Form,Cmpt,nCmpt>& \
318 ); \
319  \
320 template<class Type, class Form, class Cmpt, int nCmpt> \
321 dimensioned<typename product<Form, Type>::type> \
322 operator op \
323 ( \
324  const VectorSpace<Form,Cmpt,nCmpt>&, \
325  const dimensioned<Type>& \
326 );
327 
328 PRODUCT_OPERATOR(outerProduct, *, outer)
329 PRODUCT_OPERATOR(crossProduct, ^, cross)
330 PRODUCT_OPERATOR(innerProduct, &, dot)
331 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
332 
333 #undef PRODUCT_OPERATOR
334 
335 
336 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
337 
338 } // End namespace Foam
339 
340 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
341 
342 #ifdef NoRepository
343 # include "dimensionedType.C"
344 #endif
345 
346 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
347 
348 #endif
349 
350 // ************************************************************************* //
void outer(FieldField< Field1, typename outerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
unsigned char direction
Definition: direction.H:43
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
#define PRODUCT_OPERATOR(product, op, opFunc)
dimensioned< scalar > mag(const dimensioned< Type > &)
void operator/=(const scalar)
void operator*=(const scalar)
dimensioned< scalar > magSqr(const dimensioned< Type > &)
tmp< fvMatrix< Type > > operator+(const fvMatrix< Type > &, const fvMatrix< Type > &)
An STL-conforming hash table.
Definition: HashTable.H:61
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A class for handling words, derived from string.
Definition: word.H:59
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
static dimensioned< Type > lookupOrAddToDict(const word &, dictionary &, const dimensionSet &dims=dimless, const Type &defaultValue=pTraits< Type >::zero)
Construct from dictionary, with default value.
Namespace for OpenFOAM.
const dimensionSet & dimensions() const
Return const reference to dimensions.
tmp< fvMatrix< Type > > operator-(const fvMatrix< Type > &)
void dot(FieldField< Field1, typename innerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Generic dimensioned Type class.
bool operator>(const dimensioned< Type > &, const dimensioned< Type > &)
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
const word & name() const
Return const reference to name.
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Dimension set for the base types.
Definition: dimensionSet.H:116
dimensioned()
Null constructor.
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:47
bool readIfPresent(const dictionary &)
Update the value of dimensioned<Type> if found in the dictionary.
dimensioned< Type > T() const
Return transpose.
Traits class for primitives.
Definition: pTraits.H:50
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
void replace(const direction, const dimensioned< cmptType > &)
Return a component with a dimensioned<cmptType>
void operator+=(const dimensioned< Type > &)
dimensioned< cmptType > component(const direction) const
Return a component as a dimensioned<cmptType>
Direction is an integer type used to represent the Cartesian directions etc. Currently it is a typede...
Istream & operator>>(Istream &, edgeMesh &)
Definition: edgeMeshIO.C:144
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
void operator-=(const dimensioned< Type > &)
void dotdot(FieldField< Field1, typename scalarProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
static dimensioned< Type > lookupOrDefault(const word &, const dictionary &, const dimensionSet &dims=dimless, const Type &defaultValue=pTraits< Type >::zero)
Construct from dictionary, with default dimensions and value.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
dimensioned< cmptType > operator[](const direction) const
Return a component as a dimensioned<cmptType>
void cross(FieldField< Field1, typename crossProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
symmTypeOfRank< typename pTraits< arg1 >::cmptType, arg2 *int(pTraits< arg1 >::rank) >::type type
Definition: products.H:118
pTraits< Type >::cmptType cmptType
Component type.
void read(const dictionary &)
Update the value of dimensioned<Type>
const Type & value() const
Return const reference to value.