39 Foam::dimensionSet::tokeniser::tokeniser(
Istream& is)
50 void Foam::dimensionSet::tokeniser::push(
const token& t)
52 label end = (start_+size_)%tokens_.size();
54 if (size_ == tokens_.size())
56 start_ = tokens_.fcIndex(start_);
67 token t = tokens_[start_];
68 start_ = tokens_.fcIndex(start_);
74 void Foam::dimensionSet::tokeniser::unpop(
const token& t)
77 start_ = tokens_.rcIndex(start_);
82 bool Foam::dimensionSet::tokeniser::hasToken()
const
84 return size_ || is_.
good();
109 Foam::label Foam::dimensionSet::tokeniser::priority(
const token& t)
111 if (!t.isPunctuation())
123 else if (t.pToken() ==
'^')
134 void Foam::dimensionSet::tokeniser::splitWord(
const word& w)
137 for (
size_t i=0; i<w.size(); ++i)
143 word subWord = w(start, i-start);
146 push(token(
readScalar(IStringStream(subWord)())));
150 push(token(subWord));
157 push(token(
readScalar(IStringStream(w[i])())));
167 if (start < w.size())
169 word subWord = w(start, w.size()-start);
172 push(token(
readScalar(IStringStream(subWord)())));
176 push(token(subWord));
182 Foam::token Foam::dimensionSet::tokeniser::nextToken()
189 splitWord(t.wordToken());
204 void Foam::dimensionSet::tokeniser::putBack(
const token& t)
217 void Foam::dimensionSet::round(
const scalar tol)
222 scalar fractionalPart = std::modf(exponents_[i], &integralPart);
224 if (
mag(fractionalPart-1.0) <= tol)
226 exponents_[i] = 1.0+integralPart;
228 else if (
mag(fractionalPart+1.0) <= tol)
230 exponents_[i] = -1.0+integralPart;
232 else if (
mag(fractionalPart) <= tol)
234 exponents_[i] = integralPart;
242 const label lastPrior,
244 const HashTable<dimensionedScalar>& readSet
250 token nextToken(tis.nextToken());
254 bool haveReadSymbol =
false;
259 if (nextToken.isWord())
261 const word& unitName = nextToken.wordToken();
264 ds.value() *= unitDim.value();
265 haveReadSymbol =
true;
267 else if (nextToken.isNumber())
270 ds.value() *= nextToken.number();
271 haveReadSymbol =
true;
273 else if (nextToken.isPunctuation())
275 label nextPrior = tokeniser::priority(nextToken);
280 tis.putBack(nextToken);
285 tis.putBack(nextToken);
292 token t = tis.nextToken();
301 ds.dimensions() *= sub.dimensions();
302 ds.value() *= sub.value();
304 haveReadSymbol =
true;
308 tis.putBack(nextToken);
313 if (nextPrior > lastPrior)
317 ds.dimensions() *= sub.dimensions();
318 ds.value() *= sub.value();
323 tis.putBack(nextToken);
326 haveReadSymbol =
false;
330 if (nextPrior > lastPrior)
334 ds.dimensions() /= sub.dimensions();
335 ds.value() /= sub.value();
339 tis.putBack(nextToken);
342 haveReadSymbol =
false;
344 else if (nextToken.pToken() ==
'^')
346 if (nextPrior > lastPrior)
350 ds.dimensions().reset(
pow(ds.dimensions(),
exp.
value()));
352 ds.dimensions().round(10*smallExponent);
357 tis.putBack(nextToken);
360 haveReadSymbol =
false;
384 nextToken = tis.nextToken();
385 if (nextToken.error())
390 if (haveReadSymbol && (nextToken.isWord() || nextToken.isNumber()))
393 tis.putBack(nextToken);
412 token startToken(is);
420 <<
endl <<
"in stream " << is.
info()
435 multiplier = ds.
value();
447 is >> exponents_[Dimension];
476 <<
endl <<
"in stream " << is.
info()
481 is.
check(
"Istream& operator>>(Istream&, dimensionSet&)");
507 token startToken(is);
515 <<
endl <<
"in stream " << is.
info()
524 bool continueParsing =
true;
530 symbolPow = symbolPow(0, symbolPow.size()-1);
531 continueParsing =
false;
538 size_t index = symbolPow.find(
'^');
539 if (index != string::npos)
541 word symbol = symbolPow(0, index);
542 word exp = symbolPow(index+1, symbolPow.size()-index+1);
546 s.read(readSet[symbol], readSet);
548 symbolSet.
reset(
pow(
s.dimensions(), exponent));
550 symbolSet.round(10*smallExponent);
556 s.read(readSet[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);
586 is >> exponents_[Dimension];
615 <<
endl <<
"in stream " << is.
info()
621 is.
check(
"Istream& operator>>(Istream&, dimensionSet&)");
643 exponents[d] = exponents_[d];
647 bool hasPrinted =
false;
650 std::streamsize oldPrecision = os.
precision
652 std::numeric_limits<scalar>::digits10
657 if (
mag(exponents[i]) > smallExponent)
667 if (
mag(exponents[i]-1) > smallExponent)
669 os <<
'^' << exponents[i];
675 multiplier *= ds.
value();
695 os.
check(
"Ostream& operator<<(Ostream&, const dimensionSet&)");
722 dset.
read(is, multiplier);
727 <<
"Cannot use scaled units in dimensionSet"
732 is.
check(
"Istream& operator>>(Istream&, dimensionSet&)");
741 dset.
write(os, multiplier);
744 os.
check(
"Ostream& operator<<(Ostream&, const dimensionSet&)");
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
#define forAll(list, i)
Loop across all elements in list.
An STL-conforming hash table.
streamFormat format() const
Return current stream format.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
InfoProxy< IOstream > info() const
Return info proxy.
Input from memory buffer stream.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
void putBack(const token &)
Put back token.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
virtual int precision() const =0
Get precision of output field.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Dimension set for the base types.
dimensionSet(const scalar mass, const scalar length, const scalar time, const scalar temperature, const scalar moles, const scalar current, const scalar luminousIntensity)
Construct given individual dimension exponents for all.
Istream & read(Istream &is, scalar &multiplier, const dictionary &)
Read using provided units. Used only in initial parsing.
static const scalar smallExponent
void reset(const dimensionSet &)
Ostream & write(Ostream &os, scalar &multiplier, const dimensionSets &) const
Write using provided units.
void coefficients(scalarField &) const
(if valid) obtain set of coefficients of unitNames
bool valid() const
Is there a valid inverse of the selected unit.
const PtrList< dimensionedScalar > & units() const
Return the units.
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 token holds items read from Istream.
punctuationToken
Standard punctuation tokens.
const word & wordToken() const
A class for handling words, derived from string.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
bool valid(const PtrList< ModelType > &l)
const dimensionedScalar c
Speed of light in a vacuum.
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
errorManipArg< error, int > exit(error &err, const int errNo=1)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
dimensionedScalar exp(const dimensionedScalar &ds)
bool read(const char *, int32_t &)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Ostream & endl(Ostream &os)
Add newline and flush stream.
const HashTable< dimensionedScalar > & unitSet()
Set of all dimensions.
const dimensionSet dimless
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
const dimensionSets & writeUnitSet()
Set of units.
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
Istream & operator>>(Istream &, directionInfo &)
dimensioned< scalar > mag(const dimensioned< Type > &)
Ostream & operator<<(Ostream &, const ensightPart &)