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" },
91 "printExecutionFormat",
101 bool adjustTime =
false;
102 scalar timeToNextWrite = VGREAT;
107 timeToNextWrite =
max 116 scalar nSteps = timeToNextWrite/
deltaT_;
122 label nStepsToNextWrite =
max(1, round(nSteps));
124 scalar newDeltaT = timeToNextWrite/nStepsToNextWrite;
146 const word startFrom = controlDict_.getOrDefault<word>
152 if (startFrom ==
"startTime")
154 controlDict_.readEntry(
"startTime", startTime_);
161 const label nTimes = timeDirs.size();
163 if (startFrom ==
"firstTime")
165 if (nTimes > 1 && timeDirs.first().name() == constant())
167 startTime_ = timeDirs[1].value();
171 startTime_ = timeDirs.first().value();
174 else if (startFrom ==
"latestTime")
178 startTime_ = timeDirs.last().value();
184 <<
"expected startTime, firstTime or latestTime" 185 <<
" found '" << startFrom <<
"'" 193 deltaTSave_ = deltaT_;
202 if (
fileHandler().filePath(timePath(),
false).empty())
204 const int oldPrecision = precision_;
205 int requiredPrecision = -1;
209 precision_ = maxPrecision_;
210 precision_ > oldPrecision;
225 if (!
fileHandler().filePath(timePath(),
false).empty())
227 requiredPrecision = precision_;
231 if (requiredPrecision > 0)
234 precision_ = requiredPrecision;
240 <<
"Increasing the timePrecision from " << oldPrecision
241 <<
" to " << precision_
242 <<
" to support the formatting of the current time directory " 248 precision_ = oldPrecision;
257 scalar sumStartTime = startTime_;
258 reduce(sumStartTime, sumOp<scalar>());
266 <<
"Start time is not the same for all processors" <<
nl 272 IOdictionary timeDict
288 if (controlDict_.getOrDefault(
"adjustTimeStep",
false))
290 if (timeDict.readIfPresent(
"deltaT", deltaT_))
292 deltaTSave_ = deltaT_;
297 timeDict.readIfPresent(
"deltaT0", deltaT0_);
299 if (timeDict.readIfPresent(
"index", startTimeIndex_))
301 timeIndex_ = startTimeIndex_;
308 bool checkValue =
true;
310 string storedTimeName;
311 if (timeDict.readIfPresent(
"name", storedTimeName))
325 scalar storedTimeValue;
326 if (timeDict.readIfPresent(
"value", storedTimeValue))
328 word storedTimeName(
timeName(storedTimeValue));
333 <<
"Time read from time dictionary " << storedTimeName
334 <<
" differs from actual time " <<
timeName() <<
'.' <<
nl 335 <<
" This may cause unexpected database behaviour." 336 <<
" If you are not interested" <<
nl 337 <<
" in preserving time state delete" 338 <<
" the time dictionary." 348 const dictionary* profilingDict = controlDict_.findDict(
"profiling");
377 && profilingDict->getOrDefault(
"active",
true)
397 if (runTimeModifiable_)
406 fileHandler().addWatches(controlDict_, controlDict_.files());
410 controlDict_.files().clear();
418 const word& ctrlDictName,
421 const word& systemName,
422 const word& constantName,
423 const bool enableFunctionObjects,
424 const bool enableLibs
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& systemName,
495 const word& constantName,
496 const bool enableFunctionObjects,
497 const bool enableLibs
504 loopProfiling_(nullptr),
525 writeControl_(wcTimeStep),
526 writeInterval_(GREAT),
530 sigWriteNow_(*this, true),
531 sigStopAtWriteNow_(*this, true),
534 runTimeModifiable_(false),
535 cacheTemporaryObjects_(true),
536 functionObjects_(*this, false)
545 functionObjects_.
on();
553 libs_.
open(
"libs", controlDict_);
572 const word& systemName,
573 const word& constantName,
574 const bool enableFunctionObjects,
575 const bool enableLibs
588 loopProfiling_(nullptr),
610 writeControl_(wcTimeStep),
611 writeInterval_(GREAT),
615 sigWriteNow_(*this, true),
616 sigStopAtWriteNow_(*this, true),
619 runTimeModifiable_(false),
620 cacheTemporaryObjects_(true),
621 functionObjects_(*this, false)
623 if (enableFunctionObjects)
625 functionObjects_.
on();
630 libs_.
open(
"libs", controlDict_);
650 const word& systemName,
651 const word& constantName,
652 const bool enableFunctionObjects,
653 const bool enableLibs
666 loopProfiling_(nullptr),
687 writeControl_(wcTimeStep),
688 writeInterval_(GREAT),
694 runTimeModifiable_(false),
695 cacheTemporaryObjects_(true),
696 functionObjects_(*this, false)
698 if (enableFunctionObjects)
700 functionObjects_.
on();
705 libs_.
open(
"libs", controlDict_);
757 loopProfiling_.reset(
nullptr);
761 fileHandler().removeWatch(controlDict_.watchIndices()[i]);
765 functionObjects_.clear();
779 std::ostringstream buf;
780 buf.setf(ios_base::fmtflags(format_), ios_base::floatfield);
781 buf.precision(precision);
798 const word& stopInstance
836 if (t.
equal(timeDirs[i].value()))
838 return timeDirs[i].name();
848 return findInstancePath(
path(), t);
854 return startTimeIndex_;
878 loopProfiling_.reset(
nullptr);
880 bool isRunning = value() < (endTime_ - 0.5*deltaT_);
886 if (!isRunning && timeIndex_ != startTimeIndex_)
892 functionObjects_.execute();
896 functionObjects_.end();
899 if (cacheTemporaryObjects_)
901 cacheTemporaryObjects_ = checkCacheTemporaryObjects();
910 const_cast<Time&
>(*this).readModifiedObjects();
912 if (timeIndex_ == startTimeIndex_)
914 addProfiling(functionObjects,
"functionObjects.start()");
915 functionObjects_.start();
919 addProfiling(functionObjects,
"functionObjects.execute()");
920 functionObjects_.execute();
929 if (functionObjects_.filesModified())
931 const_cast<Time&
>(*this).readModifiedObjects();
934 if (cacheTemporaryObjects_)
936 cacheTemporaryObjects_ = checkCacheTemporaryObjects();
942 isRunning = value() < (endTime_ - 0.5*deltaT_);
960 const bool isRunning = run();
973 return value() > (endTime_ + 0.5*deltaT_);
979 if (stopCtrl == stopAtControls::saUnknown)
984 const bool changed = (stopAt_ != stopCtrl);
989 if (stopCtrl == stopAtControls::saEndTime)
991 controlDict_.readEntry(
"endTime", endTime_);
1000 return controlDict_.getOrDefault(
"adjustTimeStep",
false);
1015 value() = inst.
value();
1017 timeIndex_ = newIndex;
1050 timeIndex_ = newIndex;
1057 setEndTime(endTime.
value());
1073 setDeltaT(deltaT.
value(), adjust);
1080 deltaTchanged_ =
true;
1095 <<
"previous time state already set" <<
nl 1100 prevTimeState_.reset(
new TimeState(*
this));
1103 deltaT_ /= nSubCycles;
1104 deltaT0_ /= nSubCycles;
1105 deltaTSave_ = deltaT0_;
1107 subCycling_ = nSubCycles;
1109 return prevTimeState();
1119 if (subCycling_ && index > 0)
1121 subCycling_ = index;
1130 TimeState::operator=(prevTimeState());
1131 prevTimeState_.reset(
nullptr);
1142 return operator+=(deltaT.
value());
1149 return operator++();
1155 deltaT0_ = deltaTSave_;
1156 deltaTSave_ = deltaT_;
1159 const scalar oldTimeValue = timeToUserTime(value());
1163 setTime(value() + deltaT_, timeIndex_ + 1);
1168 if (
mag(value()) < 10*SMALL*deltaT_)
1173 if (sigStopAtWriteNow_.active() || sigWriteNow_.active())
1179 if (sigStopAtWriteNow_.active() && stopAt_ == saWriteNow)
1183 if (sigWriteNow_.active() && writeOnce_)
1187 reduce(flag, maxOp<label>());
1191 stopAt_ = saWriteNow;
1201 switch (writeControl_)
1208 writeTime_ = !(timeIndex_ % label(writeInterval_));
1212 case wcAdjustableRunTime:
1214 const label writeIndex = label
1216 ((value() - startTime_) + 0.5*deltaT_)
1220 if (writeIndex > writeTimeIndex_)
1223 writeTimeIndex_ = writeIndex;
1230 const label writeIndex = label
1235 if (writeIndex > writeTimeIndex_)
1238 writeTimeIndex_ = writeIndex;
1245 const label writeIndex = label
1250 if (writeIndex > writeTimeIndex_)
1253 writeTimeIndex_ = writeIndex;
1263 if (stopAt_ == saNoWriteNow)
1267 else if (stopAt_ == saWriteNow)
1272 else if (stopAt_ == saNextWrite && writeTime_ ==
true)
1289 const scalar userDeltaT =
1290 timeToUserTime(value()) - timeToUserTime(value() - deltaT_);
1293 const scalar timeTol =
1294 max(
min(
pow(scalar(10), -precision_), 0.1*userDeltaT), SMALL);
1297 scalar timeNameValue = -VGREAT;
1304 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1307 int oldPrecision = precision_;
1310 precision_ < maxPrecision_
1312 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1319 if (precision_ != oldPrecision)
1322 <<
"Increased the timePrecision from " << oldPrecision
1323 <<
" to " << precision_
1324 <<
" to distinguish between timeNames at time " 1328 if (precision_ == maxPrecision_)
1334 <<
" The maximum time precision has been reached" 1335 " which might result in overwriting previous" 1341 scalar oldTimeNameValue = -VGREAT;
1344 readScalar(oldTimeName, oldTimeNameValue)
1346 sign(timeNameValue - oldTimeNameValue)
1353 <<
" is set to an instance prior to the " 1355 << oldTimeName <<
nl 1356 <<
" This might result in temporal " 1371 return operator++();
virtual Time & operator++()
Prefix increment,.
dimensionedScalar sign(const dimensionedScalar &ds)
List< instant > instantList
List of instants.
const Type & value() const noexcept
Return const reference to value.
#define addProfiling(name, descr)
Define profiling trigger with specified name and description string.
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)
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 fmtflags format_
Time directory name format.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static bool & parRun() noexcept
Test if this a parallel run.
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
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.
static std::string path(const std::string &str)
Return directory path name (part before last /)
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.
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.
virtual word timeName() const
Return current time name.
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 processes in communicator.
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. ...
const T & name() const noexcept
The name/key (const access)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for 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.
Reading is optional [identical to LAZY_READ].
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.
Time(const word &ctrlDictName, const argList &args, const bool enableFunctionObjects=true, const bool enableLibs=true)
Construct from dictionary name to read and argument list.
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 bool active()
True if profiling is allowed and is active.
static std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
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++()
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.
virtual void endSubCycle()
Reset time after sub-cycling back to previous TimeState.
fmtflags
Supported time directory name formats.
#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)
Registry of regIOobjects.
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
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)
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...
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.