85 bool adjustTime =
false;
86 scalar timeToNextWrite = VGREAT;
88 if (writeControl_ == wcAdjustableRunTime)
94 (writeTimeIndex_ + 1)*writeInterval_ - (value() - startTime_)
100 scalar nSteps = timeToNextWrite/deltaT_ - SMALL;
107 scalar newDeltaT = timeToNextWrite/nStepsToNextWrite;
111 if (newDeltaT >= deltaT_)
113 deltaT_ =
min(newDeltaT, 2.0*deltaT_);
117 deltaT_ =
max(newDeltaT, 0.2*deltaT_);
122 functionObjects_.adjustTimeStep();
129 const word startFrom = controlDict_.lookupOrDefault<
word>
135 if (startFrom ==
"startTime")
137 controlDict_.lookup(
"startTime") >> startTime_;
144 if (startFrom ==
"firstTime")
150 startTime_ = timeDirs[1].value();
154 startTime_ = timeDirs[0].value();
158 else if (startFrom ==
"latestTime")
162 startTime_ = timeDirs.
last().value();
168 <<
"expected startTime, firstTime or latestTime" 169 <<
" found '" << startFrom <<
"'" 177 deltaTSave_ = deltaT_;
182 if (!
exists(timePath(),
false))
184 int oldPrecision = precision_;
185 int requiredPrecision = -1;
189 precision_ = maxPrecision_;
190 precision_ > oldPrecision;
198 found =
exists(timePath(),
false);
202 requiredPrecision = precision_;
206 if (requiredPrecision > 0)
209 precision_ = requiredPrecision;
215 <<
"Increasing the timePrecision from " << oldPrecision
216 <<
" to " << precision_
217 <<
" to support the formatting of the current time directory " 223 precision_ = oldPrecision;
232 scalar sumStartTime = startTime_;
241 <<
"Start time is not the same for all processors" <<
nl 263 if (controlDict_.lookupOrDefault<
Switch>(
"adjustTimeStep",
false))
267 deltaTSave_ = deltaT_;
276 timeIndex_ = startTimeIndex_;
283 bool checkValue =
true;
285 string storedTimeName;
300 scalar storedTimeValue;
308 <<
"Time read from time dictionary " << storedTimeName
309 <<
" differs from actual time " <<
timeName() <<
'.' <<
nl 310 <<
" This may cause unexpected database behaviour." 311 <<
" If you are not interested" <<
nl 312 <<
" in preserving time state delete" 313 <<
" the time dictionary." 325 const word& controlDictName,
328 const word& systemName,
329 const word& constantName,
330 const bool enableFunctionObjects
363 writeControl_(wcTimeStep),
364 writeInterval_(GREAT),
368 sigWriteNow_(
true, *
this),
369 sigStopAtWriteNow_(
true, *
this),
375 runTimeModifiable_(
false),
377 functionObjects_(*
this, enableFunctionObjects)
379 libs_.open(controlDict_,
"libs");
388 if (runTimeModifiable_)
407 f = controlDict_.objectPath();
410 controlDict_.watchIndex() = addWatch(
f);
417 const word& controlDictName,
419 const word& systemName,
420 const word& constantName
455 writeControl_(wcTimeStep),
456 writeInterval_(GREAT),
460 sigWriteNow_(
true, *
this),
461 sigStopAtWriteNow_(
true, *
this),
467 runTimeModifiable_(
false),
477 libs_.open(controlDict_,
"libs");
486 if (runTimeModifiable_)
505 f = controlDict_.objectPath();
508 controlDict_.watchIndex() = addWatch(
f);
518 const word& systemName,
519 const word& constantName,
520 const bool enableFunctionObjects
554 writeControl_(wcTimeStep),
555 writeInterval_(GREAT),
559 sigWriteNow_(
true, *
this),
560 sigStopAtWriteNow_(
true, *
this),
566 runTimeModifiable_(
false),
568 functionObjects_(*
this, enableFunctionObjects)
570 libs_.open(controlDict_,
"libs");
583 if (runTimeModifiable_)
602 f = controlDict_.objectPath();
605 controlDict_.watchIndex() = addWatch(
f);
614 const word& systemName,
615 const word& constantName,
616 const bool enableFunctionObjects
649 writeControl_(wcTimeStep),
650 writeInterval_(GREAT),
659 runTimeModifiable_(
false),
661 functionObjects_(*
this, enableFunctionObjects)
663 libs_.open(controlDict_,
"libs");
671 if (controlDict_.watchIndex() != -1)
673 removeWatch(controlDict_.watchIndex());
677 functionObjects_.clear();
685 return monitorPtr_().addWatch(fName);
691 return monitorPtr_().removeWatch(watchIndex);
696 return monitorPtr_().getFile(watchIndex);
705 return monitorPtr_().getState(watchFd);
711 monitorPtr_().setUnmodified(watchFd);
717 std::ostringstream buf;
718 buf.setf(ios_base::fmtflags(format_), ios_base::floatfield);
719 buf.precision(precision);
748 if (
readScalar(dirEntries[i].c_str(), timeValue) && t.
equal(timeValue))
750 return dirEntries[i];
757 if (
isDir(directory/constantName))
772 if (timeDirs.
size() == 1)
777 if (t < timeDirs[1].value())
781 else if (t > timeDirs.
last().value())
783 return timeDirs.
last();
786 label nearestIndex = -1;
787 scalar deltaT = GREAT;
789 for (
label timei=1; timei < timeDirs.
size(); ++timei)
791 scalar
diff =
mag(timeDirs[timei].value() - t);
795 nearestIndex = timei;
799 return timeDirs[nearestIndex];
807 const word& constantName
810 label nearestIndex = -1;
811 scalar deltaT = GREAT;
815 if (timeDirs[timei].
name() == constantName)
continue;
817 scalar
diff =
mag(timeDirs[timei].value() - t);
821 nearestIndex = timei;
831 return startTimeIndex_;
849 bool running = value() < (endTime_ - 0.5*deltaT_);
855 if (!running && timeIndex_ != startTimeIndex_)
858 functionObjects_.end();
868 if (timeIndex_ == startTimeIndex_)
870 functionObjects_.start();
874 functionObjects_.execute();
880 running = value() < (endTime_ - 0.5*deltaT_);
889 bool running = run();
902 return value() > (endTime_ + 0.5*deltaT_);
908 const bool changed = (stopAt_ != sa);
914 controlDict_.lookup(
"endTime") >> endTime_;
934 value() = inst.
value();
936 timeIndex_ = newIndex;
968 timeIndex_ = newIndex;
974 setEndTime(endTime.
value());
987 const bool bAdjustDeltaT
990 setDeltaT(deltaT.
value(), bAdjustDeltaT);
997 deltaTchanged_ =
true;
1009 prevTimeState_.set(
new TimeState(*
this));
1012 deltaT_ /= nSubCycles;
1013 deltaT0_ /= nSubCycles;
1014 deltaTSave_ = deltaT0_;
1016 return prevTimeState();
1024 subCycling_ =
false;
1025 TimeState::operator=(prevTimeState());
1026 prevTimeState_.clear();
1035 return operator+=(deltaT.
value());
1042 return operator++();
1048 deltaT0_ = deltaTSave_;
1049 deltaTSave_ = deltaT_;
1052 const scalar oldTimeValue = timeToUserTime(value());
1056 setTime(value() + deltaT_, timeIndex_ + 1);
1061 if (
mag(value()) < 10*SMALL*deltaT_)
1066 if (sigStopAtWriteNow_.active() || sigWriteNow_.active())
1072 if (sigStopAtWriteNow_.active() && stopAt_ == saWriteNow)
1076 if (sigWriteNow_.active() && writeOnce_)
1084 stopAt_ = saWriteNow;
1094 switch (writeControl_)
1097 writeTime_ = !(timeIndex_ %
label(writeInterval_));
1101 case wcAdjustableRunTime:
1105 ((value() - startTime_) + 0.5*deltaT_)
1109 if (writeIndex > writeTimeIndex_)
1112 writeTimeIndex_ = writeIndex;
1124 if (writeIndex > writeTimeIndex_)
1127 writeTimeIndex_ = writeIndex;
1139 if (writeIndex > writeTimeIndex_)
1142 writeTimeIndex_ = writeIndex;
1152 if (stopAt_ == saNoWriteNow)
1156 else if (stopAt_ == saWriteNow)
1161 else if (stopAt_ == saNextWrite && writeTime_ ==
true)
1178 const scalar timeTol =
1179 max(
min(
pow(10.0, -precision_), 0.1*deltaT_), SMALL);
1182 const scalar userDeltaT = timeToUserTime(deltaT_);
1185 scalar timeNameValue = -VGREAT;
1192 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1195 int oldPrecision = precision_;
1198 precision_ < maxPrecision_
1200 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1207 if (precision_ != oldPrecision)
1210 <<
"Increased the timePrecision from " << oldPrecision
1211 <<
" to " << precision_
1212 <<
" to distinguish between timeNames at time " 1216 if (precision_ == maxPrecision_)
1222 <<
" The maximum time precision has been reached" 1223 " which might result in overwriting previous" 1229 scalar oldTimeNameValue = -VGREAT;
1232 readScalar(oldTimeName.c_str(), oldTimeNameValue)
1234 sign(timeNameValue - oldTimeNameValue)
1241 <<
" is set to an instance prior to the " 1243 << oldTimeName <<
nl 1244 <<
" This might result in temporal " 1259 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.
void adjustDeltaT()
Adjust the time step so that writing occurs at the specified time.
virtual bool end() const
Return true if end of run,.
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 > &)
Checking for changes to files.
virtual word timeName() const
Return current time name.
virtual ~Time()
Destructor.
fileMonitor::fileState getState(const label) const
Get current state of file (using handle)
fileState
Enumeration defining the file state.
void size(const label)
Override size to be inconsistent with allocated storage.
instant findClosestTime(const scalar) const
Search the case for the time closest to the given time.
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.
scalar value() const
Value (const access)
static fmtflags format_
Time directory name format.
Ostream & endl(Ostream &os)
Add newline and flush stream.
virtual dimensionedScalar startTime() const
Return start time.
const ParRunControl & parRunControl() const
Return parRunControl.
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.
runTimeSource setTime(sourceTimes[sourceTimeIndex], sourceTimeIndex)
const Type & value() const
Return const reference to value.
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
const fileName & rootPath() const
Return root path.
Initialise the NamedEnum HashTable from the static list of names.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
bool removeWatch(const label) const
Remove watch on a file (using handle)
static const int maxPrecision_
Maximum time directory name precision.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
static fileCheckTypes fileModificationChecking
const fileName & caseName() const
Return case name (parallel run) or global case (serial run)
const word & name() const
Return const reference to name.
word findInstancePath(const instant &) const
Search the case for the time directory path.
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.
bool optionFound(const word &opt) const
Return true if the named option is found.
static int precision_
Time directory name precision.
A class for handling words, derived from string.
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
Extract command arguments and options from the supplied argc and argv parameters. ...
bool equal(const scalar) const
Comparison used for instants to be equal.
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.
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
const fileName & globalCaseName() const
Return case name.
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")
virtual bool run() const
Return true if run should continue,.
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
defineTypeNameAndDebug(combustionModel, 0)
const word & name() const
Name (const access)
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.
bool exists(const fileName &, const bool checkGzip=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
#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.
const fileName & getFile(const label) const
Get name of file being watched (using handle)
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
virtual dimensionedScalar endTime() const
Return end time.
instantList times() const
Search the case for valid time directories.
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.
virtual label startTimeIndex() const
Return start time index.
virtual bool stopAt(const stopAtControls) const
Adjust the current stopAtControl. Note that this value.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
void setUnmodified(const label) const
Set current state of file (using handle) to unmodified.
fileNameList readDir(const fileName &, const fileName::Type=fileName::FILE, const bool filtergz=true)
Read a directory and return the entries as a string list.
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++()
label addWatch(const fileName &) const
Add watching of a file. Returns 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.