Commit d8ec3376 authored by Mark Olesen's avatar Mark Olesen
Browse files

avoid calling functionObjectList twice with Time::operator+=()

- make functionObjectList mutable so it can change behind our back
parent b5a1f093
......@@ -27,8 +27,6 @@ License
#include "Time.H"
#include "PstreamReduceOps.H"
#include <sstream>
// * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * * //
defineTypeNameAndDebug(Foam::Time, 0);
......@@ -490,9 +488,13 @@ bool Foam::Time::run() const
{
bool running = value() < (endTime_ - 0.5*deltaT_);
if (!subCycling_ && !running && timeIndex_ != startTimeIndex_)
if (!running && !subCycling_)
{
const_cast<functionObjectList&>(functionObjects_).execute();
// Note, the execute() also calls an indirect start() if required
if (timeIndex_ != startTimeIndex_)
{
functionObjects_.execute();
}
}
return running;
......@@ -610,24 +612,8 @@ Foam::Time& Foam::Time::operator+=(const dimensionedScalar& deltaT)
Foam::Time& Foam::Time::operator+=(const scalar deltaT)
{
readModifiedObjects();
if (!subCycling_)
{
if (timeIndex_ == startTimeIndex_)
{
functionObjects_.start();
}
else
{
functionObjects_.execute();
}
}
setDeltaT(deltaT);
operator++();
return *this;
return operator++();
}
......@@ -660,19 +646,19 @@ Foam::Time& Foam::Time::operator++()
switch(writeControl_)
{
case wcTimeStep:
outputTime_ = !(timeIndex_%label(writeInterval_));
outputTime_ = !(timeIndex_ % label(writeInterval_));
break;
case wcRunTime:
case wcAdjustableRunTime:
{
label outputTimeIndex =
label outputIndex =
label(((value() - startTime_) + 0.5*deltaT_)/writeInterval_);
if (outputTimeIndex > outputTimeIndex_)
if (outputIndex > outputTimeIndex_)
{
outputTime_ = true;
outputTimeIndex_ = outputTimeIndex;
outputTimeIndex_ = outputIndex;
}
else
{
......@@ -683,13 +669,11 @@ Foam::Time& Foam::Time::operator++()
case wcCpuTime:
{
label outputTimeIndex =
label(elapsedCpuTime()/writeInterval_);
if (outputTimeIndex > outputTimeIndex_)
label outputIndex = label(elapsedCpuTime()/writeInterval_);
if (outputIndex > outputTimeIndex_)
{
outputTime_ = true;
outputTimeIndex_ = outputTimeIndex;
outputTimeIndex_ = outputIndex;
}
else
{
......@@ -700,11 +684,11 @@ Foam::Time& Foam::Time::operator++()
case wcClockTime:
{
label outputTimeIndex = label(elapsedClockTime()/writeInterval_);
if (outputTimeIndex > outputTimeIndex_)
label outputIndex = label(elapsedClockTime()/writeInterval_);
if (outputIndex > outputTimeIndex_)
{
outputTime_ = true;
outputTimeIndex_ = outputTimeIndex;
outputTimeIndex_ = outputIndex;
}
else
{
......
......@@ -26,7 +26,7 @@ Class
Foam::Time
Description
Class to control time during FOAM simulations which is also the
Class to control time during OpenFOAM simulations that is also the
top-level objectRegistry.
SourceFiles
......@@ -109,7 +109,7 @@ protected:
// Protected data
label startTimeIndex_;
label startTimeIndex_;
scalar startTime_;
scalar endTime_;
......@@ -121,10 +121,10 @@ protected:
scalar writeInterval_;
label purgeWrite_;
label purgeWrite_;
mutable FIFOStack<word> previousOutputTimes_;
//- Is the time currently being sub-cycled
//- Is the time currently being sub-cycled?
bool subCycling_;
//- Time directory name format
......@@ -157,21 +157,21 @@ private:
//- Default graph format
word graphFormat_;
//- Is runtim modification of dictionaries allowed
//- Is runtime modification of dictionaries allowed?
Switch runTimeModifiable_;
//- Instantiate a dummy class to cause the reading of dynamic libraries
dlLibraryTable::readDlLibrary readLibs_;
//- Function objects executed at start and on ++, +=
functionObjectList functionObjects_;
mutable functionObjectList functionObjects_;
public:
TypeName("time");
//- The default control dictionary name
//- The default control dictionary name (normally "controlDict")
static word controlDictName;
......@@ -282,8 +282,8 @@ public:
void readModifiedObjects();
//- Return the location of "dir" containing the file "name".
// (Used in reading mesh data)
// If name is null search for the directory "dir" only
// (eg, used in reading mesh data)
// If name is null, search for the directory "dir" only
word findInstance
(
const fileName& dir,
......@@ -291,7 +291,7 @@ public:
const IOobject::readOption rOpt = IOobject::MUST_READ
) const;
//- Search tha case for valid time directories
//- Search the case for valid time directories
instantList times() const;
//- Search the case for the time directory path
......@@ -307,9 +307,9 @@ public:
//- Write using given format, version and compression
virtual bool writeObject
(
IOstream::streamFormat fmt,
IOstream::versionNumber ver,
IOstream::compressionType cmp
IOstream::streamFormat,
IOstream::versionNumber,
IOstream::compressionType
) const;
//- Write the objects now and continue the run
......@@ -409,7 +409,7 @@ public:
//- Prefix increment
virtual Time& operator++();
//- Postfix increment
//- Postfix increment, this is identical to the prefix increment
virtual Time& operator++(int);
};
......
......@@ -61,7 +61,7 @@ void Foam::Time::readDict()
if (oldWriteInterval != writeInterval_)
{
switch(writeControl_)
switch (writeControl_)
{
case wcRunTime:
case wcAdjustableRunTime:
......@@ -180,11 +180,7 @@ void Foam::Time::readDict()
}
controlDict_.readIfPresent("graphFormat", graphFormat_);
if (controlDict_.found("runTimeModifiable"))
{
runTimeModifiable_ = Switch(controlDict_.lookup("runTimeModifiable"));
}
controlDict_.readIfPresent("runTimeModifiable", runTimeModifiable_);
}
......@@ -286,7 +282,7 @@ bool Foam::Time::writeObject
{
previousOutputTimes_.push(timeName());
while(previousOutputTimes_.size() > purgeWrite_)
while (previousOutputTimes_.size() > purgeWrite_)
{
rmDir(objectRegistry::path(previousOutputTimes_.pop()));
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment