72 const scalar timeToNextAction =
min
82 const scalar nSteps = timeToNextAction/deltaT_;
88 const label nStepsToNextAction =
label(nSteps + 0.99);
91 if (nStepsToNextAction > 0)
93 deltaT_ = timeToNextAction/nStepsToNextAction;
102 const word startFrom = controlDict_.lookupOrDefault<
word>
108 if (startFrom ==
"startTime")
110 startTime_ = controlDict_.lookup<scalar>(
"startTime", userUnits());
117 if (startFrom ==
"firstTime")
123 startTime_ = userTimeToTime(
timeDirs[1].value());
127 startTime_ = userTimeToTime(
timeDirs[0].value());
131 else if (startFrom ==
"latestTime")
141 <<
"expected startTime, firstTime or latestTime"
142 <<
" found '" << startFrom <<
"'"
149 deltaTSave_ = deltaT_;
156 int oldPrecision = curPrecision_;
157 int requiredPrecision = -1;
161 curPrecision_ = maxPrecision_;
162 curPrecision_ > oldPrecision;
172 requiredPrecision = curPrecision_;
176 if (requiredPrecision > 0)
179 curPrecision_ = requiredPrecision;
185 <<
"Increasing the timePrecision from " << oldPrecision
186 <<
" to " << curPrecision_
187 <<
" to support the formatting of the current time directory "
193 curPrecision_ = oldPrecision;
202 scalar sumStartTime = startTime_;
211 <<
"Start time is not the same for all processors" <<
nl
231 if (controlDict_.found(
"beginTime"))
233 beginTime_ = controlDict_.lookup<scalar>(
"beginTime", userUnits());
235 else if (timeDict.
found(
"beginTime"))
237 beginTime_ = timeDict.
lookup<scalar>(
"beginTime", userUnits());
241 beginTime_ = startTime_;
246 if (controlDict_.lookupOrDefault<
Switch>(
"adjustTimeStep",
false))
248 if (timeDict.
found(
"deltaT"))
250 deltaT_ = timeDict.
lookup<scalar>(
"deltaT", userUnits());
251 deltaTSave_ = deltaT_;
256 if (timeDict.
found(
"deltaT0"))
258 deltaT0_ = timeDict.
lookup<scalar>(
"deltaT0", userUnits());
263 timeIndex_ = startTimeIndex_;
270 writeControl_ == writeControl::runTime
271 || writeControl_ == writeControl::adjustableRunTime
275 writeTimeIndex_ =
label
277 ((value() - beginTime_) + 0.5*deltaT_)/writeInterval_
285 bool checkValue =
true;
287 string storedTimeName;
290 if (storedTimeName ==
name())
302 scalar storedTimeValue;
307 if (storedTimeName !=
name())
310 <<
"Time read from time dictionary " << storedTimeName
311 <<
" differs from actual time " <<
name() <<
'.' <<
nl
312 <<
" This may cause unexpected database behaviour."
313 <<
" If you are not interested" <<
nl
314 <<
" in preserving time state delete"
315 <<
" the time dictionary."
327 const word& controlDictName,
329 const bool enableFunctionObjects
334 args.parRunControl().parRun(),
336 args.globalCaseName(),
342 runTimeModifiable_(false),
360 beginTime_(startTime_),
366 writeInterval_(great),
376 writeVersion_(
IOstream::currentVersion),
377 writeCompression_(
IOstream::UNCOMPRESSED),
378 cacheTemporaryObjects_(true),
383 enableFunctionObjects
385 ?
args.optionFound(
"functionObjects")
386 : !
args.optionFound(
"noFunctionObjects")
402 "OptimisationSwitches",
404 "DimensionedConstants",
412 if (controlDict_.
found(switchSets[i]))
416 <<
" in system/controlDict are only processed if "
434 const word& controlDictName,
437 const bool enableFunctionObjects
444 runTimeModifiable_(false),
462 beginTime_(startTime_),
468 writeInterval_(great),
478 writeVersion_(
IOstream::currentVersion),
479 writeCompression_(
IOstream::UNCOMPRESSED),
480 cacheTemporaryObjects_(true),
482 functionObjects_(*this, enableFunctionObjects)
504 const bool enableFunctionObjects
511 runTimeModifiable_(false),
530 beginTime_(startTime_),
536 writeInterval_(great),
546 writeVersion_(
IOstream::currentVersion),
547 writeCompression_(
IOstream::UNCOMPRESSED),
548 cacheTemporaryObjects_(true),
550 functionObjects_(*this, enableFunctionObjects)
571 const bool enableFunctionObjects
578 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
708 return findInstancePath(path(), t);
731 label nearestIndex = -1;
732 scalar deltaT = great;
740 nearestIndex = timei;
752 const word& constantName
755 label nearestIndex = -1;
756 scalar deltaT = great;
766 nearestIndex = timei;
776 return startTimeIndex_;
784 timeName(timeToUserTime(beginTime_)),
795 timeName(timeToUserTime(startTime_)),
821 return userTime_->timeToUserTime(value());
828 userTime_->timeToUserTime(value())
829 - userTime_->timeToUserTime(value() - deltaT_);
835 return userTime_->userTimeToTime(
tau);
841 return userTime_->timeToUserTime(t);
847 if (
name() == constant())
853 return timeName(userTimeValue()) + userTime_->unitName();
860 return userTime_->units();
868 switch (writeControl_)
870 case writeControl::timeStep:
872 case writeControl::runTime:
873 case writeControl::adjustableRunTime:
875 case writeControl::cpuTime:
876 case writeControl::clockTime:
886 return value() < (endTime_ - 0.5*deltaT_);
892 bool running = this->running();
896 if (!running && timeIndex_ != startTimeIndex_)
898 functionObjects_.execute();
899 functionObjects_.end();
901 if (cacheTemporaryObjects_)
903 cacheTemporaryObjects_ = checkCacheTemporaryObjects();
914 if (timeIndex_ == startTimeIndex_)
916 functionObjects_.start();
920 functionObjects_.execute();
922 if (cacheTemporaryObjects_)
924 cacheTemporaryObjects_ = checkCacheTemporaryObjects();
930 running = this->running();
939 bool running = run();
952 return value() > (endTime_ + 0.5*deltaT_);
958 const bool changed = (stopAt_ != sa);
962 if (sa == stopAtControl::endTime)
964 controlDict_.lookup(
"endTime") >> endTime_;
978 timeIndex_ = t.timeIndex_;
985 value() = userTimeToTime(inst.
value());
987 timeIndex_ = newIndex;
1003 if (timeDict.
found(
"deltaT"))
1005 deltaT_ = timeDict.
lookup<scalar>(
"deltaT", userUnits());
1008 if (timeDict.
found(
"deltaT0"))
1010 deltaT0_ = timeDict.
lookup<scalar>(
"deltaT0", userUnits());
1029 timeIndex_ = newIndex;
1036 setEndTime(endTime.
value());
1054 setDeltaTNoAdjust(deltaT);
1056 if (writeControl_ == writeControl::adjustableRunTime)
1066 deltaTchanged_ =
true;
1072 if (writeInterval_ == great || !
equal(writeInterval, writeInterval_))
1074 writeInterval_ = writeInterval;
1078 writeControl_ == writeControl::runTime
1079 || writeControl_ == writeControl::adjustableRunTime
1084 writeTimeIndex_ =
label
1086 ((value() - beginTime_) + 0.5*deltaT_)/writeInterval_
1089 else if (writeControl_ == writeControl::timeStep)
1092 writeInterval_ =
label(writeInterval + 0.5);
1101 prevTimeState_.set(
new TimeState(*
this));
1104 deltaT_ /= nSubCycles;
1105 deltaT0_ /= nSubCycles;
1106 deltaTSave_ = deltaT0_;
1108 return prevTimeState();
1116 subCycling_ =
false;
1117 TimeState::operator=(prevTimeState());
1118 prevTimeState_.clear();
1134 return operator++();
1140 deltaT0_ = deltaTSave_;
1141 deltaTSave_ = deltaT_;
1144 const scalar oldTimeValue = timeToUserTime(value());
1148 setTime(value() + deltaT_, timeIndex_ + 1);
1153 if (
mag(value()) < 10*small*deltaT_)
1158 if (sigStopAtWriteNow_.active() || sigWriteNow_.active())
1166 sigStopAtWriteNow_.active()
1167 && stopAt_ == stopAtControl::writeNow
1172 if (sigWriteNow_.active() && writeOnce_)
1180 stopAt_ = stopAtControl::writeNow;
1190 switch (writeControl_)
1192 case writeControl::timeStep:
1193 writeTime_ = !(timeIndex_ %
label(writeInterval_));
1196 case writeControl::runTime:
1197 case writeControl::adjustableRunTime:
1201 ((value() - beginTime_) + 0.5*deltaT_)
1205 if (writeIndex > writeTimeIndex_)
1208 writeTimeIndex_ = writeIndex;
1213 case writeControl::cpuTime:
1220 if (writeIndex > writeTimeIndex_)
1223 writeTimeIndex_ = writeIndex;
1228 case writeControl::clockTime:
1235 if (writeIndex > writeTimeIndex_)
1238 writeTimeIndex_ = writeIndex;
1248 if (stopAt_ == stopAtControl::noWriteNow)
1252 else if (stopAt_ == stopAtControl::writeNow)
1257 else if (stopAt_ == stopAtControl::nextWrite && writeTime_ ==
true)
1273 const scalar userDeltaT = userDeltaTValue();
1276 const scalar timeTol =
1277 max(
min(
pow(10.0, -precision_), 0.1*userDeltaT), small);
1280 scalar timeNameValue = -vGreat;
1287 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1290 int oldPrecision = curPrecision_;
1293 curPrecision_ < maxPrecision_
1295 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1302 if (curPrecision_ != oldPrecision)
1305 <<
"Increased the timePrecision from " << oldPrecision
1306 <<
" to " << curPrecision_
1307 <<
" to distinguish between timeNames at time "
1311 if (curPrecision_ == maxPrecision_)
1317 <<
" The maximum time precision has been reached"
1318 " which might result in overwriting previous"
1324 scalar oldTimeNameValue = -vGreat;
1327 readScalar(oldTimeName.c_str(), oldTimeNameValue)
1329 sign(timeNameValue - oldTimeNameValue)
1336 <<
" is set to an instance prior to the "
1338 << oldTimeName <<
nl
1339 <<
" This might result in temporal "
1354 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 keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
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.
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
void mag(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
const dimensionSet dimTime
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
void pow(LagrangianPatchField< typename powProduct< Type, r >::type > &f, const LagrangianPatchField< Type > &f1)
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.
defineTypeNameAndDebug(combustionModel, 0)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
static const label labelMax
const unitConversion unitless
void operator+=(fvMatrix< Type > &fvEqn, const CarrierEqn< Type > &cEqn)
Add to a finite-volume equation.
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Foam::argList args(argc, argv)