86 const scalar timeToNextWrite =
min 91 (writeTimeIndex_ + 1)*writeInterval_ - (value() - startTime_)
93 functionObjects_.timeToNextWrite()
96 const scalar nSteps = timeToNextWrite/deltaT_;
103 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_;
127 if (startFrom ==
"firstTime")
131 if (timeDirs[0].
name() == constant() && timeDirs.
size() >= 2)
133 startTime_ = timeDirs[1].value();
137 startTime_ = timeDirs[0].value();
141 else if (startFrom ==
"latestTime")
145 startTime_ = timeDirs.
last().value();
151 <<
"expected startTime, firstTime or latestTime" 152 <<
" found '" << startFrom <<
"'" 160 deltaTSave_ = deltaT_;
167 int oldPrecision = precision_;
168 int requiredPrecision = -1;
173 precision_ = maxPrecision_;
174 precision_ > oldPrecision;
182 if (newTime == oldTime)
193 requiredPrecision = precision_;
197 if (requiredPrecision > 0)
200 precision_ = requiredPrecision;
206 <<
"Increasing the timePrecision from " << oldPrecision
207 <<
" to " << precision_
208 <<
" to support the formatting of the current time directory " 214 precision_ = oldPrecision;
223 scalar sumStartTime = startTime_;
232 <<
"Start time is not the same for all processors" <<
nl 254 if (controlDict_.lookupOrDefault<
Switch>(
"adjustTimeStep",
false))
258 deltaTSave_ = deltaT_;
267 timeIndex_ = startTimeIndex_;
274 bool checkValue =
true;
276 string storedTimeName;
291 scalar storedTimeValue;
299 <<
"Time read from time dictionary " << storedTimeName
300 <<
" differs from actual time " <<
timeName() <<
'.' <<
nl 301 <<
" This may cause unexpected database behaviour." 302 <<
" If you are not interested" <<
nl 303 <<
" in preserving time state delete" 304 <<
" the time dictionary." 316 const word& controlDictName,
319 const word& systemName,
320 const word& constantName,
321 const bool enableFunctionObjects
353 stopAt_(stopAtControl::endTime),
354 writeControl_(writeControl::timeStep),
355 writeInterval_(great),
359 sigWriteNow_(
true, *
this),
360 sigStopAtWriteNow_(
true, *
this),
366 runTimeModifiable_(
false),
368 functionObjects_(*
this, enableFunctionObjects)
370 libs_.open(controlDict_,
"libs");
379 if (runTimeModifiable_)
386 controlDict_.files().clear();
392 const word& controlDictName,
394 const word& systemName,
395 const word& constantName
429 stopAt_(stopAtControl::endTime),
430 writeControl_(writeControl::timeStep),
431 writeInterval_(great),
435 sigWriteNow_(
true, *
this),
436 sigStopAtWriteNow_(
true, *
this),
442 runTimeModifiable_(
false),
452 libs_.open(controlDict_,
"libs");
461 if (runTimeModifiable_)
468 controlDict_.files().clear();
477 const word& systemName,
478 const word& constantName,
479 const bool enableFunctionObjects
512 stopAt_(stopAtControl::endTime),
513 writeControl_(writeControl::timeStep),
514 writeInterval_(great),
518 sigWriteNow_(
true, *
this),
519 sigStopAtWriteNow_(
true, *
this),
525 runTimeModifiable_(
false),
527 functionObjects_(*
this, enableFunctionObjects)
529 libs_.open(controlDict_,
"libs");
542 if (runTimeModifiable_)
549 controlDict_.files().clear();
557 const word& systemName,
558 const word& constantName,
559 const bool enableFunctionObjects
591 stopAt_(stopAtControl::endTime),
592 writeControl_(writeControl::timeStep),
593 writeInterval_(great),
602 runTimeModifiable_(
false),
604 functionObjects_(*
this, enableFunctionObjects)
606 libs_.open(controlDict_,
"libs");
620 functionObjects_.clear();
628 std::ostringstream buf;
629 buf.setf(ios_base::fmtflags(format_), ios_base::floatfield);
630 buf.precision(precision);
644 return findTimes(
path(), constant());
653 const word& stopInstance
697 if (t.
equal(timeDirs[i].value()))
699 return timeDirs[i].name();
709 return findInstancePath(
path(), t);
718 if (timeDirs.
size() == 1)
723 if (t < timeDirs[1].value())
727 else if (t > timeDirs.
last().value())
729 return timeDirs.
last();
732 label nearestIndex = -1;
733 scalar deltaT = great;
735 for (
label timei=1; timei < timeDirs.
size(); ++timei)
737 scalar
diff =
mag(timeDirs[timei].value() - t);
741 nearestIndex = timei;
745 return timeDirs[nearestIndex];
753 const word& constantName
756 label nearestIndex = -1;
757 scalar deltaT = great;
761 if (timeDirs[timei].
name() == constantName)
continue;
763 scalar
diff =
mag(timeDirs[timei].value() - t);
767 nearestIndex = timei;
777 return startTimeIndex_;
795 return value() < (endTime_ - 0.5*deltaT_);
801 bool running = this->running();
805 if (!running && timeIndex_ != startTimeIndex_)
807 functionObjects_.execute();
808 functionObjects_.end();
818 if (timeIndex_ == startTimeIndex_)
820 functionObjects_.start();
824 functionObjects_.execute();
829 running = this->running();
838 bool running = run();
851 return value() > (endTime_ + 0.5*deltaT_);
857 const bool changed = (stopAt_ != sa);
861 if (sa == stopAtControl::endTime)
863 controlDict_.lookup(
"endTime") >> endTime_;
884 value() = inst.
value();
886 timeIndex_ = newIndex;
919 timeIndex_ = newIndex;
926 setEndTime(endTime.
value());
938 setDeltaT(deltaT.
value());
944 setDeltaTNoAdjust(deltaT);
946 functionObjects_.setTimeStep();
948 if (writeControl_ == writeControl::adjustableRunTime)
958 deltaTchanged_ =
true;
965 prevTimeState_.set(
new TimeState(*
this));
968 deltaT_ /= nSubCycles;
969 deltaT0_ /= nSubCycles;
970 deltaTSave_ = deltaT0_;
972 return prevTimeState();
981 TimeState::operator=(prevTimeState());
982 prevTimeState_.clear();
991 return operator+=(deltaT.
value());
1004 deltaT0_ = deltaTSave_;
1005 deltaTSave_ = deltaT_;
1008 const scalar oldTimeValue = timeToUserTime(value());
1012 setTime(value() + deltaT_, timeIndex_ + 1);
1017 if (
mag(value()) < 10*small*deltaT_)
1022 if (sigStopAtWriteNow_.active() || sigWriteNow_.active())
1030 sigStopAtWriteNow_.active()
1031 && stopAt_ == stopAtControl::writeNow
1036 if (sigWriteNow_.active() && writeOnce_)
1044 stopAt_ = stopAtControl::writeNow;
1054 switch (writeControl_)
1056 case writeControl::timeStep:
1057 writeTime_ = !(timeIndex_ %
label(writeInterval_));
1061 case writeControl::adjustableRunTime:
1065 ((value() - startTime_) + 0.5*deltaT_)
1069 if (writeIndex > writeTimeIndex_)
1072 writeTimeIndex_ = writeIndex;
1077 case writeControl::cpuTime:
1084 if (writeIndex > writeTimeIndex_)
1087 writeTimeIndex_ = writeIndex;
1092 case writeControl::clockTime:
1099 if (writeIndex > writeTimeIndex_)
1102 writeTimeIndex_ = writeIndex;
1112 if (stopAt_ == stopAtControl::noWriteNow)
1116 else if (stopAt_ == stopAtControl::writeNow)
1121 else if (stopAt_ == stopAtControl::nextWrite && writeTime_ ==
true)
1138 const scalar timeTol =
1139 max(
min(
pow(10.0, -precision_), 0.1*deltaT_), small);
1142 const scalar userDeltaT = timeToUserTime(deltaT_);
1145 scalar timeNameValue = -vGreat;
1152 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1155 int oldPrecision = precision_;
1158 precision_ < maxPrecision_
1160 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1167 if (precision_ != oldPrecision)
1170 <<
"Increased the timePrecision from " << oldPrecision
1171 <<
" to " << precision_
1172 <<
" to distinguish between timeNames at time " 1176 if (precision_ == maxPrecision_)
1182 <<
" The maximum time precision has been reached" 1183 " which might result in overwriting previous" 1189 scalar oldTimeNameValue = -vGreat;
1192 readScalar(oldTimeName.c_str(), oldTimeNameValue)
1194 sign(timeNameValue - oldTimeNameValue)
1201 <<
" is set to an instance prior to the " 1203 << oldTimeName <<
nl 1204 <<
" This might result in temporal " 1219 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 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.
Inter-processor communication reduction functions.
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.
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.
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.
virtual bool stopAt(const stopAtControl) const
Adjust the current stopAtControl. Note that this value.
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.
virtual void addWatches(regIOobject &, const fileNameList &) const
Helper: add watches for list of regIOobjects.
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.
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.
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.
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.
instantList times() const
Search the case for valid time directories.
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
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)
#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.
virtual bool removeWatch(const label) const
Remove watch on a file (using handle)
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())