Go to the documentation of this file.
39 const word& entryName,
46 this->readEntry(entryName,
dict, mandatory);
53 const word& entryName,
59 this->readEntry(entryName,
dict, mandatory);
69 Foam::dimensionSet::tokeniser::tokeniser(
Istream& is)
80 void Foam::dimensionSet::tokeniser::push(
const token& t)
82 const label
end = (start_+size_)%tokens_.size();
84 if (size_ == tokens_.size())
86 start_ = tokens_.fcIndex(start_);
97 token t = tokens_[start_];
98 start_ = tokens_.fcIndex(start_);
104 void Foam::dimensionSet::tokeniser::unpop(
const token& t)
107 start_ = tokens_.rcIndex(start_);
112 bool Foam::dimensionSet::tokeniser::hasToken()
const
114 return size_ || is_.
good();
118 bool Foam::dimensionSet::tokeniser::valid(
char c)
139 Foam::label Foam::dimensionSet::tokeniser::priority(
const token& t)
141 if (t.isPunctuation())
151 else if (t.pToken() ==
'^')
162 void Foam::dimensionSet::tokeniser::splitWord(
const word& w)
165 for (
size_t i=0; i<w.size(); ++i)
171 const word subWord = w.substr(start, i-start);
174 push(token(readScalar(subWord)));
178 push(token(subWord));
186 const scalar val = (w[i] -
'0');
197 if (start < w.size())
199 const word subWord = w.substr(start);
202 push(token(readScalar(subWord)));
206 push(token(subWord));
212 Foam::token Foam::dimensionSet::tokeniser::nextToken()
219 splitWord(t.wordToken());
234 void Foam::dimensionSet::tokeniser::putBack(
const token& t)
249 void Foam::dimensionSet::round(
const scalar tol)
252 for (scalar& val : exponents_)
254 const scalar fractionalPart = std::modf(val, &integralPart);
256 if (
mag(fractionalPart-1.0) <= tol)
258 val = 1.0+integralPart;
260 else if (
mag(fractionalPart+1.0) <= tol)
262 val = -1.0+integralPart;
264 else if (
mag(fractionalPart) <= tol)
274 const label lastPrior,
276 const HashTable<dimensionedScalar>& readSet
282 token nextToken(tis.nextToken());
286 bool haveReadSymbol =
false;
291 if (nextToken.isWord())
293 const word& unitName = nextToken.wordToken();
296 ds.value() *= unitDim.value();
297 haveReadSymbol =
true;
299 else if (nextToken.isNumber())
302 ds.value() *= nextToken.number();
303 haveReadSymbol =
true;
305 else if (nextToken.isPunctuation())
307 label nextPrior = tokeniser::priority(nextToken);
312 tis.putBack(nextToken);
317 tis.putBack(nextToken);
324 token t = tis.nextToken();
331 ds.dimensions() *= sub.dimensions();
332 ds.value() *= sub.value();
334 haveReadSymbol =
true;
338 tis.putBack(nextToken);
343 if (nextPrior > lastPrior)
347 ds.dimensions() *= sub.dimensions();
348 ds.value() *= sub.value();
353 tis.putBack(nextToken);
356 haveReadSymbol =
false;
360 if (nextPrior > lastPrior)
364 ds.dimensions() /= sub.dimensions();
365 ds.value() /= sub.value();
369 tis.putBack(nextToken);
372 haveReadSymbol =
false;
374 else if (nextToken.pToken() ==
'^')
376 if (nextPrior > lastPrior)
380 ds.dimensions().reset(
pow(ds.dimensions(),
expon.value()));
382 ds.dimensions().round(10*smallExponent);
387 tis.putBack(nextToken);
390 haveReadSymbol =
false;
410 nextToken = tis.nextToken();
411 if (nextToken.error())
416 if (haveReadSymbol && (nextToken.isWord() || nextToken.isNumber()))
419 tis.putBack(nextToken);
430 const word& entryName,
451 <<
"Entry '" << entryName <<
"' not found in dictionary "
470 token startToken(is);
476 <<
"in stream " << is.
info() <<
nl
491 multiplier = ds.
value();
527 <<
"in stream " << is.
info() <<
nl
557 token startToken(is);
563 <<
"in stream " << is.
info() <<
nl
572 bool continueParsing =
true;
578 symbolPow.resize(symbolPow.size()-1);
579 continueParsing =
false;
586 const auto index = symbolPow.find(
'^');
587 if (index != std::string::npos)
589 const word symbol = symbolPow.substr(0, index);
590 const scalar exponent = readScalar(symbolPow.substr(index+1));
595 symbolSet.
reset(
pow(
s.dimensions(), exponent));
598 symbolSet.round(10*smallExponent);
606 symbolSet.
reset(
s.dimensions());
607 multiplier *=
s.value();
613 exponents_[i] += symbolSet[i];
618 nextToken =
token(is);
622 continueParsing =
false;
626 while (continueParsing);
661 <<
"in stream " << is.
info() <<
nl
687 exponents[d] = exponents_[d];
691 bool hasPrinted =
false;
696 std::numeric_limits<scalar>::digits10
701 if (
mag(exponents[i]) > smallExponent)
711 if (
mag(exponents[i]-1) > smallExponent)
713 os <<
'^' << exponents[i];
719 multiplier *= ds.
value();
763 <<
"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.
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
bool readEntry(const word &entryName, const dictionary &dict, const bool mandatory=true)
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 isspace(char c) noexcept
Test for whitespace (C-locale)
static constexpr const zero Zero
Global zero (0)
static const scalar smallExponent
Tolerance for 'small' exponents, for near-zero rounding.
bool read(const char *buf, int32_t &val)
Same as readInt32.
bool valid() const noexcept
Is there a valid inverse of the selected unit.
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.
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
const HashTable< dimensionedScalar > & unitSet()
Set of all dimensions.
bool isWord() const noexcept
Token is word-variant (WORD, DIRECTIVE)
#define forAll(list, i)
Loop across all elements in list.
dimensionSet()
Default construct (dimensionless).
bool isNumber() const noexcept
Token is LABEL, FLOAT or DOUBLE.
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.
const PtrList< dimensionedScalar > & units() const noexcept
Return the units.
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)....
fileName relativeName(const bool caseTag=false) const
The dictionary name relative to the case.
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,...
End dimensions [isseparator].
OBJstream os(runTime.globalPath()/outputName)
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.
const FixedList< scalar, 7 > & values() const noexcept
Const access to the exponents as a list.
errorManipArg< error, int > exit(error &err, const int errNo=1)
A HashTable similar to std::unordered_map.
bool good() const noexcept
True if token is not UNDEFINED or ERROR.
virtual int precision() const
Get precision of output field.
Ostream & write(Ostream &os, scalar &multiplier, const dimensionSets &) const
Write using provided units.
void putBack(const token &tok)
Put back a token. Only a single put back is permitted.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
entry * findEntry(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
Find for an entry (non-const access) with the given keyword.
const dimensionedScalar e
Elementary charge.
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.
#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].
Construction of unit sets.
void reset(const dimensionSet &ds)
Copy assign the exponents from the dimensionSet.
punctuationToken
Standard punctuation tokens (a character)
const dimensionSet dimless
Dimensionless.