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_)
400 fileHandler().addWatches(controlDict_, controlDict_.files());
404 controlDict_.files().clear();
412 const word& ctrlDictName,
415 const word& systemName,
416 const word& constantName,
417 const bool enableFunctionObjects,
418 const bool enableLibs
431 loopProfiling_(nullptr),
452 writeControl_(wcTimeStep),
453 writeInterval_(GREAT),
457 sigWriteNow_(*this, true),
458 sigStopAtWriteNow_(*this, true),
461 runTimeModifiable_(false),
462 functionObjects_(*this, false)
464 if (enableFunctionObjects)
466 functionObjects_.
on();
471 libs_.
open(
"libs", controlDict_);
485 const word& ctrlDictName,
487 const word& systemName,
488 const word& constantName,
489 const bool enableFunctionObjects,
490 const bool enableLibs
497 loopProfiling_(nullptr),
518 writeControl_(wcTimeStep),
519 writeInterval_(GREAT),
523 sigWriteNow_(*this, true),
524 sigStopAtWriteNow_(*this, true),
527 runTimeModifiable_(false),
528 functionObjects_(*this, false)
537 functionObjects_.
on();
545 libs_.
open(
"libs", controlDict_);
564 const word& systemName,
565 const word& constantName,
566 const bool enableFunctionObjects,
567 const bool enableLibs
580 loopProfiling_(nullptr),
602 writeControl_(wcTimeStep),
603 writeInterval_(GREAT),
607 sigWriteNow_(*this, true),
608 sigStopAtWriteNow_(*this, true),
611 runTimeModifiable_(false),
612 functionObjects_(*this, false)
614 if (enableFunctionObjects)
616 functionObjects_.
on();
621 libs_.
open(
"libs", controlDict_);
641 const word& systemName,
642 const word& constantName,
643 const bool enableFunctionObjects,
644 const bool enableLibs
657 loopProfiling_(nullptr),
678 writeControl_(wcTimeStep),
679 writeInterval_(GREAT),
685 runTimeModifiable_(false),
686 functionObjects_(*this, false)
688 if (enableFunctionObjects)
690 functionObjects_.
on();
695 libs_.
open(
"libs", controlDict_);
747 loopProfiling_.reset(
nullptr);
751 fileHandler().removeWatch(controlDict_.watchIndices()[i]);
755 functionObjects_.clear();
769 std::ostringstream buf;
770 buf.setf(ios_base::fmtflags(format_), ios_base::floatfield);
771 buf.precision(precision);
788 const word& stopInstance
826 if (t.
equal(timeDirs[i].value()))
828 return timeDirs[i].name();
838 return findInstancePath(
path(), t);
844 return startTimeIndex_;
868 loopProfiling_.reset(
nullptr);
870 bool isRunning = value() < (endTime_ - 0.5*deltaT_);
876 if (!isRunning && timeIndex_ != startTimeIndex_)
882 functionObjects_.execute();
886 functionObjects_.end();
895 const_cast<Time&
>(*this).readModifiedObjects();
897 if (timeIndex_ == startTimeIndex_)
899 addProfiling(functionObjects,
"functionObjects.start()");
900 functionObjects_.start();
904 addProfiling(functionObjects,
"functionObjects.execute()");
905 functionObjects_.execute();
914 if (functionObjects_.filesModified())
916 const_cast<Time&
>(*this).readModifiedObjects();
922 isRunning = value() < (endTime_ - 0.5*deltaT_);
940 const bool isRunning = run();
953 return value() > (endTime_ + 0.5*deltaT_);
959 if (stopCtrl == stopAtControls::saUnknown)
964 const bool changed = (stopAt_ != stopCtrl);
969 if (stopCtrl == stopAtControls::saEndTime)
971 controlDict_.readEntry(
"endTime", endTime_);
980 return controlDict_.getOrDefault(
"adjustTimeStep",
false);
995 value() = inst.
value();
997 timeIndex_ = newIndex;
1030 timeIndex_ = newIndex;
1037 setEndTime(endTime.
value());
1053 setDeltaT(deltaT.
value(), adjust);
1060 deltaTchanged_ =
true;
1075 <<
"previous time state already set" <<
nl 1080 prevTimeState_.reset(
new TimeState(*
this));
1083 deltaT_ /= nSubCycles;
1084 deltaT0_ /= nSubCycles;
1085 deltaTSave_ = deltaT0_;
1087 subCycling_ = nSubCycles;
1089 return prevTimeState();
1099 if (subCycling_ && index > 0)
1101 subCycling_ = index;
1110 TimeState::operator=(prevTimeState());
1111 prevTimeState_.reset(
nullptr);
1122 return operator+=(deltaT.
value());
1129 return operator++();
1135 deltaT0_ = deltaTSave_;
1136 deltaTSave_ = deltaT_;
1139 const scalar oldTimeValue = timeToUserTime(value());
1143 setTime(value() + deltaT_, timeIndex_ + 1);
1148 if (
mag(value()) < 10*SMALL*deltaT_)
1153 if (sigStopAtWriteNow_.active() || sigWriteNow_.active())
1159 if (sigStopAtWriteNow_.active() && stopAt_ == saWriteNow)
1163 if (sigWriteNow_.active() && writeOnce_)
1167 reduce(flag, maxOp<label>());
1171 stopAt_ = saWriteNow;
1181 switch (writeControl_)
1188 writeTime_ = !(timeIndex_ % label(writeInterval_));
1192 case wcAdjustableRunTime:
1194 const label writeIndex = label
1196 ((value() - startTime_) + 0.5*deltaT_)
1200 if (writeIndex > writeTimeIndex_)
1203 writeTimeIndex_ = writeIndex;
1210 const label writeIndex = label
1215 if (writeIndex > writeTimeIndex_)
1218 writeTimeIndex_ = writeIndex;
1225 const label writeIndex = label
1230 if (writeIndex > writeTimeIndex_)
1233 writeTimeIndex_ = writeIndex;
1243 if (stopAt_ == saNoWriteNow)
1247 else if (stopAt_ == saWriteNow)
1252 else if (stopAt_ == saNextWrite && writeTime_ ==
true)
1269 const scalar userDeltaT =
1270 timeToUserTime(value()) - timeToUserTime(value() - deltaT_);
1273 const scalar timeTol =
1274 max(
min(
pow(scalar(10), -precision_), 0.1*userDeltaT), SMALL);
1277 scalar timeNameValue = -VGREAT;
1284 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1287 int oldPrecision = precision_;
1290 precision_ < maxPrecision_
1292 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1299 if (precision_ != oldPrecision)
1302 <<
"Increased the timePrecision from " << oldPrecision
1303 <<
" to " << precision_
1304 <<
" to distinguish between timeNames at time " 1308 if (precision_ == maxPrecision_)
1314 <<
" The maximum time precision has been reached" 1315 " which might result in overwriting previous" 1321 scalar oldTimeNameValue = -VGREAT;
1324 readScalar(oldTimeName, oldTimeNameValue)
1326 sign(timeNameValue - oldTimeNameValue)
1333 <<
" is set to an instance prior to the " 1335 << oldTimeName <<
nl 1336 <<
" This might result in temporal " 1351 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.
autoPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file 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)
Number of this process (starting from masterNo() = 0)
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 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) is 1 for serial run.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
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.
Reading required, file watched for runTime modification.
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.
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.
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)
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.