85 bool adjustTime =
false;
86 scalar timeToNextWrite = VGREAT;
88 if (writeControl_ == wcAdjustableRunTime)
94 (outputTimeIndex_ + 1)*writeInterval_ - (value() - startTime_)
97 if (secondaryWriteControl_ == wcAdjustableRunTime)
100 timeToNextWrite =
max 106 (secondaryOutputTimeIndex_ + 1)*secondaryWriteInterval_
107 - (value() - startTime_)
114 scalar nSteps = timeToNextWrite/deltaT_ - SMALL;
121 scalar newDeltaT = timeToNextWrite/nStepsToNextWrite;
125 if (newDeltaT >= deltaT_)
127 deltaT_ =
min(newDeltaT, 2.0*deltaT_);
131 deltaT_ =
max(newDeltaT, 0.2*deltaT_);
136 functionObjects_.adjustTimeStep();
143 const word startFrom = controlDict_.lookupOrDefault<
word>
149 if (startFrom ==
"startTime")
151 controlDict_.lookup(
"startTime") >> startTime_;
158 if (startFrom ==
"firstTime")
164 startTime_ = timeDirs[1].value();
168 startTime_ = timeDirs[0].value();
172 else if (startFrom ==
"latestTime")
176 startTime_ = timeDirs.
last().value();
182 <<
"expected startTime, firstTime or latestTime" 183 <<
" found '" << startFrom <<
"'" 191 deltaTSave_ = deltaT_;
196 if (!
exists(timePath(),
false))
198 int oldPrecision = precision_;
199 int requiredPrecision = -1;
203 precision_ = maxPrecision_;
204 precision_ > oldPrecision;
212 found =
exists(timePath(),
false);
216 requiredPrecision = precision_;
220 if (requiredPrecision > 0)
223 precision_ = requiredPrecision;
229 <<
"Increasing the timePrecision from " << oldPrecision
230 <<
" to " << precision_
231 <<
" to support the formatting of the current time directory " 237 precision_ = oldPrecision;
246 scalar sumStartTime = startTime_;
255 <<
"Start time is not the same for all processors" <<
nl 277 if (controlDict_.lookupOrDefault<
Switch>(
"adjustTimeStep",
false))
281 deltaTSave_ = deltaT_;
290 timeIndex_ = startTimeIndex_;
297 bool checkValue =
true;
299 string storedTimeName;
314 scalar storedTimeValue;
322 <<
"Time read from time dictionary " << storedTimeName
323 <<
" differs from actual time " <<
timeName() <<
'.' <<
nl 324 <<
" This may cause unexpected database behaviour." 325 <<
" If you are not interested" <<
nl 326 <<
" in preserving time state delete" 327 <<
" the time dictionary." 339 const word& controlDictName,
342 const word& systemName,
343 const word& constantName,
344 const bool enableFunctionObjects
377 writeControl_(wcTimeStep),
378 writeInterval_(GREAT),
379 secondaryWriteControl_(wcTimeStep),
380 secondaryWriteInterval_(
labelMax/10.0),
382 secondaryPurgeWrite_(0),
385 sigWriteNow_(
true, *
this),
386 sigStopAtWriteNow_(
true, *
this),
392 runTimeModifiable_(
false),
394 functionObjects_(*
this, enableFunctionObjects)
396 libs_.open(controlDict_,
"libs");
405 if (runTimeModifiable_)
424 f = controlDict_.objectPath();
427 controlDict_.watchIndex() = addWatch(
f);
434 const word& controlDictName,
436 const word& systemName,
437 const word& constantName
472 writeControl_(wcTimeStep),
473 writeInterval_(GREAT),
474 secondaryWriteControl_(wcTimeStep),
475 secondaryWriteInterval_(
labelMax/10.0),
477 secondaryPurgeWrite_(0),
480 sigWriteNow_(
true, *
this),
481 sigStopAtWriteNow_(
true, *
this),
487 runTimeModifiable_(
false),
497 libs_.open(controlDict_,
"libs");
506 if (runTimeModifiable_)
525 f = controlDict_.objectPath();
528 controlDict_.watchIndex() = addWatch(
f);
538 const word& systemName,
539 const word& constantName,
540 const bool enableFunctionObjects
574 writeControl_(wcTimeStep),
575 writeInterval_(GREAT),
576 secondaryWriteControl_(wcTimeStep),
577 secondaryWriteInterval_(
labelMax/10.0),
579 secondaryPurgeWrite_(0),
582 sigWriteNow_(
true, *
this),
583 sigStopAtWriteNow_(
true, *
this),
589 runTimeModifiable_(
false),
591 functionObjects_(*
this, enableFunctionObjects)
593 libs_.open(controlDict_,
"libs");
606 if (runTimeModifiable_)
625 f = controlDict_.objectPath();
628 controlDict_.watchIndex() = addWatch(
f);
637 const word& systemName,
638 const word& constantName,
639 const bool enableFunctionObjects
672 writeControl_(wcTimeStep),
673 writeInterval_(GREAT),
674 secondaryWriteControl_(wcTimeStep),
675 secondaryWriteInterval_(
labelMax/10.0),
677 secondaryPurgeWrite_(0),
685 runTimeModifiable_(
false),
687 functionObjects_(*
this, enableFunctionObjects)
689 libs_.open(controlDict_,
"libs");
697 if (controlDict_.watchIndex() != -1)
699 removeWatch(controlDict_.watchIndex());
703 functionObjects_.clear();
711 return monitorPtr_().addWatch(fName);
717 return monitorPtr_().removeWatch(watchIndex);
722 return monitorPtr_().getFile(watchIndex);
731 return monitorPtr_().getState(watchFd);
737 monitorPtr_().setUnmodified(watchFd);
743 std::ostringstream buf;
744 buf.setf(ios_base::fmtflags(format_), ios_base::floatfield);
745 buf.precision(precision);
775 if (
readScalar(dirEntries[i].c_str(), timeValue) && t.
equal(timeValue))
777 return dirEntries[i];
784 if (
isDir(directory/constantName))
799 if (timeDirs.
size() == 1)
804 if (t < timeDirs[1].value())
808 else if (t > timeDirs.
last().value())
810 return timeDirs.
last();
813 label nearestIndex = -1;
814 scalar deltaT = GREAT;
816 for (
label timei=1; timei < timeDirs.
size(); ++timei)
818 scalar
diff =
mag(timeDirs[timei].value() - t);
822 nearestIndex = timei;
826 return timeDirs[nearestIndex];
844 const word& constantName
847 label nearestIndex = -1;
848 scalar deltaT = GREAT;
852 if (timeDirs[timei].
name() == constantName)
continue;
854 scalar
diff =
mag(timeDirs[timei].value() - t);
858 nearestIndex = timei;
868 return startTimeIndex_;
886 bool running = value() < (endTime_ - 0.5*deltaT_);
892 if (!running && timeIndex_ != startTimeIndex_)
895 functionObjects_.end();
905 if (timeIndex_ == startTimeIndex_)
907 functionObjects_.start();
911 functionObjects_.execute();
917 running = value() < (endTime_ - 0.5*deltaT_);
926 bool running = run();
939 return value() > (endTime_ + 0.5*deltaT_);
945 const bool changed = (stopAt_ != sa);
951 controlDict_.lookup(
"endTime") >> endTime_;
971 value() = inst.
value();
973 timeIndex_ = newIndex;
1005 timeIndex_ = newIndex;
1011 setEndTime(endTime.
value());
1024 const bool bAdjustDeltaT
1027 setDeltaT(deltaT.
value(), bAdjustDeltaT);
1034 deltaTchanged_ =
true;
1046 prevTimeState_.set(
new TimeState(*
this));
1049 deltaT_ /= nSubCycles;
1050 deltaT0_ /= nSubCycles;
1051 deltaTSave_ = deltaT0_;
1053 return prevTimeState();
1061 subCycling_ =
false;
1062 TimeState::operator=(prevTimeState());
1063 prevTimeState_.clear();
1072 return operator+=(deltaT.
value());
1079 return operator++();
1085 deltaT0_ = deltaTSave_;
1086 deltaTSave_ = deltaT_;
1089 const scalar oldTimeValue = timeToUserTime(value());
1093 setTime(value() + deltaT_, timeIndex_ + 1);
1098 if (
mag(value()) < 10*SMALL*deltaT_)
1103 if (sigStopAtWriteNow_.active() || sigWriteNow_.active())
1109 if (sigStopAtWriteNow_.active() && stopAt_ == saWriteNow)
1113 if (sigWriteNow_.active() && writeOnce_)
1121 stopAt_ = saWriteNow;
1130 outputTime_ =
false;
1131 primaryOutputTime_ =
false;
1132 secondaryOutputTime_ =
false;
1134 switch (writeControl_)
1137 primaryOutputTime_ = !(timeIndex_ %
label(writeInterval_));
1141 case wcAdjustableRunTime:
1145 ((value() - startTime_) + 0.5*deltaT_)
1149 if (outputIndex > outputTimeIndex_)
1151 primaryOutputTime_ =
true;
1152 outputTimeIndex_ = outputIndex;
1164 if (outputIndex > outputTimeIndex_)
1166 primaryOutputTime_ =
true;
1167 outputTimeIndex_ = outputIndex;
1179 if (outputIndex > outputTimeIndex_)
1181 primaryOutputTime_ =
true;
1182 outputTimeIndex_ = outputIndex;
1190 switch (secondaryWriteControl_)
1193 secondaryOutputTime_ =
1194 !(timeIndex_ %
label(secondaryWriteInterval_));
1198 case wcAdjustableRunTime:
1202 ((value() - startTime_) + 0.5*deltaT_)
1203 / secondaryWriteInterval_
1206 if (outputIndex > secondaryOutputTimeIndex_)
1208 secondaryOutputTime_ =
true;
1209 secondaryOutputTimeIndex_ = outputIndex;
1219 / secondaryWriteInterval_
1221 if (outputIndex > secondaryOutputTimeIndex_)
1223 secondaryOutputTime_ =
true;
1224 secondaryOutputTimeIndex_ = outputIndex;
1234 / secondaryWriteInterval_
1236 if (outputIndex > secondaryOutputTimeIndex_)
1238 secondaryOutputTime_ =
true;
1239 secondaryOutputTimeIndex_ = outputIndex;
1246 outputTime_ = primaryOutputTime_ || secondaryOutputTime_;
1252 if (stopAt_ == saNoWriteNow)
1256 else if (stopAt_ == saWriteNow)
1260 primaryOutputTime_ =
true;
1262 else if (stopAt_ == saNextWrite && outputTime_ ==
true)
1271 primaryOutputTime_ =
true;
1280 const scalar timeTol =
1281 max(
min(
pow(10.0, -precision_), 0.1*deltaT_), SMALL);
1284 const scalar userDeltaT = timeToUserTime(deltaT_);
1287 scalar timeNameValue = -VGREAT;
1294 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1297 int oldPrecision = precision_;
1300 precision_ < maxPrecision_
1302 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1309 if (precision_ != oldPrecision)
1312 <<
"Increased the timePrecision from " << oldPrecision
1313 <<
" to " << precision_
1314 <<
" to distinguish between timeNames at time " 1318 if (precision_ == maxPrecision_)
1324 <<
" The maximum time precision has been reached" 1325 " which might result in overwriting previous" 1331 scalar oldTimeNameValue = -VGREAT;
1334 readScalar(oldTimeName.c_str(), oldTimeNameValue)
1336 sign(timeNameValue - oldTimeNameValue)
1343 <<
" is set to an instance prior to the " 1345 << oldTimeName <<
nl 1346 <<
" This might result in temporal " 1354 functionObjects_.timeSet();
1363 return operator++();
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
static bool & parRun()
Is this a parallel run?
static HashTable< string > validOptions
A list of valid options.
const ParRunControl & parRunControl() const
Return parRunControl.
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.
const fileName & rootPath() const
Return root path.
void readModifiedObjects()
Read the objects that have been modified.
virtual TimeState subCycle(const label nSubCycles)
Set time to sub-cycle for the given number of steps.
virtual bool end() const
Return true if end of run,.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
instant findClosestTime(const scalar) const
Search the case for the time closest to the given time.
dimensioned< scalar > mag(const dimensioned< Type > &)
word name(const complex &)
Return a string representation of a complex.
scalar diff(const triad &A, const triad &B)
Return a quantity of the difference between two triads.
static int precision_
Time directory name precision.
static const NamedEnum< stopAtControls, 4 > stopAtControlNames_
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
T & last()
Return the last element of the list.
static fmtflags format_
Time directory name format.
static const int maxPrecision_
Maximum time directory name precision.
stopAtControls
Stop-run control options.
A class for handling words, derived from string.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
void size(const label)
Override size to be inconsistent with allocated storage.
errorManipArg< error, int > exit(error &err, const int errNo=1)
dimensionedScalar log10(const dimensionedScalar &ds)
bool exists(const fileName &, const bool checkGzip=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
dimensionedScalar sign(const dimensionedScalar &ds)
The time value with time-stepping information, user-defined remapping, etc.
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.
static const NamedEnum< writeControls, 5 > writeControlNames_
A list of keyword definitions, which are a keyword followed by any number of values (e...
virtual dimensionedScalar startTime() const
Return start time.
void setUnmodified(const label) const
Set current state of file (using handle) to unmodified.
#define IOWarningIn(functionName, ios)
Report an IO warning using Foam::Warning.
fmtflags
Supported time directory name formats.
virtual ~Time()
Destructor.
fileState
Enumeration defining the file state.
virtual void setEndTime(const dimensionedScalar &)
Reset end time.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
static label nProcs(const label communicator=0)
Number of processes in parallel run.
label addWatch(const fileName &) const
Add watching of a file. Returns handle.
Ostream & endl(Ostream &os)
Add newline and flush stream.
const fileName & getFile(const label) const
Get name of file being watched (using handle)
fileNameList readDir(const fileName &, const fileName::Type=fileName::FILE, const bool filtergz=true)
Read a directory and return the entries as a string list.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
#define WarningIn(functionName)
Report a warning using Foam::Warning.
scalar value() const
Value (const access)
const word & name() const
Return const reference to name.
word findInstancePath(const instant &) const
Search the case for the time directory path.
bool equal(const scalar) const
Comparison used for instants to be equal.
static label findClosestTimeIndex(const instantList &, const scalar, const word &constantName="constant")
Search instantList for the time index closest to the given time.
A class for addressing time paths without using the Time class.
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
virtual bool run() const
Return true if run should continue,.
bool optionFound(const word &opt) const
Return true if the named option is found.
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
static word controlDictName
The default control dictionary name (normally "controlDict")
runTimeSource setTime(sourceTimes[sourceTimeIndex], sourceTimeIndex)
An instant of time. Contains the time value and name.
Extract command arguments and options from the supplied argc and argv parameters. ...
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
const fileName & caseName() const
Return case name (parallel run) or global case (serial run)
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
Initialise the NamedEnum HashTable from the static list of names.
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
virtual label startTimeIndex() const
Return start time index.
virtual Time & operator++()
Prefix increment,.
virtual dimensionedScalar endTime() const
Return end time.
int system(const std::string &command)
Execute the specified command.
Constant dispersed-phase particle diameter model.
Registry of regIOobjects.
virtual Time & operator+=(const dimensionedScalar &)
Set deltaT to that specified and increment time via operator++()
A class for handling file names.
writeControls
Write control options.
virtual bool loop()
Return true if run should continue and if so increment time.
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
Checking for changes to files.
static fileCheckTypes fileModificationChecking
fileMonitor::fileState getState(const label) const
Get current state of file (using handle)
void setControls()
Set the controls from the current controlDict.
instantList times() const
Search the case for valid time directories.
virtual void setDeltaT(const dimensionedScalar &, const bool adjustDeltaT=true)
Reset time step.
void adjustDeltaT()
Adjust the time step so that writing occurs at the specified time.
const word & name() const
Name (const access)
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
virtual void setTime(const Time &)
Reset the time and time-index to those of the given time.
const fileName & globalCaseName() const
Return case name.
#define FatalIOErrorIn(functionName, ios)
Report an error message using Foam::FatalIOError.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
static const versionNumber currentVersion
Current version number.
virtual bool stopAt(const stopAtControls) const
Adjust the current stopAtControl. Note that this value.
virtual void endSubCycle()
Reset time after sub-cycling back to previous TimeState.
static const word null
An empty word.
const Type & value() const
Return const reference to value.
defineTypeNameAndDebug(combustionModel, 0)
bool removeWatch(const label) const
Remove watch on a file (using handle)
static const label labelMax
virtual word timeName() const
Return current time name.