All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2021 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  //- Initialise from Istream
82  // Helper-function for constructors
83  void initialise(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 name, dimensions and value
95  dimensioned(const word&, const dimensionSet&, const Type&);
96 
97  //- Construct given dimensions and value
98  // with the name obtained from the value
99  dimensioned(const dimensionSet&, const Type&);
100 
101  //- Construct dimensionless given value only
102  // with a name obtained from the value
103  dimensioned(const Type&);
104 
105  //- Construct from a dimensioned<Type> changing the name.
106  dimensioned(const word&, const dimensioned<Type>&);
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 template<class Type>
233 void writeEntry(Ostream& os, const dimensioned<Type>& dt);
234 
235 
236 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
237 
238 template<class Type, direction r>
240 pow
241 (
242  const dimensioned<Type>&,
245 );
246 
247 template<class Type>
249 sqr(const dimensioned<Type>&);
250 
251 template<class Type>
252 dimensioned<scalar> magSqr(const dimensioned<Type>&);
253 
254 template<class Type>
255 dimensioned<scalar> mag(const dimensioned<Type>&);
256 
257 template<class Type>
259 (
260  const dimensioned<Type>&,
261  const dimensioned<Type>&
262 );
263 
264 template<class Type>
266 (
267  const dimensioned<Type>&,
268  const dimensioned<Type>&
269 );
270 
271 template<class Type>
273 
274 template<class Type>
276 
277 template<class Type>
278 bool operator>(const dimensioned<Type>&, const dimensioned<Type>&);
279 
280 template<class Type>
281 bool operator<(const dimensioned<Type>&, const dimensioned<Type>&);
282 
283 template<class Type>
285 
286 template<class Type>
288 
289 template<class Type>
291 
292 template<class Type>
293 dimensioned<Type> operator*
294 (
295  const dimensioned<scalar>&,
296  const dimensioned<Type>&
297 );
298 
299 template<class Type>
300 dimensioned<Type> operator/
301 (
302  const dimensioned<Type>&,
303  const dimensioned<scalar>&
304 );
305 
307 #define PRODUCT_OPERATOR(product, op, opFunc) \
308  \
309 template<class Type1, class Type2> \
310 dimensioned<typename product<Type1, Type2>::type> \
311 operator op(const dimensioned<Type1>&, const dimensioned<Type2>&); \
312  \
313 template<class Type, class Form, class Cmpt, direction nCmpt> \
314 dimensioned<typename product<Type, Form>::type> \
315 operator op \
316 ( \
317  const dimensioned<Type>&, \
318  const VectorSpace<Form,Cmpt,nCmpt>& \
319 ); \
320  \
321 template<class Type, class Form, class Cmpt, direction nCmpt> \
322 dimensioned<typename product<Form, Type>::type> \
323 operator op \
324 ( \
325  const VectorSpace<Form,Cmpt,nCmpt>&, \
326  const dimensioned<Type>& \
327 );
328 
329 PRODUCT_OPERATOR(outerProduct, *, outer)
330 PRODUCT_OPERATOR(crossProduct, ^, cross)
331 PRODUCT_OPERATOR(innerProduct, &, dot)
332 PRODUCT_OPERATOR(scalarProduct, &&, dotdot)
333 
334 #undef PRODUCT_OPERATOR
335 
336 
337 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
338 
339 } // End namespace Foam
340 
341 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
342 
343 #ifdef NoRepository
344  #include "dimensionedType.C"
345 #endif
346 
347 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
348 
349 #endif
350 
351 // ************************************************************************* //
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:156
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)
const dimensionSet dimless
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:61
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:54
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.
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
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 & 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 > &)