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
386 ?
args.optionFound(
"functionObjects")
388 ? !
args.optionFound(
"noFunctionObjects")
406 "OptimisationSwitches",
411 "DimensionedConstants",
412 "dimensionedConstants"
418 if (controlDict_.
found(switchSets[i]))
422 <<
" in system/controlDict are only processed if "
440 const word& controlDictName,
443 const bool enableFunctionObjects
450 runTimeModifiable_(false),
468 beginTime_(startTime_),
474 writeInterval_(great),
484 writeVersion_(
IOstream::currentVersion),
485 writeCompression_(
IOstream::UNCOMPRESSED),
486 cacheTemporaryObjects_(true),
488 functionObjects_(*this, enableFunctionObjects)
510 const bool enableFunctionObjects
517 runTimeModifiable_(false),
536 beginTime_(startTime_),
542 writeInterval_(great),
552 writeVersion_(
IOstream::currentVersion),
553 writeCompression_(
IOstream::UNCOMPRESSED),
554 cacheTemporaryObjects_(true),
556 functionObjects_(*this, enableFunctionObjects)
577 const bool enableFunctionObjects
584 runTimeModifiable_(false),
602 beginTime_(startTime_),
608 writeInterval_(great),
615 writeVersion_(
IOstream::currentVersion),
616 writeCompression_(
IOstream::UNCOMPRESSED),
617 cacheTemporaryObjects_(true),
619 functionObjects_(*this, enableFunctionObjects)
630 functionObjects_.clear();
638 if (controlDict_.found(
"regionSolvers"))
640 return controlDict_.subDict(
"regionSolvers").toc();
651 std::ostringstream buf;
652 buf.setf(ios_base::fmtflags(format_), ios_base::floatfield);
653 buf.precision(precision);
661 return findTimes(path(), constant());
670 const word& stopInstance
727 return findInstancePath(path(), t);
750 label nearestIndex = -1;
751 scalar deltaT = great;
759 nearestIndex = timei;
771 const word& constantName
774 label nearestIndex = -1;
775 scalar deltaT = great;
785 nearestIndex = timei;
795 return startTimeIndex_;
803 timeName(timeToUserTime(beginTime_)),
814 timeName(timeToUserTime(startTime_)),
840 return userTime_->timeToUserTime(value());
847 userTime_->timeToUserTime(value())
848 - userTime_->timeToUserTime(value() - deltaT_);
854 return userTime_->userTimeToTime(
tau);
860 return userTime_->timeToUserTime(t);
866 if (
name() == constant())
872 return timeName(userTimeValue()) + userTime_->unitName();
879 return userTime_->units();
887 switch (writeControl_)
889 case writeControl::timeStep:
891 case writeControl::runTime:
892 case writeControl::adjustableRunTime:
894 case writeControl::cpuTime:
895 case writeControl::clockTime:
905 return value() < (endTime_ - 0.5*deltaT_);
911 bool running = this->running();
915 if (!running && timeIndex_ != startTimeIndex_)
917 functionObjects_.execute();
918 functionObjects_.end();
920 if (cacheTemporaryObjects_)
922 cacheTemporaryObjects_ = checkCacheTemporaryObjects();
933 if (timeIndex_ == startTimeIndex_)
935 functionObjects_.start();
939 functionObjects_.execute();
941 if (cacheTemporaryObjects_)
943 cacheTemporaryObjects_ = checkCacheTemporaryObjects();
949 running = this->running();
958 bool running = run();
971 return value() > (endTime_ + 0.5*deltaT_);
977 const bool changed = (stopAt_ != sa);
981 if (sa == stopAtControl::endTime)
983 controlDict_.lookup(
"endTime") >> endTime_;
997 timeIndex_ = t.timeIndex_;
1004 value() = userTimeToTime(inst.
value());
1006 timeIndex_ = newIndex;
1022 if (timeDict.
found(
"deltaT"))
1024 deltaT_ = timeDict.
lookup<scalar>(
"deltaT", userUnits());
1027 if (timeDict.
found(
"deltaT0"))
1029 deltaT0_ = timeDict.
lookup<scalar>(
"deltaT0", userUnits());
1048 timeIndex_ = newIndex;
1055 setEndTime(endTime.
value());
1073 setDeltaTNoAdjust(deltaT);
1075 if (writeControl_ == writeControl::adjustableRunTime)
1085 deltaTchanged_ =
true;
1091 if (writeInterval_ == great || !
equal(writeInterval, writeInterval_))
1093 writeInterval_ = writeInterval;
1097 writeControl_ == writeControl::runTime
1098 || writeControl_ == writeControl::adjustableRunTime
1103 writeTimeIndex_ =
label
1105 ((value() - beginTime_) + 0.5*deltaT_)/writeInterval_
1108 else if (writeControl_ == writeControl::timeStep)
1111 writeInterval_ =
label(writeInterval + 0.5);
1120 prevTimeState_.set(
new TimeState(*
this));
1123 deltaT_ /= nSubCycles;
1124 deltaT0_ /= nSubCycles;
1125 deltaTSave_ = deltaT0_;
1127 return prevTimeState();
1135 subCycling_ =
false;
1136 TimeState::operator=(prevTimeState());
1137 prevTimeState_.clear();
1153 return operator++();
1159 deltaT0_ = deltaTSave_;
1160 deltaTSave_ = deltaT_;
1163 const scalar oldTimeValue = timeToUserTime(value());
1167 setTime(value() + deltaT_, timeIndex_ + 1);
1172 if (
mag(value()) < 10*small*deltaT_)
1177 if (sigStopAtWriteNow_.active() || sigWriteNow_.active())
1185 sigStopAtWriteNow_.active()
1186 && stopAt_ == stopAtControl::writeNow
1191 if (sigWriteNow_.active() && writeOnce_)
1199 stopAt_ = stopAtControl::writeNow;
1209 switch (writeControl_)
1211 case writeControl::timeStep:
1212 writeTime_ = !(timeIndex_ %
label(writeInterval_));
1215 case writeControl::runTime:
1216 case writeControl::adjustableRunTime:
1220 ((value() - beginTime_) + 0.5*deltaT_)
1224 if (writeIndex > writeTimeIndex_)
1227 writeTimeIndex_ = writeIndex;
1232 case writeControl::cpuTime:
1239 if (writeIndex > writeTimeIndex_)
1242 writeTimeIndex_ = writeIndex;
1247 case writeControl::clockTime:
1254 if (writeIndex > writeTimeIndex_)
1257 writeTimeIndex_ = writeIndex;
1267 if (stopAt_ == stopAtControl::noWriteNow)
1271 else if (stopAt_ == stopAtControl::writeNow)
1276 else if (stopAt_ == stopAtControl::nextWrite && writeTime_ ==
true)
1292 const scalar userDeltaT = userDeltaTValue();
1295 const scalar timeTol =
1296 max(
min(
pow(10.0, -precision_), 0.1*userDeltaT), small);
1299 scalar timeNameValue = -vGreat;
1306 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1309 int oldPrecision = curPrecision_;
1312 curPrecision_ < maxPrecision_
1314 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1321 if (curPrecision_ != oldPrecision)
1324 <<
"Increased the timePrecision from " << oldPrecision
1325 <<
" to " << curPrecision_
1326 <<
" to distinguish between timeNames at time "
1330 if (curPrecision_ == maxPrecision_)
1336 <<
" The maximum time precision has been reached"
1337 " which might result in overwriting previous"
1343 scalar oldTimeNameValue = -vGreat;
1346 readScalar(oldTimeName.c_str(), oldTimeNameValue)
1348 sign(timeNameValue - oldTimeNameValue)
1355 <<
" is set to an instance prior to the "
1357 << oldTimeName <<
nl
1358 <<
" This might result in temporal "
1373 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.
static const List< word > & null()
Return a null List.
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.
virtual dimensionedScalar startTime() const
Return start time.
static const NamedEnum< stopAtControl, 4 > stopAtControlNames
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".
const unitSet & userUnits() const
Return the user-time unit conversion.
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.
wordList regionNames() const
Return the list of region names.
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.
const unitSet & writeIntervalUnits() const
Return the write interval units.
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)
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.
const dimensionSet & dimTime
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< Type > min(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
tmp< DimensionedField< typename powProduct< Type, r >::type, GeoMesh, Field > > pow(const DimensionedField< Type, GeoMesh, PrimitiveField > &df, typename powProduct< Type, r >::type)
tmp< DimensionedField< scalar, GeoMesh, Field > > mag(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
static const label labelMax
void operator+=(fvMatrix< Type > &fvEqn, const CarrierEqn< Type > &cEqn)
Add to a finite-volume equation.
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
dimensioned< Type > max(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Foam::argList args(argc, argv)