86 const scalar timeToNextAction =
min
96 const scalar nSteps = timeToNextAction/deltaT_;
103 const label nStepsToNextWrite =
label(
max(nSteps, 1) + 0.99);
105 deltaT_ = timeToNextAction/nStepsToNextWrite;
113 const word startFrom = controlDict_.lookupOrDefault<
word>
119 if (startFrom ==
"startTime")
121 startTime_ = controlDict_.lookup<scalar>(
"startTime", userUnits());
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_ = controlDict_.lookup<scalar>(
"beginTime", userUnits());
246 else if (timeDict.
found(
"beginTime"))
248 beginTime_ = timeDict.
lookup<scalar>(
"beginTime", userUnits());
252 beginTime_ = startTime_;
257 if (controlDict_.lookupOrDefault<
Switch>(
"adjustTimeStep",
false))
259 if (timeDict.
found(
"deltaT"))
261 deltaT_ = timeDict.
lookup<scalar>(
"deltaT", userUnits());
262 deltaTSave_ = deltaT_;
267 if (timeDict.
found(
"deltaT0"))
269 deltaT0_ = timeDict.
lookup<scalar>(
"deltaT0", userUnits());
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),
371 beginTime_(startTime_),
377 writeInterval_(great),
387 writeVersion_(
IOstream::currentVersion),
388 writeCompression_(
IOstream::UNCOMPRESSED),
389 cacheTemporaryObjects_(true),
394 enableFunctionObjects
396 ?
args.optionFound(
"functionObjects")
397 : !
args.optionFound(
"noFunctionObjects")
413 "OptimisationSwitches",
415 "DimensionedConstants",
423 if (controlDict_.
found(switchSets[i]))
427 <<
" in system/controlDict are only processed if "
445 const word& controlDictName,
448 const bool enableFunctionObjects
455 runTimeModifiable_(false),
473 beginTime_(startTime_),
479 writeInterval_(great),
489 writeVersion_(
IOstream::currentVersion),
490 writeCompression_(
IOstream::UNCOMPRESSED),
491 cacheTemporaryObjects_(true),
493 functionObjects_(*this, enableFunctionObjects)
515 const bool enableFunctionObjects
522 runTimeModifiable_(false),
541 beginTime_(startTime_),
547 writeInterval_(great),
557 writeVersion_(
IOstream::currentVersion),
558 writeCompression_(
IOstream::UNCOMPRESSED),
559 cacheTemporaryObjects_(true),
561 functionObjects_(*this, enableFunctionObjects)
582 const bool enableFunctionObjects
589 runTimeModifiable_(false),
607 beginTime_(startTime_),
613 writeInterval_(great),
620 writeVersion_(
IOstream::currentVersion),
621 writeCompression_(
IOstream::UNCOMPRESSED),
622 cacheTemporaryObjects_(true),
624 functionObjects_(*this, enableFunctionObjects)
635 functionObjects_.clear();
643 std::ostringstream buf;
644 buf.setf(ios_base::fmtflags(format_), ios_base::floatfield);
645 buf.precision(precision);
653 return findTimes(path(), constant());
662 const word& stopInstance
719 return findInstancePath(path(), t);
742 label nearestIndex = -1;
743 scalar deltaT = great;
751 nearestIndex = timei;
763 const word& constantName
766 label nearestIndex = -1;
767 scalar deltaT = great;
777 nearestIndex = timei;
787 return startTimeIndex_;
795 timeName(timeToUserTime(beginTime_)),
806 timeName(timeToUserTime(startTime_)),
832 return userTime_->timeToUserTime(value());
839 userTime_->timeToUserTime(value())
840 - userTime_->timeToUserTime(value() - deltaT_);
846 return userTime_->userTimeToTime(tau);
852 return userTime_->timeToUserTime(t);
858 if (
name() == constant())
864 return timeName(userTimeValue()) + userTime_->unitName();
871 return userTime_->units();
879 switch (writeControl_)
881 case writeControl::timeStep:
883 case writeControl::runTime:
884 case writeControl::adjustableRunTime:
886 case writeControl::cpuTime:
887 case writeControl::clockTime:
897 return value() < (endTime_ - 0.5*deltaT_);
903 bool running = this->running();
907 if (!running && timeIndex_ != startTimeIndex_)
909 functionObjects_.execute();
910 functionObjects_.end();
912 if (cacheTemporaryObjects_)
914 cacheTemporaryObjects_ = checkCacheTemporaryObjects();
925 if (timeIndex_ == startTimeIndex_)
927 functionObjects_.start();
931 functionObjects_.execute();
933 if (cacheTemporaryObjects_)
935 cacheTemporaryObjects_ = checkCacheTemporaryObjects();
941 running = this->running();
950 bool running = run();
963 return value() > (endTime_ + 0.5*deltaT_);
969 const bool changed = (stopAt_ != sa);
973 if (sa == stopAtControl::endTime)
975 controlDict_.lookup(
"endTime") >> endTime_;
989 timeIndex_ = t.timeIndex_;
996 value() = userTimeToTime(inst.
value());
998 timeIndex_ = newIndex;
1014 if (timeDict.
found(
"deltaT"))
1016 deltaT_ = timeDict.
lookup<scalar>(
"deltaT", userUnits());
1019 if (timeDict.
found(
"deltaT0"))
1021 deltaT0_ = timeDict.
lookup<scalar>(
"deltaT0", userUnits());
1040 timeIndex_ = newIndex;
1047 setEndTime(endTime.
value());
1065 setDeltaTNoAdjust(deltaT);
1067 if (writeControl_ == writeControl::adjustableRunTime)
1077 deltaTchanged_ =
true;
1083 if (writeInterval_ == great || !
equal(writeInterval, writeInterval_))
1085 writeInterval_ = writeInterval;
1089 writeControl_ == writeControl::runTime
1090 || writeControl_ == writeControl::adjustableRunTime
1095 writeTimeIndex_ =
label
1097 ((value() - beginTime_) + 0.5*deltaT_)/writeInterval_
1100 else if (writeControl_ == writeControl::timeStep)
1103 writeInterval_ =
label(writeInterval + 0.5);
1112 prevTimeState_.set(
new TimeState(*
this));
1115 deltaT_ /= nSubCycles;
1116 deltaT0_ /= nSubCycles;
1117 deltaTSave_ = deltaT0_;
1119 return prevTimeState();
1127 subCycling_ =
false;
1128 TimeState::operator=(prevTimeState());
1129 prevTimeState_.clear();
1138 return operator+=(deltaT.
value());
1145 return operator++();
1151 deltaT0_ = deltaTSave_;
1152 deltaTSave_ = deltaT_;
1155 const scalar oldTimeValue = timeToUserTime(value());
1159 setTime(value() + deltaT_, timeIndex_ + 1);
1164 if (
mag(value()) < 10*small*deltaT_)
1169 if (sigStopAtWriteNow_.active() || sigWriteNow_.active())
1177 sigStopAtWriteNow_.active()
1178 && stopAt_ == stopAtControl::writeNow
1183 if (sigWriteNow_.active() && writeOnce_)
1191 stopAt_ = stopAtControl::writeNow;
1201 switch (writeControl_)
1203 case writeControl::timeStep:
1204 writeTime_ = !(timeIndex_ %
label(writeInterval_));
1207 case writeControl::runTime:
1208 case writeControl::adjustableRunTime:
1212 ((value() - beginTime_) + 0.5*deltaT_)
1216 if (writeIndex > writeTimeIndex_)
1219 writeTimeIndex_ = writeIndex;
1224 case writeControl::cpuTime:
1231 if (writeIndex > writeTimeIndex_)
1234 writeTimeIndex_ = writeIndex;
1239 case writeControl::clockTime:
1246 if (writeIndex > writeTimeIndex_)
1249 writeTimeIndex_ = writeIndex;
1259 if (stopAt_ == stopAtControl::noWriteNow)
1263 else if (stopAt_ == stopAtControl::writeNow)
1268 else if (stopAt_ == stopAtControl::nextWrite && writeTime_ ==
true)
1284 const scalar userDeltaT = userDeltaTValue();
1287 const scalar timeTol =
1288 max(
min(
pow(10.0, -precision_), 0.1*userDeltaT), small);
1291 scalar timeNameValue = -vGreat;
1298 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1301 int oldPrecision = curPrecision_;
1304 curPrecision_ < maxPrecision_
1306 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1313 if (curPrecision_ != oldPrecision)
1316 <<
"Increased the timePrecision from " << oldPrecision
1317 <<
" to " << curPrecision_
1318 <<
" to distinguish between timeNames at time "
1322 if (curPrecision_ == maxPrecision_)
1328 <<
" The maximum time precision has been reached"
1329 " which might result in overwriting previous"
1335 scalar oldTimeNameValue = -vGreat;
1338 readScalar(oldTimeName.c_str(), oldTimeNameValue)
1340 sign(timeNameValue - oldTimeNameValue)
1347 <<
" is set to an instance prior to the "
1349 << oldTimeName <<
nl
1350 <<
" This might result in temporal "
1365 return operator++();
Inter-processor communication reduction functions.
#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)
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.
const unitConversion & userUnits() const
Return the user-time unit conversion.
virtual dimensionedScalar startTime() const
Return start time.
static const NamedEnum< stopAtControl, 4 > stopAtControlNames
const unitConversion & writeIntervalUnits() const
Return the write interval units.
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)
scalar userTimeValue() const
Return current user time value.
scalar userDeltaTValue() const
Return user time step 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")
static word timeName(const scalar, const int precision=curPrecision_)
Return time name of given scalar time.
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,.
static const NamedEnum< writeControl, 5 > writeControlNames
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...
Unit conversion structure. Contains the associated dimensions and the multiplier with which to conver...
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.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
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.
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.
word name(const bool)
Return a word representation of a bool.
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)
const unitConversion unitNone
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
const unitConversion unitless
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Foam::argList args(argc, argv)