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
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)),
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>&,
240  = pTraits<typename powProduct<Type, r>::type>::zero
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>
254 dimensioned<Type> cmptMultiply
255 (
256  const dimensioned<Type>&,
257  const dimensioned<Type>&
258 );
259 
260 template<class Type>
261 dimensioned<Type> cmptDivide
262 (
263  const dimensioned<Type>&,
264  const dimensioned<Type>&
265 );
266 
267 template<class Type>
268 dimensioned<Type> max(const dimensioned<Type>&, const dimensioned<Type>&);
269 
270 template<class Type>
271 dimensioned<Type> min(const dimensioned<Type>&, const dimensioned<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>
280 dimensioned<Type> operator+(const dimensioned<Type>&, const dimensioned<Type>&);
281 
282 template<class Type>
283 dimensioned<Type> operator-(const dimensioned<Type>&);
284 
285 template<class Type>
286 dimensioned<Type> operator-(const dimensioned<Type>&, const dimensioned<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 // ~~~~~~~~
305 
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 // ************************************************************************* //
Foam::dimensioned::dimensioned
dimensioned(const Type &t)
Construct given a value (creates dimensionless value).
Definition: dimensionedType.H:100
Foam::dimensioned::component
dimensioned< cmptType > component(const direction) const
Return a component as a dimensioned<cmptType>
Definition: dimensionedType.C:276
VectorSpace.H
Foam::dimensioned::lookupOrAddToDict
static dimensioned< Type > lookupOrAddToDict(const word &, dictionary &, const dimensionSet &dims=dimless, const Type &defaultValue=pTraits< Type >::zero)
Construct from dictionary, with default value.
Foam::dimensioned::initialize
void initialize(Istream &is)
Initialize from Istream.
Definition: dimensionedType.C:33
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
Foam::dimensioned::lookupOrDefault
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.
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::dimensioned::T
dimensioned< Type > T() const
Return transpose.
Foam::cmptMultiply
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::operator<
bool operator<(const dimensioned< Type > &, const dimensioned< Type > &)
Definition: dimensionedType.C:647
Foam::dot
void dot(FieldField< Field1, typename innerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:875
Foam::dimensioned::name
const word & name() const
Return const reference to name.
Definition: dimensionedType.C:235
Foam::dimensioned::value_
Type value_
The data value.
Definition: dimensionedType.H:75
Foam::dimensioned::value
const Type & value() const
Return const reference to value.
Definition: dimensionedType.C:261
Foam::dimensionSet
Dimension set for the base types.
Definition: dimensionSet.H:116
Foam::dimensioned::operator[]
dimensioned< cmptType > operator[](const direction) const
Return a component as a dimensioned<cmptType>
Definition: dimensionedType.C:398
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
dimensionedType.C
Foam::powProduct::type
symmTypeOfRank< typename pTraits< arg1 >::cmptType, arg2 *int(pTraits< arg1 >::rank) >::type type
Definition: products.H:118
Foam::operator-
tmp< fvMatrix< Type > > operator-(const fvMatrix< Type > &)
Foam::operator>
bool operator>(const dimensioned< Type > &, const dimensioned< Type > &)
Definition: dimensionedType.C:636
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::dimensioned::operator/=
void operator/=(const scalar)
Definition: dimensionedType.C:440
Foam::dimensioned::read
void read(const dictionary &)
Update the value of dimensioned<Type>
Foam::pow
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
Definition: dimensionedScalar.C:73
Foam::operator<<
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:130
dimensionSet.H
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::dimensioned< Type >
Foam::dimensioned::readIfPresent
bool readIfPresent(const dictionary &)
Update the value of dimensioned<Type> if found in the dictionary.
Definition: dimensionedType.C:309
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::dimensioned::operator-=
void operator-=(const dimensioned< Type > &)
Definition: dimensionedType.C:419
direction.H
Direction is an integer type used to represent the Cartesian directions etc. Currently it is a typede...
Foam::HashTable
An STL-conforming hash table.
Definition: HashTable.H:61
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::cmptDivide
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:49
Foam::dimensioned::dimensions_
dimensionSet dimensions_
The dimension set.
Definition: dimensionedType.H:72
Foam::dimensioned::replace
void replace(const direction, const dimensioned< cmptType > &)
Return a component with a dimensioned<cmptType>
Definition: dimensionedType.C:291
Foam::dimensioned::dimensioned
dimensioned()
Null constructor.
Definition: dimensionedType.C:164
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:50
Foam::dimensioned::operator*=
void operator*=(const scalar)
Definition: dimensionedType.C:430
Foam::dimensioned::name_
word name_
Variable name.
Definition: dimensionedType.H:69
Foam::outer
void outer(FieldField< Field1, typename outerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:873
Foam::operator>>
Istream & operator>>(Istream &, edgeMesh &)
Definition: edgeMeshIO.C:141
Foam::direction
unsigned char direction
Definition: direction.H:43
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
word.H
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::dimensioned::dimensions
const dimensionSet & dimensions() const
Return const reference to dimensions.
Definition: dimensionedType.C:248
PRODUCT_OPERATOR
#define PRODUCT_OPERATOR(product, op, opFunc)
Definition: dimensionedType.H:305
Foam::cross
void cross(FieldField< Field1, typename crossProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:874
Foam::dimensioned::cmptType
pTraits< Type >::cmptType cmptType
Component type.
Definition: dimensionedType.H:88
Foam::min
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::operator+
tmp< fvMatrix< Type > > operator+(const fvMatrix< Type > &, const fvMatrix< Type > &)
Foam::magSqr
dimensioned< scalar > magSqr(const dimensioned< Type > &)
Foam::dimensioned::operator+=
void operator+=(const dimensioned< Type > &)
Definition: dimensionedType.C:408
Foam::dotdot
void dotdot(FieldField< Field1, typename scalarProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:876