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_.getOrDefault<
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_;
204 int oldPrecision = precision_;
205 int requiredPrecision = -1;
210 precision_ = maxPrecision_;
211 precision_ > oldPrecision;
228 found = !dirName.empty();
232 requiredPrecision = precision_;
236 if (requiredPrecision > 0)
239 precision_ = requiredPrecision;
245 <<
"Increasing the timePrecision from " << oldPrecision
246 <<
" to " << precision_
247 <<
" to support the formatting of the current time directory "
253 precision_ = oldPrecision;
262 scalar sumStartTime = startTime_;
271 <<
"Start time is not the same for all processors" <<
nl
293 if (controlDict_.getOrDefault(
"adjustTimeStep",
false))
297 deltaTSave_ = deltaT_;
306 timeIndex_ = startTimeIndex_;
313 bool checkValue =
true;
315 string storedTimeName;
330 scalar storedTimeValue;
338 <<
"Time read from time dictionary " << storedTimeName
339 <<
" differs from actual time " <<
timeName() <<
'.' <<
nl
340 <<
" This may cause unexpected database behaviour."
341 <<
" If you are not interested" <<
nl
342 <<
" in preserving time state delete"
343 <<
" the time dictionary."
402 if (runTimeModifiable_)
409 controlDict_.files().clear();
417 const word& ctrlDictName,
420 const word& systemName,
421 const word& constantName,
422 const bool enableFunctionObjects,
423 const bool enableLibs
436 loopProfiling_(
nullptr),
457 writeControl_(wcTimeStep),
458 writeInterval_(GREAT),
462 sigWriteNow_(*
this,
true),
463 sigStopAtWriteNow_(*
this,
true),
466 runTimeModifiable_(
false),
467 functionObjects_(*
this,
false)
469 if (enableFunctionObjects)
471 functionObjects_.on();
476 libs_.open(controlDict_,
"libs");
490 const word& ctrlDictName,
492 const word& systemName,
493 const word& constantName,
494 const bool enableFunctionObjects,
495 const bool enableLibs
502 loopProfiling_(
nullptr),
523 writeControl_(wcTimeStep),
524 writeInterval_(GREAT),
528 sigWriteNow_(*
this,
true),
529 sigStopAtWriteNow_(*
this,
true),
532 runTimeModifiable_(
false),
533 functionObjects_(*
this,
false)
549 if (enableFunctionObjects)
551 functionObjects_.on();
562 libs_.open(controlDict_,
"libs");
582 const word& systemName,
583 const word& constantName,
584 const bool enableFunctionObjects,
585 const bool enableLibs
598 loopProfiling_(
nullptr),
620 writeControl_(wcTimeStep),
621 writeInterval_(GREAT),
625 sigWriteNow_(*
this,
true),
626 sigStopAtWriteNow_(*
this,
true),
629 runTimeModifiable_(
false),
630 functionObjects_(*
this,
false)
632 if (enableFunctionObjects)
634 functionObjects_.on();
639 libs_.open(controlDict_,
"libs");
659 const word& systemName,
660 const word& constantName,
661 const bool enableFunctionObjects,
662 const bool enableLibs
675 loopProfiling_(
nullptr),
696 writeControl_(wcTimeStep),
697 writeInterval_(GREAT),
703 runTimeModifiable_(
false),
704 functionObjects_(*
this,
false)
706 if (enableFunctionObjects)
708 functionObjects_.on();
713 libs_.open(controlDict_,
"libs");
773 functionObjects_.clear();
787 std::ostringstream buf;
788 buf.setf(ios_base::fmtflags(format_), ios_base::floatfield);
789 buf.precision(precision);
806 const word& stopInstance
850 if (t.
equal(timeDirs[i].value()))
852 return timeDirs[i].name();
862 return findInstancePath(
path(), t);
868 return startTimeIndex_;
894 bool isRunning = value() < (endTime_ - 0.5*deltaT_);
900 if (!isRunning && timeIndex_ != startTimeIndex_)
906 functionObjects_.execute();
910 functionObjects_.end();
921 if (timeIndex_ == startTimeIndex_)
923 addProfiling(functionObjects,
"functionObjects.start()");
924 functionObjects_.start();
928 addProfiling(functionObjects,
"functionObjects.execute()");
929 functionObjects_.execute();
938 if (functionObjects_.filesModified())
946 isRunning = value() < (endTime_ - 0.5*deltaT_);
962 const bool isRunning = run();
975 return value() > (endTime_ + 0.5*deltaT_);
981 if (stopCtrl == stopAtControls::saUnknown)
986 const bool changed = (stopAt_ != stopCtrl);
991 if (stopCtrl == stopAtControls::saEndTime)
993 controlDict_.readEntry(
"endTime", endTime_);
1002 return controlDict_.getOrDefault(
"adjustTimeStep",
false);
1008 value() = t.
value();
1017 value() = inst.
value();
1019 timeIndex_ = newIndex;
1052 timeIndex_ = newIndex;
1059 setEndTime(endTime.
value());
1075 setDeltaT(deltaT.
value(), adjust);
1082 deltaTchanged_ =
true;
1093 prevTimeState_.set(
new TimeState(*
this));
1096 deltaT_ /= nSubCycles;
1097 deltaT0_ /= nSubCycles;
1098 deltaTSave_ = deltaT0_;
1100 subCycling_ = nSubCycles;
1102 return prevTimeState();
1112 if (subCycling_ && index > 0)
1114 subCycling_ = index;
1123 TimeState::operator=(prevTimeState());
1124 prevTimeState_.clear();
1135 return operator+=(deltaT.
value());
1142 return operator++();
1148 deltaT0_ = deltaTSave_;
1149 deltaTSave_ = deltaT_;
1152 const scalar oldTimeValue = timeToUserTime(value());
1156 setTime(value() + deltaT_, timeIndex_ + 1);
1161 if (
mag(value()) < 10*SMALL*deltaT_)
1166 if (sigStopAtWriteNow_.active() || sigWriteNow_.active())
1172 if (sigStopAtWriteNow_.active() && stopAt_ == saWriteNow)
1176 if (sigWriteNow_.active() && writeOnce_)
1184 stopAt_ = saWriteNow;
1194 switch (writeControl_)
1201 writeTime_ = !(timeIndex_ % label(writeInterval_));
1205 case wcAdjustableRunTime:
1207 const label writeIndex = label
1209 ((value() - startTime_) + 0.5*deltaT_)
1213 if (writeIndex > writeTimeIndex_)
1216 writeTimeIndex_ = writeIndex;
1223 const label writeIndex = label
1228 if (writeIndex > writeTimeIndex_)
1231 writeTimeIndex_ = writeIndex;
1238 const label writeIndex = label
1243 if (writeIndex > writeTimeIndex_)
1246 writeTimeIndex_ = writeIndex;
1256 if (stopAt_ == saNoWriteNow)
1260 else if (stopAt_ == saWriteNow)
1265 else if (stopAt_ == saNextWrite && writeTime_ ==
true)
1282 const scalar timeTol =
1283 max(
min(
pow(10.0, -precision_), 0.1*deltaT_), SMALL);
1286 const scalar userDeltaT = timeToUserTime(deltaT_);
1289 scalar timeNameValue = -VGREAT;
1296 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1299 int oldPrecision = precision_;
1302 precision_ < maxPrecision_
1304 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1311 if (precision_ != oldPrecision)
1314 <<
"Increased the timePrecision from " << oldPrecision
1315 <<
" to " << precision_
1316 <<
" to distinguish between timeNames at time "
1320 if (precision_ == maxPrecision_)
1326 <<
" The maximum time precision has been reached"
1327 " which might result in overwriting previous"
1333 scalar oldTimeNameValue = -VGREAT;
1336 readScalar(oldTimeName, oldTimeNameValue)
1338 sign(timeNameValue - oldTimeNameValue)
1345 <<
" is set to an instance prior to the "
1347 << oldTimeName <<
nl
1348 <<
" This might result in temporal "
1363 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...
Time(const word &ctrlDictName, const argList &args, const bool enableFunctionObjects=true, const bool enableLibs=true)
Construct from dictionary name to read and argument list.
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...
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)
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.
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 - no 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
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()
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
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.
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.
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
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.