85 const scalar timeToNextWrite =
min 90 (writeTimeIndex_ + 1)*writeInterval_ - (value() - beginTime_)
92 functionObjects_.timeToNextWrite()
95 const scalar nSteps = timeToNextWrite/deltaT_;
102 const label nStepsToNextWrite =
label(
max(nSteps, 1) + 0.99);
104 deltaT_ = timeToNextWrite/nStepsToNextWrite;
112 const word startFrom = controlDict_.lookupOrDefault<
word>
118 if (startFrom ==
"startTime")
120 controlDict_.lookup(
"startTime") >> startTime_;
121 startTime_ = userTimeToTime(startTime_);
126 instantList timeDirs = findTimes(path(), constant());
128 if (startFrom ==
"firstTime")
132 if (timeDirs[0].
name() == constant() && timeDirs.
size() >= 2)
134 startTime_ = userTimeToTime(timeDirs[1].value());
138 startTime_ = userTimeToTime(timeDirs[0].value());
142 else if (startFrom ==
"latestTime")
146 startTime_ = userTimeToTime(timeDirs.
last().value());
152 <<
"expected startTime, firstTime or latestTime" 153 <<
" found '" << startFrom <<
"'" 160 deltaTSave_ = deltaT_;
167 int oldPrecision = curPrecision_;
168 int requiredPrecision = -1;
173 curPrecision_ = maxPrecision_;
174 curPrecision_ > oldPrecision;
183 if (newTime == oldTime)
194 requiredPrecision = curPrecision_;
198 if (requiredPrecision > 0)
201 curPrecision_ = requiredPrecision;
207 <<
"Increasing the timePrecision from " << oldPrecision
208 <<
" to " << curPrecision_
209 <<
" to support the formatting of the current time directory " 215 curPrecision_ = oldPrecision;
224 scalar sumStartTime = startTime_;
233 <<
"Start time is not the same for all processors" <<
nl 253 if (timeDict.
found(
"beginTime"))
255 beginTime_ = userTimeToTime(timeDict.
lookup<scalar>(
"beginTime"));
259 beginTime_ = startTime_;
264 if (controlDict_.lookupOrDefault<
Switch>(
"adjustTimeStep",
false))
266 if (timeDict.
found(
"deltaT"))
268 deltaT_ = userTimeToTime(timeDict.
lookup<scalar>(
"deltaT"));
269 deltaTSave_ = deltaT_;
274 if (timeDict.
found(
"deltaT0"))
276 deltaT0_ = userTimeToTime(timeDict.
lookup<scalar>(
"deltaT0"));
281 timeIndex_ = startTimeIndex_;
288 writeControl_ == writeControl::runTime
289 || writeControl_ == writeControl::adjustableRunTime
293 writeTimeIndex_ =
label 295 ((value() - beginTime_) + 0.5*deltaT_)/writeInterval_
303 bool checkValue =
true;
305 string storedTimeName;
320 scalar storedTimeValue;
328 <<
"Time read from time dictionary " << storedTimeName
329 <<
" differs from actual time " <<
timeName() <<
'.' <<
nl 330 <<
" This may cause unexpected database behaviour." 331 <<
" If you are not interested" <<
nl 332 <<
" in preserving time state delete" 333 <<
" the time dictionary." 345 const word& controlDictName,
348 const word& systemName,
349 const word& constantName,
350 const bool enableFunctionObjects
363 runTimeModifiable_(
false),
380 beginTime_(startTime_),
384 stopAt_(stopAtControl::endTime),
385 writeControl_(writeControl::timeStep),
386 writeInterval_(great),
399 cacheTemporaryObjects_(
true),
401 functionObjects_(*
this, enableFunctionObjects)
412 controlDict_.addWatch();
418 const word& controlDictName,
420 const word& systemName,
421 const word& constantName
436 runTimeModifiable_(
false),
453 beginTime_(startTime_),
457 stopAt_(stopAtControl::endTime),
458 writeControl_(writeControl::timeStep),
459 writeInterval_(great),
472 cacheTemporaryObjects_(
true),
488 if (args.
options().found(
"case"))
494 "OptimisationSwitches",
496 "DimensionedConstants",
503 if (controlDict_.found(switchSets[i]))
507 <<
" in system/controlDict are only processed if " 509 << args.
path() <<
" directory" <<
endl;
517 controlDict_.addWatch();
526 const word& systemName,
527 const word& constantName,
528 const bool enableFunctionObjects
541 runTimeModifiable_(
false),
559 beginTime_(startTime_),
563 stopAt_(stopAtControl::endTime),
564 writeControl_(writeControl::timeStep),
565 writeInterval_(great),
578 cacheTemporaryObjects_(
true),
580 functionObjects_(*
this, enableFunctionObjects)
591 controlDict_.addWatch();
599 const word& systemName,
600 const word& constantName,
601 const bool enableFunctionObjects
614 runTimeModifiable_(
false),
631 beginTime_(startTime_),
635 stopAt_(stopAtControl::endTime),
636 writeControl_(writeControl::timeStep),
637 writeInterval_(great),
647 cacheTemporaryObjects_(
true),
649 functionObjects_(*
this, enableFunctionObjects)
660 functionObjects_.clear();
668 std::ostringstream buf;
669 buf.setf(ios_base::fmtflags(format_), ios_base::floatfield);
670 buf.precision(precision);
684 return findTimes(path(), constant());
693 const word& stopInstance
728 instantList timeDirs = findTimes(path(), constant());
737 if (t.
equal(timeDirs[i].value()))
739 return timeDirs[i].name();
749 return findInstancePath(path(), t);
755 instantList timeDirs = findTimes(path(), constant());
758 if (timeDirs.
size() == 1)
763 if (t < timeDirs[1].value())
767 else if (t > timeDirs.
last().value())
769 return timeDirs.
last();
772 label nearestIndex = -1;
773 scalar deltaT = great;
775 for (
label timei=1; timei < timeDirs.
size(); ++timei)
777 scalar
diff =
mag(timeDirs[timei].value() - t);
781 nearestIndex = timei;
785 return timeDirs[nearestIndex];
793 const word& constantName
796 label nearestIndex = -1;
797 scalar deltaT = great;
801 if (timeDirs[timei].
name() == constantName)
continue;
803 scalar
diff =
mag(timeDirs[timei].value() - t);
807 nearestIndex = timei;
817 return startTimeIndex_;
847 return userTime_->timeToUserTime(value());
853 return userTime_->userTimeToTime(tau);
859 return userTime_->timeToUserTime(t);
865 return timeName(userTimeValue()) + userTime_->unit();
871 return value() < (endTime_ - 0.5*deltaT_);
877 bool running = this->running();
881 if (!running && timeIndex_ != startTimeIndex_)
883 functionObjects_.execute();
884 functionObjects_.end();
886 if (cacheTemporaryObjects_)
888 cacheTemporaryObjects_ = checkCacheTemporaryObjects();
899 if (timeIndex_ == startTimeIndex_)
901 functionObjects_.start();
905 functionObjects_.execute();
907 if (cacheTemporaryObjects_)
909 cacheTemporaryObjects_ = checkCacheTemporaryObjects();
915 running = this->running();
924 bool running = run();
937 return value() > (endTime_ + 0.5*deltaT_);
943 const bool changed = (stopAt_ != sa);
947 if (sa == stopAtControl::endTime)
949 controlDict_.lookup(
"endTime") >> endTime_;
963 timeIndex_ = t.timeIndex_;
970 value() = userTimeToTime(inst.
value());
972 timeIndex_ = newIndex;
988 if (timeDict.
found(
"deltaT"))
990 deltaT_ = userTimeToTime(timeDict.
lookup<scalar>(
"deltaT"));
993 if (timeDict.
found(
"deltaT0"))
995 deltaT0_ = userTimeToTime(timeDict.
lookup<scalar>(
"deltaT0"));
1014 timeIndex_ = newIndex;
1021 setEndTime(endTime.
value());
1033 setDeltaT(deltaT.
value());
1039 setDeltaTNoAdjust(deltaT);
1041 if (writeControl_ == writeControl::adjustableRunTime)
1051 deltaTchanged_ =
true;
1057 if (writeInterval_ == great || !
equal(writeInterval, writeInterval_))
1059 writeInterval_ = writeInterval;
1063 writeControl_ == writeControl::runTime
1064 || writeControl_ == writeControl::adjustableRunTime
1069 writeTimeIndex_ =
label 1071 ((value() - beginTime_) + 0.5*deltaT_)/writeInterval_
1074 else if (writeControl_ == writeControl::timeStep)
1077 writeInterval_ =
label(writeInterval + 0.5);
1086 prevTimeState_.set(
new TimeState(*
this));
1089 deltaT_ /= nSubCycles;
1090 deltaT0_ /= nSubCycles;
1091 deltaTSave_ = deltaT0_;
1093 return prevTimeState();
1101 subCycling_ =
false;
1102 TimeState::operator=(prevTimeState());
1103 prevTimeState_.clear();
1112 return operator+=(deltaT.
value());
1119 return operator++();
1125 deltaT0_ = deltaTSave_;
1126 deltaTSave_ = deltaT_;
1129 const scalar oldTimeValue = timeToUserTime(value());
1133 setTime(value() + deltaT_, timeIndex_ + 1);
1138 if (
mag(value()) < 10*small*deltaT_)
1143 if (sigStopAtWriteNow_.active() || sigWriteNow_.active())
1151 sigStopAtWriteNow_.active()
1152 && stopAt_ == stopAtControl::writeNow
1157 if (sigWriteNow_.active() && writeOnce_)
1165 stopAt_ = stopAtControl::writeNow;
1175 switch (writeControl_)
1177 case writeControl::timeStep:
1178 writeTime_ = !(timeIndex_ %
label(writeInterval_));
1181 case writeControl::runTime:
1182 case writeControl::adjustableRunTime:
1186 ((value() - beginTime_) + 0.5*deltaT_)
1190 if (writeIndex > writeTimeIndex_)
1193 writeTimeIndex_ = writeIndex;
1198 case writeControl::cpuTime:
1205 if (writeIndex > writeTimeIndex_)
1208 writeTimeIndex_ = writeIndex;
1213 case writeControl::clockTime:
1220 if (writeIndex > writeTimeIndex_)
1223 writeTimeIndex_ = writeIndex;
1233 if (stopAt_ == stopAtControl::noWriteNow)
1237 else if (stopAt_ == stopAtControl::writeNow)
1242 else if (stopAt_ == stopAtControl::nextWrite && writeTime_ ==
true)
1259 const scalar userDeltaT =
1260 timeToUserTime(value()) - timeToUserTime(value() - deltaT_);
1263 const scalar timeTol =
1264 max(
min(
pow(10.0, -precision_), 0.1*userDeltaT), small);
1267 scalar timeNameValue = -vGreat;
1274 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1277 int oldPrecision = curPrecision_;
1280 curPrecision_ < maxPrecision_
1282 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1289 if (curPrecision_ != oldPrecision)
1292 <<
"Increased the timePrecision from " << oldPrecision
1293 <<
" to " << curPrecision_
1294 <<
" to distinguish between timeNames at time " 1298 if (curPrecision_ == maxPrecision_)
1304 <<
" The maximum time precision has been reached" 1305 " which might result in overwriting previous" 1311 scalar oldTimeNameValue = -vGreat;
1314 readScalar(oldTimeName.c_str(), oldTimeNameValue)
1316 sign(timeNameValue - oldTimeNameValue)
1323 <<
" is set to an instance prior to the " 1325 << oldTimeName <<
nl 1326 <<
" This might result in temporal " 1341 return operator++();
virtual Time & operator++()
Prefix increment,.
dimensionedScalar sign(const dimensionedScalar &ds)
scalar diff(const triad &A, const triad &B)
Return a quantity of the difference between two triads.
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
const word & executable() const
Name of executable without the path.
bool exists(const fileName &, const bool checkVariants=true, const bool followLink=true)
Does the name exist (as directory or file) in the file system?
#define forAll(list, i)
Loop across all elements in list.
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
A class for addressing time paths without using the Time class.
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
A class for handling file names.
errorManipArg< error, int > exit(error &err, const int errNo=1)
The time value with time-stepping information, user-defined remapping, etc.
const fileName & globalCaseName() const
Return case name.
virtual dimensionedScalar beginTime() const
Return begin time (initial start time)
const word & name() const
Name (const access)
void adjustDeltaT()
Adjust the time step so that writing occurs at the specified time.
A list of keyword definitions, which are a keyword followed by any number of values (e...
virtual ~Time()
Destructor.
const fileName & rootPath() const
Return root path.
static autoPtr< userTime > New(const dictionary &controlDict)
void size(const label)
Override size to be inconsistent with allocated storage.
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
virtual bool loop()
Return true if run should continue and if so increment time.
virtual dimensionedScalar startTime() const
Return start time.
bool exists(IOobject &io) const
Does ioobject exist. Is either a directory (empty name()) or.
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool optionFound(const word &opt) const
Return true if the named option is found.
word findInstance(const fileName &dir, const word &name=word::null, const IOobject::readOption rOpt=IOobject::MUST_READ, const word &stopInstance=word::null) const
Return the location of "dir" containing the file "name".
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none/any.
#define forAllReverse(list, i)
Reverse loop across all elements in list.
runTimeSource setTime(sourceTimes[sourceTimeIndex], sourceTimeIndex)
virtual dimensionedScalar endTime() const
Return end time.
stopAtControl
Stop-run control options.
readOption
Enumeration defining the read options.
Initialise the NamedEnum HashTable from the static list of names.
virtual word timeName() const
Return current time name.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
dlLibraryTable libs
Table of loaded dynamic libraries.
virtual bool run() const
Return true if run should continue,.
const ParRunControl & parRunControl() const
Return parRunControl.
static const int maxPrecision_
Maximum time directory name precision.
scalar userTimeValue() const
Return current user time value.
const userTimes::userTime & userTime() const
Return the userTime.
virtual TimeState subCycle(const label nSubCycles)
Set time to sub-cycle for the given number of steps.
const dimensionSet dimTime
virtual bool stopAt(const stopAtControl) const
Adjust the current stopAtControl. Note that this value.
const Foam::HashTable< string > & options() const
Return options.
static int precision_
Time directory name precision.
A class for handling words, derived from string.
virtual bool running() const
Return true if run should continue without any side effects.
Extract command arguments and options from the supplied argc and argv parameters. ...
static int curPrecision_
Current time directory name precision adjusted as necessary.
const Type & value() const
Return const reference to value.
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
static const word null
An empty word.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
static const label labelMax
virtual void setTime(const Time &)
Reset the time and time-index to those of the given time.
format
Supported time directory name formats.
const fileOperation & fileHandler()
Get current file handler.
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
Time(const word &name, const argList &args, const word &systemName="system", const word &constantName="constant")
Construct given name of dictionary to read and argument list.
static word controlDictName
The default control dictionary name (normally "controlDict")
const fileName & caseName() const
Return case name (parallel run) or global case (serial run)
static format format_
Time directory name format.
virtual void setDeltaTNoAdjust(const scalar)
Reset time step without additional adjustment or modification.
defineTypeNameAndDebug(combustionModel, 0)
scalar value() const
Value (const access)
static const NamedEnum< stopAtControl, 4 > stopAtControlNames_
const word & name() const
Return const reference to name.
bool open(const fileName &libName, const bool verbose=true)
Open the named library, optionally with warnings if problems occur.
void readModifiedObjects()
Read the objects that have been modified.
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
word name(const complex &)
Return a string representation of a complex.
fileName path() const
Return the path to the caseName.
virtual void setEndTime(const dimensionedScalar &)
Reset end time.
static const NamedEnum< writeControl, 5 > writeControlNames_
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
timeIOdictionary derived from IOdictionary with globalFile set false to enable writing to processor t...
An instant of time. Contains the time value and name.
static bool & parRun()
Is this a parallel run?
static label nProcs(const label communicator=0)
Number of processes in parallel run.
bool equal(const T &s1, const T &s2)
virtual bool end() const
Return true if end of run,.
virtual void setTime(const Time &) const
Callback for time change.
#define WarningInFunction
Report a warning using Foam::Warning.
static const versionNumber currentVersion
Current version number.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
word userTimeName() const
Return current user time name with units.
instantList times() const
Search the case for valid time directories.
instant findClosestTime(const scalar) const
Search the case for the time closest to the given time.
virtual void setDeltaT(const dimensionedScalar &)
Reset time step.
writeControl
Write control options.
scalar userTimeToTime(const scalar tau) const
Convert the user-time (e.g. CA deg) to real-time (s).
dimensioned< scalar > mag(const dimensioned< Type > &)
virtual void endSubCycle()
Reset time after sub-cycling back to previous TimeState.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
virtual void setWriteInterval(const scalar writeInterval)
Reset the write interval.
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
fileName & instance() const
Return the instance directory, constant, system, <time> etc.
scalar timeToUserTime(const scalar t) const
Convert the real-time (s) into user-time (e.g. CA deg)
Registry of regIOobjects.
T & last()
Return the last element of the list.
word findInstancePath(const fileName &path, const instant &) const
Search the case for the time directory path.
virtual label startTimeIndex() const
Return start time index.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
dimensionedScalar log10(const dimensionedScalar &ds)
static HashTable< string > validOptions
A list of valid options.
virtual Time & operator+=(const dimensionedScalar &)
Set deltaT to that specified and increment time via operator++()
bool equal(const scalar) const
Comparison used for instants to be equal.
void setControls()
Set the controls from the current controlDict.
static label findClosestTimeIndex(const instantList &, const scalar, const word &constantName="constant")
Search instantList for the time index closest to the given time.
int system(const std::string &command)
Execute the specified command.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.