dimensionedType.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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, direction 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 
303 #define PRODUCT_OPERATOR(product, op, opFunc) \
304  \
305 template<class Type1, class Type2> \
306 dimensioned<typename product<Type1, Type2>::type> \
307 operator op(const dimensioned<Type1>&, const dimensioned<Type2>&); \
308  \
309 template<class Type, class Form, class Cmpt, direction nCmpt> \
310 dimensioned<typename product<Type, Form>::type> \
311 operator op \
312 ( \
313  const dimensioned<Type>&, \
314  const VectorSpace<Form,Cmpt,nCmpt>& \
315 ); \
316  \
317 template<class Type, class Form, class Cmpt, direction nCmpt> \
318 dimensioned<typename product<Form, Type>::type> \
319 operator op \
320 ( \
321  const VectorSpace<Form,Cmpt,nCmpt>&, \
322  const dimensioned<Type>& \
323 );
324 
325 PRODUCT_OPERATOR(outerProduct, *, outer)
326 PRODUCT_OPERATOR(crossProduct, ^, cross)
327 PRODUCT_OPERATOR(innerProduct, &, dot)
328 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
329 
330 #undef PRODUCT_OPERATOR
331 
332 
333 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
334 
335 } // End namespace Foam
336 
337 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
338 
339 #ifdef NoRepository
340  #include "dimensionedType.C"
341 #endif
342 
343 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
344 
345 #endif
346 
347 // ************************************************************************* //
static dimensioned< Type > lookupOrAddToDict(const word &, dictionary &, const dimensionSet &dims=dimless, const Type &defaultValue=pTraits< Type >::zero)
Construct from dictionary, with default value.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
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.
void operator*=(const scalar)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
uint8_t direction
Definition: direction.H:45
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Traits class for primitives.
Definition: pTraits.H:50
bool readIfPresent(const dictionary &)
Update the value of dimensioned<Type> if found in the dictionary.
void replace(const direction, const dimensioned< cmptType > &)
Return a component with a dimensioned<cmptType>
void cross(FieldField< Field1, typename crossProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Generic dimensioned Type class.
void dotdot(FieldField< Field1, typename scalarProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
void outer(FieldField< Field1, typename outerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
void dot(FieldField< Field1, typename innerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
#define PRODUCT_OPERATOR(product, op, opFunc)
Dimension set for the base types.
Definition: dimensionSet.H:120
pTraits< Type >::cmptType cmptType
Component type.
void read(const dictionary &)
Update the value of dimensioned<Type>
A class for handling words, derived from string.
Definition: word.H:59
Istream & operator>>(Istream &, directionInfo &)
const Type & value() const
Return const reference to value.
dimensioned< cmptType > component(const direction) const
Return a component as a dimensioned<cmptType>
tmp< fvMatrix< Type > > operator-(const fvMatrix< Type > &)
void operator+=(const dimensioned< Type > &)
tmp< fvMatrix< Type > > operator+(const fvMatrix< Type > &, const fvMatrix< Type > &)
An STL-conforming hash table.
Definition: HashTable.H:62
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
dimensioned< scalar > magSqr(const dimensioned< Type > &)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
bool operator>(const instant &, const instant &)
Definition: instant.C:85
void operator/=(const scalar)
dimensioned()
Null constructor.
dimensioned< Type > T() const
Return transpose.
const word & name() const
Return const reference to name.
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
symmTypeOfRank< typename pTraits< arg1 >::cmptType, arg2 *direction(pTraits< arg1 >::rank) >::type type
Definition: products.H:136
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
dimensioned< cmptType > operator[](const direction) const
Return a component as a dimensioned<cmptType>
Direction is an 8-bit unsigned integer type used to represent the Cartesian directions etc...
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
const dimensionSet & dimensions() const
Return const reference to dimensions.
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:49
dimensioned< scalar > mag(const dimensioned< Type > &)
Namespace for OpenFOAM.
void operator-=(const dimensioned< Type > &)