objectRegistry: Corrected caching of registered temporary objects

For example the generation term in the k-epsilon turbulence kEpsilon:G is a
temporary field that is specifically named and registered so that it can be
looked-up be the wall-function boundary conditions and requires slightly
different handling compared to normal temporary fields which are not registered.

The tutorials/incompressible/simpleFoam/pitzDaily case now demostrates this
functionality with the addition of

cacheTemporaryObjects
(
    kEpsilon:G
);

functions
{
    #includeFunc writeObjects(objects = (kEpsilon:G))
}

in controlDict which caches kEpsilon:G and writes it at every write time.
This commit is contained in:
Henry Weller
2019-09-01 10:18:45 +01:00
parent c909bdc38d
commit 30cceb42c0
4 changed files with 52 additions and 4 deletions

View File

@ -82,6 +82,15 @@ void Foam::objectRegistry::readCacheTemporaryObjects() const
}
void Foam::objectRegistry::deleteCachedObject(regIOobject& cachedOb) const
{
cachedOb.release();
cachedOb.checkOut();
cachedOb.rename(cachedOb.name() + "Cached");
delete &cachedOb;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::objectRegistry::objectRegistry
@ -255,6 +264,34 @@ bool Foam::objectRegistry::checkIn(regIOobject& io) const
<< endl;
}
// Delete cached object with the same name as io and if it is in the
// cacheTemporaryObjects list
if (cacheTemporaryObjects_.size())
{
HashTable<Pair<bool>>::iterator cacheIter
(
cacheTemporaryObjects_.find(io.name())
);
if (cacheIter != cacheTemporaryObjects_.end())
{
iterator iter = const_cast<objectRegistry&>(*this).find(io.name());
if (iter != end() && iter() != &io && iter()->ownedByRegistry())
{
if (objectRegistry::debug)
{
Pout<< "objectRegistry::checkIn(regIOobject&) : "
<< name() << " : deleting cached object " << iter.key()
<< endl;
}
cacheIter().first() = false;
deleteCachedObject(*iter());
}
}
}
return const_cast<objectRegistry&>(*this).insert(io.name(), &io);
}

View File

@ -87,8 +87,12 @@ class objectRegistry
// Used to terminate searching within the ancestors
bool parentNotTime() const;
//- Read the cacheTemporaryObjects list from controlDict
void readCacheTemporaryObjects() const;
//- Delete the current cached object before caching a new object
void deleteCachedObject(regIOobject& cachedOb) const;
public:

View File

@ -240,10 +240,7 @@ bool Foam::objectRegistry::cacheTemporaryObject(Object& ob) const
// If the object is already cached in the database delete it
if (&cachedOb != &ob && cachedOb.ownedByRegistry())
{
cachedOb.release();
cachedOb.checkOut();
cachedOb.rename(cachedOb.name() + "Cached");
delete &cachedOb;
deleteCachedObject(cachedOb);
}
}

View File

@ -50,4 +50,14 @@ functions
#includeFunc streamlines
}
cacheTemporaryObjects
(
kEpsilon:G
);
functions
{
#includeFunc writeObjects(objects = (kEpsilon:G))
}
// ************************************************************************* //