diff --git a/applications/solvers/basic/potentialFoam/potentialFoam.C b/applications/solvers/basic/potentialFoam/potentialFoam.C index ceabbca4b3..8e4a12ee0d 100644 --- a/applications/solvers/basic/potentialFoam/potentialFoam.C +++ b/applications/solvers/basic/potentialFoam/potentialFoam.C @@ -39,12 +39,6 @@ int main(int argc, char *argv[]) { argList::addBoolOption("writep", "write the final pressure field"); - argList::addBoolOption - ( - "noFunctionObjects", - "do not execute functionObjects" - ); - #include "setRootCase.H" #include "createTime.H" #include "createMesh.H" @@ -57,10 +51,7 @@ int main(int argc, char *argv[]) // Since solver contains no time loop it would never execute // function objects so do it ourselves. - if (!args.optionFound("noFunctionObjects")) - { - runTime.functionObjects().start(); - } + runTime.functionObjects().start(); adjustPhi(phi, U, p); @@ -112,10 +103,7 @@ int main(int argc, char *argv[]) p.write(); } - if (!args.optionFound("noFunctionObjects")) - { - runTime.functionObjects().end(); - } + runTime.functionObjects().end(); Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << " ClockTime = " << runTime.elapsedClockTime() << " s" diff --git a/src/OpenFOAM/db/Time/Time.C b/src/OpenFOAM/db/Time/Time.C index 8e509a738b..e90758dafd 100644 --- a/src/OpenFOAM/db/Time/Time.C +++ b/src/OpenFOAM/db/Time/Time.C @@ -25,6 +25,7 @@ License #include "Time.H" #include "PstreamReduceOps.H" +#include "argList.H" #include @@ -215,7 +216,8 @@ Foam::Time::Time const fileName& rootPath, const fileName& caseName, const word& systemName, - const word& constantName + const word& constantName, + const bool enableFunctionObjects ) : TimePaths @@ -259,7 +261,94 @@ Foam::Time::Time graphFormat_("raw"), runTimeModifiable_(true), - functionObjects_(*this) + functionObjects_(*this, enableFunctionObjects) +{ + libs_.open(controlDict_, "libs"); + + // Explicitly set read flags on objectRegistry so anything constructed + // from it reads as well (e.g. fvSolution). + readOpt() = IOobject::MUST_READ_IF_MODIFIED; + + setControls(); + + // Time objects not registered so do like objectRegistry::checkIn ourselves. + if (runTimeModifiable_) + { + monitorPtr_.reset + ( + new fileMonitor + ( + regIOobject::fileModificationChecking == inotify + || regIOobject::fileModificationChecking == inotifyMaster + ) + ); + + // File might not exist yet. + fileName f(controlDict_.filePath()); + + if (!f.size()) + { + // We don't have this file but would like to re-read it. + // Possibly if in master-only reading mode. Use a non-existing + // file to keep fileMonitor synced. + f = controlDict_.objectPath(); + } + + controlDict_.watchIndex() = addWatch(f); + } +} + + +Foam::Time::Time +( + const word& controlDictName, + const argList& args, + const word& systemName, + const word& constantName +) +: + TimePaths + ( + args.rootPath(), + args.caseName(), + systemName, + constantName + ), + + objectRegistry(*this), + + libs_(), + + controlDict_ + ( + IOobject + ( + controlDictName, + system(), + *this, + IOobject::MUST_READ_IF_MODIFIED, + IOobject::NO_WRITE, + false + ) + ), + + startTimeIndex_(0), + startTime_(0), + endTime_(0), + + stopAt_(saEndTime), + writeControl_(wcTimeStep), + writeInterval_(GREAT), + purgeWrite_(0), + subCycling_(false), + + writeFormat_(IOstream::ASCII), + writeVersion_(IOstream::currentVersion), + writeCompression_(IOstream::UNCOMPRESSED), + graphFormat_("raw"), + runTimeModifiable_(true), + + functionObjects_(*this, !args.optionFound("noFunctionObjects")) { libs_.open(controlDict_, "libs"); @@ -303,7 +392,8 @@ Foam::Time::Time const fileName& rootPath, const fileName& caseName, const word& systemName, - const word& constantName + const word& constantName, + const bool enableFunctionObjects ) : TimePaths @@ -348,7 +438,7 @@ Foam::Time::Time graphFormat_("raw"), runTimeModifiable_(true), - functionObjects_(*this) + functionObjects_(*this, enableFunctionObjects) { libs_.open(controlDict_, "libs"); @@ -395,7 +485,8 @@ Foam::Time::Time const fileName& rootPath, const fileName& caseName, const word& systemName, - const word& constantName + const word& constantName, + const bool enableFunctionObjects ) : TimePaths @@ -439,7 +530,7 @@ Foam::Time::Time graphFormat_("raw"), runTimeModifiable_(true), - functionObjects_(*this) + functionObjects_(*this, enableFunctionObjects) { libs_.open(controlDict_, "libs"); } diff --git a/src/OpenFOAM/db/Time/Time.H b/src/OpenFOAM/db/Time/Time.H index b9da549895..216ae12985 100644 --- a/src/OpenFOAM/db/Time/Time.H +++ b/src/OpenFOAM/db/Time/Time.H @@ -57,6 +57,8 @@ SourceFiles namespace Foam { +// Forward declaration of classes +class argList; /*---------------------------------------------------------------------------*\ Class Time Declaration @@ -184,14 +186,24 @@ public: // Constructors - //- Construct given name, rootPath and casePath + //- Construct given name of dictionary to read and argument list + Time + ( + const word& name, + const argList& args, + const word& systemName = "system", + const word& constantName = "constant" + ); + + //- Construct given name of dictionary to read, rootPath and casePath Time ( const word& name, const fileName& rootPath, const fileName& caseName, const word& systemName = "system", - const word& constantName = "constant" + const word& constantName = "constant", + const bool enableFunctionObjects = true ); //- Construct given dictionary, rootPath and casePath @@ -201,7 +213,8 @@ public: const fileName& rootPath, const fileName& caseName, const word& systemName = "system", - const word& constantName = "constant" + const word& constantName = "constant", + const bool enableFunctionObjects = true ); //- Construct given endTime, rootPath and casePath @@ -210,7 +223,8 @@ public: const fileName& rootPath, const fileName& caseName, const word& systemName = "system", - const word& constantName = "constant" + const word& constantName = "constant", + const bool enableFunctionObjects = true ); diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index fba0cefe17..75e129e271 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -64,6 +64,12 @@ Foam::argList::initValidTables::initValidTables() ); validParOptions.set("roots", "(dir1 .. dirN)"); + argList::addBoolOption + ( + "noFunctionObjects", + "do not execute functionObjects" + ); + Pstream::addValidParOptions(validParOptions); } diff --git a/src/OpenFOAM/include/createTime.H b/src/OpenFOAM/include/createTime.H index 057814a870..36fc675dc3 100644 --- a/src/OpenFOAM/include/createTime.H +++ b/src/OpenFOAM/include/createTime.H @@ -4,9 +4,4 @@ Foam::Info<< "Create time\n" << Foam::endl; - Foam::Time runTime - ( - Foam::Time::controlDictName, - args.rootPath(), - args.caseName() - ); + Foam::Time runTime(Foam::Time::controlDictName, args);