Skip to content
Snippets Groups Projects
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
No related merge requests found
...@@ -27,8 +27,6 @@ License ...@@ -27,8 +27,6 @@ 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);
...@@ -490,9 +488,13 @@ bool Foam::Time::run() const ...@@ -490,9 +488,13 @@ bool Foam::Time::run() const
{ {
bool running = value() < (endTime_ - 0.5*deltaT_); 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; return running;
...@@ -610,24 +612,8 @@ Foam::Time& Foam::Time::operator+=(const dimensionedScalar& deltaT) ...@@ -610,24 +612,8 @@ Foam::Time& Foam::Time::operator+=(const dimensionedScalar& deltaT)
Foam::Time& Foam::Time::operator+=(const scalar deltaT) Foam::Time& Foam::Time::operator+=(const scalar deltaT)
{ {
readModifiedObjects();
if (!subCycling_)
{
if (timeIndex_ == startTimeIndex_)
{
functionObjects_.start();
}
else
{
functionObjects_.execute();
}
}
setDeltaT(deltaT); setDeltaT(deltaT);
operator++(); return operator++();
return *this;
} }
...@@ -660,19 +646,19 @@ Foam::Time& Foam::Time::operator++() ...@@ -660,19 +646,19 @@ Foam::Time& Foam::Time::operator++()
switch(writeControl_) switch(writeControl_)
{ {
case wcTimeStep: case wcTimeStep:
outputTime_ = !(timeIndex_%label(writeInterval_)); outputTime_ = !(timeIndex_ % label(writeInterval_));
break; break;
case wcRunTime: case wcRunTime:
case wcAdjustableRunTime: case wcAdjustableRunTime:
{ {
label outputTimeIndex = label outputIndex =
label(((value() - startTime_) + 0.5*deltaT_)/writeInterval_); label(((value() - startTime_) + 0.5*deltaT_)/writeInterval_);
if (outputTimeIndex > outputTimeIndex_) if (outputIndex > outputTimeIndex_)
{ {
outputTime_ = true; outputTime_ = true;
outputTimeIndex_ = outputTimeIndex; outputTimeIndex_ = outputIndex;
} }
else else
{ {
...@@ -683,13 +669,11 @@ Foam::Time& Foam::Time::operator++() ...@@ -683,13 +669,11 @@ Foam::Time& Foam::Time::operator++()
case wcCpuTime: case wcCpuTime:
{ {
label outputTimeIndex = label outputIndex = label(elapsedCpuTime()/writeInterval_);
label(elapsedCpuTime()/writeInterval_); if (outputIndex > outputTimeIndex_)
if (outputTimeIndex > outputTimeIndex_)
{ {
outputTime_ = true; outputTime_ = true;
outputTimeIndex_ = outputTimeIndex; outputTimeIndex_ = outputIndex;
} }
else else
{ {
...@@ -700,11 +684,11 @@ Foam::Time& Foam::Time::operator++() ...@@ -700,11 +684,11 @@ Foam::Time& Foam::Time::operator++()
case wcClockTime: case wcClockTime:
{ {
label outputTimeIndex = label(elapsedClockTime()/writeInterval_); label outputIndex = label(elapsedClockTime()/writeInterval_);
if (outputTimeIndex > outputTimeIndex_) if (outputIndex > outputTimeIndex_)
{ {
outputTime_ = true; outputTime_ = true;
outputTimeIndex_ = outputTimeIndex; outputTimeIndex_ = outputIndex;
} }
else else
{ {
......
...@@ -26,7 +26,7 @@ Class ...@@ -26,7 +26,7 @@ Class
Foam::Time Foam::Time
Description 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. top-level objectRegistry.
SourceFiles SourceFiles
...@@ -109,7 +109,7 @@ protected: ...@@ -109,7 +109,7 @@ protected:
// Protected data // Protected data
label startTimeIndex_; label startTimeIndex_;
scalar startTime_; scalar startTime_;
scalar endTime_; scalar endTime_;
...@@ -121,10 +121,10 @@ protected: ...@@ -121,10 +121,10 @@ protected:
scalar writeInterval_; scalar writeInterval_;
label purgeWrite_; label purgeWrite_;
mutable FIFOStack<word> previousOutputTimes_; mutable FIFOStack<word> previousOutputTimes_;
//- Is the time currently being sub-cycled //- Is the time currently being sub-cycled?
bool subCycling_; bool subCycling_;
//- Time directory name format //- Time directory name format
...@@ -157,21 +157,21 @@ private: ...@@ -157,21 +157,21 @@ private:
//- Default graph format //- Default graph format
word graphFormat_; word graphFormat_;
//- Is runtim modification of dictionaries allowed //- Is runtime modification of dictionaries allowed?
Switch runTimeModifiable_; Switch runTimeModifiable_;
//- Instantiate a dummy class to cause the reading of dynamic libraries //- Instantiate a dummy class to cause the reading of dynamic libraries
dlLibraryTable::readDlLibrary readLibs_; dlLibraryTable::readDlLibrary readLibs_;
//- Function objects executed at start and on ++, += //- Function objects executed at start and on ++, +=
functionObjectList functionObjects_; mutable functionObjectList functionObjects_;
public: public:
TypeName("time"); TypeName("time");
//- The default control dictionary name //- The default control dictionary name (normally "controlDict")
static word controlDictName; static word controlDictName;
...@@ -282,8 +282,8 @@ public: ...@@ -282,8 +282,8 @@ public:
void readModifiedObjects(); void readModifiedObjects();
//- Return the location of "dir" containing the file "name". //- Return the location of "dir" containing the file "name".
// (Used in reading mesh data) // (eg, used in reading mesh data)
// If name is null search for the directory "dir" only // If name is null, search for the directory "dir" only
word findInstance word findInstance
( (
const fileName& dir, const fileName& dir,
...@@ -291,7 +291,7 @@ public: ...@@ -291,7 +291,7 @@ public:
const IOobject::readOption rOpt = IOobject::MUST_READ const IOobject::readOption rOpt = IOobject::MUST_READ
) const; ) const;
//- Search tha case for valid time directories //- Search the case for valid time directories
instantList times() const; instantList times() const;
//- Search the case for the time directory path //- Search the case for the time directory path
...@@ -307,9 +307,9 @@ public: ...@@ -307,9 +307,9 @@ public:
//- Write using given format, version and compression //- Write using given format, version and compression
virtual bool writeObject virtual bool writeObject
( (
IOstream::streamFormat fmt, IOstream::streamFormat,
IOstream::versionNumber ver, IOstream::versionNumber,
IOstream::compressionType cmp IOstream::compressionType
) const; ) const;
//- Write the objects now and continue the run //- Write the objects now and continue the run
...@@ -409,7 +409,7 @@ public: ...@@ -409,7 +409,7 @@ public:
//- Prefix increment //- Prefix increment
virtual Time& operator++(); virtual Time& operator++();
//- Postfix increment //- Postfix increment, this is identical to the prefix increment
virtual Time& operator++(int); virtual Time& operator++(int);
}; };
......
...@@ -61,7 +61,7 @@ void Foam::Time::readDict() ...@@ -61,7 +61,7 @@ void Foam::Time::readDict()
if (oldWriteInterval != writeInterval_) if (oldWriteInterval != writeInterval_)
{ {
switch(writeControl_) switch (writeControl_)
{ {
case wcRunTime: case wcRunTime:
case wcAdjustableRunTime: case wcAdjustableRunTime:
...@@ -180,11 +180,7 @@ void Foam::Time::readDict() ...@@ -180,11 +180,7 @@ void Foam::Time::readDict()
} }
controlDict_.readIfPresent("graphFormat", graphFormat_); controlDict_.readIfPresent("graphFormat", graphFormat_);
controlDict_.readIfPresent("runTimeModifiable", runTimeModifiable_);
if (controlDict_.found("runTimeModifiable"))
{
runTimeModifiable_ = Switch(controlDict_.lookup("runTimeModifiable"));
}
} }
...@@ -286,7 +282,7 @@ bool Foam::Time::writeObject ...@@ -286,7 +282,7 @@ bool Foam::Time::writeObject
{ {
previousOutputTimes_.push(timeName()); previousOutputTimes_.push(timeName());
while(previousOutputTimes_.size() > purgeWrite_) while (previousOutputTimes_.size() > purgeWrite_)
{ {
rmDir(objectRegistry::path(previousOutputTimes_.pop())); rmDir(objectRegistry::path(previousOutputTimes_.pop()));
} }
......
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