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,
737 const bool constant_fallback
759 return startTimeIndex_;
783 loopProfiling_.reset(
nullptr);
785 bool isRunning = value() < (endTime_ - 0.5*deltaT_);
791 if (!isRunning && timeIndex_ != startTimeIndex_)
797 functionObjects_.execute();
801 functionObjects_.end();
804 if (cacheTemporaryObjects_)
806 cacheTemporaryObjects_ = checkCacheTemporaryObjects();
815 const_cast<Time&
>(*this).readModifiedObjects();
817 if (timeIndex_ == startTimeIndex_)
819 addProfiling(functionObjects,
"functionObjects.start()");
820 functionObjects_.start();
824 addProfiling(functionObjects,
"functionObjects.execute()");
825 functionObjects_.execute();
834 if (functionObjects_.filesModified())
836 const_cast<Time&
>(*this).readModifiedObjects();
839 if (cacheTemporaryObjects_)
841 cacheTemporaryObjects_ = checkCacheTemporaryObjects();
847 isRunning = value() < (endTime_ - 0.5*deltaT_);
865 const bool isRunning = run();
878 return value() > (endTime_ + 0.5*deltaT_);
884 if (stopCtrl == stopAtControls::saUnknown)
889 const bool changed = (stopAt_ != stopCtrl);
894 if (stopCtrl == stopAtControls::saEndTime)
896 controlDict_.readEntry(
"endTime", endTime_);
905 return controlDict_.getOrDefault(
"adjustTimeStep",
false);
918 resetTimeState(inst.
name(), inst.
value(), newIndex);
934 timeDict.readIfPresent(
"deltaT", deltaT_);
935 timeDict.readIfPresent(
"deltaT0", deltaT0_);
936 timeDict.readIfPresent(
"index", timeIndex_);
961 setEndTime(endTime.
value());
977 setDeltaT(deltaT.
value(), adjust);
984 deltaTchanged_ =
true;
999 <<
"previous time state already set" <<
nl 1004 prevTimeState_.reset(
new TimeState(*
this));
1007 deltaT_ /= nSubCycles;
1008 deltaT0_ /= nSubCycles;
1009 deltaTSave_ = deltaT0_;
1011 subCycling_ = nSubCycles;
1013 return prevTimeState();
1023 if (subCycling_ && index > 0)
1025 subCycling_ = index;
1034 TimeState::operator=(prevTimeState());
1035 prevTimeState_.reset(
nullptr);
1046 return operator+=(deltaT.
value());
1053 return operator++();
1059 deltaT0_ = deltaTSave_;
1060 deltaTSave_ = deltaT_;
1063 const scalar oldTimeValue = timeToUserTime(value());
1067 setTime(value() + deltaT_, timeIndex_ + 1);
1072 if (
mag(value()) < 10*SMALL*deltaT_)
1077 if (sigStopAtWriteNow_.active() || sigWriteNow_.active())
1083 if (sigStopAtWriteNow_.active() && stopAt_ == saWriteNow)
1087 if (sigWriteNow_.active() && writeOnce_)
1091 reduce(flag, maxOp<label>());
1095 stopAt_ = saWriteNow;
1105 switch (writeControl_)
1112 writeTime_ = !(timeIndex_ % label(writeInterval_));
1116 case wcAdjustableRunTime:
1118 const label writeIndex = label
1120 ((value() - startTime_) + 0.5*deltaT_)
1124 if (writeIndex > writeTimeIndex_)
1127 writeTimeIndex_ = writeIndex;
1134 const label writeIndex = label
1139 if (writeIndex > writeTimeIndex_)
1142 writeTimeIndex_ = writeIndex;
1149 const label writeIndex = label
1154 if (writeIndex > writeTimeIndex_)
1157 writeTimeIndex_ = writeIndex;
1167 if (stopAt_ == saNoWriteNow)
1171 else if (stopAt_ == saWriteNow)
1176 else if (stopAt_ == saNextWrite && writeTime_ ==
true)
1193 const scalar userDeltaT =
1194 timeToUserTime(value()) - timeToUserTime(value() - deltaT_);
1197 const scalar timeTol =
1198 max(
min(
pow(scalar(10), -precision_), 0.1*userDeltaT), SMALL);
1201 scalar timeNameValue = -VGREAT;
1208 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1211 int oldPrecision = precision_;
1214 precision_ < maxPrecision_
1216 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1223 if (precision_ != oldPrecision)
1226 <<
"Increased the timePrecision from " << oldPrecision
1227 <<
" to " << precision_
1228 <<
" to distinguish between timeNames at time " 1232 if (precision_ == maxPrecision_)
1238 <<
" The maximum time precision has been reached" 1239 " which might result in overwriting previous" 1245 scalar oldTimeNameValue = -VGREAT;
1248 readScalar(oldTimeName, oldTimeNameValue)
1250 sign(timeNameValue - oldTimeNameValue)
1257 <<
" is set to an instance prior to the " 1259 << oldTimeName <<
nl 1260 <<
" This might result in temporal " 1275 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)
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.
#define addProfiling(Name,...)
Define profiling trigger with specified name and description string. The description is generated by ...
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. ...
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.
word findInstance(const fileName &directory, const word &name=word::null, IOobjectOption::readOption rOpt=IOobjectOption::MUST_READ, const word &stopInstance=word::null, const bool constant_fallback=true) const
Return time instance (location) of directory containing the file name (eg, used in reading mesh data)...
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 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)
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.
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 open(bool verbose=true)
Open named, but unopened libraries. These names will normally have been added with push_back()...
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)
void reduce(T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) using linear/tree communication schedule.
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 it is a 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.