From fd9670d4a3958bf6f99fed25ae2950da6e156a15 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 23 Nov 2021 11:34:50 +0100 Subject: [PATCH] ENH: add objectRegistry handling to expressions driver - needed for future embedding --- .../expressions/exprDriver/exprDriver.C | 60 +++++++++++++------ .../expressions/exprDriver/exprDriver.H | 23 ++++--- .../expressions/exprDriver/exprDriverI.H | 1 - .../exprDriver/exprDriverTemplates.C | 7 +-- .../expressions/base/fvExprDriver.C | 10 ++-- .../expressions/base/fvExprDriver.H | 9 +-- .../expressions/patch/patchExprDriver.C | 23 ++++--- .../expressions/volume/volumeExprDriver.C | 33 ++++------ 8 files changed, 87 insertions(+), 79 deletions(-) diff --git a/src/OpenFOAM/expressions/exprDriver/exprDriver.C b/src/OpenFOAM/expressions/exprDriver/exprDriver.C index 123ed9f9d5..d9b27f1f28 100644 --- a/src/OpenFOAM/expressions/exprDriver/exprDriver.C +++ b/src/OpenFOAM/expressions/exprDriver/exprDriver.C @@ -29,7 +29,7 @@ License #include "exprDriver.H" #include "expressionEntry.H" #include "stringOps.H" -#include "TimeState.H" +#include "Time.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -115,34 +115,40 @@ void Foam::expressions::exprDriver::resetTimeReference(const TimeState& ts) } +void Foam::expressions::exprDriver::resetDb(const objectRegistry* obrPtr) +{ + obrPtr_ = obrPtr; +} + + +void Foam::expressions::exprDriver::resetDb(const objectRegistry& db) +{ + resetDb(&db); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::expressions::exprDriver::exprDriver ( enum searchControls search, - const dictionary& dict, - const TimeState* ts + const dictionary& dict ) : dict_(dict), result_(), variableStrings_(), - variables_(), + variables_(16), arg1Value_(0), - timeStatePtr_(ts), + timeStatePtr_(nullptr), + obrPtr_(nullptr), stashedTokenId_(0), // Controls debugScanner_(dict.getOrDefault("debugScanner", false)), debugParser_(dict.getOrDefault("debugParser", false)), - allowShadowing_ - ( - dict.getOrDefault("allowShadowing", false) - ), - prevIterIsOldTime_ - ( - dict.getOrDefault("prevIterIsOldTime", false) - ), + allowShadowing_(dict.getOrDefault("allowShadowing", false)), + prevIterIsOldTime_(dict.getOrDefault("prevIterIsOldTime", false)), searchCtrl_(search) {} @@ -158,8 +164,10 @@ Foam::expressions::exprDriver::exprDriver variables_(rhs.variables_), arg1Value_(rhs.arg1Value_), timeStatePtr_(rhs.timeStatePtr_), + obrPtr_(rhs.obrPtr_), stashedTokenId_(0), + // Controls debugScanner_(rhs.debugScanner_), debugParser_(rhs.debugParser_), allowShadowing_(rhs.allowShadowing_), @@ -171,15 +179,13 @@ Foam::expressions::exprDriver::exprDriver Foam::expressions::exprDriver::exprDriver ( - const dictionary& dict, - const TimeState* ts + const dictionary& dict ) : exprDriver ( searchControls(exprDriver::getSearchControls(dict)), - dict, - ts + dict ) { readDict(dict); @@ -188,9 +194,17 @@ Foam::expressions::exprDriver::exprDriver // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -const Foam::TimeState* Foam::expressions::exprDriver::timeState() const +const Foam::TimeState* Foam::expressions::exprDriver::timeState() const noexcept { - return timeStatePtr_; + if (timeStatePtr_) + { + return timeStatePtr_; + } + else if (obrPtr_) + { + return &(obrPtr_->time()); + } + return nullptr; } @@ -200,6 +214,10 @@ Foam::scalar Foam::expressions::exprDriver::timeValue() const { return timeStatePtr_->value(); } + else if (obrPtr_) + { + return obrPtr_->time().value(); + } return 0; } @@ -210,6 +228,10 @@ Foam::scalar Foam::expressions::exprDriver::deltaT() const { return timeStatePtr_->deltaT().value(); } + else if (obrPtr_) + { + return obrPtr_->time().deltaT().value(); + } return 0; } diff --git a/src/OpenFOAM/expressions/exprDriver/exprDriver.H b/src/OpenFOAM/expressions/exprDriver/exprDriver.H index 408c0f7fb6..2aed2664aa 100644 --- a/src/OpenFOAM/expressions/exprDriver/exprDriver.H +++ b/src/OpenFOAM/expressions/exprDriver/exprDriver.H @@ -130,6 +130,9 @@ protected: //- Reference to the time-state mutable const TimeState* timeStatePtr_; + //- Pointer to an object registry (for functions etc). + const objectRegistry* obrPtr_; + // Controls, tracing etc. @@ -274,19 +277,14 @@ public: explicit exprDriver ( enum searchControls search = searchControls::DEFAULT_SEARCH, - const dictionary& dict = dictionary::null, - const TimeState* ts = nullptr + const dictionary& dict = dictionary::null ); //- Copy construct exprDriver(const exprDriver& rhs); //- Construct from a dictionary - explicit exprDriver - ( - const dictionary& dict, - const TimeState* ts = nullptr - ); + explicit exprDriver(const dictionary& dict); //- Destructor @@ -308,7 +306,7 @@ public: } //- Reference to the current time-state (can be nullptr) - const TimeState* timeState() const; + const TimeState* timeState() const noexcept; //- The current time value virtual scalar timeValue() const; @@ -349,6 +347,15 @@ public: } + // External References + + //- Reset the objectRegistry (for functions) + void resetDb(const objectRegistry* obrPtr = nullptr); + + //- Reset the objectRegistry (for functions) + void resetDb(const objectRegistry& db); + + // Specials //- Get special-purpose scalar reference argument. diff --git a/src/OpenFOAM/expressions/exprDriver/exprDriverI.H b/src/OpenFOAM/expressions/exprDriver/exprDriverI.H index 478218a5c2..b7904aabfa 100644 --- a/src/OpenFOAM/expressions/exprDriver/exprDriverI.H +++ b/src/OpenFOAM/expressions/exprDriver/exprDriverI.H @@ -82,7 +82,6 @@ inline void Foam::expressions::exprDriver::addUniformVariable } - template Foam::tmp> Foam::expressions::exprDriver::evaluate ( diff --git a/src/OpenFOAM/expressions/exprDriver/exprDriverTemplates.C b/src/OpenFOAM/expressions/exprDriver/exprDriverTemplates.C index b4e9879f07..d7462f3a38 100644 --- a/src/OpenFOAM/expressions/exprDriver/exprDriverTemplates.C +++ b/src/OpenFOAM/expressions/exprDriver/exprDriverTemplates.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2010-2018 + Copyright (C) 2010-2018 Bernhard Gschaider Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -201,9 +201,8 @@ bool Foam::expressions::exprDriver::isLocalVariable const exprResult& var = variable(name); DebugInfo - << " - found (" << var.valueType() << ' ' - << var.isPointData() << ')'; - + << " - found (" << var.valueType() + << (var.isPointData() ? " point" : "") << ')'; good = (var.isType() && var.isPointData(wantPointData)); diff --git a/src/finiteVolume/expressions/base/fvExprDriver.C b/src/finiteVolume/expressions/base/fvExprDriver.C index a31ea14268..bbf7f6d80a 100644 --- a/src/finiteVolume/expressions/base/fvExprDriver.C +++ b/src/finiteVolume/expressions/base/fvExprDriver.C @@ -95,11 +95,10 @@ const Foam::fvMesh* Foam::expressions::fvExprDriver::resetDefaultMesh Foam::expressions::fvExprDriver::fvExprDriver ( enum exprDriver::searchControls search, - const dictionary& dict, - const TimeState* ts + const dictionary& dict ) : - expressions::exprDriver(search, dict, ts), + expressions::exprDriver(search, dict), globalScopes_(), delayedVariables_(), storedVariables_(), @@ -126,11 +125,10 @@ Foam::expressions::fvExprDriver::fvExprDriver Foam::expressions::fvExprDriver::fvExprDriver ( - const dictionary& dict, - const TimeState* ts + const dictionary& dict ) : - expressions::exprDriver(dict, ts), + expressions::exprDriver(dict), globalScopes_(), delayedVariables_(), storedVariables_(), diff --git a/src/finiteVolume/expressions/base/fvExprDriver.H b/src/finiteVolume/expressions/base/fvExprDriver.H index 3d38ab6b97..e1e29c88f6 100644 --- a/src/finiteVolume/expressions/base/fvExprDriver.H +++ b/src/finiteVolume/expressions/base/fvExprDriver.H @@ -365,19 +365,14 @@ public: ( enum exprDriver::searchControls search = exprDriver::searchControls::DEFAULT_SEARCH, - const dictionary& dict = dictionary::null, - const TimeState* ts = nullptr + const dictionary& dict = dictionary::null ); //- Copy construct fvExprDriver(const fvExprDriver&); //- Construct from a dictionary - explicit fvExprDriver - ( - const dictionary& dict, - const TimeState* ts = nullptr - ); + explicit fvExprDriver(const dictionary& dict); //- Return a reference to the selected value driver diff --git a/src/finiteVolume/expressions/patch/patchExprDriver.C b/src/finiteVolume/expressions/patch/patchExprDriver.C index c558716309..1263b44486 100644 --- a/src/finiteVolume/expressions/patch/patchExprDriver.C +++ b/src/finiteVolume/expressions/patch/patchExprDriver.C @@ -28,9 +28,8 @@ License #include "patchExprDriver.H" #include "patchExprScanner.H" #include "error.H" -#include "fvPatch.H" #include "fvMesh.H" -#include "className.H" +#include "fvPatch.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -70,14 +69,6 @@ addNamedToRunTimeSelectionTable namespace Foam { -static inline const TimeState* lookupTimeState -( - const fvPatch& p -) -{ - return &static_cast(p.boundaryMesh().mesh().time()); -} - static inline const fvPatch& lookupFvPatch ( const fvMesh& mesh, @@ -115,9 +106,12 @@ Foam::expressions::patchExpr::parseDriver::parseDriver ) : parsing::genericRagelLemonDriver(), - expressions::fvExprDriver(dict, lookupTimeState(p)), + expressions::fvExprDriver(dict), patch_(p) -{} +{ + resetTimeReference(nullptr); + resetDb(patch_.boundaryMesh().mesh().thisDb()); +} Foam::expressions::patchExpr::parseDriver::parseDriver @@ -129,7 +123,10 @@ Foam::expressions::patchExpr::parseDriver::parseDriver parsing::genericRagelLemonDriver(), expressions::fvExprDriver(rhs), patch_(p) -{} +{ + resetTimeReference(nullptr); + resetDb(patch_.boundaryMesh().mesh().thisDb()); +} Foam::expressions::patchExpr::parseDriver::parseDriver diff --git a/src/finiteVolume/expressions/volume/volumeExprDriver.C b/src/finiteVolume/expressions/volume/volumeExprDriver.C index 9010fc03d4..c1e7eccb70 100644 --- a/src/finiteVolume/expressions/volume/volumeExprDriver.C +++ b/src/finiteVolume/expressions/volume/volumeExprDriver.C @@ -81,22 +81,6 @@ addNamedToRunTimeSelectionTable } // End namespace Foam -// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // - -namespace Foam -{ - -static inline const TimeState* lookupTimeState -( - const polyMesh& m -) -{ - return &static_cast(m.time()); -} - -} // End namespace Foam - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::expressions::volumeExpr::parseDriver::parseDriver @@ -106,13 +90,16 @@ Foam::expressions::volumeExpr::parseDriver::parseDriver ) : parsing::genericRagelLemonDriver(), - expressions::fvExprDriver(dict, lookupTimeState(mesh)), + expressions::fvExprDriver(dict), mesh_(mesh), resultType_(), isLogical_(false), fieldGeoType_(NO_DATA), resultDimension_() -{} +{ + resetTimeReference(nullptr); + resetDb(mesh_.thisDb()); +} Foam::expressions::volumeExpr::parseDriver::parseDriver @@ -129,7 +116,8 @@ Foam::expressions::volumeExpr::parseDriver::parseDriver fieldGeoType_(NO_DATA), resultDimension_() { - resetTimeReference(mesh_.time()); // Extra safety + resetTimeReference(nullptr); + resetDb(mesh_.thisDb()); } @@ -152,13 +140,16 @@ Foam::expressions::volumeExpr::parseDriver::parseDriver ) : parsing::genericRagelLemonDriver(), - expressions::fvExprDriver(dict, lookupTimeState(mesh)), + expressions::fvExprDriver(dict), mesh_(mesh), resultType_(), isLogical_(false), fieldGeoType_(NO_DATA), resultDimension_() -{} +{ + resetTimeReference(nullptr); + resetDb(mesh_.thisDb()); +} // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //