Go to the documentation of this file.
53 Foam::dimensionSet::tokeniser::tokeniser(
Istream& is)
64 void Foam::dimensionSet::tokeniser::push(
const token& t)
66 const label
end = (start_+size_)%tokens_.size();
68 if (size_ == tokens_.size())
70 start_ = tokens_.fcIndex(start_);
81 token t = tokens_[start_];
82 start_ = tokens_.fcIndex(start_);
88 void Foam::dimensionSet::tokeniser::unpop(
const token& t)
91 start_ = tokens_.rcIndex(start_);
96 bool Foam::dimensionSet::tokeniser::hasToken()
const
98 return size_ || is_.
good();
102 bool Foam::dimensionSet::tokeniser::valid(
char c)
123 Foam::label Foam::dimensionSet::tokeniser::priority(
const token& t)
125 if (!t.isPunctuation())
137 else if (t.pToken() ==
'^')
148 void Foam::dimensionSet::tokeniser::splitWord(
const word& w)
151 for (
size_t i=0; i<w.size(); ++i)
157 const word subWord = w.substr(start, i-start);
160 push(token(readScalar(subWord)));
164 push(token(subWord));
172 const scalar val = (w[i] -
'0');
183 if (start < w.size())
185 const word subWord = w.substr(start);
188 push(token(readScalar(subWord)));
192 push(token(subWord));
198 Foam::token Foam::dimensionSet::tokeniser::nextToken()
205 splitWord(t.wordToken());
220 void Foam::dimensionSet::tokeniser::putBack(
const token& t)
233 void Foam::dimensionSet::round(
const scalar tol)
236 for (scalar& val : exponents_)
238 const scalar fractionalPart = std::modf(val, &integralPart);
240 if (
mag(fractionalPart-1.0) <= tol)
242 val = 1.0+integralPart;
244 else if (
mag(fractionalPart+1.0) <= tol)
246 val = -1.0+integralPart;
248 else if (
mag(fractionalPart) <= tol)
258 const label lastPrior,
260 const HashTable<dimensionedScalar>& readSet
266 token nextToken(tis.nextToken());
270 bool haveReadSymbol =
false;
275 if (nextToken.isWord())
277 const word& unitName = nextToken.wordToken();
280 ds.value() *= unitDim.value();
281 haveReadSymbol =
true;
283 else if (nextToken.isNumber())
286 ds.value() *= nextToken.number();
287 haveReadSymbol =
true;
289 else if (nextToken.isPunctuation())
291 label nextPrior = tokeniser::priority(nextToken);
296 tis.putBack(nextToken);
301 tis.putBack(nextToken);
308 token t = tis.nextToken();
315 ds.dimensions() *= sub.dimensions();
316 ds.value() *= sub.value();
318 haveReadSymbol =
true;
322 tis.putBack(nextToken);
327 if (nextPrior > lastPrior)
331 ds.dimensions() *= sub.dimensions();
332 ds.value() *= sub.value();
337 tis.putBack(nextToken);
340 haveReadSymbol =
false;
344 if (nextPrior > lastPrior)
348 ds.dimensions() /= sub.dimensions();
349 ds.value() /= sub.value();
353 tis.putBack(nextToken);
356 haveReadSymbol =
false;
358 else if (nextToken.pToken() ==
'^')
360 if (nextPrior > lastPrior)
364 ds.dimensions().reset(
pow(ds.dimensions(),
exp.
value()));
366 ds.dimensions().round(10*smallExponent);
371 tis.putBack(nextToken);
374 haveReadSymbol =
false;
394 nextToken = tis.nextToken();
395 if (nextToken.error())
400 if (haveReadSymbol && (nextToken.isWord() || nextToken.isNumber()))
403 tis.putBack(nextToken);
422 token startToken(is);
428 <<
"in stream " << is.
info() <<
nl
443 multiplier = ds.
value();
479 <<
"in stream " << is.
info() <<
nl
509 token startToken(is);
515 <<
"in stream " << is.
info() <<
nl
524 bool continueParsing =
true;
530 symbolPow.resize(symbolPow.size()-1);
531 continueParsing =
false;
538 const auto index = symbolPow.find(
'^');
539 if (index != std::string::npos)
541 const word symbol = symbolPow.substr(0, index);
542 const scalar exponent = readScalar(symbolPow.substr(index+1));
545 s.read(readSet.
lookup(symbol), readSet);
547 symbolSet.
reset(
pow(
s.dimensions(), exponent));
550 symbolSet.round(10*smallExponent);
556 s.read(readSet.
lookup(symbolPow), readSet);
558 symbolSet.
reset(
s.dimensions());
559 multiplier *=
s.value();
565 exponents_[i] += symbolSet[i];
570 nextToken =
token(is);
574 continueParsing =
false;
578 while (continueParsing);
613 <<
"in stream " << is.
info() <<
nl
639 exponents[d] = exponents_[d];
643 bool hasPrinted =
false;
646 std::streamsize oldPrecision = os.
precision
648 std::numeric_limits<scalar>::digits10
653 if (
mag(exponents[i]) > smallExponent)
663 if (
mag(exponents[i]-1) > smallExponent)
665 os <<
'^' << exponents[i];
671 multiplier *= ds.
value();
715 <<
"Cannot use scaled units in dimensionSet"
Subtract or start of negative number.
A keyword and a list of tokens is an 'entry'.
static constexpr int nDimensions
There are 7 base dimensions.
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Dimensionless.
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
A class for handling words, derived from Foam::string.
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
bool isNumber() const
Token is LABEL, FLOAT or DOUBLE.
static const scalar smallExponent
Tolerance for 'small' exponents, for near-zero rounding.
bool read(const char *buf, int32_t &val)
Same as readInt32.
streamFormat format() const noexcept
Get the current stream format.
const word & name() const
Return const reference to name.
Istream & operator>>(Istream &, directionInfo &)
A token holds an item read from Istream.
const Type & value() const
Return const reference to value.
dimensionedScalar exp(const dimensionedScalar &ds)
Dimension set for the base types.
const HashTable< dimensionedScalar > & unitSet()
Set of all dimensions.
bool good() const
True if token is not UNDEFINED or ERROR.
virtual int precision() const =0
Get precision of output field.
#define forAll(list, i)
Loop across all elements in list.
dimensionSet()
Construct null (dimensionless).
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Istream & read(Istream &is, scalar &multiplier, const dictionary &)
Read using provided units. Used only in initial parsing.
scalar number() const
Return label, float or double value.
An input stream of tokens.
Begin dimensions [isseparator].
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
const dimensionSets & writeUnitSet()
Set of units.
InfoProxy< IOstream > info() const
Return info proxy.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
void coefficients(scalarField &exponents) const
(if valid) obtain set of coefficients of unitNames
ITstream & lookup(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
virtual bool check(const char *operation) const
Check IOstream status for given operation.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
bool isWord() const
Token is WORD or DIRECTIVE word.
End dimensions [isseparator].
Generic dimensioned Type class.
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
const word & wordToken() const
Return const reference to the word contents.
errorManipArg< error, int > exit(error &err, const int errNo=1)
A HashTable similar to std::unordered_map.
Ostream & write(Ostream &os, scalar &multiplier, const dimensionSets &) const
Write using provided units.
const FixedList< scalar, 7 > & values() const
Return const access to the exponents as a list.
void putBack(const token &tok)
Put back token.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
const dimensionedScalar e
Elementary charge.
const PtrList< dimensionedScalar > & units() const
Return the units.
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
const dimensionedScalar c
Speed of light in a vacuum.
bool valid() const
Is there a valid inverse of the selected unit.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
const dimensionSet & dimensions() const
Return const reference to dimensions.
Begin list [isseparator].
bool isspace(char c)
Test for horizontal whitespace.
Construction of unit sets.
void reset(const dimensionSet &ds)
Copy assign the exponents from the dimensionSet.
punctuationToken
Standard punctuation tokens (a character)