39 const word& entryName,
53 const word& entryName,
69Foam::dimensionSet::tokeniser::tokeniser(
Istream& is)
80void 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_);
104void Foam::dimensionSet::tokeniser::unpop(
const token& t)
107 start_ = tokens_.rcIndex(start_);
112bool Foam::dimensionSet::tokeniser::hasToken()
const
114 return size_ || is_.
good();
141 if (t.isPunctuation())
151 else if (t.pToken() ==
'^')
162void 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));
212Foam::token Foam::dimensionSet::tokeniser::nextToken()
219 splitWord(t.wordToken());
234void Foam::dimensionSet::tokeniser::putBack(
const token& t)
249void 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"
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
A HashTable similar to std::unordered_map.
streamFormat format() const noexcept
Get the current stream format.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
InfoProxy< IOstream > info() const
Return info proxy.
An input stream of tokens.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
void putBack(const token &tok)
Put back a token. Only a single put back is permitted.
virtual int precision() const
Get precision of output field.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
virtual bool read()
Re-read model coefficients if they have changed.
bool valid() const
True if all internal ids are non-negative.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
fileName relativeName(const bool caseTag=false) const
The dictionary name relative to the case.
entry * findEntry(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
Find for an entry (non-const access) with the given keyword.
ITstream & lookup(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
static constexpr int nDimensions
There are 7 base dimensions.
Istream & read(Istream &is, scalar &multiplier, const dictionary &)
Read using provided units. Used only in initial parsing.
dimensionSet()
Default construct (dimensionless).
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.
void reset(const dimensionSet &ds)
Copy assign the exponents from the dimensionSet.
@ LUMINOUS_INTENSITY
Candela cd.
bool readEntry(const word &entryName, const dictionary &dict, const bool mandatory=true)
Ostream & write(Ostream &os, scalar &multiplier, const dimensionSets &) const
Write using provided units.
Construction of unit sets.
const PtrList< dimensionedScalar > & units() const noexcept
Return the units.
void coefficients(scalarField &exponents) const
(if valid) obtain set of coefficients of unitNames
bool valid() const noexcept
Is there a valid inverse of the selected unit.
const dimensionSet & dimensions() const
Return const reference to dimensions.
const Type & value() const
Return const reference to value.
const word & name() const
Return const reference to name.
A keyword and a list of tokens is an 'entry'.
virtual bool write()
Write the output fields.
A token holds an item read from Istream.
bool isNumber() const noexcept
Token is LABEL, FLOAT or DOUBLE.
punctuationToken
Standard punctuation tokens (a character)
@ DIVIDE
Divide [isseparator].
@ BEGIN_SQR
Begin dimensions [isseparator].
@ BEGIN_LIST
Begin list [isseparator].
@ SUBTRACT
Subtract or start of negative number.
@ END_LIST
End list [isseparator].
@ END_SQR
End dimensions [isseparator].
@ MULTIPLY
Multiply [isseparator].
bool good() const noexcept
True if token is not UNDEFINED or ERROR.
const word & wordToken() const
Return const reference to the word contents.
bool isWord() const noexcept
Token is word-variant (WORD, DIRECTIVE)
scalar number() const
Return label, float or double value.
A class for handling words, derived from Foam::string.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
OBJstream os(runTime.globalPath()/outputName)
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))
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
const dimensionSet dimless
Dimensionless.
bool read(const char *buf, int32_t &val)
Same as readInt32.
bool isspace(char c) noexcept
Test for whitespace (C-locale)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
const HashTable< dimensionedScalar > & unitSet()
Set of all dimensions.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Istream & operator>>(Istream &, directionInfo &)
const dimensionSets & writeUnitSet()
Set of units.
static constexpr const zero Zero
Global zero (0)
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a)
#define forAll(list, i)
Loop across all elements in list.