diff --git a/src/OpenFOAM/db/Time/Time.C b/src/OpenFOAM/db/Time/Time.C index f2096b7968827712150b6d89bdf431ca0d196f9b..b65652fb9ca01d6d66b3cb5bf9e2e1c5fa2fbf71 100644 --- a/src/OpenFOAM/db/Time/Time.C +++ b/src/OpenFOAM/db/Time/Time.C @@ -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 { diff --git a/src/OpenFOAM/db/Time/Time.H b/src/OpenFOAM/db/Time/Time.H index f69f11b581f87ba334c0af3e20b1e3fe2799d938..b0ce9536427a6b779aa451a93ef60e07104aa633 100644 --- a/src/OpenFOAM/db/Time/Time.H +++ b/src/OpenFOAM/db/Time/Time.H @@ -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); }; diff --git a/src/OpenFOAM/db/Time/TimeIO.C b/src/OpenFOAM/db/Time/TimeIO.C index 1f1df0507e9340410546d9fc5fb222d11740a0c7..5a1795e1ef0220a68208667493e3b42f2fc412b4 100644 --- a/src/OpenFOAM/db/Time/TimeIO.C +++ b/src/OpenFOAM/db/Time/TimeIO.C @@ -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())); }