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-2026 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 #include "dictionary.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 // Forward declaration of friend functions and operators
50 class dictionary;
51 template<class Type>
52 class dimensioned;
53 template<class Type>
55 template<class Type>
57 
58 /*---------------------------------------------------------------------------*\
59  Class dimensioned Declaration
60 \*---------------------------------------------------------------------------*/
61 
62 template<class Type>
63 class dimensioned
64 {
65  // Private Data
66 
67  //- Variable name
68  word name_;
69 
70  //- The dimension set
71  dimensionSet dimensions_;
72 
73  //- The data value
74  Type value_;
75 
76 
77  // Private Member Functions
78 
79  //- Read the dimensions if present. Return whether dimensions were read.
80  bool readDimensions
81  (
82  Istream& is,
83  scalar& multiplier,
84  const bool haveDims
85  );
86 
87  //- Initialise from Istream
88  void initialise(Istream& is, const bool haveName, const bool haveDims);
89 
90  //- Initialise from Istream
91  void initialise
92  (
93  const word& name,
94  const unitSet& defaultUnits,
95  Istream& is
96  );
97 
98 
99 public:
100 
101  //- Component type
102  typedef typename pTraits<Type>::cmptType cmptType;
103 
104 
105  // Constructors
106 
107  //- Null constructor
108  dimensioned();
109 
110  //- Construct given name, dimensions and value
111  dimensioned(const word&, const dimensionSet&, const Type&);
112 
113  //- Construct given dimensions and value
114  // with the name obtained from the value
115  dimensioned(const dimensionSet&, const Type&);
116 
117  //- Construct dimensionless given value only
118  // with a name obtained from the value
119  dimensioned(const Type&);
120 
121  //- Construct from a dimensioned<Type> changing the name.
122  dimensioned(const word&, const dimensioned<Type>&);
123 
124  //- Construct from Istream.
126 
127  //- Construct from an Istream with a given name
128  dimensioned(const word&, Istream&);
129 
130  //- Construct from an Istream with a given name and dimensions
131  dimensioned(const word&, const dimensionSet&, Istream&);
132 
133  //- Construct from an Istream with a given name and units
134  dimensioned(const word&, const unitSet&, Istream&);
135 
136  //- Construct from dictionary lookup with a given name and dimensions
137  dimensioned(const word&, const dimensionSet&, const dictionary&);
138 
139  //- Construct from dictionary lookup with a given name and units
140  dimensioned(const word&, const unitSet&, const dictionary&);
141 
142  //- Construct from dictionary lookup with a given name and dimensions
143  // and if not found set to the given default value
145  (
146  const word& name,
147  const dimensionSet& dimensions,
148  const dictionary& dict,
149  const Type& defaultValue
150  );
151 
152  //- Construct from dictionary lookup with the given name, dimensionless,
153  // and if not found set to the given default value
155  (
156  const word& name,
157  const dictionary& dict,
158  const Type& defaultValue
159  );
160 
161  //- Construct from dictionary lookup with the given name and units
162  // and if not found set to the given default value
164  (
165  const word& name,
166  const unitSet&,
167  const dictionary&,
168  const Type& defaultValue
169  );
170 
171 
172  // Member Functions
173 
174  //- Return const reference to name.
175  const word& name() const;
176 
177  //- Return non-const reference to name.
178  word& name();
179 
180  //- Return const reference to dimensions.
181  const dimensionSet& dimensions() const;
182 
183  //- Return non-const reference to dimensions.
185 
186  //- Return const reference to value.
187  const Type& value() const;
188 
189  //- Return non-const reference to value.
190  Type& value();
191 
192  //- Return a component as a dimensioned<cmptType>
194 
195  //- Return a component with a dimensioned<cmptType>
196  void replace(const direction, const dimensioned<cmptType>&);
197 
198  //- Return transpose.
199  dimensioned<Type> T() const;
200 
201  //- Update the value of dimensioned<Type>
202  void read
203  (
204  const dictionary&,
205  const unitSet& defaultUnits = NullObjectRef<unitSet>()
206  );
207 
208  //- Update the value of dimensioned<Type> if found in the dictionary.
209  bool readIfPresent
210  (
211  const dictionary&,
212  const unitSet& defaultUnits = NullObjectRef<unitSet>()
213  );
214 
215  //- Update the value of dimensioned<Type> if found in the dictionary
216  // and if not found set to the given default value
217  void readOrDefault
218  (
219  const dictionary&,
220  const Type& defaultValue,
221  const unitSet& defaultUnits = NullObjectRef<unitSet>()
222  );
223 
224 
225  // Member Operators
226 
227  //- Return a component as a dimensioned<cmptType>
229 
230  void operator+=(const dimensioned<Type>&);
231  void operator-=(const dimensioned<Type>&);
232  void operator*=(const scalar);
233  void operator/=(const scalar);
234 
235 
236  // IOstream Operators
237 
238  friend Istream& operator>> <Type>(Istream&, dimensioned<Type>&);
239  friend Ostream& operator<< <Type>(Ostream&, const dimensioned<Type>&);
240 };
241 
242 
243 template<class Type>
244 void writeEntry(Ostream& os, const dimensioned<Type>& dt);
245 
246 
247 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
248 
249 template<class Type, direction r>
251 pow
252 (
253  const dimensioned<Type>&,
256 );
257 
258 template<class Type>
260 sqr(const dimensioned<Type>&);
261 
262 template<class Type>
264 
265 template<class Type>
267 
268 template<class Type>
270 (
271  const dimensioned<Type>&,
272  const dimensioned<Type>&
273 );
274 
275 template<class Type>
277 (
278  const dimensioned<Type>&,
279  const dimensioned<Type>&
280 );
281 
282 template<class Type>
284 
285 template<class Type>
287 
288 template<class Type>
289 bool operator>(const dimensioned<Type>&, const dimensioned<Type>&);
290 
291 template<class Type>
292 bool operator<(const dimensioned<Type>&, const dimensioned<Type>&);
293 
294 template<class Type>
296 
297 template<class Type>
299 
300 template<class Type>
302 
303 template<class Type>
304 dimensioned<Type> operator*
305 (
306  const dimensioned<scalar>&,
307  const dimensioned<Type>&
308 );
309 
310 template<class Type>
311 dimensioned<Type> operator/
312 (
313  const dimensioned<Type>&,
314  const dimensioned<scalar>&
315 );
316 
317 
318 #define PRODUCT_OPERATOR(product, op, opFunc) \
319  \
320 template<class Type1, class Type2> \
321 dimensioned<typename product<Type1, Type2>::type> \
322 operator op(const dimensioned<Type1>&, const dimensioned<Type2>&); \
323  \
324 template<class Type, class Form, class Cmpt, direction nCmpt> \
325 dimensioned<typename product<Type, Form>::type> \
326 operator op \
327 ( \
328  const dimensioned<Type>&, \
329  const VectorSpace<Form,Cmpt,nCmpt>& \
330 ); \
331  \
332 template<class Type, class Form, class Cmpt, direction nCmpt> \
333 dimensioned<typename product<Form, Type>::type> \
334 operator op \
335 ( \
336  const VectorSpace<Form,Cmpt,nCmpt>&, \
337  const dimensioned<Type>& \
338 );
339 
344 
345 #undef PRODUCT_OPERATOR
346 
347 
348 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
349 
350 } // End namespace Foam
351 
352 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
353 
354 #ifdef NoRepository
355  #include "dimensionedType.C"
356 #endif
357 
358 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
359 
360 #endif
361 
362 // ************************************************************************* //
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 keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Dimension set for the base types.
Definition: dimensionSet.H:125
Generic dimensioned Type class.
void operator+=(const dimensioned< Type > &)
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.
void read(const dictionary &, const unitSet &defaultUnits=NullObjectRef< unitSet >())
Update the value of dimensioned<Type>
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 > &)
dimensioned< cmptType > operator[](const direction) const
Return a component as a dimensioned<cmptType>
bool readIfPresent(const dictionary &, const unitSet &defaultUnits=NullObjectRef< unitSet >())
Update the value of dimensioned<Type> if found in the dictionary.
void readOrDefault(const dictionary &, const Type &defaultValue, const unitSet &defaultUnits=NullObjectRef< unitSet >())
Update the value of dimensioned<Type> if found in the dictionary.
const word & name() const
Return const reference to name.
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...
Definition: unitSet.H:68
A class for handling words, derived from string.
Definition: word.H:63
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.
Istream & operator>>(Istream &, pointEdgeDist &)
Definition: pointEdgeDist.C:41
void outer(GeometricField< typename outerProduct< Type1, Type2 >::type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type1, GeoMesh, PrimitiveField2 > &gf1, const GeometricField< Type2, GeoMesh, PrimitiveField3 > &gf2)
tmp< DimensionedField< Type, GeoMesh, Field > > cmptMultiply(const DimensionedField< Type, GeoMesh, PrimitiveField1 > &df1, const DimensionedField< Type, GeoMesh, PrimitiveField2 > &df2)
bool operator<(const instant &, const instant &)
Definition: instant.C:79
tmp< DimensionedField< typename typeOfSum< Type1, Type2 >::type, GeoMesh, Field > > operator+(const DimensionedField< Type1, GeoMesh, PrimitiveField1 > &df1, const DimensionedField< Type2, GeoMesh, PrimitiveField2 > &df2)
tmp< DimensionedField< typename outerProduct< Type, Type >::type, GeoMesh, Field >> sqr(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
tmp< DimensionedField< Type, GeoMesh, Field > > cmptDivide(const DimensionedField< Type, GeoMesh, PrimitiveField1 > &df1, const DimensionedField< Type, GeoMesh, PrimitiveField2 > &df2)
void dotdot(GeometricField< typename scalarProduct< Type1, Type2 >::type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type1, GeoMesh, PrimitiveField2 > &gf1, const GeometricField< Type2, GeoMesh, PrimitiveField3 > &gf2)
tmp< DimensionedField< Type, GeoMesh, Field > > operator-(const DimensionedField< Type, GeoMesh, PrimitiveField > &df1)
dimensioned< Type > min(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
void cross(GeometricField< typename crossProduct< Type1, Type2 >::type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type1, GeoMesh, PrimitiveField2 > &gf1, const GeometricField< Type2, GeoMesh, PrimitiveField3 > &gf2)
bool operator>(const instant &, const instant &)
Definition: instant.C:85
tmp< DimensionedField< typename powProduct< Type, r >::type, GeoMesh, Field > > pow(const DimensionedField< Type, GeoMesh, PrimitiveField > &df, typename powProduct< Type, r >::type)
tmp< DimensionedField< scalar, GeoMesh, Field > > mag(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
tmp< DimensionedField< scalar, GeoMesh, Field > > magSqr(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
void writeEntry(Ostream &os, const word &key, const DimensionedFieldFunction< DimensionedFieldType > &f)
uint8_t direction
Definition: direction.H:45
dimensioned< Type > max(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
void dot(GeometricField< typename innerProduct< Type1, Type2 >::type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type1, GeoMesh, PrimitiveField2 > &gf1, const GeometricField< Type2, GeoMesh, PrimitiveField3 > &gf2)
dictionary dict