mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
functionObjectList with SHA1Digest tracking
This commit is contained in:
@ -74,7 +74,7 @@ namespace Foam
|
||||
}
|
||||
else
|
||||
{
|
||||
functionObjectList fol(runTime, runTime.controlDict());
|
||||
functionObjectList fol(runTime);
|
||||
fol.start();
|
||||
fol.execute();
|
||||
}
|
||||
|
||||
@ -71,10 +71,10 @@ Foam::autoPtr<Foam::functionObject> Foam::functionObject::New
|
||||
FatalErrorIn
|
||||
(
|
||||
"functionObject::New"
|
||||
"(const word& functionType, const Time&, const dictionary&)"
|
||||
"(const word& name, const Time&, const dictionary&)"
|
||||
) << "Unknown function type "
|
||||
<< functionType << endl << endl
|
||||
<< "Table of functionObjects is empty"
|
||||
<< functionType << nl << nl
|
||||
<< "Table of functionObjects is empty" << endl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
@ -86,11 +86,11 @@ Foam::autoPtr<Foam::functionObject> Foam::functionObject::New
|
||||
FatalErrorIn
|
||||
(
|
||||
"functionObject::New"
|
||||
"(const word& functionType, const Time&, const dictionary&)"
|
||||
"(const word& name, const Time&, const dictionary&)"
|
||||
) << "Unknown function type "
|
||||
<< functionType << endl << endl
|
||||
<< "Valid functions are : " << endl
|
||||
<< dictionaryConstructorTablePtr_->toc()
|
||||
<< functionType << nl << nl
|
||||
<< "Valid functions are : " << nl
|
||||
<< dictionaryConstructorTablePtr_->toc() << endl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
|
||||
@ -121,7 +121,7 @@ public:
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Select from Time and Istream
|
||||
//- Select from dictionary, based on its "type" entry
|
||||
static autoPtr<functionObject> New
|
||||
(
|
||||
const word& name,
|
||||
@ -143,7 +143,7 @@ public:
|
||||
//- execute is called at each ++ or += of the time-loop
|
||||
virtual bool execute() = 0;
|
||||
|
||||
//- Read and set the function object if its data has changed
|
||||
//- Read and set the function object if its data have changed
|
||||
virtual bool read(const dictionary& dict) = 0;
|
||||
};
|
||||
|
||||
|
||||
@ -29,7 +29,8 @@ License
|
||||
|
||||
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObject* Foam::functionObjectList::remove(const word& key)
|
||||
Foam::functionObject*
|
||||
Foam::functionObjectList::remove(const word& key, label& oldIndex)
|
||||
{
|
||||
functionObject* ptr = 0;
|
||||
|
||||
@ -38,10 +39,16 @@ Foam::functionObject* Foam::functionObjectList::remove(const word& key)
|
||||
|
||||
if (fnd != indices_.end())
|
||||
{
|
||||
// remove the pointer from the old list
|
||||
ptr = functions_.set(fnd(), 0).ptr();
|
||||
oldIndex = fnd();
|
||||
|
||||
// retrieve the pointer and remove it from the old list
|
||||
ptr = this->set(oldIndex, 0).ptr();
|
||||
indices_.erase(fnd);
|
||||
}
|
||||
else
|
||||
{
|
||||
oldIndex = -1;
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
||||
@ -55,7 +62,8 @@ Foam::functionObjectList::functionObjectList
|
||||
const bool execution
|
||||
)
|
||||
:
|
||||
functions_(),
|
||||
PtrList<functionObject>(),
|
||||
digests_(),
|
||||
indices_(),
|
||||
time_(t),
|
||||
parentDict_(t.controlDict()),
|
||||
@ -71,7 +79,8 @@ Foam::functionObjectList::functionObjectList
|
||||
const bool execution
|
||||
)
|
||||
:
|
||||
functions_(),
|
||||
PtrList<functionObject>(),
|
||||
digests_(),
|
||||
indices_(),
|
||||
time_(t),
|
||||
parentDict_(parentDict),
|
||||
@ -105,7 +114,7 @@ bool Foam::functionObjectList::execute()
|
||||
read();
|
||||
}
|
||||
|
||||
forAllIter(PtrList<functionObject>, functions_, iter)
|
||||
forAllIter(PtrList<functionObject>, *this, iter)
|
||||
{
|
||||
ok = iter().execute() && ok;
|
||||
}
|
||||
@ -123,7 +132,8 @@ void Foam::functionObjectList::on()
|
||||
|
||||
void Foam::functionObjectList::off()
|
||||
{
|
||||
execution_ = false;
|
||||
// for safety, also force a read() when execution is turned back on
|
||||
updated_ = execution_ = false;
|
||||
}
|
||||
|
||||
|
||||
@ -143,15 +153,19 @@ bool Foam::functionObjectList::read()
|
||||
if (entryPtr)
|
||||
{
|
||||
PtrList<functionObject> newPtrs;
|
||||
List<SHA1Digest> newDigs;
|
||||
HashTable<label> newIndices;
|
||||
|
||||
label nFunc = 0;
|
||||
label oldIndex = -1;
|
||||
|
||||
if (entryPtr->isDict())
|
||||
{
|
||||
// a dictionary of functionObjects
|
||||
const dictionary& functionDicts = entryPtr->dict();
|
||||
|
||||
newPtrs.setSize(functionDicts.size());
|
||||
newDigs.setSize(functionDicts.size());
|
||||
|
||||
forAllConstIter(dictionary, functionDicts, iter)
|
||||
{
|
||||
@ -163,11 +177,16 @@ bool Foam::functionObjectList::read()
|
||||
const word& key = iter().keyword();
|
||||
const dictionary& dict = iter().dict();
|
||||
|
||||
functionObject* objPtr = remove(key);
|
||||
newDigs[nFunc] = dict.digest();
|
||||
|
||||
functionObject* objPtr = remove(key, oldIndex);
|
||||
if (objPtr)
|
||||
{
|
||||
// existing functionObject
|
||||
ok = objPtr->read(dict) && ok;
|
||||
// an existing functionObject, and dictionary changed
|
||||
if (newDigs[nFunc] != digests_[oldIndex])
|
||||
{
|
||||
ok = objPtr->read(dict) && ok;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -185,7 +204,9 @@ bool Foam::functionObjectList::read()
|
||||
{
|
||||
// a list of functionObjects
|
||||
PtrList<entry> functionDicts(entryPtr->stream());
|
||||
|
||||
newPtrs.setSize(functionDicts.size());
|
||||
newDigs.setSize(functionDicts.size());
|
||||
|
||||
forAllIter(PtrList<entry>, functionDicts, iter)
|
||||
{
|
||||
@ -197,11 +218,16 @@ bool Foam::functionObjectList::read()
|
||||
const word& key = iter().keyword();
|
||||
const dictionary& dict = iter().dict();
|
||||
|
||||
functionObject* objPtr = remove(key);
|
||||
newDigs[nFunc] = dict.digest();
|
||||
|
||||
functionObject* objPtr = remove(key, oldIndex);
|
||||
if (objPtr)
|
||||
{
|
||||
// existing functionObject
|
||||
ok = objPtr->read(dict) && ok;
|
||||
// an existing functionObject, and dictionary changed
|
||||
if (newDigs[nFunc] != digests_[oldIndex])
|
||||
{
|
||||
ok = objPtr->read(dict) && ok;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -218,15 +244,18 @@ bool Foam::functionObjectList::read()
|
||||
|
||||
// safety:
|
||||
newPtrs.setSize(nFunc);
|
||||
newDigs.setSize(nFunc);
|
||||
|
||||
// update PtrList of functionObjects
|
||||
// also deletes existing, unused functionObjects
|
||||
functions_.transfer(newPtrs);
|
||||
// updating the PtrList of functionObjects also deletes any existing,
|
||||
// but unused functionObjects
|
||||
this->transfer(newPtrs);
|
||||
digests_.transfer(newDigs);
|
||||
indices_.transfer(newIndices);
|
||||
}
|
||||
else
|
||||
{
|
||||
functions_.clear();
|
||||
this->clear();
|
||||
digests_.clear();
|
||||
indices_.clear();
|
||||
}
|
||||
|
||||
|
||||
@ -43,6 +43,7 @@ SourceFiles
|
||||
#include "functionObject.H"
|
||||
#include "HashTable.H"
|
||||
#include "PtrList.H"
|
||||
#include "SHA1Digest.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -54,20 +55,20 @@ namespace Foam
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class functionObjectList
|
||||
:
|
||||
private PtrList<functionObject>
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- A list of function objects
|
||||
// Avoid 'is-a' relationship for protection
|
||||
PtrList<functionObject> functions_;
|
||||
//- A list of SHA1 digests for the function object dictionaries
|
||||
List<SHA1Digest> digests_;
|
||||
|
||||
//- Quick lookup of the index into the PtrList<functionObject>
|
||||
// Currently only used to manage rereading/deletion
|
||||
HashTable<label> indices_;
|
||||
//- Quick lookup of the index into functions/digests
|
||||
HashTable<label> indices_;
|
||||
|
||||
const Time& time_;
|
||||
|
||||
//- Dictionary containing the "functions" entry
|
||||
//- The parent dictionary containing a "functions" entry
|
||||
// This entry can either be a list or a dictionary of
|
||||
// functionObject specifications.
|
||||
const dictionary& parentDict_;
|
||||
@ -75,15 +76,16 @@ class functionObjectList
|
||||
//- Switch for the execution of the functionObjects
|
||||
bool execution_;
|
||||
|
||||
//- Tracks if read() was called while execution was turned off
|
||||
//- Tracks if read() was called while execution is on
|
||||
bool updated_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Remove and return the function object pointer by name.
|
||||
// Return NULL if it didn't exist.
|
||||
functionObject* remove(const word&);
|
||||
//- Remove and return the function object pointer by name,
|
||||
// and returns the old index via the parameter.
|
||||
// Returns a NULL pointer (and index -1) if it didn't exist.
|
||||
functionObject* remove(const word&, label& oldIndex);
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
functionObjectList(const functionObjectList&);
|
||||
@ -105,8 +107,11 @@ public:
|
||||
);
|
||||
|
||||
|
||||
//- Construct from Time, dictionary with "functions" entry
|
||||
// and the execution setting
|
||||
//- Construct from Time, a dictionary with "functions" entry
|
||||
// and the execution setting.
|
||||
// @param[in] parentDict - the parent dictionary containing
|
||||
// a "functions" entry, which can either be a list or a dictionary
|
||||
// of functionObject specifications.
|
||||
functionObjectList
|
||||
(
|
||||
const Time&,
|
||||
|
||||
Reference in New Issue
Block a user