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();
88 bool Foam::dimensionSet::tokeniser::valid(
char c)
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);
150 push(
token(subWord));
167 if (start < w.size())
169 word subWord = w(start, w.size()-start);
176 push(
token(subWord));
182 Foam::token Foam::dimensionSet::tokeniser::nextToken()
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,
250 token nextToken(tis.nextToken());
254 bool haveReadSymbol =
false;
259 if (nextToken.isWord())
261 const word& unitName = nextToken.wordToken();
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();
304 haveReadSymbol =
true;
308 tis.putBack(nextToken);
313 if (nextPrior > lastPrior)
323 tis.putBack(nextToken);
326 haveReadSymbol =
false;
330 if (nextPrior > lastPrior)
339 tis.putBack(nextToken);
342 haveReadSymbol =
false;
344 else if (nextToken.pToken() ==
'^')
346 if (nextPrior > lastPrior)
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);
556 s.
read(readSet[symbolPow], readSet);
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
669 os <<
'^' << exponents[i];
675 multiplier *= ds.
value();
689 os << exponents_[dimensionSet::nDimensions-1];
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&)");
#define forAll(list, i)
Loop across all elements in list.
punctuationToken pToken() const
friend dimensionSet pow(const dimensionSet &, const scalar)
errorManipArg< error, int > exit(error &err, const int errNo=1)
A list of keyword definitions, which are a keyword followed by any number of values (e...
virtual bool check(const char *operation) const
Check IOstream status for given operation.
friend dimensionSet mag(const dimensionSet &)
const word & wordToken() const
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
A token holds items read from Istream.
void putBack(const token &)
Put back token.
Ostream & endl(Ostream &os)
Add newline and flush stream.
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.
const dimensionSet dimless
Ostream & write(Ostream &os, scalar &multiplier, const dimensionSets &) const
Write using provided units.
const dimensionedScalar c
Speed of light in a vacuum.
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
const HashTable< dimensionedScalar > & unitSet()
Set of all dimensions.
Dimension set for the base types.
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.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
dimensionedScalar exp(const dimensionedScalar &ds)
void read(const dictionary &)
Update the value of dimensioned<Type>
A class for handling words, derived from string.
Istream & operator>>(Istream &, directionInfo &)
const PtrList< dimensionedScalar > & units() const
Return the units.
const Type & value() const
Return const reference to value.
punctuationToken
Standard punctuation tokens.
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
streamFormat format() const
Return current stream format.
An STL-conforming hash table.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
const word & name() const
Return const reference to name.
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
void reset(const dimensionSet &)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Input from memory buffer stream.
Ostream & operator<<(Ostream &, const ensightPart &)
const dimensionSet & dimensions() const
Return const reference to dimensions.
const dimensionSets & writeUnitSet()
Set of units.
static const scalar smallExponent
void coefficients(scalarField &) const
(if valid) obtain set of coefficients of unitNames
bool isPunctuation() const
InfoProxy< IOstream > info() const
Return info proxy.
Istream & read(Istream &is, scalar &multiplier, const dictionary &)
Read using provided units. Used only in initial parsing.
bool valid() const
Is there a valid inverse of the selected unit.
virtual int precision() const =0
Get precision of output field.