Go to the documentation of this file.
53 { stopAtControls::saEndTime,
"endTime" },
54 { stopAtControls::saNoWriteNow,
"noWriteNow" },
55 { stopAtControls::saWriteNow,
"writeNow" },
56 { stopAtControls::saNextWrite,
"nextWrite" },
67 { writeControls::wcNone,
"none" },
68 { writeControls::wcTimeStep,
"timeStep" },
69 { writeControls::wcRunTime,
"runTime" },
70 { writeControls::wcAdjustableRunTime,
"adjustable" },
71 { writeControls::wcAdjustableRunTime,
"adjustableRunTime" },
72 { writeControls::wcClockTime,
"clockTime" },
73 { writeControls::wcCpuTime,
"cpuTime" },
93 "printExecutionFormat",
103 bool adjustTime =
false;
104 scalar timeToNextWrite = VGREAT;
109 timeToNextWrite =
max
118 scalar nSteps = timeToNextWrite/
deltaT_;
124 label nStepsToNextWrite =
max(1, round(nSteps));
126 scalar newDeltaT = timeToNextWrite/nStepsToNextWrite;
148 const word startFrom = controlDict_.lookupOrDefault<
word>
154 if (startFrom ==
"startTime")
156 controlDict_.readEntry(
"startTime", startTime_);
163 const label nTimes = timeDirs.size();
165 if (startFrom ==
"firstTime")
167 if (nTimes > 1 && timeDirs.first().name() ==
constant())
169 startTime_ = timeDirs[1].value();
173 startTime_ = timeDirs.first().value();
176 else if (startFrom ==
"latestTime")
180 startTime_ = timeDirs.last().value();
186 <<
"expected startTime, firstTime or latestTime"
187 <<
" found '" << startFrom <<
"'"
195 deltaTSave_ = deltaT_;
202 int oldPrecision = precision_;
203 int requiredPrecision = -1;
208 precision_ = maxPrecision_;
209 precision_ > oldPrecision;
228 requiredPrecision = precision_;
232 if (requiredPrecision > 0)
235 precision_ = requiredPrecision;
241 <<
"Increasing the timePrecision from " << oldPrecision
242 <<
" to " << precision_
243 <<
" to support the formatting of the current time directory "
249 precision_ = oldPrecision;
258 scalar sumStartTime = startTime_;
267 <<
"Start time is not the same for all processors" <<
nl
289 if (controlDict_.lookupOrDefault(
"adjustTimeStep",
false))
293 deltaTSave_ = deltaT_;
302 timeIndex_ = startTimeIndex_;
309 bool checkValue =
true;
311 string storedTimeName;
326 scalar storedTimeValue;
334 <<
"Time read from time dictionary " << storedTimeName
335 <<
" differs from actual time " <<
timeName() <<
'.' <<
nl
336 <<
" This may cause unexpected database behaviour."
337 <<
" If you are not interested" <<
nl
338 <<
" in preserving time state delete"
339 <<
" the time dictionary."
398 if (runTimeModifiable_)
405 controlDict_.files().clear();
413 const word& ctrlDictName,
416 const word& systemName,
417 const word& constantName,
418 const bool enableFunctionObjects,
419 const bool enableLibs
432 loopProfiling_(
nullptr),
453 writeControl_(wcTimeStep),
454 writeInterval_(GREAT),
458 sigWriteNow_(*
this,
true),
459 sigStopAtWriteNow_(*
this,
true),
462 runTimeModifiable_(
false),
463 functionObjects_(*
this,
false)
465 if (enableFunctionObjects)
467 functionObjects_.on();
472 libs_.open(controlDict_,
"libs");
486 const word& ctrlDictName,
488 const word& systemName,
489 const word& constantName
496 loopProfiling_(
nullptr),
517 writeControl_(wcTimeStep),
518 writeInterval_(GREAT),
522 sigWriteNow_(*
this,
true),
523 sigStopAtWriteNow_(*
this,
true),
526 runTimeModifiable_(
false),
527 functionObjects_(*
this,
false)
543 functionObjects_.on();
551 libs_.open(controlDict_,
"libs");
570 const word& systemName,
571 const word& constantName,
572 const bool enableFunctionObjects,
573 const bool enableLibs
586 loopProfiling_(
nullptr),
608 writeControl_(wcTimeStep),
609 writeInterval_(GREAT),
613 sigWriteNow_(*
this,
true),
614 sigStopAtWriteNow_(*
this,
true),
617 runTimeModifiable_(
false),
618 functionObjects_(*
this,
false)
620 if (enableFunctionObjects)
622 functionObjects_.on();
627 libs_.open(controlDict_,
"libs");
647 const word& systemName,
648 const word& constantName,
649 const bool enableFunctionObjects,
650 const bool enableLibs
663 loopProfiling_(
nullptr),
684 writeControl_(wcTimeStep),
685 writeInterval_(GREAT),
691 runTimeModifiable_(
false),
692 functionObjects_(*
this,
false)
694 if (enableFunctionObjects)
696 functionObjects_.on();
701 libs_.open(controlDict_,
"libs");
752 functionObjects_.clear();
766 std::ostringstream buf;
767 buf.setf(ios_base::fmtflags(format_), ios_base::floatfield);
768 buf.precision(precision);
785 const word& stopInstance
829 if (t.
equal(timeDirs[i].value()))
831 return timeDirs[i].name();
841 return findInstancePath(
path(), t);
847 return startTimeIndex_;
873 bool isRunning = value() < (endTime_ - 0.5*deltaT_);
879 if (!isRunning && timeIndex_ != startTimeIndex_)
885 functionObjects_.execute();
889 functionObjects_.end();
900 if (timeIndex_ == startTimeIndex_)
902 addProfiling(functionObjects,
"functionObjects.start()");
903 functionObjects_.start();
907 addProfiling(functionObjects,
"functionObjects.execute()");
908 functionObjects_.execute();
917 if (functionObjects_.filesModified())
925 isRunning = value() < (endTime_ - 0.5*deltaT_);
941 const bool isRunning = run();
954 return value() > (endTime_ + 0.5*deltaT_);
960 if (stopCtrl == stopAtControls::saUnknown)
965 const bool changed = (stopAt_ != stopCtrl);
970 if (stopCtrl == stopAtControls::saEndTime)
972 controlDict_.readEntry(
"endTime", endTime_);
981 return controlDict_.lookupOrDefault(
"adjustTimeStep",
false);
996 value() = inst.
value();
998 timeIndex_ = newIndex;
1031 timeIndex_ = newIndex;
1038 setEndTime(endTime.
value());
1054 setDeltaT(deltaT.
value(), adjust);
1061 deltaTchanged_ =
true;
1072 prevTimeState_.set(
new TimeState(*
this));
1075 deltaT_ /= nSubCycles;
1076 deltaT0_ /= nSubCycles;
1077 deltaTSave_ = deltaT0_;
1079 subCycling_ = nSubCycles;
1081 return prevTimeState();
1091 if (subCycling_ && index > 0)
1093 subCycling_ = index;
1102 TimeState::operator=(prevTimeState());
1103 prevTimeState_.clear();
1114 return operator+=(deltaT.
value());
1121 return operator++();
1127 deltaT0_ = deltaTSave_;
1128 deltaTSave_ = deltaT_;
1131 const scalar oldTimeValue = timeToUserTime(value());
1135 setTime(value() + deltaT_, timeIndex_ + 1);
1140 if (
mag(value()) < 10*SMALL*deltaT_)
1145 if (sigStopAtWriteNow_.active() || sigWriteNow_.active())
1151 if (sigStopAtWriteNow_.active() && stopAt_ == saWriteNow)
1155 if (sigWriteNow_.active() && writeOnce_)
1163 stopAt_ = saWriteNow;
1173 switch (writeControl_)
1180 writeTime_ = !(timeIndex_ %
label(writeInterval_));
1184 case wcAdjustableRunTime:
1188 ((value() - startTime_) + 0.5*deltaT_)
1192 if (writeIndex > writeTimeIndex_)
1195 writeTimeIndex_ = writeIndex;
1207 if (writeIndex > writeTimeIndex_)
1210 writeTimeIndex_ = writeIndex;
1222 if (writeIndex > writeTimeIndex_)
1225 writeTimeIndex_ = writeIndex;
1235 if (stopAt_ == saNoWriteNow)
1239 else if (stopAt_ == saWriteNow)
1244 else if (stopAt_ == saNextWrite && writeTime_ ==
true)
1261 const scalar timeTol =
1262 max(
min(
pow(10.0, -precision_), 0.1*deltaT_), SMALL);
1265 const scalar userDeltaT = timeToUserTime(deltaT_);
1268 scalar timeNameValue = -VGREAT;
1275 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1278 int oldPrecision = precision_;
1281 precision_ < maxPrecision_
1283 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1290 if (precision_ != oldPrecision)
1293 <<
"Increased the timePrecision from " << oldPrecision
1294 <<
" to " << precision_
1295 <<
" to distinguish between timeNames at time "
1299 if (precision_ == maxPrecision_)
1305 <<
" The maximum time precision has been reached"
1306 " which might result in overwriting previous"
1312 scalar oldTimeNameValue = -VGREAT;
1315 readScalar(oldTimeName, oldTimeNameValue)
1317 sign(timeNameValue - oldTimeNameValue)
1324 <<
" is set to an instance prior to the "
1326 << oldTimeName <<
nl
1327 <<
" This might result in temporal "
1342 return operator++();
dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
Find and return a sub-dictionary pointer if present.
static autoPtr< T > New(Args &&... args)
Construct autoPtr of T with forwarding arguments.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
writeControls
Write control options.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
bool exists(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
bool adjustTimeStep()
Called at the end of Time::adjustDeltaT() if adjustTime is true.
const word & name() const
Return name.
virtual bool end() const
Return true if end of run,.
A class for handling words, derived from Foam::string.
A class for handling file names.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
virtual void addWatches(regIOobject &, const fileNameList &) const
Helper: add watches for list of regIOobjects.
static std::string path(const std::string &str)
Return directory path name (part before last /)
Template functions to aid in the implementation of demand driven data.
static const Enum< writeControls > writeControlNames
Names for writeControls.
const fileName & instance() const
static label nProcs(const label communicator=0)
Number of processes in parallel run.
static std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
int system(const std::string &command, const bool bg=false)
Execute the specified command via the shell.
static bool & parRun()
Is this a parallel run?
Info<< "Creating field kinetic energy K\n"<< endl;volScalarField K("K", 0.5 *magSqr(U));if(U.nOldTimes()){ volVectorField *Uold=&U.oldTime();volScalarField *Kold=&K.oldTime();*Kold==0.5 *magSqr(*Uold);while(Uold->nOldTimes()) { Uold=&Uold-> oldTime()
const word & name() const
Return const reference to name.
virtual stopAtControls stopAt() const
Return the stop control information.
Extract command arguments and options from the supplied argc and argv parameters.
const fileOperation & fileHandler()
Get current file handler.
void clear()
Clear all entries from the registry.
Ostream & endl(Ostream &os)
Add newline and flush stream.
const scalar & value() const
Return const reference to value.
bool equal(scalar val) const
True if values are equal (includes SMALL for rounding)
T lookupOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
dimensionedScalar sign(const dimensionedScalar &ds)
static word controlDictName
The default control dictionary name (normally "controlDict")
runTimeSource setTime(sourceTimes[sourceTimeIndex], sourceTimeIndex)
fmtflags
Supported time directory name formats.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Registry of regIOobjects.
int infoSwitch(const char *name, const int deflt=0)
Lookup info switch or add default value.
void deleteDemandDrivenData(DataPtr &dataPtr)
static const Enum< stopAtControls > stopAtControlNames
Names for stopAtControls.
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
static int precision_
Time directory name precision.
virtual word timeName() const
Return current time name.
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
void adjustDeltaT()
Adjust the time step so that writing occurs at the specified time.
The time value with time-stepping information, user-defined remapping, etc.
virtual ~Time()
Destructor.
registerInfoSwitch("printExecutionFormat", int, Foam::Time::printExecutionFormat_)
virtual TimeState subCycle(const label nSubCycles)
Set time to sub-cycle for the given number of steps.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
static void stop(const Time &owner)
Stop profiling, cleanup pool if possible.
virtual void setEndTime(const dimensionedScalar &endTime)
Reset end time.
word name(const complex &c)
Return string representation of complex.
static bool active()
True if profiling is allowed and is active.
dimensionedScalar log10(const dimensionedScalar &ds)
virtual void setTime(const Time &) const
Callback for time change.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
virtual Time & operator+=(const dimensionedScalar &deltaT)
Set deltaT to that specified and increment time via operator++()
#define addProfiling(name, descr)
Define profiling trigger with specified name and description string.
static HashTable< string > validOptions
A list of valid options.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
virtual bool loop()
Return true if run should continue and if so increment time.
virtual Time & operator++()
Prefix increment,.
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
"adjustable" / "adjustableRunTime"
static autoPtr< Time > New()
Construct dummy time, without functionObjects or libraries.
Inter-processor communication reduction functions.
Address the time paths without using the Time class.
word findInstance(const fileName &dir, const word &name=word::null, const IOobject::readOption rOpt=IOobject::MUST_READ, const word &stopInstance=word::null) const
Time(const word &ctrlDictName, const argList &args, const word &systemName="system", const word &constantName="constant")
Construct given name of dictionary to read and argument list.
errorManipArg< error, int > exit(error &err, const int errNo=1)
virtual bool removeWatch(const label) const
Remove watch on a file (using handle)
static void initialize(const IOobject &ioObj, const Time &owner)
Singleton to initialize profiling pool, everything enabled.
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
const T & name() const
The name/key (const access)
virtual void setDeltaT(const dimensionedScalar &deltaT, const bool adjust=true)
Reset time step, normally also calling adjustDeltaT()
word findInstancePath(const fileName &directory, const instant &t) const
void readModifiedObjects()
Read the objects that have been modified.
Triggers for starting/stopping code profiling.
static int printExecutionFormat_
Style for "ExecutionTime = " output.
bool exists(IOobject &io) const
Does ioobject exist. Is either a directory (empty name()) or.
static const int maxPrecision_
Maximum time directory name precision.
virtual void setTime(const Time &t)
Reset the time and time-index to those of the given time.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
scalar value() const
The value (const access)
static fmtflags format_
Time directory name format.
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
static const word null
An empty word.
#define forAllReverse(list, i)
Reverse loop across all elements in list.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
virtual bool isAdjustTimeStep() const
Return true if adjustTimeStep is true.
virtual dimensionedScalar endTime() const
Return end time.
An instant of time. Contains the time value and name.
void setMonitoring(const bool forceProfiling=false)
Set file monitoring, profiling, etc.
dictionary & controlDict()
readOption
Enumeration defining the read options.
virtual void endSubCycle()
Reset time after sub-cycling back to previous TimeState.
void setControls()
Set the controls from the current controlDict.
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
Foam::argList args(argc, argv)
constant condensation/saturation model.
writeControls writeControl_
virtual bool run() const
Return true if run should continue,.
defineTypeNameAndDebug(combustionModel, 0)
virtual dimensionedScalar startTime() const
Return start time.
#define WarningInFunction
Report a warning using Foam::Warning.
virtual label startTimeIndex() const
Return start time index.
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
virtual void subCycleIndex(const label index)
Adjust the reported sub-cycle index.
bool found(const word &optName) const
Return true if the named option is found.