54bool Foam::expressions::fvExprDriver::cacheSets_ =
true;
56const Foam::fvMesh* Foam::expressions::fvExprDriver::defaultMeshPtr_ =
nullptr;
66 <<
"No default mesh set" <<
nl
67 <<
"Try the 'fvExprDriverFunctionObject' as a workaround"
72 return *defaultMeshPtr_;
82 const fvMesh* ptr = defaultMeshPtr_;
84 if (force || (ptr !=
nullptr))
86 defaultMeshPtr_ = &
mesh;
105 specialVariablesIndex_(-1),
118 globalScopes_(
rhs.globalScopes_),
119 delayedVariables_(
rhs.delayedVariables_),
120 storedVariables_(
rhs.storedVariables_),
121 specialVariablesIndex_(
rhs.specialVariablesIndex_),
136 specialVariablesIndex_(-1),
171 dict.readIfPresent(
"globalScopes", globalScopes_);
173 const entry* eptr =
nullptr;
186 if (writer_ && !storedVariables_.empty())
190 <<
"The 'storedVariables' was already read."
191 <<
" No update from " << is
199 dict.checkITstream(is,
"storedVariables");
210 ITstream& is = eptr->
stream();
212 if (writer_ && !delayedVariables_.empty())
216 <<
"Seems like 'delayedVariables' was already read."
217 <<
" No update from " << is
222 List<exprResultDelayed> inputs(is);
225 dict.checkITstream(is,
"delayedVariables");
227 for (
auto& var : inputs)
229 delayedVariables_.insert(var.name(), var);
242 const bool updated = this->
update();
244 const label eventIndex =
mesh().time().timeIndex();
245 const scalar eventTime =
mesh().time().value();
248 <<
"fvExprDriver::updateSpecialVariables(force="
249 << force <<
") Updated: " << updated <<
endl;
251 if (specialVariablesIndex_ < 0)
254 <<
"First update: " << eventIndex <<
endl;
256 specialVariablesIndex_ = eventIndex;
261 << v.name() <<
" = " << v.initialValueExpression()
263 << v.hasValue() <<
")" <<
endl;
268 <<
"First value: " << v.initialValueExpression()
269 <<
" -> " << v.name() <<
endl;
271 parse(v.initialValueExpression());
274 <<
"Parser size: " << this->size() <<
nl
275 <<
"Calculated: " << result_ <<
nl
276 <<
"Stored: " << v <<
nl;
281 if (force || specialVariablesIndex_ != eventIndex)
284 <<
"Store variables: " << force <<
' '
285 << specialVariablesIndex_ <<
' '
286 << eventIndex <<
endl;
288 for (exprResultStored& v : storedVariables_)
290 if (variables_.found(v.name()))
293 <<
"Storing variable: " << v.name() <<
" "
294 << variables_[v.name()] <<
endl;
296 v = variables_[v.name()];
299 specialVariablesIndex_ = eventIndex;
305 <<
"Updating delayed variable " << iter().name() <<
endl;
307 if (!iter().updateReadValue(eventTime))
315 iter().setReadValue(result_);
318 <<
"Value " << iter() <<
nl
319 <<
"Type " << iter().valueType() <<
"("
320 << result_.valueType() <<
")" <<
endl;
325 << iter().name() <<
" updated without problem" <<
endl;
334 <<
"Clearing variables" <<
endl;
336 const scalar eventTime =
mesh().time().value();
340 updateSpecialVariables();
342 for (exprResultStored& v : storedVariables_)
344 variables_.insert(v.name(), v);
347 addVariables(variableStrings_,
false);
351 iter().storeValue(eventTime);
364 if (!allowShadowing_ && objPtr)
369 <<
") is shadowed by a variable of the same name." <<
nl
370 <<
"This may lead to trouble" <<
nl
371 <<
"If this is OK set 'allowShadowing'"
372 <<
" in the relevant parser" <<
nl
377 result_.testIfSingleValue();
380 <<
"Evaluating: " << expr <<
" -> " << varName <<
endl
385 if (delayedVariables_.found(varName))
388 variables_.erase(varName);
391 << varName <<
" is delayed" <<
endl;
394 delayedVariables_[varName] = result_;
412 <<
"Evaluating remote " << remote.c_str()
413 <<
" : " << expr <<
" -> " << varName <<
endl;
415 word driverType(
"patch");
418 const auto slashPos = remote.find(
'/');
419 if (slashPos != std::string::npos)
422 remote.resize(slashPos);
425 const auto quotePos = remote.find(
'\'');
426 if (quotePos != std::string::npos)
438 driverType ==
"patch"
442 || identName ==
"volume"
443 || identName ==
"internalField"
447 driverType =
"internalField";
450 const fvMesh* pRegion = &(this->
mesh());
454 pRegion = pRegion->time().cfindObject<fvMesh>(
regionName);
465 <<
"Call other with ("
466 << driverType <<
", " << identName <<
", " <<
regionName <<
")\n";
468 autoPtr<fvExprDriver> otherDriver =
471 otherDriver->setSearchBehaviour(*
this);
472 otherDriver->setGlobalScopes(this->globalScopes_);
474 otherDriver->parse(expr);
476 exprResult otherResult(this->getRemoteResult(*otherDriver));
479 if (!otherResult.isUniform())
481 otherResult.testIfSingleValue();
485 <<
"Remote result: " << otherResult <<
nl;
488 if (delayedVariables_.found(varName))
491 variables_.erase(varName);
494 << varName <<
" is delayed - setting" <<
nl;
497 delayedVariables_[varName] = std::move(otherResult);
502 variables_.set(varName, std::move(otherResult));
527 if (!
meshPtr && readIfNecessary)
531 <<
" not in memory. Loading it" <<
endl;
538 mesh.time().constant(),
565 return getHeaderClassName(this->
mesh(), fieldName);
574 if (searchRegistry())
580 return ioptr->type();
586 return getHeaderClassName(this->
mesh(), name);
602 if (
io.isHeaderClass<faceSet>())
606 if (
io.isHeaderClass<pointSet>())
618 if (
mesh().cellZones().findZoneID(setName) >= 0)
623 if (
mesh().faceZones().findZoneID(setName) >= 0)
628 if (
mesh().pointZones().findZoneID(setName) >= 0)
640 auto setType = topoZoneType(setName);
644 setType = topoSetType(setName);
684 return (
mesh().cellZones().findZoneID(
name) >= 0);
690 return (
mesh().faceZones().findZoneID(
name) >= 0);
696 return (
mesh().pointZones().findZoneID(
name) >= 0);
712 return (!storedVariables_.empty() || !delayedVariables_.empty());
721 dict.readIfPresent(
"storedVariables", storedVariables_);
734 if (storedVariables_.size())
736 driver.updateSpecialVariables(
true);
738 dict.add(
"storedVariables", storedVariables_);
@ REGISTER
Request registration (bool: true).
@ MUST_READ
Reading required.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
const word & headerClassName() const noexcept
Return name of the class name read from header.
An input stream of tokens.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
A collection of cell labels.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
A keyword and a list of tokens is an 'entry'.
virtual ITstream & stream() const =0
Return token stream, if entry is a primitive entry.
Base driver for parsing (field) values.
bool searchFiles() const noexcept
exprResult result_
The result.
void addVariables(const expressions::exprString &expr, bool clear=true)
Add/set string expressions for variables.
bool searchRegistry() const noexcept
exprDriver(const exprDriver &)=delete
No copy construct.
bool allowShadowing_
Allow variable names to mask field names.
searchControls
Search/caching controls.
virtual bool readDict(const dictionary &dict)
Read variables, tables etc.
List< expressions::exprString > variableStrings_
Variable definitions, as read from a dictionary.
HashTable< exprResult > variables_
The variables table.
virtual exprResult getRemoteResult(const exprDriver &other) const
Get the result from another driver.
virtual bool update()
Update things.
virtual unsigned parse(const std::string &expr, size_t pos=0, size_t len=std::string::npos)=0
Execute the parser.
const dictionary & dict() const noexcept
The dictionary with all input data/specification.
const exprResult & get(const word &name, const wordUList &scopes) const
Return a global variable, if it exists, or a exprResult::null.
static exprResultGlobals & New(const objectRegistry &obr)
Static constructor for singleton.
An exprResult with persistence.
A polymorphic field/result from evaluating an expression.
void testIfSingleValue(const bool parRun=UPstream::parRun())
Test if field corresponds to a single-value and thus uniform.
bool isUniform() const
True if single, uniform value.
A variant of Foam::string with expansion of dictionary variables into a comma-separated form.
Base driver for parsing value expressions associated with an fvMesh.
static autoPtr< fvExprDriver > New(const dictionary &dict, const fvMesh &mesh)
Return a reference to the selected value driver.
bool isPointSet(const word &name) const
Test if name is a known pointSet.
bool isFaceSet(const word &name) const
Test if name is a known faceSet.
virtual void updateSpecialVariables(bool force=false)
Examine current variable values and update stored variables.
virtual void prepareData(dictionary &dict) const
Prepare/update special variables and add to dictionary, normally via the reader/writer.
static const fvMesh & regionMesh(const dictionary &dict, const fvMesh &mesh, bool readIfNecessary)
Determine mesh or region mesh as specified in the dictionary with the keyword "region".
virtual bool hasDataToWrite() const
Do we need a data file to be written.
const exprResult & lookupGlobal(const word &name) const
Return the global variable if available or a null result.
static const fvMesh & defaultMesh()
Get the default mesh, if one is defined.
bool isCellSet(const word &name) const
Test if name is a known cellSet.
bool isPointZone(const word &name) const
Test if name is a known pointZone.
virtual const fvMesh & mesh() const =0
The mesh we are attached to.
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.
topoSetSource::sourceType topoZoneType(const word &name) const
Return cell/face/point zone type or unknown.
virtual bool readDict(const dictionary &dict)
Read variables, tables etc.
word getFieldClassName(const word &name) const
Lookup the field class name (memory or read from disk).
bool isCellZone(const word &name) const
Test if name is a known cellZone.
fvExprDriver(enum exprDriver::searchControls search=exprDriver::searchControls::DEFAULT_SEARCH, const dictionary &dict=dictionary::null)
Default construct, and default construct with search preferences.
virtual label size() const =0
The natural field size for the expression.
bool isFaceZone(const word &name) const
Test if name is a known faceZone.
virtual void evaluateVariable(const word &varName, const expressions::exprString &expr)
Evaluate the expression and save as the specified named variable.
topoSetSource::sourceType topoSetType(const word &name) const
Return cell/face/point set type or unknown.
virtual ~fvExprDriver()
Destructor.
virtual void clearVariables()
Clear temporary variables, reset from expression strings.
static const fvMesh * resetDefaultMesh(const fvMesh &mesh, const bool force=false)
Set the default mesh (if not already set).
topoSetSource::sourceType topoSourceType(const word &name) const
Return cell/face/point zone/set type or unknown.
virtual void getData(const dictionary &dict)
Read data from dictionary, normally via the reader/writer.
word getTypeOfField(const word &fieldName) const
Read the IOobject for fieldName and return its headerClassName.
Mesh data needed to do the Finite Volume discretisation.
const Time & time() const
Return the top-level database.
const Type * cfindObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
sourceType
Enumeration defining the types of sources.
@ POINTSET_SOURCE
Points as set.
@ FACESET_SOURCE
Faces as set.
@ FACEZONE_SOURCE
Faces as zone.
@ UNKNOWN_SOURCE
Placeholder.
@ POINTZONE_SOURCE
Points as zone.
@ CELLSET_SOURCE
Cells as set.
@ CELLZONE_SOURCE
Cells as zone.
static IOobject findIOobject(const polyMesh &mesh, const word &name, IOobjectOption::readOption rOpt=IOobjectOption::MUST_READ, IOobjectOption::writeOption wOpt=IOobjectOption::NO_WRITE, IOobjectOption::registerOption reg=IOobjectOption::LEGACY_REGISTER)
Find IOobject in the polyMesh/sets/ (used as constructor helper).
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).
static const word null
An empty word.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Foam::autoPtr< Foam::dynamicFvMesh > meshPtr
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define DebugInfo
Report an information message using Foam::Info.
#define WarningInFunction
Report a warning using Foam::Warning.
#define DebugInFunction
Report an information message using Foam::Info.
ListConstRefWrap< typename Expr::value_type > expr
Fully self-contained constant field wrapper. Not needed?
A namespace for expression-related classes/traits etc.
Ostream & endl(Ostream &os)
Add newline and flush stream.
errorManip< error > abort(error &err)
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...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
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 defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.
#define forAllIters(container, iter)
Iterate across all elements in the container object.