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 #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 unitConversion& 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 unitConversion&, 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 unitConversion&, 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  const bool writeDefault = dictionary::writeOptionalEntries > 0
151  );
152 
153  //- Construct from dictionary lookup with the given name, dimensionless,
154  // and if not found set to the given default value
156  (
157  const word& name,
158  const dictionary& dict,
159  const Type& defaultValue,
160  const bool writeDefault = dictionary::writeOptionalEntries > 0
161  );
162 
163  //- Construct from dictionary lookup with the given name and units
164  // and if not found set to the given default value
166  (
167  const word& name,
168  const unitConversion&,
169  const dictionary&,
170  const Type& defaultValue,
171  const bool writeDefault = dictionary::writeOptionalEntries > 0
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
206  (
207  const dictionary&,
208  const unitConversion& defaultUnits = NullObjectRef<unitConversion>()
209  );
210 
211  //- Update the value of dimensioned<Type> if found in the dictionary.
212  bool readIfPresent
213  (
214  const dictionary&,
215  const unitConversion& defaultUnits = NullObjectRef<unitConversion>()
216  );
217 
218 
219  // Member Operators
220 
221  //- Return a component as a dimensioned<cmptType>
223 
224  void operator+=(const dimensioned<Type>&);
225  void operator-=(const dimensioned<Type>&);
226  void operator*=(const scalar);
227  void operator/=(const scalar);
228 
229 
230  // IOstream Operators
231 
232  friend Istream& operator>> <Type>(Istream&, dimensioned<Type>&);
233  friend Ostream& operator<< <Type>(Ostream&, const dimensioned<Type>&);
234 };
235 
236 
237 template<class Type>
238 void writeEntry(Ostream& os, const dimensioned<Type>& dt);
239 
240 
241 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
242 
243 template<class Type, direction r>
245 pow
246 (
247  const dimensioned<Type>&,
250 );
251 
252 template<class Type>
254 sqr(const dimensioned<Type>&);
255 
256 template<class Type>
258 
259 template<class Type>
261 
262 template<class Type>
264 (
265  const dimensioned<Type>&,
266  const dimensioned<Type>&
267 );
268 
269 template<class Type>
271 (
272  const dimensioned<Type>&,
273  const dimensioned<Type>&
274 );
275 
276 template<class Type>
278 
279 template<class Type>
281 
282 template<class Type>
283 bool operator>(const dimensioned<Type>&, const dimensioned<Type>&);
284 
285 template<class Type>
286 bool operator<(const dimensioned<Type>&, const dimensioned<Type>&);
287 
288 template<class Type>
290 
291 template<class Type>
293 
294 template<class Type>
296 
297 template<class Type>
298 dimensioned<Type> operator*
299 (
300  const dimensioned<scalar>&,
301  const dimensioned<Type>&
302 );
303 
304 template<class Type>
305 dimensioned<Type> operator/
306 (
307  const dimensioned<Type>&,
308  const dimensioned<scalar>&
309 );
310 
311 
312 #define PRODUCT_OPERATOR(product, op, opFunc) \
313  \
314 template<class Type1, class Type2> \
315 dimensioned<typename product<Type1, Type2>::type> \
316 operator op(const dimensioned<Type1>&, const dimensioned<Type2>&); \
317  \
318 template<class Type, class Form, class Cmpt, direction nCmpt> \
319 dimensioned<typename product<Type, Form>::type> \
320 operator op \
321 ( \
322  const dimensioned<Type>&, \
323  const VectorSpace<Form,Cmpt,nCmpt>& \
324 ); \
325  \
326 template<class Type, class Form, class Cmpt, direction nCmpt> \
327 dimensioned<typename product<Form, Type>::type> \
328 operator op \
329 ( \
330  const VectorSpace<Form,Cmpt,nCmpt>&, \
331  const dimensioned<Type>& \
332 );
333 
338 
339 #undef PRODUCT_OPERATOR
340 
341 
342 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
343 
344 } // End namespace Foam
345 
346 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
347 
348 #ifdef NoRepository
349  #include "dimensionedType.C"
350 #endif
351 
352 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
353 
354 #endif
355 
356 // ************************************************************************* //
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
static int writeOptionalEntries
If true write optional keywords and values.
Definition: dictionary.H:277
Dimension set for the base types.
Definition: dimensionSet.H:125
Generic dimensioned Type class.
void operator+=(const dimensioned< Type > &)
void read(const dictionary &, const unitConversion &defaultUnits=NullObjectRef< unitConversion >())
Update the value of 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.
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>
const word & name() const
Return const reference to name.
bool readIfPresent(const dictionary &, const unitConversion &defaultUnits=NullObjectRef< unitConversion >())
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.
void dot(LagrangianPatchField< typename innerProduct< Type1, Type2 >::type > &f, const LagrangianPatchField< Type1 > &f1, const LagrangianPatchField< Type2 > &f2)
void cmptMultiply(LagrangianPatchField< Type > &f, const LagrangianPatchField< Type > &f1, const LagrangianPatchField< Type > &f2)
void outer(LagrangianPatchField< typename outerProduct< Type1, Type2 >::type > &f, const LagrangianPatchField< Type1 > &f1, const LagrangianPatchField< Type2 > &f2)
void dotdot(LagrangianPatchField< typename scalarProduct< Type1, Type2 >::type > &f, const LagrangianPatchField< Type1 > &f1, const LagrangianPatchField< Type2 > &f2)
void cmptDivide(LagrangianPatchField< Type > &f, const LagrangianPatchField< Type > &f1, const LagrangianPatchField< Type > &f2)
bool operator<(const instant &, const instant &)
Definition: instant.C:79
void cross(LagrangianPatchField< typename crossProduct< Type1, Type2 >::type > &f, const LagrangianPatchField< Type1 > &f1, const LagrangianPatchField< Type2 > &f2)
void mag(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
void pow(LagrangianPatchField< typename powProduct< Type, r >::type > &f, const LagrangianPatchField< Type > &f1)
Istream & operator>>(Istream &, pistonPointEdgeData &)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
void sqr(LagrangianPatchField< typename outerProduct< Type, Type >::type > &f, const LagrangianPatchField< Type > &f1)
bool operator>(const instant &, const instant &)
Definition: instant.C:85
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
tmp< fvMatrix< Type > > operator+(const fvMatrix< Type > &, const fvMatrix< Type > &)
void magSqr(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
tmp< fvMatrix< Type > > operator-(const fvMatrix< Type > &)
uint8_t direction
Definition: direction.H:45
dictionary dict