82 const scalar timeToNextWrite =
min 87 (writeTimeIndex_ + 1)*writeInterval_ - (value() - beginTime_)
89 functionObjects_.timeToNextWrite()
92 const scalar nSteps = timeToNextWrite/deltaT_;
101 deltaT_ = timeToNextWrite/nStepsToNextWrite;
109 const word startFrom = controlDict_.lookupOrDefault<
word>
115 if (startFrom ==
"startTime")
117 controlDict_.lookup(
"startTime") >> startTime_;
124 if (startFrom ==
"firstTime")
128 if (timeDirs[0].
name() == constant() && timeDirs.
size() >= 2)
130 startTime_ = timeDirs[1].value();
134 startTime_ = timeDirs[0].value();
138 else if (startFrom ==
"latestTime")
142 startTime_ = timeDirs.
last().value();
148 <<
"expected startTime, firstTime or latestTime" 149 <<
" found '" << startFrom <<
"'" 157 deltaTSave_ = deltaT_;
164 int oldPrecision = precision_;
165 int requiredPrecision = -1;
170 precision_ = maxPrecision_;
171 precision_ > oldPrecision;
179 if (newTime == oldTime)
190 requiredPrecision = precision_;
194 if (requiredPrecision > 0)
197 precision_ = requiredPrecision;
203 <<
"Increasing the timePrecision from " << oldPrecision
204 <<
" to " << precision_
205 <<
" to support the formatting of the current time directory " 211 precision_ = oldPrecision;
220 scalar sumStartTime = startTime_;
229 <<
"Start time is not the same for all processors" <<
nl 253 if (controlDict_.lookupOrDefault<
Switch>(
"adjustTimeStep",
false))
257 deltaTSave_ = deltaT_;
266 timeIndex_ = startTimeIndex_;
274 || writeControl_ == writeControl::adjustableRunTime
278 writeTimeIndex_ =
label 280 ((value() - beginTime_) + 0.5*deltaT_)/writeInterval_
288 bool checkValue =
true;
290 string storedTimeName;
305 scalar storedTimeValue;
313 <<
"Time read from time dictionary " << storedTimeName
314 <<
" differs from actual time " <<
timeName() <<
'.' <<
nl 315 <<
" This may cause unexpected database behaviour." 316 <<
" If you are not interested" <<
nl 317 <<
" in preserving time state delete" 318 <<
" the time dictionary." 330 const word& controlDictName,
333 const word& systemName,
334 const word& constantName,
335 const bool enableFunctionObjects
348 runTimeModifiable_(
false),
365 beginTime_(startTime_),
367 stopAt_(stopAtControl::endTime),
368 writeControl_(writeControl::timeStep),
369 writeInterval_(great),
380 cacheTemporaryObjects_(
true),
382 functionObjects_(*
this, enableFunctionObjects)
393 controlDict_.addWatch();
399 const word& controlDictName,
401 const word& systemName,
402 const word& constantName
417 runTimeModifiable_(
false),
434 beginTime_(startTime_),
436 stopAt_(stopAtControl::endTime),
437 writeControl_(writeControl::timeStep),
438 writeInterval_(great),
449 cacheTemporaryObjects_(
true),
465 if (args.
options().found(
"case"))
471 "OptimisationSwitches",
473 "DimensionedConstants",
480 if (controlDict_.found(switchSets[i]))
484 <<
" in system/controlDict are only processed if " 486 << args.
path() <<
" directory" <<
endl;
494 controlDict_.addWatch();
503 const word& systemName,
504 const word& constantName,
505 const bool enableFunctionObjects
518 runTimeModifiable_(
false),
536 beginTime_(startTime_),
538 stopAt_(stopAtControl::endTime),
539 writeControl_(writeControl::timeStep),
540 writeInterval_(great),
551 cacheTemporaryObjects_(
true),
553 functionObjects_(*
this, enableFunctionObjects)
564 controlDict_.addWatch();
572 const word& systemName,
573 const word& constantName,
574 const bool enableFunctionObjects
587 runTimeModifiable_(
false),
604 beginTime_(startTime_),
606 stopAt_(stopAtControl::endTime),
607 writeControl_(writeControl::timeStep),
608 writeInterval_(great),
617 cacheTemporaryObjects_(
true),
619 functionObjects_(*
this, enableFunctionObjects)
630 functionObjects_.clear();
638 std::ostringstream buf;
639 buf.setf(ios_base::fmtflags(format_), ios_base::floatfield);
640 buf.precision(precision);
654 return findTimes(
path(), constant());
663 const word& stopInstance
707 if (t.
equal(timeDirs[i].value()))
709 return timeDirs[i].name();
719 return findInstancePath(
path(), t);
728 if (timeDirs.
size() == 1)
733 if (t < timeDirs[1].value())
737 else if (t > timeDirs.
last().value())
739 return timeDirs.
last();
742 label nearestIndex = -1;
743 scalar deltaT = great;
745 for (
label timei=1; timei < timeDirs.
size(); ++timei)
747 scalar
diff =
mag(timeDirs[timei].value() - t);
751 nearestIndex = timei;
755 return timeDirs[nearestIndex];
763 const word& constantName
766 label nearestIndex = -1;
767 scalar deltaT = great;
771 if (timeDirs[timei].
name() == constantName)
continue;
773 scalar
diff =
mag(timeDirs[timei].value() - t);
777 nearestIndex = timei;
787 return startTimeIndex_;
811 return value() < (endTime_ - 0.5*deltaT_);
817 bool running = this->running();
821 if (!running && timeIndex_ != startTimeIndex_)
823 functionObjects_.execute();
824 functionObjects_.end();
826 if (cacheTemporaryObjects_)
828 cacheTemporaryObjects_ = checkCacheTemporaryObjects();
839 if (timeIndex_ == startTimeIndex_)
841 functionObjects_.start();
845 functionObjects_.execute();
847 if (cacheTemporaryObjects_)
849 cacheTemporaryObjects_ = checkCacheTemporaryObjects();
855 running = this->running();
864 bool running = run();
877 return value() > (endTime_ + 0.5*deltaT_);
883 const bool changed = (stopAt_ != sa);
887 if (sa == stopAtControl::endTime)
889 controlDict_.lookup(
"endTime") >> endTime_;
910 value() = inst.
value();
912 timeIndex_ = newIndex;
945 timeIndex_ = newIndex;
952 setEndTime(endTime.
value());
964 setDeltaT(deltaT.
value());
970 setDeltaTNoAdjust(deltaT);
972 if (writeControl_ == writeControl::adjustableRunTime)
982 deltaTchanged_ =
true;
988 if (writeInterval_ == great || !
equal(writeInterval, writeInterval_))
990 writeInterval_ = writeInterval;
995 || writeControl_ == writeControl::adjustableRunTime
1000 writeTimeIndex_ =
label 1002 ((value() - beginTime_) + 0.5*deltaT_)/writeInterval_
1005 else if (writeControl_ == writeControl::timeStep)
1008 writeInterval_ =
label(writeInterval + 0.5);
1017 prevTimeState_.set(
new TimeState(*
this));
1020 deltaT_ /= nSubCycles;
1021 deltaT0_ /= nSubCycles;
1022 deltaTSave_ = deltaT0_;
1024 return prevTimeState();
1032 subCycling_ =
false;
1033 TimeState::operator=(prevTimeState());
1034 prevTimeState_.clear();
1043 return operator+=(deltaT.
value());
1050 return operator++();
1056 deltaT0_ = deltaTSave_;
1057 deltaTSave_ = deltaT_;
1060 const scalar oldTimeValue = timeToUserTime(value());
1064 setTime(value() + deltaT_, timeIndex_ + 1);
1069 if (
mag(value()) < 10*small*deltaT_)
1074 if (sigStopAtWriteNow_.active() || sigWriteNow_.active())
1082 sigStopAtWriteNow_.active()
1083 && stopAt_ == stopAtControl::writeNow
1088 if (sigWriteNow_.active() && writeOnce_)
1096 stopAt_ = stopAtControl::writeNow;
1106 switch (writeControl_)
1108 case writeControl::timeStep:
1109 writeTime_ = !(timeIndex_ %
label(writeInterval_));
1113 case writeControl::adjustableRunTime:
1117 ((value() - beginTime_) + 0.5*deltaT_)
1121 if (writeIndex > writeTimeIndex_)
1124 writeTimeIndex_ = writeIndex;
1129 case writeControl::cpuTime:
1136 if (writeIndex > writeTimeIndex_)
1139 writeTimeIndex_ = writeIndex;
1144 case writeControl::clockTime:
1151 if (writeIndex > writeTimeIndex_)
1154 writeTimeIndex_ = writeIndex;
1164 if (stopAt_ == stopAtControl::noWriteNow)
1168 else if (stopAt_ == stopAtControl::writeNow)
1173 else if (stopAt_ == stopAtControl::nextWrite && writeTime_ ==
true)
1190 const scalar timeTol =
1191 max(
min(
pow(10.0, -precision_), 0.1*deltaT_), small);
1194 const scalar userDeltaT = timeToUserTime(deltaT_);
1197 scalar timeNameValue = -vGreat;
1204 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1207 int oldPrecision = precision_;
1210 precision_ < maxPrecision_
1212 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1219 if (precision_ != oldPrecision)
1222 <<
"Increased the timePrecision from " << oldPrecision
1223 <<
" to " << precision_
1224 <<
" to distinguish between timeNames at time " 1228 if (precision_ == maxPrecision_)
1234 <<
" The maximum time precision has been reached" 1235 " which might result in overwriting previous" 1241 scalar oldTimeNameValue = -vGreat;
1244 readScalar(oldTimeName.c_str(), oldTimeNameValue)
1246 sign(timeNameValue - oldTimeNameValue)
1253 <<
" is set to an instance prior to the " 1255 << oldTimeName <<
nl 1256 <<
" This might result in temporal " 1271 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.
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.
A class for addressing time paths without using the Time class.
intWM_LABEL_SIZE_t 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...
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
virtual ~Time()
Destructor.
const fileName & rootPath() const
Return root path.
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.
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.
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. ...
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.
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.
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
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)
An instant of time. Contains the time value and name.
static bool & parRun()
Is this a parallel run?
const fileName & instance() const
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.
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
#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.
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.
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.
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.
fileName path(UMean.rootPath()/UMean.caseName()/functionObjects::writeFile::outputPrefix/"graphs"/UMean.instance())