Base driver for parsing (field) values. More...
Public Member Functions | |
TypeName ("exprDriver") | |
Runtime type information. More... | |
exprDriver (bool cacheReadFields=false, bool searchInMemory=true, bool searchFiles=false, const dictionary &dict=dictionary::null) | |
Null constructor, and null construct with search preferences. More... | |
exprDriver (const exprDriver &) | |
Copy construct. More... | |
exprDriver (const dictionary &dict) | |
Construct from a dictionary. More... | |
virtual | ~exprDriver ()=default |
Destructor. More... | |
virtual label | size () const |
The underlying field size for the expression. More... | |
virtual label | pointSize () const |
The underlying point field size for the expression. More... | |
const dictionary & | dict () const |
The dictionary with all input data/specification. More... | |
virtual const exprResult & | result () const |
Const access to expression result. More... | |
virtual exprResult & | result () |
Non-const access to expression result. More... | |
void | clearResult () |
Clear the result. More... | |
template<class Type > | |
tmp< Field< Type > > | getResult (bool wantPointData=false) |
Return the expression result as a tmp field. More... | |
virtual word | getResultType () const |
The result type as word - same as result().valueType() More... | |
scalar | argValue () const |
Set special-purpose scalar reference argument. More... | |
int | stashedTokenId () const |
Get "look-behind" parsing context (internal bookkeeping) More... | |
int | resetStashedTokenId (int tokenId=0) const |
Reset "look-behind" parsing context (mutable operation) More... | |
void | setDebugging (bool scannerDebug, bool parserDebug) |
Set the scanner/parser debug. More... | |
void | setDebugging (const exprDriver &rhs) |
Set the scanner/parser debug to match the input. More... | |
void | setSearchBehaviour (bool cacheReadFields, bool searchInMemory, bool searchFiles) |
Set search behaviour. More... | |
void | setSearchBehaviour (const exprDriver &rhs) |
Set search behaviour to be identical to rhs. More... | |
bool | debugScanner () const |
Read access to scanner debug. More... | |
bool | debugParser () const |
Read access to parser debug. More... | |
bool | cacheReadFields () const |
bool | searchInMemory () const |
bool | searchFiles () const |
bool | prevIterIsOldTime () const |
virtual void | clearVariables () |
Clear temporary variables and resets from expression strings. More... | |
virtual void | setArgument (const scalar val) |
Set special-purpose scalar reference argument. More... | |
virtual bool | hasVariable (const word &name) const |
True if named variable exists. More... | |
virtual const exprResult & | variable (const word &name) const |
Return const-access to the named variable. More... | |
void | addVariables (const expressions::exprString &expr, bool clear=true) |
Add/set string expressions for variables. More... | |
void | addVariables (const UList< expressions::exprString > &list, bool clear=true) |
Add/set string expressions for variables. More... | |
template<class T > | |
void | addUniformVariable (const word &name, const T &val) |
Add a uniform variable from an outside caller. More... | |
template<class T > | |
bool | isLocalVariable (const word &name, bool wantPointData=false, label expectedSize=-1) const |
Test existence of a local variable. More... | |
template<class Type > | |
tmp< Field< Type > > | getLocalVariable (const word &name, label expectSize, const bool mandatory=true) const |
Retrieve local/global variable as a tmp field. More... | |
virtual unsigned | parse (const std::string &expr, size_t pos=0, size_t len=std::string::npos)=0 |
Execute the parser. More... | |
template<class Type > | |
tmp< Field< Type > > | evaluate (const expressions::exprString &expr, bool wantPointData=false) |
Evaluate the expression and return the field. More... | |
template<class Type > | |
Type | evaluateUniform (const expressions::exprString &expr, bool wantPointData=false) |
Evaluate the expression and return a single value. More... | |
void | evaluateVariable (const word &varName, const expressions::exprString &expr) |
virtual void | evaluateVariableRemote (string remote, const word &varName, const expressions::exprString &expr) |
template<class Type > | |
tmp< Field< Type > > | newField (const Type &val=pTraits< Type >::zero) const |
Return a new field with the size() More... | |
template<class Type > | |
tmp< Field< Type > > | newPointField (const Type &val=pTraits< Type >::zero) const |
Return a new field with the pointSize() More... | |
expressions::exprString | readExpression (const word &name) |
virtual bool | readDict (const dictionary &dict) |
Read variables, tables etc. More... | |
label | setVariableStrings (const dictionary &dict, bool mandatory=false) |
Read "variables" and assigns to the list of expression strings. More... | |
Ostream & | writeVariableStrings (Ostream &os, const word &keyword="") const |
Write "variables". More... | |
template<class Type > | |
void | addUniformVariable (const word &name, const Type &val) |
template<class Type > | |
Foam::tmp< Foam::Field< Type > > | evaluate (const expressions::exprString &expr, bool wantPointData) |
template<class Type > | |
Foam::tmp< Foam::Field< Type > > | getResult (bool wantPointData) |
template<class Type > | |
Foam::tmp< Foam::Field< Type > > | newField (const Type &val) const |
template<class Type > | |
Foam::tmp< Foam::Field< Type > > | newPointField (const Type &val) const |
Static Public Member Functions | |
static expressions::exprString | readExpression (const word &name, const dictionary &dict) |
Read an expression string and do substitutions. More... | |
static List< expressions::exprString > | readVariableStrings (const dictionary &dict, const word &name="variables", bool mandatory=false) |
Read the list of variable strings. More... | |
Protected Member Functions | |
virtual exprResult & | variable (const word &name) |
Non-const access to the named variable (sub-classes only) More... | |
void | fill_random (scalarField &field, label seed=0, const bool gaussian=false) const |
Fill a random field. More... | |
virtual bool | update () |
Update things. More... | |
virtual void | updateSpecialVariables (bool force=false) |
Examine current variable values and update stored variables. More... | |
virtual exprResult | getRemoteResult (const exprDriver &other) const |
Get the result from another driver. More... | |
void | operator= (const exprDriver &)=delete |
No copy assignment. More... | |
Static Protected Member Functions | |
template<typename TableType > | |
static bool | readTable (const word &name, const dictionary &dict, HashTable< TableType > &tbl, bool clear=true) |
Read an interpolation table. More... | |
template<class TableType > | |
static void | writeTable (Ostream &os, const word &name, const HashTable< TableType > &tbl) |
Write an interpolation table. More... | |
template<class Type > | |
static Type | weightedAverage (const scalarField &weights, const Field< Type > &fld) |
The (global) weighted average of a field, with stabilisation. More... | |
template<class Type > | |
static Type | weightedSum (const scalarField &weights, const Field< Type > &fld) |
The (global) weighted sum (integral) of a field. More... | |
static point | getPositionOfMinimum (const scalarField &vals, const pointField &locs) |
Return the location of the min value. More... | |
static point | getPositionOfMaximum (const scalarField &vals, const pointField &locs) |
Return the location of the max value. More... | |
Protected Attributes | |
const dictionary & | dict_ |
The dictionary with all input data/specification. More... | |
exprResult | result_ |
The result. More... | |
List< expressions::exprString > | variableStrings_ |
Variable definitions, as read from a dictionary. More... | |
HashTable< exprResult > | variables_ |
The variables table. More... | |
scalar | arg1Value_ |
Special-purpose scalar reference argument. More... | |
int | stashedTokenId_ |
Internal bookkeeping as "look-behind" parsing context. More... | |
bool | debugScanner_ |
Request debugging for scanner. More... | |
bool | debugParser_ |
Request debugging for parser. More... | |
bool | allowShadowing_ |
Allow variable names to mask field names. More... | |
bool | prevIterIsOldTime_ |
Use value of previous iteration when oldTime is requested. More... | |
bool | cacheReadFields_ |
Keep fields read from disc in memory. More... | |
bool | searchInMemory_ |
Search in registry before looking on disk. More... | |
bool | searchFiles_ |
Search on disk (eg, for a standalone application) More... | |
Base driver for parsing (field) values.
Largely based on code and ideas from swak4foam
Properties
Property | Description | Required | Default |
---|---|---|---|
variables | List of variables for expressions | no | () |
allowShadowing | Allow variables to shadow field names | no | false |
Debug Properties
Property | Description | Required | Default |
---|---|---|---|
debugBaseDriver | Debug level (int) for base driver | no | |
debugScanner | Add debug for scanner | no | false |
debugParser | Add debug for parser | no | false |
Definition at line 112 of file exprDriver.H.
|
explicit |
Null constructor, and null construct with search preferences.
Definition at line 84 of file exprDriver.C.
exprDriver | ( | const exprDriver & | rhs | ) |
Copy construct.
Definition at line 116 of file exprDriver.C.
|
explicit |
|
virtualdefault |
Destructor.
|
staticprotected |
Read an interpolation table.
Definition at line 33 of file exprDriverTemplates.C.
References clear(), HashTable< T, Key, Hash >::clear(), dict, Foam::input(), HashTable< T, Key, Hash >::insert(), and Foam::name().
|
staticprotected |
Write an interpolation table.
Definition at line 64 of file exprDriverTemplates.C.
References Ostream::beginBlock(), Ostream::endBlock(), forAllConstIters(), Foam::name(), Foam::nl, HashTable< T, Key, Hash >::size(), Ostream::write(), Ostream::writeEntry(), and Ostream::writeKeyword().
|
inlineprotectedvirtual |
Non-const access to the named variable (sub-classes only)
Reimplemented in fvExprDriver.
Definition at line 52 of file exprDriverI.H.
References Foam::name().
|
protected |
Fill a random field.
field | the field to populate |
seed | the seed value. |
gaussian | generate a Gaussian distribution |
Definition at line 35 of file exprDriverFields.C.
References Foam::FieldOps::assign(), and field().
|
staticprotected |
The (global) weighted average of a field, with stabilisation.
Referenced by parseDriver::areaAverage(), and parseDriver::volAverage().
|
staticprotected |
The (global) weighted sum (integral) of a field.
Referenced by parseDriver::areaSum(), and parseDriver::volSum().
|
staticprotected |
Return the location of the min value.
Definition at line 55 of file exprDriverFields.C.
References Foam::FieldOps::findMinData().
|
staticprotected |
Return the location of the max value.
Definition at line 65 of file exprDriverFields.C.
References Foam::FieldOps::findMaxData().
|
protectedvirtual |
Update things.
Definition at line 182 of file exprDriver.C.
Referenced by fvExprDriver::prepareData().
|
protectedvirtual |
Examine current variable values and update stored variables.
Reimplemented in fvExprDriver.
Definition at line 188 of file exprDriver.C.
|
protectedvirtual |
Get the result from another driver.
Override to allow mapping
Definition at line 242 of file exprDriver.C.
References exprResult::getUniform(), and exprDriver::result().
|
protecteddelete |
No copy assignment.
TypeName | ( | "exprDriver" | ) |
Runtime type information.
|
inlinevirtual |
The underlying field size for the expression.
Reimplemented in fvExprDriver, parseDriver, parseDriver, and parseDriver.
Definition at line 287 of file exprDriver.H.
|
inlinevirtual |
The underlying point field size for the expression.
Reimplemented in fvExprDriver, parseDriver, parseDriver, and parseDriver.
Definition at line 293 of file exprDriver.H.
|
inline |
The dictionary with all input data/specification.
Definition at line 299 of file exprDriver.H.
References exprDriver::dict_.
|
inlinevirtual |
Const access to expression result.
Definition at line 305 of file exprDriver.H.
References exprDriver::result_.
Referenced by Foam::stringOps::evaluate(), exprDriver::getRemoteResult(), and parseDriver::setResult().
|
inlinevirtual |
Non-const access to expression result.
Definition at line 311 of file exprDriver.H.
References exprDriver::result_.
void clearResult | ( | ) |
Clear the result.
Definition at line 176 of file exprDriver.C.
References exprResult::clear(), and exprDriver::result_.
Return the expression result as a tmp field.
|
inlinevirtual |
The result type as word - same as result().valueType()
Definition at line 324 of file exprDriver.H.
References exprDriver::result_, and exprResult::valueType().
Foam::scalar argValue | ( | ) | const |
Set special-purpose scalar reference argument.
Typically available as arg()
in an expression and may corrspond to table index, time value etc.
Definition at line 205 of file exprDriver.C.
|
inline |
Get "look-behind" parsing context (internal bookkeeping)
Definition at line 104 of file exprDriverI.H.
References exprDriver::stashedTokenId_.
|
inline |
Reset "look-behind" parsing context (mutable operation)
Definition at line 111 of file exprDriverI.H.
Set the scanner/parser debug.
Definition at line 366 of file exprDriver.C.
void setDebugging | ( | const exprDriver & | rhs | ) |
Set the scanner/parser debug to match the input.
Definition at line 377 of file exprDriver.C.
References exprDriver::debugParser_, and exprDriver::debugScanner_.
Set search behaviour.
Definition at line 387 of file exprDriver.C.
References Foam::Info, and Foam::nl.
Referenced by fvExprDriver::evaluateVariableRemote().
void setSearchBehaviour | ( | const exprDriver & | rhs | ) |
Set search behaviour to be identical to rhs.
Definition at line 405 of file exprDriver.C.
References exprDriver::cacheReadFields_, exprDriver::searchFiles_, and exprDriver::searchInMemory_.
|
inline |
Read access to scanner debug.
Definition at line 366 of file exprDriver.H.
References exprDriver::debugScanner_.
|
inline |
Read access to parser debug.
Definition at line 369 of file exprDriver.H.
References exprDriver::debugParser_.
|
inline |
Definition at line 371 of file exprDriver.H.
References exprDriver::cacheReadFields_.
|
inline |
Definition at line 372 of file exprDriver.H.
References exprDriver::searchInMemory_.
|
inline |
Definition at line 373 of file exprDriver.H.
References exprDriver::searchFiles_.
|
inline |
Definition at line 374 of file exprDriver.H.
References exprDriver::prevIterIsOldTime_.
|
virtual |
Clear temporary variables and resets from expression strings.
Reimplemented in fvExprDriver.
Definition at line 192 of file exprDriver.C.
|
virtual |
Set special-purpose scalar reference argument.
Typically available as arg()
in an expression and may corrspond to table index, time value etc.
Definition at line 199 of file exprDriver.C.
True if named variable exists.
Reimplemented in fvExprDriver.
Definition at line 32 of file exprDriverI.H.
References Foam::name().
|
inlinevirtual |
Return const-access to the named variable.
Reimplemented in fvExprDriver.
Definition at line 42 of file exprDriverI.H.
References Foam::name().
void addVariables | ( | const expressions::exprString & | expr, |
bool | clear = true |
||
) |
Add/set string expressions for variables.
Can include multiple definitions inline
clear | Remove previously defined variables |
Definition at line 252 of file exprDriver.C.
References clear(), Foam::exit(), Foam::FatalError, FatalErrorInFunction, Foam::FatalIOError, FatalIOErrorInFunction, Foam::stringOps::inplaceTrim(), Foam::nl, exprString::toExpr(), Foam::stringOps::trim(), and word::validate().
void addVariables | ( | const UList< expressions::exprString > & | list, |
bool | clear = true |
||
) |
Add/set string expressions for variables.
Can include multiple definitions inline
clear | Remove previously defined variables |
Definition at line 348 of file exprDriver.C.
References clear().
Add a uniform variable from an outside caller.
bool isLocalVariable | ( | const word & | name, |
bool | wantPointData = false , |
||
label | expectedSize = -1 |
||
) | const |
Test existence of a local variable.
Definition at line 167 of file exprDriverTemplates.C.
References Foam::expressions::patchExpr::debug, DebugInfo, Foam::endl(), Foam::Info, exprResult::isPointData(), exprResult::isType(), Foam::name(), Foam::reduce(), exprResult::size(), and exprResult::valueType().
tmp<Field<Type> > getLocalVariable | ( | const word & | name, |
label | expectSize, | ||
const bool | mandatory = true |
||
) | const |
Retrieve local/global variable as a tmp field.
name | The name of the local/global field |
expectSize | The size check on the variable, -1 to ignore |
mandatory | A missing variable is Fatal, or return an invalid tmp |
|
pure virtual |
Execute the parser.
The return value currently has no meaning.
Implemented in parseDriver, parseDriver, and parseDriver.
Referenced by fvExprDriver::evaluateVariableRemote().
|
inline |
Evaluate the expression and return the field.
|
inline |
Evaluate the expression and return a single value.
Definition at line 90 of file exprDriverI.H.
void evaluateVariable | ( | const word & | varName, |
const expressions::exprString & | expr | ||
) |
Evaluate the expression and save as the specified named variable
Definition at line 212 of file exprDriver.C.
References DebugInfo, and Foam::endl().
|
virtual |
Evaluate an expression on a remote and save as the specified named variable
Reimplemented in fvExprDriver.
Definition at line 230 of file exprDriver.C.
References NotImplemented.
Return a new field with the size()
Return a new field with the pointSize()
|
static |
Read an expression string and do substitutions.
Definition at line 75 of file exprDriverIO.C.
References dict, and Foam::name().
|
static |
Read the list of variable strings.
(or initialize with a single string)
Definition at line 96 of file exprDriverIO.C.
References dict, and Foam::exprTools::getList().
Foam::expressions::exprString readExpression | ( | const word & | name | ) |
Read an expression string (with the current dictionary) and do substitutions
Definition at line 86 of file exprDriverIO.C.
References dict, and Foam::name().
|
virtual |
Read variables, tables etc.
Also usable for objects not constructed from a dictionary.
Reimplemented in fvExprDriver, and parseDriver.
Definition at line 158 of file exprDriver.C.
References Foam::expressions::patchExpr::debug, and dict.
Referenced by fvExprDriver::readDict().
Foam::label setVariableStrings | ( | const dictionary & | dict, |
bool | mandatory = false |
||
) |
Read "variables" and assigns to the list of expression strings.
Definition at line 107 of file exprDriverIO.C.
References dict.
Foam::Ostream & writeVariableStrings | ( | Ostream & | os, |
const word & | keyword = "" |
||
) | const |
Write "variables".
Definition at line 119 of file exprDriverIO.C.
References Foam::nl, Ostream::writeKeyword(), and Foam::vtk::writeList().
|
inline |
Definition at line 62 of file exprDriverI.H.
References Foam::name(), and exprResult::setSingleValue().
Foam::tmp<Foam::Field<Type> > evaluate | ( | const expressions::exprString & | expr, |
bool | wantPointData | ||
) |
Definition at line 76 of file exprDriverI.H.
Foam::tmp<Foam::Field<Type> > getResult | ( | bool | wantPointData | ) |
Definition at line 148 of file exprDriverTemplates.C.
References Foam::exit(), Foam::FatalError, FatalErrorInFunction, exprResult::getResult(), exprResult::isPointData(), Foam::nl, and exprDriver::result_.
Foam::tmp<Foam::Field<Type> > newField | ( | const Type & | val | ) | const |
Definition at line 214 of file exprDriverTemplates.C.
References Foam::New().
Foam::tmp<Foam::Field<Type> > newPointField | ( | const Type & | val | ) | const |
Definition at line 225 of file exprDriverTemplates.C.
References Foam::New().
|
protected |
The dictionary with all input data/specification.
Definition at line 121 of file exprDriver.H.
Referenced by exprDriver::dict().
|
protected |
The result.
Definition at line 124 of file exprDriver.H.
Referenced by exprDriver::clearResult(), exprDriver::getResult(), exprDriver::getResultType(), and exprDriver::result().
|
protected |
Variable definitions, as read from a dictionary.
Definition at line 127 of file exprDriver.H.
|
protected |
The variables table.
Definition at line 130 of file exprDriver.H.
|
protected |
Special-purpose scalar reference argument.
Definition at line 133 of file exprDriver.H.
|
mutableprotected |
Internal bookkeeping as "look-behind" parsing context.
Definition at line 139 of file exprDriver.H.
Referenced by exprDriver::stashedTokenId().
|
protected |
Request debugging for scanner.
Definition at line 142 of file exprDriver.H.
Referenced by exprDriver::debugScanner(), and exprDriver::setDebugging().
|
protected |
Request debugging for parser.
Definition at line 145 of file exprDriver.H.
Referenced by exprDriver::debugParser(), and exprDriver::setDebugging().
|
protected |
Allow variable names to mask field names.
Definition at line 148 of file exprDriver.H.
|
protected |
Use value of previous iteration when oldTime is requested.
Definition at line 151 of file exprDriver.H.
Referenced by exprDriver::prevIterIsOldTime().
|
protected |
Keep fields read from disc in memory.
Definition at line 154 of file exprDriver.H.
Referenced by exprDriver::cacheReadFields(), and exprDriver::setSearchBehaviour().
|
protected |
Search in registry before looking on disk.
Definition at line 157 of file exprDriver.H.
Referenced by exprDriver::searchInMemory(), and exprDriver::setSearchBehaviour().
|
protected |
Search on disk (eg, for a standalone application)
Definition at line 160 of file exprDriver.H.
Referenced by exprDriver::searchFiles(), and exprDriver::setSearchBehaviour().