ENH: improve volRegion handling of moving meshes (#1194)

- implemented as lazy evaluation with an additional update() method.
  This avoids unnecessary changes until the values are actually
  required.

- apply mesh motion changes for momentum, volFieldValue,
  specieReactionRates function objects
This commit is contained in:
Mark Olesen
2019-02-06 10:25:47 +01:00
parent fb561daf7a
commit 8f572a5e71
12 changed files with 162 additions and 53 deletions

View File

@ -109,6 +109,8 @@ void Foam::functionObjects::volRegion::calculateCache()
<< " Region has no cells"
<< exit(FatalError);
}
requireUpdate_ = false;
}
@ -137,6 +139,7 @@ Foam::functionObjects::volRegion::volRegion
)
:
volMesh_(mesh),
requireUpdate_(true),
cellIds_(),
nCells_(0),
V_(Zero),
@ -158,10 +161,7 @@ Foam::functionObjects::volRegion::volRegion
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::volRegion::read
(
const dictionary& dict
)
bool Foam::functionObjects::volRegion::read(const dictionary& dict)
{
switch (regionType_)
{
@ -195,6 +195,15 @@ bool Foam::functionObjects::volRegion::read
const Foam::labelList& Foam::functionObjects::volRegion::cellIDs() const
{
#ifdef FULLDEBUG
if (requireUpdate_)
{
FatalErrorInFunction
<< "Retrieving cached values that are not up-to-date" << nl
<< exit(FatalError);
}
#endif
switch (regionType_)
{
case vrtCellSet:
@ -213,15 +222,27 @@ const Foam::labelList& Foam::functionObjects::volRegion::cellIDs() const
}
bool Foam::functionObjects::volRegion::update()
{
if (requireUpdate_)
{
calculateCache();
return true;
}
return false;
}
void Foam::functionObjects::volRegion::updateMesh(const mapPolyMesh&)
{
calculateCache();
requireUpdate_ = true;
}
void Foam::functionObjects::volRegion::movePoints(const polyMesh&)
{
calculateCache();
requireUpdate_ = true;
}

View File

@ -30,6 +30,11 @@ Group
Description
Volume (cell) region selection class.
The adjustments for mesh changes have been implemented with a lazy
evaluation, to avoid unnecessary recalculation until the values are
actually required. The update() method is used to ensure the cache
values are up-to-date.
Examples of function object specification:
\verbatim
volRegion0
@ -96,6 +101,9 @@ class volRegion
const fvMesh& volMesh_;
//- Flag to indicate whether the volRegion requires updating
bool requireUpdate_;
//- The cell ids, from cellSet
labelList cellIds_;
@ -178,6 +186,10 @@ public:
//- Return total volume of the selected region
inline scalar V() const;
//- Update the cached values as required
// \return False if the values were already up to date
bool update();
//- Read from dictionary
virtual bool read(const dictionary& dict);

View File

@ -28,18 +28,45 @@ License
inline const Foam::functionObjects::volRegion::regionTypes&
Foam::functionObjects::volRegion::regionType() const
{
#ifdef FULLDEBUG
if (requireUpdate_)
{
FatalErrorInFunction
<< "Retrieving cached values that are not up-to-date" << nl
<< exit(FatalError);
}
#endif
return regionType_;
}
inline Foam::label Foam::functionObjects::volRegion::nCells() const
{
#ifdef FULLDEBUG
if (requireUpdate_)
{
FatalErrorInFunction
<< "Retrieving cached values that are not up-to-date" << nl
<< exit(FatalError);
}
#endif
return nCells_;
}
inline Foam::scalar Foam::functionObjects::volRegion::V() const
{
#ifdef FULLDEBUG
if (requireUpdate_)
{
FatalErrorInFunction
<< "Retrieving cached values that are not up-to-date" << nl
<< exit(FatalError);
}
#endif
return V_;
}