Go to the documentation of this file.
85 bool adjustTime =
false;
86 scalar timeToNextWrite = VGREAT;
100 timeToNextWrite =
max
114 scalar nSteps = timeToNextWrite/
deltaT_ - SMALL;
121 scalar newDeltaT = timeToNextWrite/nStepsToNextWrite;
143 const word startFrom = controlDict_.lookupOrDefault<
word>
149 if (startFrom ==
"startTime")
151 controlDict_.lookup(
"startTime") >> startTime_;
158 if (startFrom ==
"firstTime")
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;
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))
808 else if (t >
timeDirs.last().value())
813 label nearestIndex = -1;
814 scalar deltaT = GREAT;
822 nearestIndex = timei;
844 const word& constantName
847 label nearestIndex = -1;
848 scalar deltaT = GREAT;
858 nearestIndex = timei;
868 return startTimeIndex_;
886 bool running = value() < (endTime_ - 0.5*deltaT_);
892 if (!running && timeIndex_ != startTimeIndex_)
896 functionObjects_.execute();
898 functionObjects_.end();
908 if (timeIndex_ == startTimeIndex_)
910 functionObjects_.start();
914 functionObjects_.execute();
920 running = value() < (endTime_ - 0.5*deltaT_);
929 bool running = run();
942 return value() > (endTime_ + 0.5*deltaT_);
948 const bool changed = (stopAt_ != sa);
954 controlDict_.lookup(
"endTime") >> endTime_;
974 value() = inst.
value();
976 timeIndex_ = newIndex;
1008 timeIndex_ = newIndex;
1014 setEndTime(endTime.
value());
1027 const bool bAdjustDeltaT
1030 setDeltaT(deltaT.
value(), bAdjustDeltaT);
1037 deltaTchanged_ =
true;
1049 prevTimeState_.set(
new TimeState(*
this));
1052 deltaT_ /= nSubCycles;
1053 deltaT0_ /= nSubCycles;
1054 deltaTSave_ = deltaT0_;
1056 return prevTimeState();
1064 subCycling_ =
false;
1065 TimeState::operator=(prevTimeState());
1066 prevTimeState_.clear();
1075 return operator+=(deltaT.
value());
1082 return operator++();
1088 deltaT0_ = deltaTSave_;
1089 deltaTSave_ = deltaT_;
1092 const scalar oldTimeValue = timeToUserTime(value());
1096 setTime(value() + deltaT_, timeIndex_ + 1);
1101 if (
mag(value()) < 10*SMALL*deltaT_)
1106 if (sigStopAtWriteNow_.active() || sigWriteNow_.active())
1112 if (sigStopAtWriteNow_.active() && stopAt_ == saWriteNow)
1116 if (sigWriteNow_.active() && writeOnce_)
1124 stopAt_ = saWriteNow;
1133 outputTime_ =
false;
1134 primaryOutputTime_ =
false;
1135 secondaryOutputTime_ =
false;
1137 switch (writeControl_)
1140 primaryOutputTime_ = !(timeIndex_ %
label(writeInterval_));
1144 case wcAdjustableRunTime:
1148 ((value() - startTime_) + 0.5*deltaT_)
1152 if (outputIndex > outputTimeIndex_)
1154 primaryOutputTime_ =
true;
1155 outputTimeIndex_ = outputIndex;
1167 if (outputIndex > outputTimeIndex_)
1169 primaryOutputTime_ =
true;
1170 outputTimeIndex_ = outputIndex;
1182 if (outputIndex > outputTimeIndex_)
1184 primaryOutputTime_ =
true;
1185 outputTimeIndex_ = outputIndex;
1193 switch (secondaryWriteControl_)
1196 secondaryOutputTime_ =
1197 !(timeIndex_ %
label(secondaryWriteInterval_));
1201 case wcAdjustableRunTime:
1205 ((value() - startTime_) + 0.5*deltaT_)
1206 / secondaryWriteInterval_
1209 if (outputIndex > secondaryOutputTimeIndex_)
1211 secondaryOutputTime_ =
true;
1212 secondaryOutputTimeIndex_ = outputIndex;
1222 / secondaryWriteInterval_
1224 if (outputIndex > secondaryOutputTimeIndex_)
1226 secondaryOutputTime_ =
true;
1227 secondaryOutputTimeIndex_ = outputIndex;
1237 / secondaryWriteInterval_
1239 if (outputIndex > secondaryOutputTimeIndex_)
1241 secondaryOutputTime_ =
true;
1242 secondaryOutputTimeIndex_ = outputIndex;
1249 outputTime_ = primaryOutputTime_ || secondaryOutputTime_;
1255 if (stopAt_ == saNoWriteNow)
1259 else if (stopAt_ == saWriteNow)
1263 primaryOutputTime_ =
true;
1265 else if (stopAt_ == saNextWrite && outputTime_ ==
true)
1274 primaryOutputTime_ =
true;
1283 const scalar timeTol =
1284 max(
min(
pow(10.0, -precision_), 0.1*deltaT_), SMALL);
1287 const scalar userDeltaT = timeToUserTime(deltaT_);
1290 scalar timeNameValue = -VGREAT;
1297 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1300 int oldPrecision = precision_;
1303 precision_ < maxPrecision_
1305 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1312 if (precision_ != oldPrecision)
1315 <<
"Increased the timePrecision from " << oldPrecision
1316 <<
" to " << precision_
1317 <<
" to distinguish between timeNames at time "
1321 if (precision_ == maxPrecision_)
1327 <<
" The maximum time precision has been reached"
1328 " which might result in overwriting previous"
1334 scalar oldTimeNameValue = -VGREAT;
1337 readScalar(oldTimeName.c_str(), oldTimeNameValue)
1339 sign(timeNameValue - oldTimeNameValue)
1346 <<
" is set to an instance prior to the "
1348 << oldTimeName <<
nl
1349 <<
" This might result in temporal "
1357 functionObjects_.timeSet();
1366 return operator++();
functionObjectList functionObjects_
Function objects executed at start and on ++, +=.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
writeControls
Write control options.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
static fmtflags format_
Time directory name format.
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
virtual bool adjustTimeStep()
Called at the end of Time::adjustDeltaT() if adjustTime is true.
virtual void setEndTime(const dimensionedScalar &)
Reset end time.
virtual bool end() const
Return true if end of run,.
A class for handling words, derived from string.
A class for handling file names.
bool exists(const fileName &, const bool checkGzip=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
word findInstancePath(const instant &) const
Search the case for the time directory path.
#define forAll(list, i)
Loop across all elements in list.
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
bool equal(const scalar) const
Comparison used for instants to be equal.
instantList times() const
Search the case for valid time directories.
static const label labelMax
static label nProcs(const label communicator=0)
Number of processes in parallel run.
static bool & parRun()
Is this a parallel run?
virtual Time & operator+=(const dimensionedScalar &)
Set deltaT to that specified and increment time via operator++()
const word & name() const
Return const reference to name.
Extract command arguments and options from the supplied argc and argv parameters.
fileState
Enumeration defining the file state.
static label findClosestTimeIndex(const instantList &, const scalar, const word &constantName="constant")
Search instantList for the time index closest to the given time.
Ostream & endl(Ostream &os)
Add newline and flush stream.
const Type & value() const
Return const reference to value.
fileMonitor::fileState getState(const label) const
Get current state of file (using handle)
label addWatch(const fileName &) const
Add watching of a file. Returns handle.
dimensioned< scalar > mag(const dimensioned< Type > &)
dimensionedScalar sign(const dimensionedScalar &ds)
static const versionNumber currentVersion
Current version number.
runTimeSource setTime(sourceTimes[sourceTimeIndex], sourceTimeIndex)
fmtflags
Supported time directory name formats.
static const int maxPrecision_
Maximum time directory name precision.
scalar secondaryWriteInterval_
const fileName & rootPath() const
Return root path.
const word & name() const
Name (const access)
Constant dispersed-phase particle diameter model.
const ParRunControl & parRunControl() const
Return parRunControl.
Registry of regIOobjects.
scalar diff(const triad &A, const triad &B)
Return a quantity of the difference between two triads.
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
virtual word timeName() const
Return current time name.
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
void adjustDeltaT()
Adjust the time step so that writing occurs at the specified time.
The time value with time-stepping information, user-defined remapping, etc.
void setUnmodified(const label) const
Set current state of file (using handle) to unmodified.
virtual ~Time()
Destructor.
virtual TimeState subCycle(const label nSubCycles)
Set time to sub-cycle for the given number of steps.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
dimensionedScalar log10(const dimensionedScalar &ds)
Checking for changes to files.
static const NamedEnum< stopAtControls, 4 > stopAtControlNames_
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
writeControls secondaryWriteControl_
static HashTable< string > validOptions
A list of valid options.
A list of keyword definitions, which are a keyword followed by any number of values (e....
virtual bool loop()
Return true if run should continue and if so increment time.
virtual void setTime(const Time &)
Reset the time and time-index to those of the given time.
virtual Time & operator++()
Prefix increment,.
Generic dimensioned Type class.
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
label secondaryOutputTimeIndex_
static int precision_
Time directory name precision.
A class for addressing time paths without using the Time class.
virtual bool stopAt(const stopAtControls) const
Adjust the current stopAtControl. Note that this value.
errorManipArg< error, int > exit(error &err, const int errNo=1)
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
static fileCheckTypes fileModificationChecking
scalar value() const
Value (const access)
static instantList timeDirs
void readModifiedObjects()
Read the objects that have been modified.
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
instant findClosestTime(const scalar) const
Search the case for the time closest to the given time.
bool removeWatch(const label) const
Remove watch on a file (using handle)
static const NamedEnum< writeControls, 5 > writeControlNames_
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
static const word null
An empty word.
bool optionFound(const word &opt) const
Return true if the named option is found.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
const fileName & caseName() const
Return case name (parallel run) or global case (serial run)
stopAtControls
Stop-run control options.
virtual dimensionedScalar endTime() const
Return end time.
An instant of time. Contains the time value and name.
void size(const label)
Override size to be inconsistent with allocated storage.
virtual void endSubCycle()
Reset time after sub-cycling back to previous TimeState.
void setControls()
Set the controls from the current controlDict.
fileNameList readDir(const fileName &, const fileName::Type=fileName::FILE, const bool filtergz=true)
Read a directory and return the entries as a string list.
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
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.
Foam::argList args(argc, argv)
static word controlDictName
The default control dictionary name (normally "controlDict")
writeControls writeControl_
virtual bool run() const
Return true if run should continue,.
defineTypeNameAndDebug(combustionModel, 0)
virtual dimensionedScalar startTime() const
Return start time.
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
#define WarningInFunction
Report a warning using Foam::Warning.
int system(const std::string &command)
Execute the specified command.
const fileName & globalCaseName() const
Return case name.
virtual label startTimeIndex() const
Return start time index.
word name(const complex &)
Return a string representation of a complex.
Initialise the NamedEnum HashTable from the static list of names.
virtual void setDeltaT(const dimensionedScalar &, const bool adjustDeltaT=true)
Reset time step.
const fileName & getFile(const label) const
Get name of file being watched (using handle)