functionObjectList and Time modifications

- added clear() method to functionObjectList. It also gets called by ~Time().
  This should destroy function objects before anything else gets
  destroyed (eg, objectRegistry).
This commit is contained in:
Mark Olesen
2009-02-12 22:13:30 +01:00
parent d8ec3376fc
commit fafb3e8885
9 changed files with 55 additions and 51 deletions

View File

@ -27,6 +27,8 @@ License
#include "Time.H" #include "Time.H"
#include "PstreamReduceOps.H" #include "PstreamReduceOps.H"
#include <sstream>
// * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * * // // * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * * //
defineTypeNameAndDebug(Foam::Time, 0); defineTypeNameAndDebug(Foam::Time, 0);
@ -350,18 +352,21 @@ Foam::Time::Time
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::Time::~Time() Foam::Time::~Time()
{} {
// destroy function objects first
functionObjects_.clear();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::word Foam::Time::timeName(const scalar t) Foam::word Foam::Time::timeName(const scalar t)
{ {
std::ostringstream osBuffer; std::ostringstream buf;
osBuffer.setf(ios_base::fmtflags(format_), ios_base::floatfield); buf.setf(ios_base::fmtflags(format_), ios_base::floatfield);
osBuffer.precision(precision_); buf.precision(precision_);
osBuffer << t; buf << t;
return osBuffer.str(); return buf.str();
} }
@ -643,7 +648,7 @@ Foam::Time& Foam::Time::operator++()
setTime(0.0, timeIndex_); setTime(0.0, timeIndex_);
} }
switch(writeControl_) switch (writeControl_)
{ {
case wcTimeStep: case wcTimeStep:
outputTime_ = !(timeIndex_ % label(writeInterval_)); outputTime_ = !(timeIndex_ % label(writeInterval_));

View File

@ -264,19 +264,8 @@ bool Foam::Time::writeObject
timeDict.add("deltaT", deltaT_); timeDict.add("deltaT", deltaT_);
timeDict.add("deltaT0", deltaT0_); timeDict.add("deltaT0", deltaT0_);
timeDict.regIOobject::writeObject timeDict.regIOobject::writeObject(fmt, ver, cmp);
( bool writeOK = objectRegistry::writeObject(fmt, ver, cmp);
fmt,
ver,
cmp
);
bool writeOK = objectRegistry::writeObject
(
fmt,
ver,
cmp
);
if (writeOK && purgeWrite_) if (writeOK && purgeWrite_)
{ {
@ -306,7 +295,7 @@ bool Foam::Time::writeNow()
bool Foam::Time::writeAndEnd() bool Foam::Time::writeAndEnd()
{ {
stopAt_ = saWriteNow; stopAt_ = saWriteNow;
endTime_ = value(); endTime_ = value();
return writeNow(); return writeNow();

View File

@ -97,6 +97,15 @@ Foam::functionObjectList::~functionObjectList()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::functionObjectList::clear()
{
PtrList<functionObject>::clear();
digests_.clear();
indices_.clear();
updated_ = false;
}
bool Foam::functionObjectList::start() bool Foam::functionObjectList::start()
{ {
return read(); return read();
@ -157,7 +166,6 @@ bool Foam::functionObjectList::read()
HashTable<label> newIndices; HashTable<label> newIndices;
label nFunc = 0; label nFunc = 0;
label oldIndex = -1;
if (entryPtr->isDict()) if (entryPtr->isDict())
{ {
@ -179,6 +187,7 @@ bool Foam::functionObjectList::read()
newDigs[nFunc] = dict.digest(); newDigs[nFunc] = dict.digest();
label oldIndex;
functionObject* objPtr = remove(key, oldIndex); functionObject* objPtr = remove(key, oldIndex);
if (objPtr) if (objPtr)
{ {
@ -220,6 +229,7 @@ bool Foam::functionObjectList::read()
newDigs[nFunc] = dict.digest(); newDigs[nFunc] = dict.digest();
label oldIndex;
functionObject* objPtr = remove(key, oldIndex); functionObject* objPtr = remove(key, oldIndex);
if (objPtr) if (objPtr)
{ {
@ -248,13 +258,13 @@ bool Foam::functionObjectList::read()
// updating the PtrList of functionObjects also deletes any existing, // updating the PtrList of functionObjects also deletes any existing,
// but unused functionObjects // but unused functionObjects
this->transfer(newPtrs); PtrList<functionObject>::transfer(newPtrs);
digests_.transfer(newDigs); digests_.transfer(newDigs);
indices_.transfer(newIndices); indices_.transfer(newIndices);
} }
else else
{ {
this->clear(); PtrList<functionObject>::clear();
digests_.clear(); digests_.clear();
indices_.clear(); indices_.clear();
} }

View File

@ -127,6 +127,16 @@ public:
// Member Functions // Member Functions
//- Return the number of elements in the List.
using PtrList<functionObject>::size;
//- Return true if the List is empty (ie, size() is zero).
using PtrList<functionObject>::empty;
//- Clear the list of function objects
virtual void clear();
//- Start is called at the start of the time-loop //- Start is called at the start of the time-loop
virtual bool start(); virtual bool start();

View File

@ -29,10 +29,7 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam defineTypeNameAndDebug(Foam::objectRegistry, 0);
{
defineTypeNameAndDebug(objectRegistry, 0);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -86,9 +83,9 @@ Foam::objectRegistry::~objectRegistry()
{ {
if (iter()->ownedByRegistry()) if (iter()->ownedByRegistry())
{ {
regIOobject* elemPtr = iter(); regIOobject* object = iter();
erase(iter); erase(iter);
delete elemPtr; delete object;
} }
} }
} }
@ -206,18 +203,15 @@ bool Foam::objectRegistry::checkOut(regIOobject& io) const
bool Foam::objectRegistry::modified() const bool Foam::objectRegistry::modified() const
{ {
bool anyModified = false;
for (const_iterator iter = begin(); iter != end(); ++iter) for (const_iterator iter = begin(); iter != end(); ++iter)
{ {
if (iter()->modified()) if (iter()->modified())
{ {
anyModified = true; return true;
break;
} }
} }
return anyModified; return false;
} }

View File

@ -5,6 +5,6 @@ set -x
wmake libo postCalc wmake libo postCalc
wmake libso foamCalcFunctions wmake libso foamCalcFunctions
(cd functionObjects && ./Allwmake) functionObjects/Allwmake
# ----------------------------------------------------------------- end-of-file # ----------------------------------------------------------------- end-of-file

View File

@ -47,11 +47,11 @@ const Foam::NamedEnum<Foam::outputFilterOutputControl::outputControls, 2>
Foam::outputFilterOutputControl::outputFilterOutputControl Foam::outputFilterOutputControl::outputFilterOutputControl
( (
const Time& time, const Time& t,
const dictionary& dict const dictionary& dict
) )
: :
time_(time), time_(t),
outputControl_(ocTimeStep), outputControl_(ocTimeStep),
outputInterval_(0) outputInterval_(0)
{ {
@ -93,8 +93,8 @@ bool Foam::outputFilterOutputControl::output() const
{ {
return return
( (
!(time_.timeIndex() % outputInterval_) (outputInterval_ <= 1)
|| (outputInterval_ <= 1) || !(time_.timeIndex() % outputInterval_)
); );
break; break;
} }

View File

@ -88,22 +88,18 @@ public:
// Constructors // Constructors
//- Construct from dictionary and Time object //- Construct from Time object and dictionary
outputFilterOutputControl outputFilterOutputControl(const Time&, const dictionary&);
(
const Time& time,
const dictionary& dict
);
// Destructor // Destructor
~outputFilterOutputControl(); ~outputFilterOutputControl();
// Member Functions // Member Functions
//- Read from dictionary //- Read from dictionary
void read(const dictionary& dict); void read(const dictionary&);
//- Return const access to the Time object //- Return const access to the Time object
const Time& time() const const Time& time() const

View File

@ -2,8 +2,8 @@
cd ${0%/*} || exit 1 # run from this directory cd ${0%/*} || exit 1 # run from this directory
set -x set -x
(cd LES && ./Allwmake ) LES/Allwmake
(cd incompressible && ./Allwmake ) incompressible/Allwmake
(cd compressible && ./Allwmake ) compressible/Allwmake
# ----------------------------------------------------------------- end-of-file # ----------------------------------------------------------------- end-of-file