86 bool adjustTime =
false;
87 scalar timeToNextWrite = VGREAT;
89 if (writeControl_ == wcAdjustableRunTime)
95 (writeTimeIndex_ + 1)*writeInterval_ - (value() - startTime_)
101 scalar nSteps = timeToNextWrite/deltaT_ - SMALL;
108 scalar newDeltaT = timeToNextWrite/nStepsToNextWrite;
112 if (newDeltaT >= deltaT_)
114 deltaT_ =
min(newDeltaT, 2.0*deltaT_);
118 deltaT_ =
max(newDeltaT, 0.2*deltaT_);
123 functionObjects_.adjustTimeStep();
130 const word startFrom = controlDict_.lookupOrDefault<
word>
136 if (startFrom ==
"startTime")
138 controlDict_.lookup(
"startTime") >> startTime_;
145 if (startFrom ==
"firstTime")
151 startTime_ = timeDirs[1].value();
155 startTime_ = timeDirs[0].value();
159 else if (startFrom ==
"latestTime")
163 startTime_ = timeDirs.
last().value();
169 <<
"expected startTime, firstTime or latestTime" 170 <<
" found '" << startFrom <<
"'" 178 deltaTSave_ = deltaT_;
185 int oldPrecision = precision_;
186 int requiredPrecision = -1;
191 precision_ = maxPrecision_;
192 precision_ > oldPrecision;
200 if (newTime == oldTime)
211 requiredPrecision = precision_;
215 if (requiredPrecision > 0)
218 precision_ = requiredPrecision;
224 <<
"Increasing the timePrecision from " << oldPrecision
225 <<
" to " << precision_
226 <<
" to support the formatting of the current time directory " 232 precision_ = oldPrecision;
241 scalar sumStartTime = startTime_;
250 <<
"Start time is not the same for all processors" <<
nl 272 if (controlDict_.lookupOrDefault<
Switch>(
"adjustTimeStep",
false))
276 deltaTSave_ = deltaT_;
285 timeIndex_ = startTimeIndex_;
292 bool checkValue =
true;
294 string storedTimeName;
309 scalar storedTimeValue;
317 <<
"Time read from time dictionary " << storedTimeName
318 <<
" differs from actual time " <<
timeName() <<
'.' <<
nl 319 <<
" This may cause unexpected database behaviour." 320 <<
" If you are not interested" <<
nl 321 <<
" in preserving time state delete" 322 <<
" the time dictionary." 334 const word& controlDictName,
337 const word& systemName,
338 const word& constantName,
339 const bool enableFunctionObjects
372 writeControl_(wcTimeStep),
373 writeInterval_(GREAT),
377 sigWriteNow_(
true, *
this),
378 sigStopAtWriteNow_(
true, *
this),
384 runTimeModifiable_(
false),
386 functionObjects_(*
this, enableFunctionObjects)
388 libs_.open(controlDict_,
"libs");
397 if (runTimeModifiable_)
404 controlDict_.files().clear();
410 const word& controlDictName,
412 const word& systemName,
413 const word& constantName
448 writeControl_(wcTimeStep),
449 writeInterval_(GREAT),
453 sigWriteNow_(
true, *
this),
454 sigStopAtWriteNow_(
true, *
this),
460 runTimeModifiable_(
false),
470 libs_.open(controlDict_,
"libs");
479 if (runTimeModifiable_)
486 controlDict_.files().clear();
495 const word& systemName,
496 const word& constantName,
497 const bool enableFunctionObjects
531 writeControl_(wcTimeStep),
532 writeInterval_(GREAT),
536 sigWriteNow_(
true, *
this),
537 sigStopAtWriteNow_(
true, *
this),
543 runTimeModifiable_(
false),
545 functionObjects_(*
this, enableFunctionObjects)
547 libs_.open(controlDict_,
"libs");
560 if (runTimeModifiable_)
567 controlDict_.files().clear();
575 const word& systemName,
576 const word& constantName,
577 const bool enableFunctionObjects
610 writeControl_(wcTimeStep),
611 writeInterval_(GREAT),
620 runTimeModifiable_(
false),
622 functionObjects_(*
this, enableFunctionObjects)
624 libs_.open(controlDict_,
"libs");
638 functionObjects_.clear();
646 std::ostringstream buf;
647 buf.setf(ios_base::fmtflags(format_), ios_base::floatfield);
648 buf.precision(precision);
685 if (t.
equal(timeDirs[i].value()))
687 return timeDirs[i].name();
697 return findInstancePath(
path(), t);
706 if (timeDirs.
size() == 1)
711 if (t < timeDirs[1].value())
715 else if (t > timeDirs.
last().value())
717 return timeDirs.
last();
720 label nearestIndex = -1;
721 scalar deltaT = GREAT;
723 for (
label timei=1; timei < timeDirs.
size(); ++timei)
725 scalar
diff =
mag(timeDirs[timei].value() - t);
729 nearestIndex = timei;
733 return timeDirs[nearestIndex];
741 const word& constantName
744 label nearestIndex = -1;
745 scalar deltaT = GREAT;
749 if (timeDirs[timei].
name() == constantName)
continue;
751 scalar
diff =
mag(timeDirs[timei].value() - t);
755 nearestIndex = timei;
765 return startTimeIndex_;
783 bool running = value() < (endTime_ - 0.5*deltaT_);
787 if (!running && timeIndex_ != startTimeIndex_)
789 functionObjects_.execute();
790 functionObjects_.end();
800 if (timeIndex_ == startTimeIndex_)
802 functionObjects_.start();
806 functionObjects_.execute();
812 running = value() < (endTime_ - 0.5*deltaT_);
821 bool running = run();
834 return value() > (endTime_ + 0.5*deltaT_);
840 const bool changed = (stopAt_ != sa);
846 controlDict_.lookup(
"endTime") >> endTime_;
867 value() = inst.
value();
869 timeIndex_ = newIndex;
902 timeIndex_ = newIndex;
909 setEndTime(endTime.
value());
922 const bool bAdjustDeltaT
925 setDeltaT(deltaT.
value(), bAdjustDeltaT);
932 deltaTchanged_ =
true;
944 prevTimeState_.set(
new TimeState(*
this));
947 deltaT_ /= nSubCycles;
948 deltaT0_ /= nSubCycles;
949 deltaTSave_ = deltaT0_;
951 return prevTimeState();
960 TimeState::operator=(prevTimeState());
961 prevTimeState_.clear();
970 return operator+=(deltaT.
value());
983 deltaT0_ = deltaTSave_;
984 deltaTSave_ = deltaT_;
987 const scalar oldTimeValue = timeToUserTime(value());
991 setTime(value() + deltaT_, timeIndex_ + 1);
996 if (
mag(value()) < 10*SMALL*deltaT_)
1001 if (sigStopAtWriteNow_.active() || sigWriteNow_.active())
1007 if (sigStopAtWriteNow_.active() && stopAt_ == saWriteNow)
1011 if (sigWriteNow_.active() && writeOnce_)
1019 stopAt_ = saWriteNow;
1029 switch (writeControl_)
1032 writeTime_ = !(timeIndex_ %
label(writeInterval_));
1036 case wcAdjustableRunTime:
1040 ((value() - startTime_) + 0.5*deltaT_)
1044 if (writeIndex > writeTimeIndex_)
1047 writeTimeIndex_ = writeIndex;
1059 if (writeIndex > writeTimeIndex_)
1062 writeTimeIndex_ = writeIndex;
1074 if (writeIndex > writeTimeIndex_)
1077 writeTimeIndex_ = writeIndex;
1087 if (stopAt_ == saNoWriteNow)
1091 else if (stopAt_ == saWriteNow)
1096 else if (stopAt_ == saNextWrite && writeTime_ ==
true)
1113 const scalar timeTol =
1114 max(
min(
pow(10.0, -precision_), 0.1*deltaT_), SMALL);
1117 const scalar userDeltaT = timeToUserTime(deltaT_);
1120 scalar timeNameValue = -VGREAT;
1127 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1130 int oldPrecision = precision_;
1133 precision_ < maxPrecision_
1135 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1142 if (precision_ != oldPrecision)
1145 <<
"Increased the timePrecision from " << oldPrecision
1146 <<
" to " << precision_
1147 <<
" to distinguish between timeNames at time " 1151 if (precision_ == maxPrecision_)
1157 <<
" The maximum time precision has been reached" 1158 " which might result in overwriting previous" 1164 scalar oldTimeNameValue = -VGREAT;
1167 readScalar(oldTimeName.c_str(), oldTimeNameValue)
1169 sign(timeNameValue - oldTimeNameValue)
1176 <<
" is set to an instance prior to the " 1178 << oldTimeName <<
nl 1179 <<
" This might result in temporal " 1194 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.
#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)
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.
bool optionFound(const word &opt) const
Return true if the named option is found.
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.
#define forAllReverse(list, i)
Reverse loop across all elements in list.
runTimeSource setTime(sourceTimes[sourceTimeIndex], sourceTimeIndex)
virtual dimensionedScalar endTime() const
Return end time.
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 bool exists(const fileName &, const bool checkGzip=true, const bool followLink=true) const =0
Does the name exist (as DIRECTORY or FILE) in the file system?
virtual TimeState subCycle(const label nSubCycles)
Set time to sub-cycle for the given number of steps.
static const NamedEnum< stopAtControls, 4 > stopAtControlNames_
virtual void setDeltaT(const dimensionedScalar &, const bool adjustDeltaT=true)
Reset time step.
static int precision_
Time directory name precision.
A class for handling words, derived from string.
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.
const fileOperation & fileHandler()
Get current file handler.
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
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)
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
defineTypeNameAndDebug(combustionModel, 0)
scalar value() const
Value (const access)
const word & name() const
Return const reference to name.
static const NamedEnum< writeControls, 5 > writeControlNames_
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.
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?
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.
Constant dispersed-phase particle diameter model.
#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.
dimensioned< scalar > mag(const dimensioned< Type > &)
virtual void endSubCycle()
Reset time after sub-cycling back to previous TimeState.
fmtflags
Supported time directory name formats.
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.
stopAtControls
Stop-run control options.
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...
virtual bool stopAt(const stopAtControls) const
Adjust the current stopAtControl. Note that this value.
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.
bool exists(const fileName &, const bool checkGzip=true, const bool followLink=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
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.