Loading...
Searching...
No Matches
dimensionSet.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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2017-2023 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::dimensionSet
29
30Description
31 Dimension set for the base types, which can be used to implement
32 rigorous dimension checking for algebraic manipulation.
33
34 The dimensions are specified in the following order
35 (SI units for reference only):
36 \table
37 Property | SI Description | SI unit
38 MASS | kilogram | \c kg
39 LENGTH | metre | \c m
40 TIME | second | \c s
41 TEMPERATURE | Kelvin | \c K
42 MOLES | mole | \c mol
43 CURRENT | Ampere | \c A
44 LUMINOUS_INTENSITY | Candela | \c cd
45 \endtable
46
47SourceFiles
48 dimensionSet.C
49 dimensionSetIO.C
50
51\*---------------------------------------------------------------------------*/
52
53#ifndef Foam_dimensionSet_H
54#define Foam_dimensionSet_H
55
56#include "bool.H"
58#include "className.H"
59#include "scalarField.H"
60#include "PtrList.H"
61#include "HashTable.H"
62#include "IOobjectOption.H"
63
64// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
65
66namespace Foam
67{
68
69// Forward Declarations
70class dictionary;
71class dimensionSet;
72class dimensionSets;
73
74/*---------------------------------------------------------------------------*\
75 Class dimensionSet Declaration
76\*---------------------------------------------------------------------------*/
77
78class dimensionSet
79{
80public:
81
82 //- The array of dimension exponents
83 typedef FixedList<scalar,7> list_type;
84
85
86 // Member Constants
87
88 //- There are 7 base dimensions
89 static constexpr int nDimensions = 7;
90
91 //- Enumeration for the dimension exponents
92 enum dimensionType
93 {
94 MASS,
95 LENGTH,
96 TIME,
98 MOLES,
99 CURRENT,
101 };
102
103
104 // Static Data Members
106 //- Tolerance for 'small' exponents, for near-zero rounding
107 static const scalar smallExponent;
108
109
110private:
111
112 // Private Data
113
114 //- The array of dimension exponents
115 list_type exponents_;
116
117
118 // Private Classes
119
120 class tokeniser
121 {
122 // Private Data
123
124 Istream& is_;
126 List<token> tokens_;
128 label start_;
130 label size_;
133 // Private Member Functions
134
135 void push(const token& t);
136
137 token pop();
138
139 void unpop(const token& t);
140
141 public:
143 // Constructors
144
145 explicit tokeniser(Istream& is);
146
147
148 // Member Functions
149
150 Istream& stream() noexcept { return is_; }
151
152 bool hasToken() const;
153
154 token nextToken();
155
156 void putBack(const token&);
157
158 void splitWord(const word&);
159
160 static bool valid(char c);
161
162 static label priority(const token& t);
163 };
164
165
166 //- Reset exponents to nearest integer if close to it.
167 // Handles reading with insufficient precision.
168 void round(const scalar tol);
169
171 (
172 const label lastPrior,
173 tokeniser& tis,
174 const HashTable<dimensionedScalar>&
175 ) const;
176
177
178public:
179
180 // Declare name of the class and its debug switch
181 ClassName("dimensionSet");
182
183
184 // Static Functions
185
186 //- Turn dimension checking on/off.
187 // \return the previous value
188 static bool checking(bool on) noexcept
189 {
190 bool old(debug);
191 debug = static_cast<int>(on);
192 return old;
193 }
194
195 //- True if dimension checking is enabled (the usual default)
196 static bool checking() noexcept
197 {
198 return static_cast<bool>(debug);
199 }
200
201
202 // Constructors
203
204 //- Default construct (dimensionless).
205 dimensionSet();
206
207 //- Construct from exponents for the first five or all seven dimensions
209 (
210 const scalar mass,
211 const scalar length,
212 const scalar time,
213 const scalar temperature,
214 const scalar moles,
215 const scalar current = 0,
216 const scalar luminousIntensity = 0
217 );
218
219 //- Construct from exponents for all seven dimensions
220 dimensionSet(const FixedList<scalar,7>& dimensions);
222 //- Copy construct
223 dimensionSet(const dimensionSet& ds);
224
225 //- Construct from dictionary entry (usually "dimensions")
226 // Dimensionless if non-mandatory and not found.
228 (
229 const word& entryName,
230 const dictionary& dict,
232 );
233
234 //- Construct and return a clone
236 {
237 return autoPtr<dimensionSet>::New(*this);
238 }
239
240 //- Construct from Istream
241 explicit dimensionSet(Istream& is);
242
243
244 // Member Functions
245
246 //- Return true if it is dimensionless
247 bool dimensionless() const;
248
249 //- Const access to the exponents as a list
250 const FixedList<scalar,7>& values() const noexcept;
251
252 //- Non-const access to the exponents as a list
253 FixedList<scalar,7>& values() noexcept;
254
255 //- Clear exponents - resets to be dimensionless
256 void clear();
257
258 //- Copy assign the exponents from the dimensionSet
259 void reset(const dimensionSet& ds);
260
261
262 // IO
263
264 //- Update the dimensions from dictionary entry.
265 //- FatalIOError if it is found and the number of tokens is incorrect,
266 //- or it is mandatory and not found.
267 //
268 // \return true if the entry was found.
269 bool readEntry
270 (
271 const word& entryName,
272 const dictionary& dict,
274 IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ
275 );
276
277 //- Update the dimensions from dictionary entry.
278 //- FatalIOError if it is found and the number of tokens is incorrect,
279 //- or it is mandatory and not found.
280 //
281 // \return true if the entry was found.
282 bool readIfPresent
283 (
284 const word& entryName,
285 const dictionary& dict
286 )
287 {
289 }
290
291 //- Read using provided units, return scaling in multiplier.
292 //- Used only in initial parsing
294 (
295 Istream& is,
296 scalar& multiplier,
297 const dictionary&
298 );
299
300 //- Read using provided units, return scaling in multiplier
302 (
303 Istream& is,
304 scalar& multiplier,
306 );
307
308 //- Read using system units, return scaling in multiplier
310 (
311 Istream& is,
312 scalar& multiplier
313 );
314
315 //- Write using provided write units, return scaling in multiplier
317 (
318 Ostream& os,
319 scalar& multiplier,
320 const dimensionSets& writeUnits
321 ) const;
322
323 //- Write using system units, return scaling in multiplier
324 Ostream& write(Ostream& os, scalar& multiplier) const;
325
326
327 // Member Operators
328
329 scalar operator[](const dimensionType) const;
330 scalar& operator[](const dimensionType);
331
332 scalar operator[](const int) const;
333 scalar& operator[](const int);
334
335 bool operator==(const dimensionSet&) const;
336 bool operator!=(const dimensionSet&) const;
337
338 //- Assignment operation, checks for identical dimensions.
339 //- Use reset() to change the dimensions.
340 bool operator=(const dimensionSet&) const;
341
342 //- Addition operation, checks for identical dimensions.
343 bool operator+=(const dimensionSet&) const;
344
345 //- Subtraction operation, checks for identical dimensions.
346 bool operator-=(const dimensionSet&) const;
347
348 //- Multiplication, modifies the exponents.
349 bool operator*=(const dimensionSet&);
350
351 //- Division, modifies the exponents.
352 bool operator/=(const dimensionSet&);
353};
354
355
356// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
357
358// IOstream Operators
359
362
363
364// Global Functions
365
366dimensionSet min(const dimensionSet& a, const dimensionSet& b);
367dimensionSet max(const dimensionSet& a, const dimensionSet& b);
370
371dimensionSet cmptMultiply(const dimensionSet& ds1, const dimensionSet& ds2);
372dimensionSet cmptDivide(const dimensionSet& ds1, const dimensionSet& ds2);
373
374
375dimensionSet pow(const dimensionSet& ds, const scalar p);
377
378dimensionSet sqr(const dimensionSet& ds);
385
388
390dimensionSet mag(const dimensionSet& ds);
398
399//- The dimensionSet inverted
400dimensionSet inv(const dimensionSet& ds);
401
402//- Check the argument is dimensionless (for transcendental functions)
404
405//- Arguments need the same dimensions. Return dimensionless.
406dimensionSet atan2(const dimensionSet& ds1, const dimensionSet& ds2);
407
408//- Arguments need the same dimensions. Does not change the dimension.
409dimensionSet hypot(const dimensionSet& ds1, const dimensionSet& ds2);
410
411//- Arguments need the same dimensions. Does not change the dimension.
412dimensionSet stabilise(const dimensionSet& ds1, const dimensionSet& ds2);
413
414//- Return the argument; transformations do not change the dimensions
416
417//- Return the argument; transformations do not change the dimensions
419
420
421// Global Operators
422
423//- The dimensionSet inverted
425
426//- Unary negation; does not change the dimensions
428
429dimensionSet operator+(const dimensionSet& ds1, const dimensionSet& ds2);
430dimensionSet operator-(const dimensionSet& ds1, const dimensionSet& ds2);
431dimensionSet operator*(const dimensionSet& ds1, const dimensionSet& ds2);
432dimensionSet operator/(const dimensionSet& ds1, const dimensionSet& ds2);
433dimensionSet operator&(const dimensionSet& ds1, const dimensionSet& ds2);
434dimensionSet operator^(const dimensionSet& ds1, const dimensionSet& ds2);
435dimensionSet operator&&(const dimensionSet& ds1, const dimensionSet& ds2);
436
437
438// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
439
440} // End namespace Foam
441
442// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
443
444// Predefined dimensions (eg, dimless, dimMass, dimLength, dimTime, ...)
445// and unit systems
446#include "dimensionSets.H"
447
448// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
449
450#endif
451
452// ************************************************************************* //
scalar range
System bool.
A 1D vector of objects of type <T> with a fixed length <N>.
Definition FixedList.H:73
A HashTable similar to std::unordered_map.
Definition HashTable.H:124
A simple container of IOobject preferences. Can also be used for general handling of read/no-read/rea...
readOption
Enumeration defining read preferences.
@ READ_IF_PRESENT
Reading is optional [identical to LAZY_READ].
@ MUST_READ
Reading required.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Definition autoPtr.H:178
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
bool operator+=(const dimensionSet &) const
Addition operation, checks for identical dimensions.
bool operator==(const dimensionSet &) const
static constexpr int nDimensions
There are 7 base dimensions.
bool operator!=(const dimensionSet &) const
Istream & read(Istream &is, scalar &multiplier, const dictionary &)
Read using provided units, return scaling in multiplier. Used only in initial parsing.
dimensionSet()
Default construct (dimensionless).
static bool checking(bool on) noexcept
Turn dimension checking on/off.
static bool checking() noexcept
True if dimension checking is enabled (the usual default).
bool readIfPresent(const word &entryName, const dictionary &dict)
Update the dimensions from dictionary entry. FatalIOError if it is found and the number of tokens is ...
FixedList< scalar, 7 > list_type
The array of dimension exponents.
bool readEntry(const word &entryName, const dictionary &dict, IOobjectOption::readOption readOpt=IOobjectOption::MUST_READ)
Update the dimensions from dictionary entry. FatalIOError if it is found and the number of tokens is ...
ClassName("dimensionSet")
bool operator/=(const dimensionSet &)
Division, modifies the exponents.
bool operator-=(const dimensionSet &) const
Subtraction operation, checks for identical dimensions.
scalar operator[](const dimensionType) const
const FixedList< scalar, 7 > & values() const noexcept
Const access to the exponents as a list.
static const scalar smallExponent
Tolerance for 'small' exponents, for near-zero rounding.
bool dimensionless() const
Return true if it is dimensionless.
void clear()
Clear exponents - resets to be dimensionless.
void reset(const dimensionSet &ds)
Copy assign the exponents from the dimensionSet.
dimensionType
Enumeration for the dimension exponents.
@ LUMINOUS_INTENSITY
Candela cd.
@ MASS
kilogram kg
@ TEMPERATURE
Kelvin K.
autoPtr< dimensionSet > clone() const
Construct and return a clone.
bool operator*=(const dimensionSet &)
Multiplication, modifies the exponents.
bool operator=(const dimensionSet &) const
Assignment operation, checks for identical dimensions. Use reset() to change the dimensions.
Construction of unit sets.
A token holds an item read from Istream.
Definition token.H:70
A class for handling words, derived from Foam::string.
Definition word.H:66
Macro definitions for declaring ClassName(), NamespaceName(), etc.
#define ClassName(TypeNameString)
Add typeName information from argument TypeNameString to a class.
Definition className.H:74
volScalarField & p
limits reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL))
Useful dimension sets.
OBJstream os(runTime.globalPath()/outputName)
surface1 clear()
Namespace for handling debugging switches.
Definition debug.C:45
int debug
Static debugging option.
Namespace for OpenFOAM.
tmp< faMatrix< Type > > operator-(const faMatrix< Type > &)
Unary negation.
bitSet operator~(const bitSet &bitset)
Bitset complement, returns a copy of the bitset with all its bits flipped.
Definition bitSetI.H:674
dimensionedScalar pow6(const dimensionedScalar &ds)
dimensionSet invTransform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
dimensionedScalar pos(const dimensionedScalar &ds)
dimensionedScalar pow5(const dimensionedScalar &ds)
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition hashSets.C:40
dimensionedScalar pos0(const dimensionedScalar &ds)
dimensionedScalar sign(const dimensionedScalar &ds)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
tmp< faMatrix< Type > > operator+(const faMatrix< Type > &, const faMatrix< Type > &)
dimensionedScalar pow3(const dimensionedScalar &ds)
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
refinementData transform(const tensor &, const refinementData val)
No-op rotational transform for base types.
dimensionSet clamp(const dimensionSet &a, const dimensionSet &range)
tmp< faMatrix< Type > > operator*(const areaScalarField::Internal &, const faMatrix< Type > &)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
bitSet operator^(const bitSet &a, const bitSet &b)
Bitwise-XOR of two bitsets to form a unique bit-set.
Definition bitSetI.H:702
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
dimensionedScalar operator/(const scalar s1, const dimensionedScalar &ds2)
dimensionedScalar atan2(const dimensionedScalar &x, const dimensionedScalar &y)
dimensionedScalar negPart(const dimensionedScalar &ds)
dimensionedScalar sqrt(const dimensionedScalar &ds)
tmp< GeometricField< Type, faPatchField, areaMesh > > operator&(const faMatrix< Type > &, const DimensionedField< Type, areaMesh > &)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Istream & operator>>(Istream &, directionInfo &)
dimensionedScalar hypot(const dimensionedScalar &x, const dimensionedScalar &y)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition hashSets.C:26
dimensionedScalar pow4(const dimensionedScalar &ds)
dimensionSet trans(const dimensionSet &ds)
Check the argument is dimensionless (for transcendental functions).
dimensionedScalar neg(const dimensionedScalar &ds)
dimensionedScalar stabilise(const dimensionedScalar &x, const dimensionedScalar &y)
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
const direction noexcept
Definition scalarImpl.H:265
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
dimensionedScalar neg0(const dimensionedScalar &ds)
dimensionedScalar cbrt(const dimensionedScalar &ds)
dimensioned< typename scalarProduct< Type1, Type2 >::type > operator&&(const dimensioned< Type1 > &, const dimensioned< Type2 > &)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
dimensionSet pow2(const dimensionSet &ds)
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
dimensionedScalar posPart(const dimensionedScalar &ds)
dimensioned< Type > lerp(const dimensioned< Type > &a, const dimensioned< Type > &b, const scalar t)
dimensionedScalar pow025(const dimensionedScalar &ds)
runTime write()
dictionary dict
volScalarField & b