From e03979ad3b2fa03af14aa2e4ac4d74130f67e185 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 13 Feb 2009 15:10:22 +0100 Subject: [PATCH] functionObjectList added manualStart()/manualExecute() - can call start()/execute() manually regardless of the execution status --- src/OpenFOAM/db/Time/Time.C | 17 +++--- src/OpenFOAM/db/Time/Time.H | 6 ++ src/OpenFOAM/db/Time/subCycleTime.H | 5 +- .../db/functionObject/functionObject.C | 7 +-- .../db/functionObject/functionObject.H | 2 +- .../functionObjectList/functionObjectList.C | 56 ++++++++++++++----- .../functionObjectList/functionObjectList.H | 28 +++++++--- src/OpenFOAM/db/regIOobject/regIOobject.C | 31 ++++------ .../OutputFilterFunctionObject.H | 4 +- 9 files changed, 98 insertions(+), 58 deletions(-) diff --git a/src/OpenFOAM/db/Time/Time.C b/src/OpenFOAM/db/Time/Time.C index 22c9a5236f..d157501506 100644 --- a/src/OpenFOAM/db/Time/Time.C +++ b/src/OpenFOAM/db/Time/Time.C @@ -373,7 +373,6 @@ Foam::word Foam::Time::timeName(const scalar t) Foam::word Foam::Time::timeName() const { return dimensionedScalar::name(); - //return timeName(timeOutputValue()); } @@ -435,7 +434,7 @@ Foam::instant Foam::Time::findClosestTime(const scalar t) const return times[nearestIndex]; } -// + // This should work too, // if we don't worry about checking "constant" explicitly // @@ -493,11 +492,13 @@ bool Foam::Time::run() const { bool running = value() < (endTime_ - 0.5*deltaT_); - if (!running && !subCycling_) + if (!subCycling_) { - // Note, the execute() also calls an indirect start() if required - if (timeIndex_ != startTimeIndex_) + // only execute when the condition is no longer true + // ie, when exiting the control loop + if (!running && timeIndex_ != startTimeIndex_) { + // Note, the execute() also calls an indirect start() if required functionObjects_.execute(); } } @@ -508,7 +509,8 @@ bool Foam::Time::run() const bool Foam::Time::end() const { - return (value() > (endTime_ + 0.5*deltaT_)); + bool done = value() > (endTime_ + 0.5*deltaT_); + return done; } @@ -701,8 +703,9 @@ Foam::Time& Foam::Time::operator++() } } break; - }; + } + // see if endTime needs adjustment to stop at the next run()/end() check if (!end()) { if (stopAt_ == saNoWriteNow) diff --git a/src/OpenFOAM/db/Time/Time.H b/src/OpenFOAM/db/Time/Time.H index b0ce953642..3cb65583b2 100644 --- a/src/OpenFOAM/db/Time/Time.H +++ b/src/OpenFOAM/db/Time/Time.H @@ -349,9 +349,15 @@ public: // Check //- Return true if run should continue + // @sa end() + // @note + // the rounding heuristics near endTime mean that + // @code run() @endcode and @code !end() @endcode may + // not yield the same result virtual bool run() const; //- Return true if end of run + // @sa run() virtual bool end() const; diff --git a/src/OpenFOAM/db/Time/subCycleTime.H b/src/OpenFOAM/db/Time/subCycleTime.H index 8081edbb17..01082625fb 100644 --- a/src/OpenFOAM/db/Time/subCycleTime.H +++ b/src/OpenFOAM/db/Time/subCycleTime.H @@ -44,7 +44,7 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class subCycleTimeTime Declaration + Class subCycleTime Declaration \*---------------------------------------------------------------------------*/ class subCycleTime @@ -62,7 +62,7 @@ public: // Constructors //- Construct from original time and number of sub-cycles - subCycleTime(Time& t, const label nSubCycles); + subCycleTime(Time&, const label nSubCycles); // Destructor @@ -72,6 +72,7 @@ public: // Member functions + //- Return true if the number of sub-cycles has been reached bool end() const; //- End the sub-cycling and reset the time-state diff --git a/src/OpenFOAM/db/functionObject/functionObject.C b/src/OpenFOAM/db/functionObject/functionObject.C index 5fb128a327..29ee48342b 100644 --- a/src/OpenFOAM/db/functionObject/functionObject.C +++ b/src/OpenFOAM/db/functionObject/functionObject.C @@ -30,11 +30,8 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -namespace Foam -{ - defineRunTimeSelectionTable(functionObject, dictionary); - int functionObject::debug(::Foam::debug::debugSwitch("functionObject", 0)); -} +defineRunTimeSelectionTable(Foam::functionObject, dictionary); +int Foam::functionObject::debug(Foam::debug::debugSwitch("functionObject", 0)); // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/db/functionObject/functionObject.H b/src/OpenFOAM/db/functionObject/functionObject.H index 30d0c9caf0..268bf128e4 100644 --- a/src/OpenFOAM/db/functionObject/functionObject.H +++ b/src/OpenFOAM/db/functionObject/functionObject.H @@ -144,7 +144,7 @@ public: virtual bool execute() = 0; //- Read and set the function object if its data have changed - virtual bool read(const dictionary& dict) = 0; + virtual bool read(const dictionary&) = 0; }; diff --git a/src/OpenFOAM/db/functionObjectList/functionObjectList.C b/src/OpenFOAM/db/functionObjectList/functionObjectList.C index a4f046b451..1ca37e02e3 100644 --- a/src/OpenFOAM/db/functionObjectList/functionObjectList.C +++ b/src/OpenFOAM/db/functionObjectList/functionObjectList.C @@ -106,6 +106,25 @@ void Foam::functionObjectList::clear() } +void Foam::functionObjectList::on() +{ + execution_ = true; +} + + +void Foam::functionObjectList::off() +{ + // for safety, also force a read() when execution is turned back on + updated_ = execution_ = false; +} + + +bool Foam::functionObjectList::status() const +{ + return execution_; +} + + bool Foam::functionObjectList::start() { return read(); @@ -133,19 +152,6 @@ bool Foam::functionObjectList::execute() } -void Foam::functionObjectList::on() -{ - execution_ = true; -} - - -void Foam::functionObjectList::off() -{ - // for safety, also force a read() when execution is turned back on - updated_ = execution_ = false; -} - - bool Foam::functionObjectList::read() { bool ok = true; @@ -273,4 +279,28 @@ bool Foam::functionObjectList::read() } +bool Foam::functionObjectList::manualStart() +{ + bool state = execution_; + execution_ = true; + + bool ret = start(); + + execution_ = state; + return ret; +} + + +bool Foam::functionObjectList::manualExecute() +{ + bool state = execution_; + execution_ = true; + + bool ret = execute(); + + execution_ = state; + return ret; +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/db/functionObjectList/functionObjectList.H b/src/OpenFOAM/db/functionObjectList/functionObjectList.H index 5c945dc42c..374e23775b 100644 --- a/src/OpenFOAM/db/functionObjectList/functionObjectList.H +++ b/src/OpenFOAM/db/functionObjectList/functionObjectList.H @@ -40,10 +40,10 @@ SourceFiles #ifndef functionObjectList_H #define functionObjectList_H -#include "functionObject.H" -#include "HashTable.H" #include "PtrList.H" +#include "functionObject.H" #include "SHA1Digest.H" +#include "HashTable.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -137,20 +137,32 @@ public: virtual void clear(); - //- Start is called at the start of the time-loop - virtual bool start(); - - //- Execute is called at each ++ or += of the time-loop - virtual bool execute(); - //- Switch the function objects on virtual void on(); //- Switch the function objects off virtual void off(); + //- Return the execution status (on/off) of the function objects + virtual bool status() const; + + + //- Start is called at the start of the time-loop + virtual bool start(); + + //- Execute is called at each ++ or += of the time-loop + virtual bool execute(); + //- Read and set the function objects if their data have changed virtual bool read(); + + + //- Call start() manually regardless of the execution status + virtual bool manualStart(); + + //- Call execute() manually regardless of the execution status + virtual bool manualExecute(); + }; diff --git a/src/OpenFOAM/db/regIOobject/regIOobject.C b/src/OpenFOAM/db/regIOobject/regIOobject.C index 1395772561..611dd5a923 100644 --- a/src/OpenFOAM/db/regIOobject/regIOobject.C +++ b/src/OpenFOAM/db/regIOobject/regIOobject.C @@ -31,25 +31,20 @@ Description #include "Time.H" #include "polyMesh.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -defineTypeNameAndDebug(regIOobject, 0); +defineTypeNameAndDebug(Foam::regIOobject, 0); -int regIOobject::fileModificationSkew +int Foam::regIOobject::fileModificationSkew ( - debug::optimisationSwitch("fileModificationSkew", 30) + Foam::debug::optimisationSwitch("fileModificationSkew", 30) ); // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // Construct from IOobject -regIOobject::regIOobject(const IOobject& io) +Foam::regIOobject::regIOobject(const IOobject& io) : IOobject(io), registered_(false), @@ -66,7 +61,7 @@ regIOobject::regIOobject(const IOobject& io) // Construct as copy -regIOobject::regIOobject(const regIOobject& rio) +Foam::regIOobject::regIOobject(const regIOobject& rio) : IOobject(rio), registered_(false), @@ -80,7 +75,7 @@ regIOobject::regIOobject(const regIOobject& rio) // Construct as copy, and transfering objectRegistry registration to copy // if registerCopy is true -regIOobject::regIOobject(const regIOobject& rio, bool registerCopy) +Foam::regIOobject::regIOobject(const regIOobject& rio, bool registerCopy) : IOobject(rio), registered_(false), @@ -99,7 +94,7 @@ regIOobject::regIOobject(const regIOobject& rio, bool registerCopy) // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // Delete read stream, checkout from objectRegistry and destroy -regIOobject::~regIOobject() +Foam::regIOobject::~regIOobject() { if (objectRegistry::debug) { @@ -125,7 +120,7 @@ regIOobject::~regIOobject() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void regIOobject::checkIn() +void Foam::regIOobject::checkIn() { if (!registered_) { @@ -153,7 +148,7 @@ void regIOobject::checkIn() } -void regIOobject::checkOut() +void Foam::regIOobject::checkOut() { if (registered_) { @@ -164,7 +159,7 @@ void regIOobject::checkOut() // Rename object and re-register with objectRegistry under new name -void regIOobject::rename(const word& newName) +void Foam::regIOobject::rename(const word& newName) { // Check out of objectRegistry checkOut(); @@ -177,7 +172,7 @@ void regIOobject::rename(const word& newName) // Assign to IOobject -void regIOobject::operator=(const IOobject& io) +void Foam::regIOobject::operator=(const IOobject& io) { if (isPtr_) { @@ -195,8 +190,4 @@ void regIOobject::operator=(const IOobject& io) } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/src/sampling/outputFilters/OutputFilterFunctionObject/OutputFilterFunctionObject.H b/src/sampling/outputFilters/OutputFilterFunctionObject/OutputFilterFunctionObject.H index 7800d764a6..80ee33cf81 100644 --- a/src/sampling/outputFilters/OutputFilterFunctionObject/OutputFilterFunctionObject.H +++ b/src/sampling/outputFilters/OutputFilterFunctionObject/OutputFilterFunctionObject.H @@ -126,8 +126,8 @@ public: //- Switch the function object off virtual void off(); - //- Read and set the function object if its data has changed - virtual bool read(const dictionary& dict); + //- Read and set the function object if its data have changed + virtual bool read(const dictionary&); };