Go to the documentation of this file.
54 bool Foam::expressions::fvExprDriver::cacheSets_ =
true;
56 const 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;
113 specialVariablesIndex_(-1),
126 globalScopes_(rhs.globalScopes_),
127 delayedVariables_(rhs.delayedVariables_),
128 storedVariables_(rhs.storedVariables_),
129 specialVariablesIndex_(rhs.specialVariablesIndex_),
143 dict.getOrDefault(
"cacheReadFields",
false),
144 dict.getOrDefault(
"searchInMemory",
true),
145 dict.getOrDefault(
"searchFiles",
false),
177 dict.readIfPresent(
"globalScopes", globalScopes_);
179 const entry* eptr =
nullptr;
192 if (writer_.valid() && storedVariables_.size())
196 <<
"The 'storedVariables' was already read."
197 <<
" No update from " << is
205 dict.checkITstream(is,
"storedVariables");
218 if (writer_.valid() && delayedVariables_.size())
222 <<
"Seems like 'delayedVariables' was already read."
223 <<
" No update from " << is
231 dict.checkITstream(is,
"delayedVariables");
233 for (
auto& var : inputs)
235 delayedVariables_.insert(var.name(), var);
248 return this->
mesh().time();
266 const bool updated = this->
update();
268 const label eventIndex =
mesh().time().timeIndex();
269 const scalar eventTime =
mesh().time().value();
272 <<
"fvExprDriver::updateSpecialVariables(force="
273 << force <<
") Updated: " << updated <<
endl;
275 if (specialVariablesIndex_ < 0)
278 <<
"First update: " << eventIndex <<
endl;
280 specialVariablesIndex_ = eventIndex;
285 << v.name() <<
" = " << v.initialValueExpression()
287 << v.hasValue() <<
")" <<
endl;
292 <<
"First value: " << v.initialValueExpression()
293 <<
" -> " << v.name() <<
endl;
295 parse(v.initialValueExpression());
298 <<
"Parser size: " << this->size() <<
nl
299 <<
"Calculated: " << result_ <<
nl
300 <<
"Stored: " << v <<
nl;
305 if (force || specialVariablesIndex_ != eventIndex)
308 <<
"Store variables: " << force <<
' '
309 << specialVariablesIndex_ <<
' '
310 << eventIndex <<
endl;
314 if (variables_.found(v.name()))
317 <<
"Storing variable: " << v.name() <<
" "
318 << variables_[v.name()] <<
endl;
320 v = variables_[v.name()];
323 specialVariablesIndex_ = eventIndex;
329 <<
"Updating delayed variable " << iter().name() <<
endl;
331 if (!iter().updateReadValue(eventTime))
333 const exprString& expr = iter().startupValueExpression();
336 <<
"Evaluate: " << expr <<
endl;
339 iter().setReadValue(result_);
342 <<
"Value " << iter() <<
nl
343 <<
"Type " << iter().valueType() <<
"("
344 << result_.valueType() <<
")" <<
endl;
349 << iter().name() <<
" updated without problem" <<
endl;
358 <<
"Clearing variables" <<
endl;
360 const scalar eventTime =
mesh().time().value();
364 updateSpecialVariables();
368 variables_.insert(v.name(), v);
371 addVariables(variableStrings_,
false);
375 iter().storeValue(eventTime);
388 if (!allowShadowing_ && objPtr)
393 <<
") is shadowed by a variable of the same name." <<
nl
394 <<
"This may lead to trouble" <<
nl
395 <<
"If this is OK set 'allowShadowing'"
396 <<
" in the relevant parser" <<
nl
401 result_.testIfSingleValue();
404 <<
"Evaluating: " << expr <<
" -> " << varName <<
endl
409 if (delayedVariables_.found(varName))
412 variables_.erase(varName);
415 << varName <<
" is delayed" <<
endl;
418 delayedVariables_[varName] = result_;
436 <<
"Evaluating remote " << remote.c_str()
437 <<
" : " << expr <<
" -> " << varName <<
endl;
439 word driverType(
"patch");
442 const auto slashPos = remote.find(
'/');
443 if (slashPos != std::string::npos)
446 remote.resize(slashPos);
449 const auto quotePos = remote.find(
'\'');
450 if (quotePos != std::string::npos)
462 driverType ==
"patch"
466 || identName ==
"volume"
467 || identName ==
"internalField"
471 driverType =
"internalField";
476 if (!regionName.empty())
489 <<
"Call other with ("
490 << driverType <<
", " << identName <<
", " <<
regionName <<
")\n";
498 otherDriver->
parse(expr);
500 exprResult otherResult(this->getRemoteResult(*otherDriver));
509 <<
"Remote result: " << otherResult <<
nl;
512 if (delayedVariables_.found(varName))
515 variables_.erase(varName);
518 << varName <<
" is delayed - setting" <<
nl;
521 delayedVariables_[varName] = std::move(otherResult);
526 variables_.set(varName, std::move(otherResult));
551 if (!
meshPtr && readIfNecessary)
555 <<
" not in memory. Loading it" <<
endl;
562 mesh.time().constant(),
584 const word& fieldName
587 return getHeaderClassName(this->
mesh(), fieldName);
596 if (searchInMemory())
602 return ioptr->type();
608 return getHeaderClassName(this->
mesh(), name);
622 return topoSetSource::sourceType::CELLSET_SOURCE;
626 return topoSetSource::sourceType::FACESET_SOURCE;
630 return topoSetSource::sourceType::POINTSET_SOURCE;
633 return topoSetSource::sourceType::UNKNOWN_SOURCE;
640 if (
mesh().cellZones().findZoneID(setName) >= 0)
642 return topoSetSource::sourceType::CELLZONE_SOURCE;
645 if (
mesh().faceZones().findZoneID(setName) >= 0)
647 return topoSetSource::sourceType::FACEZONE_SOURCE;
650 if (
mesh().pointZones().findZoneID(setName) >= 0)
652 return topoSetSource::sourceType::POINTZONE_SOURCE;
655 return topoSetSource::sourceType::UNKNOWN_SOURCE;
662 auto setType = topoZoneType(setName);
664 if (topoSetSource::sourceType::UNKNOWN_SOURCE == setType)
666 setType = topoSetType(setName);
678 topoSetSource::sourceType::CELLSET_SOURCE
679 == topoSetType(setName)
688 topoSetSource::sourceType::FACESET_SOURCE
689 == topoSetType(setName)
698 topoSetSource::sourceType::POINTSET_SOURCE
699 == topoSetType(setName)
706 return (
mesh().cellZones().findZoneID(
name) >= 0);
712 return (
mesh().faceZones().findZoneID(
name) >= 0);
718 return (
mesh().pointZones().findZoneID(
name) >= 0);
734 return (!storedVariables_.empty() || !delayedVariables_.empty());
743 dict.readIfPresent(
"storedVariables", storedVariables_);
756 if (storedVariables_.size())
758 driver.updateSpecialVariables(
true);
760 dict.add(
"storedVariables", storedVariables_);
A keyword and a list of tokens is an 'entry'.
static autoPtr< fvExprDriver > New(const dictionary &dict, const fvMesh &mesh)
Return a reference to the selected value driver.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
sourceType
Enumeration defining the types of sources.
Foam::autoPtr< Foam::fvMesh > meshPtr(nullptr)
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
A class for handling words, derived from Foam::string.
static const fvMesh * resetDefaultMesh(const fvMesh &mesh, const bool force=false)
Set the default mesh (if not already set)
virtual ITstream & stream() const =0
Return token stream, if entry is a primitive entry.
virtual bool hasDataToWrite() const
Do we need a data file to be written.
virtual unsigned parse(const std::string &expr, size_t pos=0, size_t len=std::string::npos)=0
Execute the parser.
void testIfSingleValue(const bool parRun=Pstream::parRun())
Test if field corresponds to a single-value and thus uniform.
virtual bool readDict(const dictionary &dict)
Read variables, tables etc.
void setSearchBehaviour(bool cacheReadFields, bool searchInMemory, bool searchFiles)
Set search behaviour.
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.
word getFieldClassName(const word &name) const
Lookup the field class name (memory or read from disk)
const Time & runTime() const
The Time associated with the mesh.
static word validate(const std::string &s, const bool prefix=false)
Construct validated word (no invalid characters).
const exprResult & get(const word &name, const wordUList &scopes) const
Return a global variable, if it exists, or a exprResult::null.
Base driver for parsing value expressions associated with an fvMesh.
bool isPointZone(const word &name) const
Test if name is a known pointZone.
Ostream & endl(Ostream &os)
Add newline and flush stream.
defineRunTimeSelectionTable(fvExprDriver, dictionary)
virtual word timeName() const
The current time name.
virtual void evaluateVariableRemote(string remote, const word &varName, const expressions::exprString &expr)
virtual void prepareData(dictionary &dict) const
static IOobject findIOobject(const polyMesh &mesh, const word &name, readOption r=MUST_READ, writeOption w=NO_WRITE)
Find IOobject in the polyMesh/sets (used as constructor helper)
fvExprDriver(bool cacheReadFields=false, bool searchInMemory=true, bool searchFiles=false, const dictionary &dict=dictionary::null)
Null constructor, and null construct with search preferences.
word getTypeOfField(const word &fieldName) const
Read the IOobject for fieldName and return its headerClassName.
A polymorphic field/result from evaluating an expression.
virtual ~fvExprDriver()
Destructor.
An input stream of tokens.
#define DebugInFunction
Report an information message using Foam::Info.
word name(const complex &c)
Return string representation of complex.
virtual scalar timeValue() const
The current time value.
virtual void updateSpecialVariables(bool force=false)
Examine current variable values and update stored variables.
Base driver for parsing (field) values.
topoSetSource::sourceType topoSourceType(const word &name) const
Return cell/face/point zone/set type or unknown.
#define forAllIters(container, iter)
Iterate across all elements in the container object.
bool isFaceZone(const word &name) const
Test if name is a known faceZone.
bool isUniform() const
True if single, uniform value.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
bool isPointSet(const word &name) const
Test if name is a known pointSet.
const exprResult & lookupGlobal(const word &name) const
Return the global variable if available or a null result.
Mesh data needed to do the Finite Volume discretisation.
An exprResult with persistence.
errorManip< error > abort(error &err)
errorManipArg< error, int > exit(error &err, const int errNo=1)
virtual void evaluateVariable(const word &varName, const expressions::exprString &expr)
const word & headerClassName() const
Return name of the class name read from header.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
bool isCellZone(const word &name) const
Test if name is a known cellZone.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
bool isFaceSet(const word &name) const
Test if name is a known faceSet.
#define DebugInfo
Report an information message using Foam::Info.
const Type * cfindObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
topoSetSource::sourceType topoSetType(const word &name) const
Return cell/face/point set type or unknown.
static const word null
An empty word.
topoSetSource::sourceType topoZoneType(const word &name) const
Return cell/face/point zone type or unknown.
const Time & time() const
Return the top-level database.
virtual void getData(const dictionary &dict)
Read data from dictionary, normally via the reader/writer.
virtual void clearVariables()
Clear temporary variables and resets from expression strings.
static const fvMesh & regionMesh(const dictionary &dict, const fvMesh &mesh, bool readIfNecessary)
void setGlobalScopes(const wordUList &scopes)
Define scopes for global variables.
defineTypeNameAndDebug(fvExprDriver, 0)
static exprResultGlobals & New(const objectRegistry &obr)
Get the singleton.
#define WarningInFunction
Report a warning using Foam::Warning.
virtual bool update()
Update things.
virtual bool readDict(const dictionary &dict)
Read variables, tables etc.