mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
functionObjectList: Rationalized and simplified the handling of disabled functionObjects
Simplified and generalized the handling of functionObjects which fail to construct by removing them from the list rather than maintaining an "enabled" switch in each functionObject.
This commit is contained in:
@ -45,7 +45,7 @@ Foam::functionObject* Foam::functionObjectList::remove
|
||||
{
|
||||
oldIndex = fnd();
|
||||
|
||||
// retrieve the pointer and remove it from the old list
|
||||
// Retrieve the pointer and remove it from the old list
|
||||
ptr = this->set(oldIndex, 0).ptr();
|
||||
indices_.erase(fnd);
|
||||
}
|
||||
@ -168,7 +168,7 @@ void Foam::functionObjectList::on()
|
||||
|
||||
void Foam::functionObjectList::off()
|
||||
{
|
||||
// for safety, also force a read() when execution is turned back on
|
||||
// For safety, also force a read() when execution is turned back on
|
||||
updated_ = execution_ = false;
|
||||
}
|
||||
|
||||
@ -274,10 +274,10 @@ bool Foam::functionObjectList::read()
|
||||
bool ok = true;
|
||||
updated_ = execution_;
|
||||
|
||||
// avoid reading/initializing if execution is off
|
||||
// Avoid reading/initializing if execution is off
|
||||
if (!execution_)
|
||||
{
|
||||
return ok;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Update existing and add new functionObjects
|
||||
@ -296,31 +296,42 @@ bool Foam::functionObjectList::read()
|
||||
|
||||
label nFunc = 0;
|
||||
|
||||
if (entryPtr->isDict())
|
||||
if (!entryPtr->isDict())
|
||||
{
|
||||
// a dictionary of functionObjects
|
||||
const dictionary& functionDicts = entryPtr->dict();
|
||||
FatalIOErrorInFunction(parentDict_)
|
||||
<< "'functions' entry is not a dictionary"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
newPtrs.setSize(functionDicts.size());
|
||||
newDigs.setSize(functionDicts.size());
|
||||
const dictionary& functionDicts = entryPtr->dict();
|
||||
|
||||
forAllConstIter(dictionary, functionDicts, iter)
|
||||
newPtrs.setSize(functionDicts.size());
|
||||
newDigs.setSize(functionDicts.size());
|
||||
|
||||
forAllConstIter(dictionary, functionDicts, iter)
|
||||
{
|
||||
const word& key = iter().keyword();
|
||||
|
||||
if (!iter().isDict())
|
||||
{
|
||||
// safety:
|
||||
if (!iter().isDict())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
const word& key = iter().keyword();
|
||||
const dictionary& dict = iter().dict();
|
||||
IOWarningInFunction(parentDict_)
|
||||
<< "Entry " << key << " is not a dictionary" << endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
newDigs[nFunc] = dict.digest();
|
||||
const dictionary& dict = iter().dict();
|
||||
bool enabled = dict.lookupOrDefault("enabled", true);
|
||||
|
||||
label oldIndex;
|
||||
functionObject* objPtr = remove(key, oldIndex);
|
||||
if (objPtr)
|
||||
newDigs[nFunc] = dict.digest();
|
||||
|
||||
label oldIndex;
|
||||
functionObject* objPtr = remove(key, oldIndex);
|
||||
|
||||
if (objPtr)
|
||||
{
|
||||
if (enabled)
|
||||
{
|
||||
// an existing functionObject, and dictionary changed
|
||||
// Dictionary changed for an existing functionObject
|
||||
if (newDigs[nFunc] != digests_[oldIndex])
|
||||
{
|
||||
ok = objPtr->read(dict) && ok;
|
||||
@ -328,65 +339,48 @@ bool Foam::functionObjectList::read()
|
||||
}
|
||||
else
|
||||
{
|
||||
// new functionObject
|
||||
objPtr = functionObject::New(key, time_, dict).ptr();
|
||||
ok = objPtr->start() && ok;
|
||||
}
|
||||
|
||||
newPtrs.set(nFunc, objPtr);
|
||||
newIndices.insert(key, nFunc);
|
||||
nFunc++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// a list of functionObjects
|
||||
PtrList<entry> functionDicts(entryPtr->stream());
|
||||
|
||||
newPtrs.setSize(functionDicts.size());
|
||||
newDigs.setSize(functionDicts.size());
|
||||
|
||||
forAllIter(PtrList<entry>, functionDicts, iter)
|
||||
{
|
||||
// safety:
|
||||
if (!iter().isDict())
|
||||
{
|
||||
// Delete the disabled functionObject
|
||||
delete objPtr;
|
||||
objPtr = NULL;
|
||||
continue;
|
||||
}
|
||||
const word& key = iter().keyword();
|
||||
const dictionary& dict = iter().dict();
|
||||
}
|
||||
else if (enabled)
|
||||
{
|
||||
autoPtr<functionObject> foPtr;
|
||||
|
||||
newDigs[nFunc] = dict.digest();
|
||||
|
||||
label oldIndex;
|
||||
functionObject* objPtr = remove(key, oldIndex);
|
||||
if (objPtr)
|
||||
FatalError.throwExceptions();
|
||||
FatalIOError.throwExceptions();
|
||||
try
|
||||
{
|
||||
// an existing functionObject, and dictionary changed
|
||||
if (newDigs[nFunc] != digests_[oldIndex])
|
||||
{
|
||||
ok = objPtr->read(dict) && ok;
|
||||
}
|
||||
foPtr = functionObject::New(key, time_, dict);
|
||||
}
|
||||
else
|
||||
catch (...)
|
||||
{}
|
||||
FatalError.dontThrowExceptions();
|
||||
FatalIOError.dontThrowExceptions();
|
||||
|
||||
if (foPtr.valid())
|
||||
{
|
||||
// new functionObject
|
||||
objPtr = functionObject::New(key, time_, dict).ptr();
|
||||
objPtr = foPtr.ptr();
|
||||
ok = objPtr->start() && ok;
|
||||
}
|
||||
}
|
||||
|
||||
// Insert active functionObjects into the list
|
||||
if (objPtr)
|
||||
{
|
||||
newPtrs.set(nFunc, objPtr);
|
||||
newIndices.insert(key, nFunc);
|
||||
nFunc++;
|
||||
}
|
||||
}
|
||||
|
||||
// safety:
|
||||
newPtrs.setSize(nFunc);
|
||||
newDigs.setSize(nFunc);
|
||||
|
||||
// updating the PtrList of functionObjects also deletes any existing,
|
||||
// but unused functionObjects
|
||||
// Updating the PtrList of functionObjects deletes any
|
||||
// existing unused functionObjects
|
||||
PtrList<functionObject>::transfer(newPtrs);
|
||||
digests_.transfer(newDigs);
|
||||
indices_.transfer(newIndices);
|
||||
|
||||
@ -138,7 +138,7 @@ public:
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~functionObjectList();
|
||||
~functionObjectList();
|
||||
|
||||
|
||||
// Member Functions
|
||||
@ -153,46 +153,45 @@ public:
|
||||
using PtrList<functionObject>::operator[];
|
||||
|
||||
//- Clear the list of function objects
|
||||
virtual void clear();
|
||||
void clear();
|
||||
|
||||
//- Find the ID of a given function object by name
|
||||
virtual label findObjectID(const word& name) const;
|
||||
label findObjectID(const word& name) const;
|
||||
|
||||
//- Switch the function objects on
|
||||
virtual void on();
|
||||
void on();
|
||||
|
||||
//- Switch the function objects off
|
||||
virtual void off();
|
||||
void off();
|
||||
|
||||
//- Return the execution status (on/off) of the function objects
|
||||
virtual bool status() const;
|
||||
|
||||
bool status() const;
|
||||
|
||||
//- Called at the start of the time-loop
|
||||
virtual bool start();
|
||||
bool start();
|
||||
|
||||
//- Called at each ++ or += of the time-loop. forceWrite overrides
|
||||
// the usual outputControl behaviour and forces writing always
|
||||
// (used in postprocessing mode)
|
||||
virtual bool execute(const bool forceWrite = false);
|
||||
// (used in post-processing mode)
|
||||
bool execute(const bool forceWrite = false);
|
||||
|
||||
//- Called when Time::run() determines that the time-loop exits
|
||||
virtual bool end();
|
||||
bool end();
|
||||
|
||||
//- Called when time was set at the end of the Time::operator++
|
||||
virtual bool timeSet();
|
||||
bool timeSet();
|
||||
|
||||
//- Called at the end of Time::adjustDeltaT() if adjustTime is true
|
||||
virtual bool adjustTimeStep();
|
||||
bool adjustTimeStep();
|
||||
|
||||
//- Read and set the function objects if their data have changed
|
||||
virtual bool read();
|
||||
bool read();
|
||||
|
||||
//- Update for changes of mesh
|
||||
virtual void updateMesh(const mapPolyMesh& mpm);
|
||||
void updateMesh(const mapPolyMesh& mpm);
|
||||
|
||||
//- Update for changes of mesh
|
||||
virtual void movePoints(const polyMesh& mesh);
|
||||
void movePoints(const polyMesh& mesh);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user