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-2024 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 class dictionary;
50 template<class Type>
51 class dimensioned;
52 template<class Type>
54 template<class Type>
56 
57 /*---------------------------------------------------------------------------*\
58  Class dimensioned Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 template<class Type>
62 class dimensioned
63 {
64  // Private Data
65 
66  //- Variable name
67  word name_;
68 
69  //- The dimension set
70  dimensionSet dimensions_;
71 
72  //- The data value
73  Type value_;
74 
75 
76  // Private Member Functions
77 
78  //- Read the dimensions if present. Return whether dimensions were read.
79  bool readDimensions
80  (
81  Istream& is,
82  scalar& multiplier,
83  const bool haveDims
84  );
85 
86  //- Initialise from Istream
87  void initialise(Istream& is, const bool haveName, const bool haveDims);
88 
89  //- Initialise from Istream
90  void initialise
91  (
92  const word& name,
93  const unitConversion& defaultUnits,
94  Istream& is
95  );
96 
97 
98 public:
99 
100  //- Component type
101  typedef typename pTraits<Type>::cmptType cmptType;
102 
103 
104  // Constructors
105 
106  //- Null constructor
107  dimensioned();
108 
109  //- Construct given name, dimensions and value
110  dimensioned(const word&, const dimensionSet&, const Type&);
111 
112  //- Construct given dimensions and value
113  // with the name obtained from the value
114  dimensioned(const dimensionSet&, const Type&);
115 
116  //- Construct dimensionless given value only
117  // with a name obtained from the value
118  dimensioned(const Type&);
119 
120  //- Construct from a dimensioned<Type> changing the name.
121  dimensioned(const word&, const dimensioned<Type>&);
122 
123  //- Construct from Istream.
125 
126  //- Construct from an Istream with a given name
127  dimensioned(const word&, Istream&);
128 
129  //- Construct from an Istream with a given name and dimensions
130  dimensioned(const word&, const dimensionSet&, Istream&);
131 
132  //- Construct from dictionary lookup with a given name and dimensions
133  dimensioned(const word&, const dimensionSet&, const dictionary&);
134 
135 
136  // Static member functions
137 
138  //- Construct from dictionary, with default dimensions and value.
140  (
141  const word&,
142  const dictionary&,
143  const dimensionSet& dims = dimless,
144  const Type& defaultValue = pTraits<Type>::zero
145  );
146 
147  //- Construct from dictionary dimensionless with value.
149  (
150  const word&,
151  const dictionary&,
152  const Type& defaultValue = pTraits<Type>::zero
153  );
154 
155  //- Construct from dictionary, with default value.
156  // If the value is not found, it is added into the dictionary.
158  (
159  const word&,
160  dictionary&,
161  const dimensionSet& dims = dimless,
162  const Type& defaultValue = pTraits<Type>::zero
163  );
164 
165  //- Construct from dictionary, dimensionless with default value.
166  // If the value is not found, it is added into the dictionary.
168  (
169  const word&,
170  dictionary&,
171  const Type& defaultValue = pTraits<Type>::zero
172  );
173 
174 
175  // Member Functions
176 
177  //- Return const reference to name.
178  const word& name() const;
179 
180  //- Return non-const reference to name.
181  word& name();
182 
183  //- Return const reference to dimensions.
184  const dimensionSet& dimensions() const;
185 
186  //- Return non-const reference to dimensions.
188 
189  //- Return const reference to value.
190  const Type& value() const;
191 
192  //- Return non-const reference to value.
193  Type& value();
194 
195  //- Return a component as a dimensioned<cmptType>
197 
198  //- Return a component with a dimensioned<cmptType>
199  void replace(const direction, const dimensioned<cmptType>&);
200 
201  //- Return transpose.
202  dimensioned<Type> T() const;
203 
204  //- Update the value of dimensioned<Type>
205  void read(const dictionary&);
206 
207  //- Update the value of dimensioned<Type> if found in the dictionary.
208  bool readIfPresent(const dictionary&);
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>(Istream&, dimensioned<Type>&);
225  friend Ostream& operator<< <Type>(Ostream&, const dimensioned<Type>&);
226 };
227 
228 
229 template<class Type>
230 void writeEntry(Ostream& os, const dimensioned<Type>& dt);
231 
232 
233 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
234 
235 template<class Type, direction r>
237 pow
238 (
239  const dimensioned<Type>&,
242 );
243 
244 template<class Type>
246 sqr(const dimensioned<Type>&);
247 
248 template<class Type>
250 
251 template<class Type>
253 
254 template<class Type>
256 (
257  const dimensioned<Type>&,
258  const dimensioned<Type>&
259 );
260 
261 template<class Type>
263 (
264  const dimensioned<Type>&,
265  const dimensioned<Type>&
266 );
267 
268 template<class Type>
270 
271 template<class Type>
273 
274 template<class Type>
275 bool operator>(const dimensioned<Type>&, const dimensioned<Type>&);
276 
277 template<class Type>
278 bool operator<(const dimensioned<Type>&, const dimensioned<Type>&);
279 
280 template<class Type>
282 
283 template<class Type>
285 
286 template<class Type>
288 
289 template<class Type>
290 dimensioned<Type> operator*
291 (
292  const dimensioned<scalar>&,
293  const dimensioned<Type>&
294 );
295 
296 template<class Type>
297 dimensioned<Type> operator/
298 (
299  const dimensioned<Type>&,
300  const dimensioned<scalar>&
301 );
302 
303 
304 #define PRODUCT_OPERATOR(product, op, opFunc) \
305  \
306 template<class Type1, class Type2> \
307 dimensioned<typename product<Type1, Type2>::type> \
308 operator op(const dimensioned<Type1>&, const dimensioned<Type2>&); \
309  \
310 template<class Type, class Form, class Cmpt, direction nCmpt> \
311 dimensioned<typename product<Type, Form>::type> \
312 operator op \
313 ( \
314  const dimensioned<Type>&, \
315  const VectorSpace<Form,Cmpt,nCmpt>& \
316 ); \
317  \
318 template<class Type, class Form, class Cmpt, direction nCmpt> \
319 dimensioned<typename product<Form, Type>::type> \
320 operator op \
321 ( \
322  const VectorSpace<Form,Cmpt,nCmpt>&, \
323  const dimensioned<Type>& \
324 );
325 
330 
331 #undef PRODUCT_OPERATOR
332 
333 
334 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
335 
336 } // End namespace Foam
337 
338 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
339 
340 #ifdef NoRepository
341  #include "dimensionedType.C"
342 #endif
343 
344 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
345 
346 #endif
347 
348 // ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Dimension set for the base types.
Definition: dimensionSet.H:125
Generic dimensioned Type class.
void operator+=(const dimensioned< Type > &)
static dimensioned< Type > lookupOrAddToDict(const word &, dictionary &, const dimensionSet &dims=dimless, const Type &defaultValue=pTraits< Type >::zero)
Construct from dictionary, with default value.
dimensioned()
Null constructor.
void replace(const direction, const dimensioned< cmptType > &)
Return a component with a dimensioned<cmptType>
const dimensionSet & dimensions() const
Return const reference to dimensions.
pTraits< Type >::cmptType cmptType
Component type.
const Type & value() const
Return const reference to value.
dimensioned< cmptType > component(const direction) const
Return a component as a dimensioned<cmptType>
void operator/=(const scalar)
void operator-=(const dimensioned< Type > &)
void read(const dictionary &)
Update the value of dimensioned<Type>
dimensioned< cmptType > operator[](const direction) const
Return a component as a dimensioned<cmptType>
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.
const word & name() const
Return const reference to name.
bool readIfPresent(const dictionary &)
Update the value of dimensioned<Type> if found in the dictionary.
void operator*=(const scalar)
dimensioned< Type > T() const
Return transpose.
Traits class for primitives.
Definition: pTraits.H:53
symmTypeOfRank< typename pTraits< arg1 >::cmptType, arg2 *direction(pTraits< arg1 >::rank) >::type type
Definition: products.H:136
Unit conversion structure. Contains the associated dimensions and the multiplier with which to conver...
A class for handling words, derived from string.
Definition: word.H:62
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:50
#define PRODUCT_OPERATOR(product, op, opFunc)
Direction is an 8-bit unsigned integer type used to represent the Cartesian directions etc.
Namespace for OpenFOAM.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
bool operator<(const instant &, const instant &)
Definition: instant.C:79
const dimensionSet dimless
void dot(FieldField< Field1, typename innerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
Istream & operator>>(Istream &, pistonPointEdgeData &)
dimensioned< scalar > mag(const dimensioned< Type > &)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
bool operator>(const instant &, const instant &)
Definition: instant.C:85
void dotdot(FieldField< Field1, typename scalarProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
tmp< fvMatrix< Type > > operator+(const fvMatrix< Type > &, const fvMatrix< Type > &)
void cross(FieldField< Field1, typename crossProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
tmp< fvMatrix< Type > > operator-(const fvMatrix< Type > &)
dimensioned< scalar > magSqr(const dimensioned< Type > &)
void outer(FieldField< Field1, typename outerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
uint8_t direction
Definition: direction.H:45