85 const scalar timeToNextAction =
min
95 const scalar nSteps = timeToNextAction/deltaT_;
102 const label nStepsToNextWrite =
label(
max(nSteps, 1) + 0.99);
104 deltaT_ = timeToNextAction/nStepsToNextWrite;
112 const word startFrom = controlDict_.lookupOrDefault<
word>
118 if (startFrom ==
"startTime")
120 controlDict_.lookup(
"startTime") >> startTime_;
121 startTime_ = userTimeToTime(startTime_);
128 if (startFrom ==
"firstTime")
134 startTime_ = userTimeToTime(
timeDirs[1].value());
138 startTime_ = userTimeToTime(
timeDirs[0].value());
142 else if (startFrom ==
"latestTime")
152 <<
"expected startTime, firstTime or latestTime"
153 <<
" found '" << startFrom <<
"'"
160 deltaTSave_ = deltaT_;
167 int oldPrecision = curPrecision_;
168 int requiredPrecision = -1;
172 curPrecision_ = maxPrecision_;
173 curPrecision_ > oldPrecision;
183 requiredPrecision = curPrecision_;
187 if (requiredPrecision > 0)
190 curPrecision_ = requiredPrecision;
196 <<
"Increasing the timePrecision from " << oldPrecision
197 <<
" to " << curPrecision_
198 <<
" to support the formatting of the current time directory "
204 curPrecision_ = oldPrecision;
213 scalar sumStartTime = startTime_;
222 <<
"Start time is not the same for all processors" <<
nl
242 if (controlDict_.found(
"beginTime"))
244 beginTime_ = userTimeToTime(controlDict_.lookup<scalar>(
"beginTime"));
246 else if (timeDict.
found(
"beginTime"))
248 beginTime_ = userTimeToTime(timeDict.
lookup<scalar>(
"beginTime"));
252 beginTime_ = startTime_;
257 if (controlDict_.lookupOrDefault<
Switch>(
"adjustTimeStep",
false))
259 if (timeDict.
found(
"deltaT"))
261 deltaT_ = userTimeToTime(timeDict.
lookup<scalar>(
"deltaT"));
262 deltaTSave_ = deltaT_;
267 if (timeDict.
found(
"deltaT0"))
269 deltaT0_ = userTimeToTime(timeDict.
lookup<scalar>(
"deltaT0"));
274 timeIndex_ = startTimeIndex_;
281 writeControl_ == writeControl::runTime
282 || writeControl_ == writeControl::adjustableRunTime
286 writeTimeIndex_ =
label
288 ((value() - beginTime_) + 0.5*deltaT_)/writeInterval_
296 bool checkValue =
true;
298 string storedTimeName;
301 if (storedTimeName ==
name())
313 scalar storedTimeValue;
318 if (storedTimeName !=
name())
321 <<
"Time read from time dictionary " << storedTimeName
322 <<
" differs from actual time " <<
name() <<
'.' <<
nl
323 <<
" This may cause unexpected database behaviour."
324 <<
" If you are not interested" <<
nl
325 <<
" in preserving time state delete"
326 <<
" the time dictionary."
338 const word& controlDictName,
340 const bool enableFunctionObjects
345 args.parRunControl().parRun(),
347 args.globalCaseName(),
353 runTimeModifiable_(false),
370 beginTime_(startTime_),
376 writeInterval_(great),
386 writeVersion_(
IOstream::currentVersion),
387 writeCompression_(
IOstream::UNCOMPRESSED),
388 cacheTemporaryObjects_(true),
393 enableFunctionObjects
395 ?
args.optionFound(
"withFunctionObjects")
396 : !
args.optionFound(
"noFunctionObjects")
412 "OptimisationSwitches",
414 "DimensionedConstants",
421 if (controlDict_.
found(switchSets[i]))
425 <<
" in system/controlDict are only processed if "
441 const word& controlDictName,
444 const bool enableFunctionObjects
451 runTimeModifiable_(false),
468 beginTime_(startTime_),
474 writeInterval_(great),
484 writeVersion_(
IOstream::currentVersion),
485 writeCompression_(
IOstream::UNCOMPRESSED),
486 cacheTemporaryObjects_(true),
488 functionObjects_(*this, enableFunctionObjects)
508 const bool enableFunctionObjects
515 runTimeModifiable_(false),
533 beginTime_(startTime_),
539 writeInterval_(great),
549 writeVersion_(
IOstream::currentVersion),
550 writeCompression_(
IOstream::UNCOMPRESSED),
551 cacheTemporaryObjects_(true),
553 functionObjects_(*this, enableFunctionObjects)
572 const bool enableFunctionObjects
579 runTimeModifiable_(false),
596 beginTime_(startTime_),
602 writeInterval_(great),
609 writeVersion_(
IOstream::currentVersion),
610 writeCompression_(
IOstream::UNCOMPRESSED),
611 cacheTemporaryObjects_(true),
613 functionObjects_(*this, enableFunctionObjects)
624 functionObjects_.clear();
632 std::ostringstream buf;
633 buf.setf(ios_base::fmtflags(format_), ios_base::floatfield);
634 buf.precision(precision);
642 return findTimes(path(), constant());
651 const word& stopInstance
707 return findInstancePath(path(), t);
730 label nearestIndex = -1;
731 scalar deltaT = great;
739 nearestIndex = timei;
751 const word& constantName
754 label nearestIndex = -1;
755 scalar deltaT = great;
765 nearestIndex = timei;
775 return startTimeIndex_;
783 timeName(timeToUserTime(beginTime_)),
794 timeName(timeToUserTime(startTime_)),
820 return userTime_->timeToUserTime(value());
826 return userTime_->userTimeToTime(tau);
832 return userTime_->timeToUserTime(t);
838 if (
name() == constant())
844 return timeName(userTimeValue()) + userTime_->unit();
851 return value() < (endTime_ - 0.5*deltaT_);
857 bool running = this->running();
861 if (!running && timeIndex_ != startTimeIndex_)
863 functionObjects_.execute();
864 functionObjects_.end();
866 if (cacheTemporaryObjects_)
868 cacheTemporaryObjects_ = checkCacheTemporaryObjects();
879 if (timeIndex_ == startTimeIndex_)
881 functionObjects_.start();
885 functionObjects_.execute();
887 if (cacheTemporaryObjects_)
889 cacheTemporaryObjects_ = checkCacheTemporaryObjects();
895 running = this->running();
904 bool running = run();
917 return value() > (endTime_ + 0.5*deltaT_);
923 const bool changed = (stopAt_ != sa);
927 if (sa == stopAtControl::endTime)
929 controlDict_.lookup(
"endTime") >> endTime_;
943 timeIndex_ = t.timeIndex_;
950 value() = userTimeToTime(inst.
value());
952 timeIndex_ = newIndex;
968 if (timeDict.
found(
"deltaT"))
970 deltaT_ = userTimeToTime(timeDict.
lookup<scalar>(
"deltaT"));
973 if (timeDict.
found(
"deltaT0"))
975 deltaT0_ = userTimeToTime(timeDict.
lookup<scalar>(
"deltaT0"));
994 timeIndex_ = newIndex;
1001 setEndTime(endTime.
value());
1019 setDeltaTNoAdjust(deltaT);
1021 if (writeControl_ == writeControl::adjustableRunTime)
1031 deltaTchanged_ =
true;
1037 if (writeInterval_ == great || !
equal(writeInterval, writeInterval_))
1039 writeInterval_ = writeInterval;
1043 writeControl_ == writeControl::runTime
1044 || writeControl_ == writeControl::adjustableRunTime
1049 writeTimeIndex_ =
label
1051 ((value() - beginTime_) + 0.5*deltaT_)/writeInterval_
1054 else if (writeControl_ == writeControl::timeStep)
1057 writeInterval_ =
label(writeInterval + 0.5);
1066 prevTimeState_.set(
new TimeState(*
this));
1069 deltaT_ /= nSubCycles;
1070 deltaT0_ /= nSubCycles;
1071 deltaTSave_ = deltaT0_;
1073 return prevTimeState();
1081 subCycling_ =
false;
1082 TimeState::operator=(prevTimeState());
1083 prevTimeState_.clear();
1092 return operator+=(deltaT.
value());
1099 return operator++();
1105 deltaT0_ = deltaTSave_;
1106 deltaTSave_ = deltaT_;
1109 const scalar oldTimeValue = timeToUserTime(value());
1113 setTime(value() + deltaT_, timeIndex_ + 1);
1118 if (
mag(value()) < 10*small*deltaT_)
1123 if (sigStopAtWriteNow_.active() || sigWriteNow_.active())
1131 sigStopAtWriteNow_.active()
1132 && stopAt_ == stopAtControl::writeNow
1137 if (sigWriteNow_.active() && writeOnce_)
1145 stopAt_ = stopAtControl::writeNow;
1155 switch (writeControl_)
1157 case writeControl::timeStep:
1158 writeTime_ = !(timeIndex_ %
label(writeInterval_));
1161 case writeControl::runTime:
1162 case writeControl::adjustableRunTime:
1166 ((value() - beginTime_) + 0.5*deltaT_)
1170 if (writeIndex > writeTimeIndex_)
1173 writeTimeIndex_ = writeIndex;
1178 case writeControl::cpuTime:
1185 if (writeIndex > writeTimeIndex_)
1188 writeTimeIndex_ = writeIndex;
1193 case writeControl::clockTime:
1200 if (writeIndex > writeTimeIndex_)
1203 writeTimeIndex_ = writeIndex;
1213 if (stopAt_ == stopAtControl::noWriteNow)
1217 else if (stopAt_ == stopAtControl::writeNow)
1222 else if (stopAt_ == stopAtControl::nextWrite && writeTime_ ==
true)
1239 const scalar userDeltaT =
1240 timeToUserTime(value()) - timeToUserTime(value() - deltaT_);
1243 const scalar timeTol =
1244 max(
min(
pow(10.0, -precision_), 0.1*userDeltaT), small);
1247 scalar timeNameValue = -vGreat;
1254 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1257 int oldPrecision = curPrecision_;
1260 curPrecision_ < maxPrecision_
1262 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1269 if (curPrecision_ != oldPrecision)
1272 <<
"Increased the timePrecision from " << oldPrecision
1273 <<
" to " << curPrecision_
1274 <<
" to distinguish between timeNames at time "
1278 if (curPrecision_ == maxPrecision_)
1284 <<
" The maximum time precision has been reached"
1285 " which might result in overwriting previous"
1291 scalar oldTimeNameValue = -vGreat;
1294 readScalar(oldTimeName.c_str(), oldTimeNameValue)
1296 sign(timeNameValue - oldTimeNameValue)
1303 <<
" is set to an instance prior to the "
1305 << oldTimeName <<
nl
1306 <<
" This might result in temporal "
1321 return operator++();
#define forAll(list, i)
Loop across all elements in list.
#define forAllReverse(list, i)
Reverse loop across all elements in list.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
readOption
Enumeration defining the read options.
fileName & instance() const
Return the instance directory, constant, system, <time> etc.
readOption readOpt() const
An IOstream is an abstract base class for all input/output systems; be they streams,...
void size(const label)
Override size to be inconsistent with allocated storage.
Initialise the NamedEnum HashTable from the static list of names.
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
A class for addressing time paths without using the Time class.
The time value with time-stepping information, user-defined remapping, etc.
friend class Time
Declare friendship with the Time class.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
virtual bool run() const
Return true if run should continue,.
static int precision_
Time directory name precision.
scalar timeToUserTime(const scalar t) const
Convert the real-time (s) into user-time (e.g. CA deg)
static const NamedEnum< stopAtControl, 4 > stopAtControlNames_
instantList times() const
Search the case for valid time directories.
virtual void setTime(const Time &)
Reset the time and time-index to those of the given time.
virtual dimensionedScalar startTime() const
Return start time.
const word & timeName() const
Return current time name (for backwards-compatibility)
static int curPrecision_
Current time directory name precision adjusted as necessary.
void adjustDeltaT()
Adjust the time step so that writing occurs at the specified time.
format
Supported time directory name formats.
scalar userTimeToTime(const scalar tau) const
Convert the user-time (e.g. CA deg) to real-time (s).
virtual dimensionedScalar beginTime() const
Return begin time (initial start time)
static const NamedEnum< writeControl, 5 > writeControlNames_
scalar userTimeValue() const
Return current user time value.
static const int maxPrecision_
Maximum time directory name precision.
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".
virtual void setWriteInterval(const scalar writeInterval)
Reset the write interval.
virtual void setEndTime(const dimensionedScalar &)
Reset end time.
word userTimeName() const
Return current user time name with units.
virtual bool running() const
Return true if run should continue without any side effects.
void setControls()
Set the controls from the current controlDict.
word findInstancePath(const fileName &path, const instant &) const
Search the case for the time directory path.
virtual void setDeltaT(const dimensionedScalar &)
Reset time step.
static word controlDictName
The default control dictionary name (normally "controlDict")
stopAtControl
Stop-run control options.
static format format_
Time directory name format.
virtual bool stopAt(const stopAtControl) const
Adjust the current stopAtControl. Note that this value.
const userTimes::userTime & userTime() const
Return the userTime.
virtual label startTimeIndex() const
Return start time index.
virtual void endSubCycle()
Reset time after sub-cycling back to previous TimeState.
virtual void setDeltaTNoAdjust(const scalar)
Reset time step without additional adjustment or modification.
virtual Time & operator++()
Prefix increment,.
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.
writeControl
Write control options.
virtual bool loop()
Return true if run should continue and if so increment time.
virtual dimensionedScalar endTime() const
Return end time.
virtual ~Time()
Destructor.
static label findClosestTimeIndex(const instantList &, const scalar, const word &constantName="constant")
Search instantList for the time index closest to the given time.
virtual Time & operator+=(const dimensionedScalar &)
Set deltaT to that specified and increment time via operator++()
virtual bool end() const
Return true if end of run,.
instant findClosestTime(const scalar) const
Search the case for the time closest to the given time.
T & last()
Return the last element of the list.
static label nProcs(const label communicator=0)
Number of processes in parallel run.
static bool & parRun()
Is this a parallel run?
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Extract command arguments and options from the supplied argc and argv parameters.
const word & executable() const
Name of executable without the path.
const Foam::HashTable< string > & options() const
Return options.
fileName path() const
Return the path to the caseName.
A list of keyword definitions, which are a keyword followed by any number of values (e....
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
const scalar & value() const
Return const reference to value.
const word & name() const
Return const reference to name.
bool open(const fileName &libName, const bool verbose=true)
Open the named library, optionally with warnings if problems occur.
A class for handling file names.
virtual void setTime(const Time &) const
Callback for time change.
scalar timeToNextAction()
Return the time to the next write.
An instant of time. Contains the time value and name.
scalar value() const
Value (const access)
const word & name() const
Name (const access)
bool equal(const scalar) const
Comparison used for instants to be equal.
Registry of regIOobjects.
void addWatch()
Add file watch on object (if registered and READ_IF_MODIFIED)
timeIOdictionary derived from IOdictionary with globalFile set false to enable writing to processor t...
An abstract class for the user time description.
A class for handling words, derived from string.
static const word null
An empty word.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
static instantList timeDirs
runTimeSource setTime(sourceTimes[sourceTimeIndex], sourceTimeIndex)
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
#define WarningInFunction
Report a warning using Foam::Warning.
const fileOperation & fileHandler()
Get current file handler.
errorManipArg< error, int > exit(error &err, const int errNo=1)
dlLibraryTable libs
Table of loaded dynamic libraries.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
void adjustDeltaT(Time &runTime, const PtrList< solver > &solvers)
Adjust the time-step according to the solver maxDeltaT.
int system(const std::string &command)
Execute the specified command.
bool equal(const T &s1, const T &s2)
void setDeltaT(Time &runTime, const PtrList< solver > &solvers)
Set the initial time-step according to the solver maxDeltaT.
dimensionedScalar sign(const dimensionedScalar &ds)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool exists(const fileName &, const bool checkVariants=true, const bool followLink=true)
Does the name exist (as directory or file) in the file system?
dimensionedScalar log10(const dimensionedScalar &ds)
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
const dimensionSet dimTime
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
scalar diff(const triad &A, const triad &B)
Return a quantity of the difference between two triads.
dimensioned< scalar > mag(const dimensioned< Type > &)
defineTypeNameAndDebug(combustionModel, 0)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
static const label labelMax
word name(const complex &)
Return a string representation of a complex.
Foam::argList args(argc, argv)