49int Foam::expressions::exprDriver::getSearchControls(
const dictionary&
dict)
53 if (
dict.getOrDefault(
"searchInMemory",
true))
57 if (
dict.getOrDefault(
"searchFiles",
false))
61 if (
dict.getOrDefault(
"cacheReadFields",
false))
75static string getEntryString
86 <<
"Entry " <<
key <<
" not found in "
90 else if (eptr->isDict())
93 <<
"Entry " <<
key <<
" found in "
106 HashTable<refPtr<Function1<Type>>>& dest,
107 const HashTable<refPtr<Function1<Type>>>&
rhs
113 const word& key = iter.key();
115 if (!dest.found(key))
117 refPtr<Function1<Type>> func;
118 func.cref(iter.val().shallowClone());
120 dest.emplace_set(key, std::move(func));
148 auto& funcPtr = iter.val();
149 if (funcPtr && !funcPtr.is_const())
151 (*funcPtr).resetDb(obrPtr_);
156 auto& funcPtr = iter.val();
157 if (funcPtr && !funcPtr.is_const())
175 enum searchControls
search,
187 timeStatePtr_(nullptr),
192 debugScanner_(
dict.getOrDefault(
"debug.scanner", false)),
207 result_(
rhs.result_),
208 variableStrings_(
rhs.variableStrings_),
209 variables_(
rhs.variables_),
212 contextObjects_(
rhs.contextObjects_),
213 arg1Value_(
rhs.arg1Value_),
214 timeStatePtr_(
rhs.timeStatePtr_),
215 obrPtr_(
rhs.obrPtr_),
219 debugScanner_(
rhs.debugScanner_),
220 debugParser_(
rhs.debugParser_),
221 allowShadowing_(
rhs.allowShadowing_),
222 prevIterIsOldTime_(
rhs.prevIterIsOldTime_),
224 searchCtrl_(
rhs.searchCtrl_)
229 resetFunctions(
dict_);
258 return timeStatePtr_;
272 return timeStatePtr_->value();
276 return obrPtr_->time().value();
286 return timeStatePtr_->deltaTValue();
290 return obrPtr_->time().deltaTValue();
301 dict.readIfPresent(
"debug.driver",
debug);
304 variableStrings_ = readVariableStrings(
dict,
"variables",
false);
307 resetFunctions(
dict);
345 result_.testIfSingleValue();
348 <<
"Evaluating: " << expr <<
" -> " << varName <<
endl
392 for (
const auto& subMatch : varExpressions)
405 const auto eqPos = varExpr.find(
'=');
407 if (eqPos == std::string::npos)
410 <<
"No '=' found in expression " << varExpr <<
nl <<
nl
415 expressions::exprString rhsExpr
424 varExpr.resize(eqPos);
428 const auto lbrace = varExpr.find(
'{');
430 if (lbrace != std::string::npos)
432 const auto rbrace = varExpr.find(
'}');
434 if (rbrace == std::string::npos || rbrace < lbrace)
438 <<
"No closing '}' found in " << varExpr <<
nl
441 else if (lbrace+1 == rbrace)
445 <<
"Empty '{}' location in " << varExpr <<
nl
451 const expressions::exprString remoteExpr
455 varExpr.substr(lbrace+1, rbrace-lbrace-1)
461 evaluateVariableRemote(remoteExpr, varName, rhsExpr);
475 const UList<expressions::exprString>& list,
484 for (
const auto& expr : list)
514 int val(searchCtrl_);
515 bool old = (val & searchControls::CACHE_READ_FIELDS);
520 val &= ~(searchControls::CACHE_READ_FIELDS);
528 searchControls::SEARCH_REGISTRY
529 | searchControls::SEARCH_FILES
530 | searchControls::CACHE_READ_FIELDS
542 enum searchControls
search,
547 if (caching || (val & searchControls::CACHE_READ_FIELDS))
552 searchControls::SEARCH_REGISTRY
553 | searchControls::SEARCH_FILES
554 | searchControls::CACHE_READ_FIELDS
557 searchCtrl_ = searchControls(val);
573 searchCtrl_ =
rhs.searchCtrl_;
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
A HashTable similar to std::unordered_map.
The time value with time-stepping information, user-defined remapping, etc.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
const fileName & name() const noexcept
The dictionary name.
const entry * findEntry(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
A keyword and a list of tokens is an 'entry'.
static string evaluate(const entry &e)
Generic concatenate tokens to space-separated string.
Base driver for parsing (field) values.
virtual label size() const
The natural field size for the expression.
bool searchFiles() const noexcept
bool cacheReadFields() const noexcept
exprResult result_
The result.
virtual void updateSpecialVariables(bool force=false)
Examine current variable values and update stored variables.
void clearResult()
Clear the result.
void addVariables(const expressions::exprString &expr, bool clear=true)
Add/set string expressions for variables.
const TimeState * timeState() const noexcept
Reference to the current time-state (can be nullptr).
void resetDb(const objectRegistry *obrPtr=nullptr)
Reset the objectRegistry (for functions).
bool searchRegistry() const noexcept
exprDriver(const exprDriver &)=delete
No copy construct.
HashTable< refPtr< Function1< scalar > > > scalarFuncs_
Function1 mappings/timelines (scalar), evaluated at the simulation time or with arbitrary scalars.
bool debugParser_
Request debugging for parser.
HashTable< refPtr< Function1< vector > > > vectorFuncs_
Function1 mappings/timelines (vector), evaluated at the simulation time or with arbitrary scalars.
bool allowShadowing_
Allow variable names to mask field names.
searchControls
Search/caching controls.
@ SEARCH_REGISTRY
Search registry before disk.
@ SEARCH_FILES
Search disk (eg, standalone app).
@ CACHE_READ_FIELDS
Cache fields read from disk.
virtual void evaluateVariableRemote(string remote, const word &varName, const expressions::exprString &expr)
Evaluate an expression on a remote and save as the specified named variable.
bool prevIterIsOldTime_
Use value of previous iteration when oldTime is requested.
bool debugScanner_
Request debugging for scanner.
virtual bool readDict(const dictionary &dict)
Read variables, tables etc.
List< expressions::exprString > variableStrings_
Variable definitions, as read from a dictionary.
virtual scalar deltaT() const
The current deltaT value.
const objectRegistry * obrPtr_
Pointer to an object registry (for functions etc).
const TimeState * timeStatePtr_
Reference to the time-state.
const dictionary & dict_
The dictionary with all input data/specification.
HashTable< exprResult > variables_
The variables table.
searchControls searchCtrl_
Registry/disk/caching control.
void setDebugging(bool scannerDebug, bool parserDebug)
Set the scanner/parser debug.
void setSearchBehaviour(enum searchControls search, const bool caching=false)
Set search behaviour, with additional CACHE_READ_FIELDS toggle on.
virtual exprResult getRemoteResult(const exprDriver &other) const
Get the result from another driver.
virtual bool update()
Update things.
const exprResult & result() const noexcept
Const access to expression result.
void evaluateVariable(const word &varName, const expressions::exprString &expr)
Evaluate the expression and save as the specified named variable.
void resetTimeReference(const TimeState *ts)
Reset the time-state reference.
virtual void clearVariables()
Clear temporary variables, reset from expression strings.
contextObjectTableType contextObjects_
Externally defined context fields.
virtual unsigned parse(const std::string &expr, size_t pos=0, size_t len=std::string::npos)=0
Execute the parser.
static List< expressions::exprString > readVariableStrings(const dictionary &dict, const word &name="variables", bool mandatory=false)
Read the list of variable strings.
const dictionary & dict() const noexcept
The dictionary with all input data/specification.
virtual scalar timeValue() const
The current time value.
bool setCaching(bool on) noexcept
Toggle CACHE_READ_FIELDS control.
int stashedTokenId_
Internal bookkeeping as "look-behind" parsing context.
scalar arg1Value_
Special-purpose scalar reference argument.
A polymorphic field/result from evaluating an expression.
exprResult getUniform(const label size, const bool noWarn, const bool parRun=UPstream::parRun()) const
Construct a uniform field from the current results.
A variant of Foam::string with expansion of dictionary variables into a comma-separated form.
static exprString toExpr(const std::string &str)
Copy convert string to exprString.
Registry of regIOobjects.
A class for managing references or pointers (no reference counting).
const T & cref() const
Return const reference to the object or to the contents of a (non-null) managed pointer.
A class for handling words, derived from Foam::string.
static word validate(const std::string &s, const bool prefix=false)
Construct validated word (no invalid characters).
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define DebugInfo
Report an information message using Foam::Info.
Namespace for handling debugging switches.
A namespace for expression-related classes/traits etc.
constexpr auto key(const Type &t) noexcept
Helper function to return the enum value.
string trim(const std::string &s)
Return string trimmed of leading and trailing whitespace.
Foam::SubStrings split(const std::string &str, const char delim, std::string::size_type pos=0, const bool keepEmpty=false)
Split string into sub-strings at the delimiter character.
void inplaceTrim(std::string &s)
Trim leading and trailing whitespace inplace.
static void shallowCloneFunctions(HashTable< refPtr< Function1< Type > > > &dest, const HashTable< refPtr< Function1< Type > > > &rhs)
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
constexpr char nl
The newline '\n' character (0x0a).
#define forAllIters(container, iter)
Iterate across all elements in the container object.
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.