mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add objectRegistry handling to expressions driver
- needed for future embedding
This commit is contained in:
@ -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
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -82,7 +82,6 @@ inline void Foam::expressions::exprDriver::addUniformVariable
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::tmp<Foam::Field<Type>> Foam::expressions::exprDriver::evaluate
|
||||
(
|
||||
|
||||
@ -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<Type>() && var.isPointData(wantPointData));
|
||||
|
||||
|
||||
@ -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_(),
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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<const TimeState&>(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
|
||||
|
||||
@ -81,22 +81,6 @@ addNamedToRunTimeSelectionTable
|
||||
} // End namespace Foam
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
static inline const TimeState* lookupTimeState
|
||||
(
|
||||
const polyMesh& m
|
||||
)
|
||||
{
|
||||
return &static_cast<const TimeState&>(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 * * * * * * * * * * * //
|
||||
|
||||
Reference in New Issue
Block a user