51 { stopAtControls::saEndTime,
"endTime" },
52 { stopAtControls::saNoWriteNow,
"noWriteNow" },
53 { stopAtControls::saWriteNow,
"writeNow" },
54 { stopAtControls::saNextWrite,
"nextWrite" },
65 { writeControls::wcNone,
"none" },
66 { writeControls::wcTimeStep,
"timeStep" },
67 { writeControls::wcRunTime,
"runTime" },
68 { writeControls::wcAdjustableRunTime,
"adjustable" },
69 { writeControls::wcAdjustableRunTime,
"adjustableRunTime" },
70 { writeControls::wcClockTime,
"clockTime" },
71 { writeControls::wcCpuTime,
"cpuTime" },
78 IOstreamOption::floatFormat::general
94 "printExecutionFormat",
104 bool adjustTime =
false;
105 scalar timeToNextWrite = VGREAT;
110 timeToNextWrite =
max 119 scalar nSteps = timeToNextWrite/
deltaT_;
125 label nStepsToNextWrite =
max(1, round(nSteps));
127 scalar newDeltaT = timeToNextWrite/nStepsToNextWrite;
149 const word startFrom = controlDict_.getOrDefault<word>
155 if (startFrom ==
"startTime")
157 controlDict_.readEntry(
"startTime", startTime_);
164 const label nTimes = timeDirs.size();
166 if (startFrom ==
"firstTime")
168 if (nTimes > 1 && timeDirs.front().name() == constant())
170 startTime_ = timeDirs[1].value();
174 startTime_ = timeDirs.front().value();
177 else if (startFrom ==
"latestTime")
181 startTime_ = timeDirs.back().value();
187 <<
"expected startTime, firstTime or latestTime" 188 <<
" found '" << startFrom <<
"'" 196 deltaTSave_ = deltaT_;
205 const fileName timeDir(
fileHandler().filePath(timePath(),
false));
208 const int oldPrecision = precision_;
209 int requiredPrecision = -1;
213 precision_ = maxPrecision_;
214 precision_ > oldPrecision;
229 const fileName timeDir(
fileHandler().filePath(timePath(),
false));
232 requiredPrecision = precision_;
236 if (requiredPrecision > 0)
239 precision_ = requiredPrecision;
245 <<
"Increasing the timePrecision from " << oldPrecision
246 <<
" to " << precision_
247 <<
" to support the formatting of the current time directory " 253 precision_ = oldPrecision;
262 scalar sumStartTime = startTime_;
263 reduce(sumStartTime, sumOp<scalar>());
271 <<
"Start time is not the same for all processors" <<
nl 277 IOdictionary timeDict
293 if (controlDict_.getOrDefault(
"adjustTimeStep",
false))
295 if (timeDict.readIfPresent(
"deltaT", deltaT_))
297 deltaTSave_ = deltaT_;
302 timeDict.readIfPresent(
"deltaT0", deltaT0_);
304 if (timeDict.readIfPresent(
"index", startTimeIndex_))
306 timeIndex_ = startTimeIndex_;
313 bool checkValue =
true;
315 string storedTimeName;
316 if (timeDict.readIfPresent(
"name", storedTimeName))
330 scalar storedTimeValue;
331 if (timeDict.readIfPresent(
"value", storedTimeValue))
333 word storedTimeName(
timeName(storedTimeValue));
338 <<
"Time read from time dictionary " << storedTimeName
339 <<
" differs from actual time " <<
timeName() <<
'.' <<
nl 340 <<
" This may cause unexpected database behaviour." 341 <<
" If you are not interested" <<
nl 342 <<
" in preserving time state delete" 343 <<
" the time dictionary." 353 const dictionary* profilingDict = controlDict_.findDict(
"profiling");
383 && profilingDict->getOrDefault(
"active",
true)
404 if (runTimeModifiable_)
413 fileHandler().addWatches(controlDict_, controlDict_.files());
417 controlDict_.files().clear();
425 const word& ctrlDictName,
428 const word& systemDirName,
429 const word& constantDirName,
430 const bool enableFunctionObjects,
431 const bool enableLibs,
435 TimePaths(rootPath, caseName, systemDirName, constantDirName),
437 loopProfiling_(nullptr),
458 writeControl_(wcTimeStep),
459 writeInterval_(GREAT),
463 sigWriteNow_(*this, true),
464 sigStopAtWriteNow_(*this, true),
467 runTimeModifiable_(false),
468 cacheTemporaryObjects_(true),
469 functionObjects_(*this, false)
471 if (enableFunctionObjects)
473 functionObjects_.
on();
478 libs_.
open(
"libs", controlDict_);
492 const word& ctrlDictName,
494 const word& systemDirName,
495 const word& constantDirName,
496 const bool enableFunctionObjects,
497 const bool enableLibs,
503 loopProfiling_(nullptr),
524 writeControl_(wcTimeStep),
525 writeInterval_(GREAT),
529 sigWriteNow_(*this, true),
530 sigStopAtWriteNow_(*this, true),
533 runTimeModifiable_(false),
534 cacheTemporaryObjects_(true),
535 functionObjects_(*this, false)
544 functionObjects_.
on();
552 libs_.
open(
"libs", controlDict_);
571 const word& systemDirName,
572 const word& constantDirName,
573 const bool enableFunctionObjects,
574 const bool enableLibs,
578 TimePaths(rootPath, caseName, systemDirName, constantDirName),
580 loopProfiling_(nullptr),
588 Time::controlDictName,
603 writeControl_(wcTimeStep),
604 writeInterval_(GREAT),
608 sigWriteNow_(*this, true),
609 sigStopAtWriteNow_(*this, true),
612 runTimeModifiable_(false),
613 cacheTemporaryObjects_(true),
614 functionObjects_(*this, false)
616 if (enableFunctionObjects)
618 functionObjects_.
on();
623 libs_.
open(
"libs", controlDict_);
643 const word& systemDirName,
644 const word& constantDirName,
645 const bool enableFunctionObjects,
646 const bool enableLibs
649 TimePaths(rootPath, caseName, systemDirName, constantDirName),
651 loopProfiling_(nullptr),
658 Time::controlDictName,
672 writeControl_(wcTimeStep),
673 writeInterval_(GREAT),
679 runTimeModifiable_(false),
680 cacheTemporaryObjects_(true),
681 functionObjects_(*this, false)
683 if (enableFunctionObjects)
685 functionObjects_.
on();
690 libs_.
open(
"libs", controlDict_);
701 loopProfiling_.reset(
nullptr);
705 fileHandler().removeWatch(controlDict_.watchIndices()[i]);
709 functionObjects_.clear();
723 std::ostringstream buf;
724 buf.setf(std::ios_base::fmtflags(format_), std::ios_base::floatfield);
725 buf.precision(precision);
736 const word& stopInstance
774 if (t.
equal(timeDirs[i].value()))
776 return timeDirs[i].name();
786 return findInstancePath(
path(), t);
792 return startTimeIndex_;
816 loopProfiling_.reset(
nullptr);
818 bool isRunning = value() < (endTime_ - 0.5*deltaT_);
824 if (!isRunning && timeIndex_ != startTimeIndex_)
830 functionObjects_.execute();
834 functionObjects_.end();
837 if (cacheTemporaryObjects_)
839 cacheTemporaryObjects_ = checkCacheTemporaryObjects();
848 const_cast<Time&
>(*this).readModifiedObjects();
850 if (timeIndex_ == startTimeIndex_)
852 addProfiling(functionObjects,
"functionObjects.start()");
853 functionObjects_.start();
857 addProfiling(functionObjects,
"functionObjects.execute()");
858 functionObjects_.execute();
867 if (functionObjects_.filesModified())
869 const_cast<Time&
>(*this).readModifiedObjects();
872 if (cacheTemporaryObjects_)
874 cacheTemporaryObjects_ = checkCacheTemporaryObjects();
880 isRunning = value() < (endTime_ - 0.5*deltaT_);
898 const bool isRunning = run();
911 return value() > (endTime_ + 0.5*deltaT_);
917 if (stopCtrl == stopAtControls::saUnknown)
922 const bool changed = (stopAt_ != stopCtrl);
927 if (stopCtrl == stopAtControls::saEndTime)
929 controlDict_.readEntry(
"endTime", endTime_);
938 return controlDict_.getOrDefault(
"adjustTimeStep",
false);
951 resetTimeState(inst.
name(), inst.
value(), newIndex);
967 timeDict.readIfPresent(
"deltaT", deltaT_);
968 timeDict.readIfPresent(
"deltaT0", deltaT0_);
969 timeDict.readIfPresent(
"index", timeIndex_);
994 setEndTime(endTime.
value());
1010 setDeltaT(deltaT.
value(), adjust);
1017 deltaTchanged_ =
true;
1032 <<
"previous time state already set" <<
nl 1037 prevTimeState_.reset(
new TimeState(*
this));
1040 deltaT_ /= nSubCycles;
1041 deltaT0_ /= nSubCycles;
1042 deltaTSave_ = deltaT0_;
1044 subCycling_ = nSubCycles;
1046 return prevTimeState();
1056 if (subCycling_ && index > 0)
1058 subCycling_ = index;
1067 TimeState::operator=(prevTimeState());
1068 prevTimeState_.reset(
nullptr);
1079 return operator+=(deltaT.
value());
1086 return operator++();
1092 deltaT0_ = deltaTSave_;
1093 deltaTSave_ = deltaT_;
1096 const scalar oldTimeValue = timeToUserTime(value());
1100 setTime(value() + deltaT_, timeIndex_ + 1);
1105 if (
mag(value()) < 10*SMALL*deltaT_)
1110 if (sigStopAtWriteNow_.active() || sigWriteNow_.active())
1116 if (sigStopAtWriteNow_.active() && stopAt_ == saWriteNow)
1120 if (sigWriteNow_.active() && writeOnce_)
1124 reduce(flag, maxOp<label>());
1128 stopAt_ = saWriteNow;
1138 switch (writeControl_)
1145 writeTime_ = !(timeIndex_ % label(writeInterval_));
1149 case wcAdjustableRunTime:
1151 const label writeIndex = label
1153 ((value() - startTime_) + 0.5*deltaT_)
1157 if (writeIndex > writeTimeIndex_)
1160 writeTimeIndex_ = writeIndex;
1167 const label writeIndex = label
1172 if (writeIndex > writeTimeIndex_)
1175 writeTimeIndex_ = writeIndex;
1182 const label writeIndex = label
1187 if (writeIndex > writeTimeIndex_)
1190 writeTimeIndex_ = writeIndex;
1200 if (stopAt_ == saNoWriteNow)
1204 else if (stopAt_ == saWriteNow)
1209 else if (stopAt_ == saNextWrite && writeTime_ ==
true)
1226 const scalar userDeltaT =
1227 timeToUserTime(value()) - timeToUserTime(value() - deltaT_);
1230 const scalar timeTol =
1231 max(
min(
pow(scalar(10), -precision_), 0.1*userDeltaT), SMALL);
1234 scalar timeNameValue = -VGREAT;
1241 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1244 int oldPrecision = precision_;
1247 precision_ < maxPrecision_
1249 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1256 if (precision_ != oldPrecision)
1259 <<
"Increased the timePrecision from " << oldPrecision
1260 <<
" to " << precision_
1261 <<
" to distinguish between timeNames at time " 1265 if (precision_ == maxPrecision_)
1271 <<
" The maximum time precision has been reached" 1272 " which might result in overwriting previous" 1278 scalar oldTimeNameValue = -VGREAT;
1281 readScalar(oldTimeName, oldTimeNameValue)
1283 sign(timeNameValue - oldTimeNameValue)
1290 <<
" is set to an instance prior to the " 1292 << oldTimeName <<
nl 1293 <<
" This might result in temporal " 1308 return operator++();
virtual Time & operator++()
Prefix increment,.
dimensionedScalar sign(const dimensionedScalar &ds)
const scalar & value() const noexcept
Return const reference to value.
registerInfoSwitch("printExecutionFormat", int, Foam::Time::printExecutionFormat_)
Info<< "Creating field kinetic energy K\"<< endl;volScalarField K("K", 0.5 *magSqr(U));if(U.nOldTimes()){ volVectorField *Uold=&U.oldTime();volScalarField *Kold=&K.oldTime();*Kold==0.5 *magSqr(*Uold);while(Uold->nOldTimes()) { Uold=&Uold-> oldTime()
Address the time paths without using the Time class.
A class for handling file names.
readOption readOpt() const noexcept
Get the read option.
Inter-processor communication reduction functions.
static int printExecutionFormat_
Style for "ExecutionTime = " output.
errorManipArg< error, int > exit(error &err, const int errNo=1)
The time value with time-stepping information, user-defined remapping, etc.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
word findInstance(const fileName &dir, const word &name=word::null, IOobjectOption::readOption rOpt=IOobjectOption::MUST_READ, const word &stopInstance=word::null) const
Return time instance (location) of dir that contains the file name (eg, used in reading mesh data)...
void adjustDeltaT()
Adjust the time step so that writing occurs at the specified time.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
virtual ~Time()
Destructor.
virtual bool isAdjustTimeStep() const
Return true if adjustTimeStep is true.
virtual stopAtControls stopAt() const
Return the stop control information.
const word & name() const noexcept
Return the object name.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
virtual void setEndTime(const dimensionedScalar &endTime)
Reset end time.
constexpr char nl
The newline '\n' character (0x0a)
floatFormat
Float formats (eg, time directory name formats)
writeControls
Write control options.
virtual bool loop()
Return true if run should continue and if so increment time.
virtual dimensionedScalar startTime() const
Return start time.
static bool active() noexcept
True if profiling is allowed and is active.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static bool & parRun() noexcept
Test if this a parallel run.
runTimeSource setTime(sourceTimes[sourceTimeIndex], sourceTimeIndex)
void on()
Switch the function objects on.
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler()
static const Enum< stopAtControls > stopAtControlNames
Names for stopAtControls.
A simple container for options an IOstream can normally have.
Time(const word &ctrlDictName, const argList &args, const bool enableFunctionObjects=true, const bool enableLibs=true, IOobjectOption::readOption rOpt=IOobjectOption::READ_MODIFIED)
Construct from argument list, reading from specified control dictionary name.
bool adjustTimeStep()
Called at the end of Time::adjustDeltaT() if adjustTime is true.
virtual dimensionedScalar endTime() const
Return end time.
Ignore writing from objectRegistry::writeObject()
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Can be negative if the process i...
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
writeControls writeControl_
void setMonitoring(const bool forceProfiling=false)
Set file monitoring, profiling, etc.
const word & timeName() const noexcept
Return the current time name.
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
int infoSwitch(const char *name, const int deflt=0)
Lookup info switch or add default value.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
bool allowFunctionObjects() const
The controlDict 'functions' entry is allowed to be used.
virtual bool run() const
Return true if run should continue,.
static void broadcast(Type &value, const label comm=UPstream::worldComm)
Broadcast content (contiguous or non-contiguous) to all communicator ranks. Does nothing in non-paral...
static const int maxPrecision_
Maximum time directory name precision.
scalar value() const noexcept
The value (const access)
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
virtual TimeState subCycle(const label nSubCycles)
Set time to sub-cycle for the given number of steps.
"adjustable" / "adjustableRunTime"
bool allowLibs() const
The controlDict 'libs' entry is allowed to be used. (eg, has not been disabled by the -no-libs option...
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run. ...
#define addProfiling(Name, Descr)
Define profiling trigger with specified name and description string.
bool returnReduceAnd(const bool value, const label comm=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
const T & name() const noexcept
The name/key (const access)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
static int precision_
Time directory name precision.
A class for handling words, derived from Foam::string.
Extract command arguments and options from the supplied argc and argv parameters. ...
static void initialize(const IOobject &ioObj, const Time &owner)
Singleton to initialize profiling pool, everything enabled.
static const word null
An empty word.
static const Enum< writeControls > writeControlNames
Names for writeControls.
virtual void setTime(const Time &t)
Reset the time and time-index to those of the given time.
label timeIndex() const noexcept
Return the current time index.
static word controlDictName
The default control dictionary name (normally "controlDict")
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
static void stop(const Time &owner)
Stop profiling, cleanup pool if possible.
virtual void subCycleIndex(const label index)
Adjust the reported sub-cycle index.
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
static IOstreamOption::floatFormat format_
Format for time directory names (general | fixed | scientific)
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
defineTypeNameAndDebug(combustionModel, 0)
const fileName & instance() const noexcept
Read access to instance path component.
const word & name() const noexcept
Return const reference to name.
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
word findInstancePath(const fileName &directory, const instant &t) const
Search the case for the time directory path corresponding to the given instance.
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name...
virtual bool end() const
Return true if end of run,.
#define WarningInFunction
Report a warning using Foam::Warning.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
virtual Time & operator+=(const dimensionedScalar &deltaT)
Set deltaT to that specified and increment time via operator++()
A simple container of IOobject preferences. Can also be used for general handling of read/no-read/rea...
virtual void setDeltaT(const dimensionedScalar &deltaT, const bool adjust=true)
Reset time step, normally also calling adjustDeltaT()
Automatically write from objectRegistry::writeObject()
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
void clear()
Clear all entries from the registry.
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
Reduce inplace (cf. MPI Allreduce) using specified communication schedule.
Reading is optional [identical to READ_IF_PRESENT].
virtual void endSubCycle()
Reset time after sub-cycling back to previous TimeState.
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
#define forAllReverse(list, i)
Reverse loop across all elements in list.
int system(const std::string &command, const bool bg=false)
Execute the specified command via the shell.
stopAtControls
Stop-run control options, which are primarily used when altering the stopAt condition.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
List< instant > instantList
List of instants.
Registry of regIOobjects.
bool equal(scalar val) const noexcept
True if values are equal (includes SMALL for rounding)
bool open(bool verbose=true)
Open named, but unopened libraries. These names will normally have been added with the append() metho...
Foam::argList args(argc, argv)
bool returnReduceOr(const bool value, const label comm=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
dictionary & controlDict()
The central control dictionary, the contents of which are either taken directly from the FOAM_CONTROL...
virtual label startTimeIndex() const
Return start time index.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Request registration (bool: true)
dimensionedScalar log10(const dimensionedScalar &ds)
Do not request registration (bool: false)
bool found(const word &optName) const
Return true if the named option is found.
void setControls()
Set the controls from the current controlDict.
const dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary pointer if present (and a sub-dictionary) otherwise return nullptr...
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
readOption
Enumeration defining read preferences.