86 const scalar timeToNextWrite =
min 91 (writeTimeIndex_ + 1)*writeInterval_ - (value() - startTime_)
93 functionObjects_.timeToNextWrite()
96 const scalar nSteps = timeToNextWrite/deltaT_;
103 const label nStepsToNextWrite =
label(
max(nSteps, 1) + 0.99);
104 deltaT_ = timeToNextWrite/nStepsToNextWrite;
112 const word startFrom = controlDict_.lookupOrDefault<
word>
118 if (startFrom ==
"startTime")
120 controlDict_.lookup(
"startTime") >> startTime_;
127 if (startFrom ==
"firstTime")
131 if (timeDirs[0].
name() == constant() && timeDirs.
size() >= 2)
133 startTime_ = timeDirs[1].value();
137 startTime_ = timeDirs[0].value();
141 else if (startFrom ==
"latestTime")
145 startTime_ = timeDirs.
last().value();
151 <<
"expected startTime, firstTime or latestTime" 152 <<
" found '" << startFrom <<
"'" 160 deltaTSave_ = deltaT_;
167 int oldPrecision = precision_;
168 int requiredPrecision = -1;
173 precision_ = maxPrecision_;
174 precision_ > oldPrecision;
182 if (newTime == oldTime)
193 requiredPrecision = precision_;
197 if (requiredPrecision > 0)
200 precision_ = requiredPrecision;
206 <<
"Increasing the timePrecision from " << oldPrecision
207 <<
" to " << precision_
208 <<
" to support the formatting of the current time directory " 214 precision_ = oldPrecision;
223 scalar sumStartTime = startTime_;
232 <<
"Start time is not the same for all processors" <<
nl 254 if (controlDict_.lookupOrDefault<
Switch>(
"adjustTimeStep",
false))
258 deltaTSave_ = deltaT_;
267 timeIndex_ = startTimeIndex_;
274 bool checkValue =
true;
276 string storedTimeName;
291 scalar storedTimeValue;
299 <<
"Time read from time dictionary " << storedTimeName
300 <<
" differs from actual time " <<
timeName() <<
'.' <<
nl 301 <<
" This may cause unexpected database behaviour." 302 <<
" If you are not interested" <<
nl 303 <<
" in preserving time state delete" 304 <<
" the time dictionary." 316 const word& controlDictName,
319 const word& systemName,
320 const word& constantName,
321 const bool enableFunctionObjects
351 stopAt_(stopAtControl::endTime),
352 writeControl_(writeControl::timeStep),
353 writeInterval_(great),
364 runTimeModifiable_(
false),
365 cacheTemporaryObjects_(
true),
367 functionObjects_(*
this, enableFunctionObjects)
378 if (runTimeModifiable_)
385 controlDict_.files().clear();
391 const word& controlDictName,
393 const word& systemName,
394 const word& constantName
426 stopAt_(stopAtControl::endTime),
427 writeControl_(writeControl::timeStep),
428 writeInterval_(great),
439 runTimeModifiable_(
false),
440 cacheTemporaryObjects_(
true),
459 if (runTimeModifiable_)
466 controlDict_.files().clear();
475 const word& systemName,
476 const word& constantName,
477 const bool enableFunctionObjects
508 stopAt_(stopAtControl::endTime),
509 writeControl_(writeControl::timeStep),
510 writeInterval_(great),
521 runTimeModifiable_(
false),
522 cacheTemporaryObjects_(
true),
524 functionObjects_(*
this, enableFunctionObjects)
539 if (runTimeModifiable_)
546 controlDict_.files().clear();
554 const word& systemName,
555 const word& constantName,
556 const bool enableFunctionObjects
586 stopAt_(stopAtControl::endTime),
587 writeControl_(writeControl::timeStep),
588 writeInterval_(great),
597 runTimeModifiable_(
false),
598 cacheTemporaryObjects_(
true),
600 functionObjects_(*
this, enableFunctionObjects)
616 functionObjects_.clear();
624 std::ostringstream buf;
625 buf.setf(ios_base::fmtflags(format_), ios_base::floatfield);
626 buf.precision(precision);
640 return findTimes(
path(), constant());
649 const word& stopInstance
693 if (t.
equal(timeDirs[i].value()))
695 return timeDirs[i].name();
705 return findInstancePath(
path(), t);
714 if (timeDirs.
size() == 1)
719 if (t < timeDirs[1].value())
723 else if (t > timeDirs.
last().value())
725 return timeDirs.
last();
728 label nearestIndex = -1;
729 scalar deltaT = great;
731 for (
label timei=1; timei < timeDirs.
size(); ++timei)
733 scalar
diff =
mag(timeDirs[timei].value() - t);
737 nearestIndex = timei;
741 return timeDirs[nearestIndex];
749 const word& constantName
752 label nearestIndex = -1;
753 scalar deltaT = great;
757 if (timeDirs[timei].
name() == constantName)
continue;
759 scalar
diff =
mag(timeDirs[timei].value() - t);
763 nearestIndex = timei;
773 return startTimeIndex_;
791 return value() < (endTime_ - 0.5*deltaT_);
797 bool running = this->running();
801 if (!running && timeIndex_ != startTimeIndex_)
803 functionObjects_.execute();
804 functionObjects_.end();
806 if (cacheTemporaryObjects_)
808 cacheTemporaryObjects_ = checkCacheTemporaryObjects();
819 if (timeIndex_ == startTimeIndex_)
821 functionObjects_.start();
825 functionObjects_.execute();
827 if (cacheTemporaryObjects_)
829 cacheTemporaryObjects_ = checkCacheTemporaryObjects();
835 running = this->running();
844 bool running = run();
857 return value() > (endTime_ + 0.5*deltaT_);
863 const bool changed = (stopAt_ != sa);
867 if (sa == stopAtControl::endTime)
869 controlDict_.lookup(
"endTime") >> endTime_;
890 value() = inst.
value();
892 timeIndex_ = newIndex;
925 timeIndex_ = newIndex;
932 setEndTime(endTime.
value());
944 setDeltaT(deltaT.
value());
950 setDeltaTNoAdjust(deltaT);
952 functionObjects_.setTimeStep();
954 if (writeControl_ == writeControl::adjustableRunTime)
964 deltaTchanged_ =
true;
971 prevTimeState_.set(
new TimeState(*
this));
974 deltaT_ /= nSubCycles;
975 deltaT0_ /= nSubCycles;
976 deltaTSave_ = deltaT0_;
978 return prevTimeState();
987 TimeState::operator=(prevTimeState());
988 prevTimeState_.clear();
997 return operator+=(deltaT.
value());
1004 return operator++();
1010 deltaT0_ = deltaTSave_;
1011 deltaTSave_ = deltaT_;
1014 const scalar oldTimeValue = timeToUserTime(value());
1018 setTime(value() + deltaT_, timeIndex_ + 1);
1023 if (
mag(value()) < 10*small*deltaT_)
1028 if (sigStopAtWriteNow_.active() || sigWriteNow_.active())
1036 sigStopAtWriteNow_.active()
1037 && stopAt_ == stopAtControl::writeNow
1042 if (sigWriteNow_.active() && writeOnce_)
1050 stopAt_ = stopAtControl::writeNow;
1060 switch (writeControl_)
1062 case writeControl::timeStep:
1063 writeTime_ = !(timeIndex_ %
label(writeInterval_));
1067 case writeControl::adjustableRunTime:
1071 ((value() - startTime_) + 0.5*deltaT_)
1075 if (writeIndex > writeTimeIndex_)
1078 writeTimeIndex_ = writeIndex;
1083 case writeControl::cpuTime:
1090 if (writeIndex > writeTimeIndex_)
1093 writeTimeIndex_ = writeIndex;
1098 case writeControl::clockTime:
1105 if (writeIndex > writeTimeIndex_)
1108 writeTimeIndex_ = writeIndex;
1118 if (stopAt_ == stopAtControl::noWriteNow)
1122 else if (stopAt_ == stopAtControl::writeNow)
1127 else if (stopAt_ == stopAtControl::nextWrite && writeTime_ ==
true)
1144 const scalar timeTol =
1145 max(
min(
pow(10.0, -precision_), 0.1*deltaT_), small);
1148 const scalar userDeltaT = timeToUserTime(deltaT_);
1151 scalar timeNameValue = -vGreat;
1158 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1161 int oldPrecision = precision_;
1164 precision_ < maxPrecision_
1166 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1173 if (precision_ != oldPrecision)
1176 <<
"Increased the timePrecision from " << oldPrecision
1177 <<
" to " << precision_
1178 <<
" to distinguish between timeNames at time " 1182 if (precision_ == maxPrecision_)
1188 <<
" The maximum time precision has been reached" 1189 " which might result in overwriting previous" 1195 scalar oldTimeNameValue = -vGreat;
1198 readScalar(oldTimeName.c_str(), oldTimeNameValue)
1200 sign(timeNameValue - oldTimeNameValue)
1207 <<
" is set to an instance prior to the " 1209 << oldTimeName <<
nl 1210 <<
" This might result in temporal " 1225 return operator++();
virtual Time & operator++()
Prefix increment,.
dimensionedScalar sign(const dimensionedScalar &ds)
scalar diff(const triad &A, const triad &B)
Return a quantity of the difference between two triads.
bool exists(const fileName &, const bool checkVariants=true, const bool followLink=true)
Does the name exist (as directory or file) in the file system?
#define forAll(list, i)
Loop across all elements in list.
A class for addressing time paths without using the Time class.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
A class for handling file names.
Inter-processor communication reduction functions.
errorManipArg< error, int > exit(error &err, const int errNo=1)
The time value with time-stepping information, user-defined remapping, etc.
const fileName & globalCaseName() const
Return case name.
const word & name() const
Name (const access)
void adjustDeltaT()
Adjust the time step so that writing occurs at the specified time.
A list of keyword definitions, which are a keyword followed by any number of values (e...
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
virtual ~Time()
Destructor.
const fileName & rootPath() const
Return root path.
void size(const label)
Override size to be inconsistent with allocated storage.
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
virtual bool loop()
Return true if run should continue and if so increment time.
virtual dimensionedScalar startTime() const
Return start time.
bool exists(IOobject &io) const
Does ioobject exist. Is either a directory (empty name()) or.
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool optionFound(const word &opt) const
Return true if the named option is found.
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".
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none/any.
#define forAllReverse(list, i)
Reverse loop across all elements in list.
runTimeSource setTime(sourceTimes[sourceTimeIndex], sourceTimeIndex)
virtual dimensionedScalar endTime() const
Return end time.
stopAtControl
Stop-run control options.
readOption
Enumeration defining the read options.
Initialise the NamedEnum HashTable from the static list of names.
virtual word timeName() const
Return current time name.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
dlLibraryTable libs
Table of loaded dynamic libraries.
virtual bool run() const
Return true if run should continue,.
const ParRunControl & parRunControl() const
Return parRunControl.
static const int maxPrecision_
Maximum time directory name precision.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
virtual TimeState subCycle(const label nSubCycles)
Set time to sub-cycle for the given number of steps.
virtual bool stopAt(const stopAtControl) const
Adjust the current stopAtControl. Note that this value.
static int precision_
Time directory name precision.
A class for handling words, derived from string.
virtual bool running() const
Return true if run should continue without any side effects.
Extract command arguments and options from the supplied argc and argv parameters. ...
const Type & value() const
Return const reference to value.
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
static const word null
An empty word.
virtual void addWatches(regIOobject &, const fileNameList &) const
Helper: add watches for list of regIOobjects.
static const label labelMax
virtual void setTime(const Time &)
Reset the time and time-index to those of the given time.
format
Supported time directory name formats.
const fileOperation & fileHandler()
Get current file handler.
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
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.
static word controlDictName
The default control dictionary name (normally "controlDict")
const fileName & caseName() const
Return case name (parallel run) or global case (serial run)
static format format_
Time directory name format.
virtual void setDeltaTNoAdjust(const scalar)
Reset time step without additional adjustment or modification.
defineTypeNameAndDebug(combustionModel, 0)
scalar value() const
Value (const access)
static const NamedEnum< stopAtControl, 4 > stopAtControlNames_
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.
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
void readModifiedObjects()
Read the objects that have been modified.
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
word name(const complex &)
Return a string representation of a complex.
virtual void setEndTime(const dimensionedScalar &)
Reset end time.
static const NamedEnum< writeControl, 5 > writeControlNames_
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
An instant of time. Contains the time value and name.
static bool & parRun()
Is this a parallel run?
const fileName & instance() const
static label nProcs(const label communicator=0)
Number of processes in parallel run.
virtual bool end() const
Return true if end of run,.
virtual void setTime(const Time &) const
Callback for time change.
#define WarningInFunction
Report a warning using Foam::Warning.
static const versionNumber currentVersion
Current version number.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
instantList times() const
Search the case for valid time directories.
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
instant findClosestTime(const scalar) const
Search the case for the time closest to the given time.
virtual void setDeltaT(const dimensionedScalar &)
Reset time step.
writeControl
Write control options.
dimensioned< scalar > mag(const dimensioned< Type > &)
virtual void endSubCycle()
Reset time after sub-cycling back to previous TimeState.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
Registry of regIOobjects.
T & last()
Return the last element of the list.
word findInstancePath(const fileName &path, const instant &) const
Search the case for the time directory path.
virtual label startTimeIndex() const
Return start time index.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
dimensionedScalar log10(const dimensionedScalar &ds)
static HashTable< string > validOptions
A list of valid options.
virtual Time & operator+=(const dimensionedScalar &)
Set deltaT to that specified and increment time via operator++()
bool equal(const scalar) const
Comparison used for instants to be equal.
virtual bool removeWatch(const label) const
Remove watch on a file (using handle)
void setControls()
Set the controls from the current controlDict.
static label findClosestTimeIndex(const instantList &, const scalar, const word &constantName="constant")
Search instantList for the time index closest to the given time.
int system(const std::string &command)
Execute the specified command.
fileName path(UMean.rootPath()/UMean.caseName()/functionObjects::writeFile::outputPrefix/"graphs"/UMean.instance())