39 const word& entryName,
46 readEntry(entryName,
dict, readOpt);
56 Foam::dimensionSet::tokeniser::tokeniser(Istream& is)
67 void Foam::dimensionSet::tokeniser::push(
const token& t)
69 const label
end = (start_+size_)%tokens_.size();
71 if (size_ == tokens_.size())
73 start_ = tokens_.fcIndex(start_);
84 token t = tokens_[start_];
85 start_ = tokens_.fcIndex(start_);
91 void Foam::dimensionSet::tokeniser::unpop(
const token& t)
94 start_ = tokens_.rcIndex(start_);
99 bool Foam::dimensionSet::tokeniser::hasToken()
const 101 return size_ || is_.
good();
105 bool Foam::dimensionSet::tokeniser::valid(
char c)
126 Foam::label Foam::dimensionSet::tokeniser::priority(
const token& t)
128 if (t.isPunctuation())
138 else if (t.pToken() ==
'^')
149 void Foam::dimensionSet::tokeniser::splitWord(
const word& w)
152 for (
size_t i=0; i<w.size(); ++i)
158 const word subWord = w.substr(start, i-start);
161 push(token(readScalar(subWord)));
165 push(token(subWord));
173 const scalar val = (w[i] -
'0');
184 if (start < w.size())
186 const word subWord = w.substr(start);
189 push(token(readScalar(subWord)));
193 push(token(subWord));
199 Foam::token Foam::dimensionSet::tokeniser::nextToken()
206 splitWord(t.wordToken());
221 void Foam::dimensionSet::tokeniser::putBack(
const token& t)
236 void Foam::dimensionSet::round(
const scalar tol)
239 for (scalar& val : exponents_)
241 const scalar fractionalPart = std::modf(val, &integralPart);
243 if (
mag(fractionalPart-1.0) <= tol)
245 val = 1.0+integralPart;
247 else if (
mag(fractionalPart+1.0) <= tol)
249 val = -1.0+integralPart;
251 else if (
mag(fractionalPart) <= tol)
261 const label lastPrior,
263 const HashTable<dimensionedScalar>& readSet
269 token nextToken(tis.nextToken());
273 bool haveReadSymbol =
false;
278 if (nextToken.isWord())
280 const word& unitName = nextToken.wordToken();
283 ds.value() *= unitDim.value();
284 haveReadSymbol =
true;
286 else if (nextToken.isNumber())
289 ds.value() *= nextToken.number();
290 haveReadSymbol =
true;
292 else if (nextToken.isPunctuation())
294 label nextPrior = tokeniser::priority(nextToken);
299 tis.putBack(nextToken);
304 tis.putBack(nextToken);
311 token t = tis.nextToken();
318 ds.dimensions() *= sub.dimensions();
319 ds.value() *= sub.value();
321 haveReadSymbol =
true;
325 tis.putBack(nextToken);
330 if (nextPrior > lastPrior)
334 ds.dimensions() *= sub.dimensions();
335 ds.value() *= sub.value();
340 tis.putBack(nextToken);
343 haveReadSymbol =
false;
347 if (nextPrior > lastPrior)
351 ds.dimensions() /= sub.dimensions();
352 ds.value() /= sub.value();
356 tis.putBack(nextToken);
359 haveReadSymbol =
false;
361 else if (nextToken.pToken() ==
'^')
363 if (nextPrior > lastPrior)
367 ds.dimensions().reset(
pow(ds.dimensions(),
expon.value()));
369 ds.dimensions().round(10*smallExponent);
374 tis.putBack(nextToken);
377 haveReadSymbol =
false;
397 nextToken = tis.nextToken();
398 if (nextToken.error())
403 if (haveReadSymbol && (nextToken.isWord() || nextToken.isNumber()))
406 tis.putBack(nextToken);
417 const word& entryName,
418 const dictionary&
dict,
431 const entry&
e = *eptr;
432 ITstream& is =
e.stream();
443 <<
"Entry '" << entryName <<
"' not found in dictionary " 456 const HashTable<dimensionedScalar>& readSet
462 token startToken(is);
468 <<
"in stream " << is.info() <<
nl 475 if (!nextToken.isNumber())
477 is.putBack(nextToken);
483 multiplier = ds.value();
484 exponents_ = ds.dimensions().values();
501 if (nextToken.isNumber())
519 <<
"in stream " << is.info() <<
nl 549 token startToken(is);
555 <<
"in stream " << is.
info() <<
nl 562 if (nextToken.isWord())
564 bool continueParsing =
true;
567 word symbolPow = nextToken.wordToken();
570 symbolPow.resize(symbolPow.size()-1);
571 continueParsing =
false;
576 dimensionSet symbolSet;
578 const auto index = symbolPow.find(
'^');
579 if (index != std::string::npos)
581 const word symbol = symbolPow.substr(0, index);
582 const scalar exponent = readScalar(symbolPow.substr(index+1));
587 symbolSet.reset(
pow(
s.dimensions(), exponent));
590 symbolSet.round(10*smallExponent);
598 symbolSet.reset(
s.dimensions());
599 multiplier *=
s.value();
605 exponents_[i] += symbolSet[i];
610 nextToken = token(is);
614 continueParsing =
false;
618 while (continueParsing);
635 if (nextToken.isNumber())
653 <<
"in stream " << is.
info() <<
nl 679 exponents[d] = exponents_[d];
683 bool hasPrinted =
false;
688 std::numeric_limits<scalar>::digits10
693 if (
mag(exponents[i]) > smallExponent)
703 if (
mag(exponents[i]-1) > smallExponent)
705 os <<
'^' << exponents[i];
711 multiplier *= ds.
value();
755 <<
"Cannot use scaled units in dimensionSet" bool good() const noexcept
True if token is not UNDEFINED or ERROR.
ITstream & lookup(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return an entry data stream. FatalIOError if not found, or not a stream. ...
const Type & value() const noexcept
Return const reference to value.
errorManipArg< error, int > exit(error &err, const int errNo=1)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
virtual int precision() const
Get precision of output field.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Begin dimensions [isseparator].
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
constexpr char nl
The newline '\n' character (0x0a)
A token holds an item read from Istream.
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 ...
static const scalar smallExponent
Tolerance for 'small' exponents, for near-zero rounding.
InfoProxy< IOstream > info() const noexcept
Return info proxy, used to print IOstream information to a stream.
void coefficients(scalarField &exponents) const
(if valid) obtain set of coefficients of unitNames
Begin list [isseparator].
Ostream & write(Ostream &os, scalar &multiplier, const dimensionSets &writeUnits) const
Write using provided write units, return scaling in multiplier.
Subtract or start of negative number.
const dimensionSet dimless
Dimensionless.
End dimensions [isseparator].
bool read(const char *buf, int32_t &val)
Same as readInt32.
#define forAll(list, i)
Loop across all elements in list.
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
const dimensionedScalar e
Elementary charge.
A class for handling words, derived from Foam::string.
Istream & operator>>(Istream &, directionInfo &)
dimensionSet()
Default construct (dimensionless).
punctuationToken
Standard punctuation tokens (a character)
const HashTable< dimensionedScalar > & unitSet()
Set of all dimensions.
const dimensionSet & dimensions() const noexcept
Return const reference to dimensions.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
OBJstream os(runTime.globalPath()/outputName)
bool isReadRequired() const noexcept
True if (MUST_READ | READ_MODIFIED) bits are set.
fileName relativeName(const bool caseTag=false) const
The dictionary name relative to the case.
const word & name() const noexcept
Return const reference to name.
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
const PtrList< dimensionedScalar > & units() const noexcept
Return the units.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
const dimensionedScalar c
Speed of light in a vacuum.
bool isspace(char c) noexcept
Test for whitespace (C-locale)
const entry * findEntry(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
static constexpr int nDimensions
There are 7 base dimensions.
const dimensionSets & writeUnitSet()
Set of units.
bool valid() const noexcept
Is there a valid inverse of the selected unit.
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))
streamFormat format() const noexcept
Get the current stream format.
Istream & read(Istream &is, scalar &multiplier, const dictionary &)
Read using provided units, return scaling in multiplier. Used only in initial parsing.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
static constexpr const zero Zero
Global zero (0)
Construction of unit sets.
readOption
Enumeration defining read preferences.