49 int Foam::expressions::exprDriver::getSearchControls(
const dictionary&
dict)
55 val |= int(searchControls::SEARCH_REGISTRY);
59 val |= int(searchControls::SEARCH_FILES);
63 val |= int(searchControls::CACHE_READ_FIELDS);
75 static string getEntryString
77 const dictionary&
dict,
86 <<
"Entry " <<
key <<
" not found in " 90 else if (eptr->isDict())
93 <<
"Entry " <<
key <<
" found in " 94 <<
dict.name() <<
" but is a dictionary" <<
nl 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())
159 (*funcPtr).resetDb(obrPtr_);
175 enum searchControls
search,
187 timeStatePtr_(nullptr),
192 debugScanner_(
dict.getOrDefault(
"debug.scanner", false)),
193 debugParser_(
dict.getOrDefault(
"debug.parser", false)),
194 allowShadowing_(
dict.getOrDefault(
"allowShadowing", false)),
195 prevIterIsOldTime_(
dict.getOrDefault(
"prevIterIsOldTime", 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_;
262 return &(obrPtr_->time());
272 return timeStatePtr_->value();
276 return obrPtr_->time().value();
286 return timeStatePtr_->deltaT().value();
290 return obrPtr_->time().deltaT().value();
301 dict.readIfPresent(
"debug.driver",
debug);
304 variableStrings_ = readVariableStrings(
dict,
"variables",
false);
307 resetFunctions(
dict);
334 addVariables(variableStrings_,
false);
345 result_.testIfSingleValue();
348 <<
"Evaluating: " << expr <<
" -> " << varName <<
endl 390 const auto varExpressions =
391 stringOps::split<expressions::exprString>(expr,
';');
393 for (
const auto& subMatch : varExpressions)
406 const auto eqPos = varExpr.find(
'=');
408 if (eqPos == std::string::npos)
411 <<
"No '=' found in expression " << varExpr <<
nl <<
nl 416 expressions::exprString rhsExpr
425 varExpr.resize(eqPos);
429 const auto lbrace = varExpr.find(
'{');
431 if (lbrace != std::string::npos)
433 const auto rbrace = varExpr.find(
'}');
435 if (rbrace == std::string::npos || rbrace < lbrace)
439 <<
"No closing '}' found in " << varExpr <<
nl 442 else if (lbrace+1 == rbrace)
446 <<
"Empty '{}' location in " << varExpr <<
nl 452 const expressions::exprString remoteExpr
456 varExpr.substr(lbrace+1, rbrace-lbrace-1)
462 evaluateVariableRemote(remoteExpr, varName, rhsExpr);
468 evaluateVariable(varName, rhsExpr);
476 const UList<expressions::exprString>& list,
485 for (
const auto& expr : list)
487 addVariables(expr,
false);
498 debugScanner_ = scannerDebug;
499 debugParser_ = parserDebug;
515 int val(searchCtrl_);
516 bool old = (val & searchControls::CACHE_READ_FIELDS);
521 val &= ~(searchControls::CACHE_READ_FIELDS);
529 searchControls::SEARCH_REGISTRY
530 | searchControls::SEARCH_FILES
531 | searchControls::CACHE_READ_FIELDS
543 enum searchControls
search,
548 if (caching || (val & searchControls::CACHE_READ_FIELDS))
553 searchControls::SEARCH_REGISTRY
554 | searchControls::SEARCH_FILES
555 | searchControls::CACHE_READ_FIELDS
558 searchCtrl_ = searchControls(val);
562 <<
" registry:" << searchRegistry()
563 <<
" disk:" << searchFiles()
564 <<
" cache-read:" << cacheReadFields() <<
nl;
static word validate(const std::string &s, const bool prefix=false)
Construct validated word (no invalid characters).
void resetTimeReference(const TimeState *ts)
Reset the time-state reference.
defineTypeNameAndDebug(fvExprDriver, 0)
errorManipArg< error, int > exit(error &err, const int errNo=1)
The time value with time-stepping information, user-defined remapping, etc.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
A polymorphic field/result from evaluating an expression.
searchControls searchCtrl_
Registry/disk/caching control.
constexpr char nl
The newline '\n' character (0x0a)
void inplaceTrim(std::string &s)
Trim leading and trailing whitespace inplace.
virtual bool readDict(const dictionary &dict)
Read variables, tables etc.
Ostream & endl(Ostream &os)
Add newline and flush stream.
virtual void clearVariables()
Clear temporary variables, reset from expression strings.
void setSearchBehaviour(enum searchControls search, const bool caching=false)
Set search behaviour, with additional CACHE_READ_FIELDS toggle on.
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.
static string evaluate(const entry &e)
Generic concatenate tokens to space-separated string.
virtual void updateSpecialVariables(bool force=false)
Examine current variable values and update stored variables.
void addVariables(const expressions::exprString &expr, bool clear=true)
Add/set string expressions for variables.
searchControls
Search/caching controls.
const TimeState * timeState() const noexcept
Reference to the current time-state (can be nullptr)
A class for handling words, derived from Foam::string.
bool setCaching(bool on) noexcept
Toggle CACHE_READ_FIELDS control.
exprDriver(const exprDriver &)=delete
No copy construct.
exprResult getUniform(const label size, const bool noWarn, const bool parRun=Pstream::parRun()) const
Construct a uniform field from the current results.
#define forAllIters(container, iter)
Iterate across all elements in the container object.
string trim(const std::string &s)
Return string trimmed of leading and trailing whitespace.
void clearResult()
Clear the result.
const exprResult & result() const noexcept
Const access to expression result.
#define DebugInfo
Report an information message using Foam::Info.
bool debugScanner_
Request debugging for scanner.
int debug
Static debugging option.
virtual exprResult getRemoteResult(const exprDriver &other) const
Get the result from another driver.
Base driver for parsing (field) values.
virtual bool update()
Update things.
HashTable< refPtr< Function1< vector > > > vectorFuncs_
Function1 mappings/timelines (vector), evaluated at the simulation time or with arbitrary scalars...
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
const dictionary & dict_
The dictionary with all input data/specification.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
void resetDb(const objectRegistry *obrPtr=nullptr)
Reset the objectRegistry (for functions)
virtual scalar deltaT() const
The current deltaT value.
const dictionary & dict() const noexcept
The dictionary with all input data/specification.
messageStream Info
Information stream (stdout output on master, null elsewhere)
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
HashTable< refPtr< Function1< scalar > > > scalarFuncs_
Function1 mappings/timelines (scalar), evaluated at the simulation time or with arbitrary scalars...
static void shallowCloneFunctions(HashTable< refPtr< Function1< Type >>> &dest, const HashTable< refPtr< Function1< Type >>> &rhs)
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
Registry of regIOobjects.
void evaluateVariable(const word &varName, const expressions::exprString &expr)
Evaluate the expression and save as the specified named variable.
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
void setDebugging(bool scannerDebug, bool parserDebug)
Set the scanner/parser debug.
forAllConstIters(mixture.phases(), phase)
bool debugParser_
Request debugging for parser.
static exprString toExpr(const std::string &str)
Copy convert string to exprString.
virtual scalar timeValue() const
The current time value.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...