Go to the documentation of this file.
51 { stopAtControls::saEndTime,
"endTime" },
52 { stopAtControls::saNoWriteNow,
"noWriteNow" },
53 { stopAtControls::saWriteNow,
"writeNow" },
54 { stopAtControls::saNextWrite,
"nextWrite" },
65 { writeControls::wcNone,
"none" },
66 { writeControls::wcTimeStep,
"timeStep" },
67 { writeControls::wcRunTime,
"runTime" },
68 { writeControls::wcAdjustableRunTime,
"adjustable" },
69 { writeControls::wcAdjustableRunTime,
"adjustableRunTime" },
70 { writeControls::wcClockTime,
"clockTime" },
71 { writeControls::wcCpuTime,
"cpuTime" },
91 "printExecutionFormat",
101 bool adjustTime =
false;
102 scalar timeToNextWrite = VGREAT;
107 timeToNextWrite =
max
116 scalar nSteps = timeToNextWrite/
deltaT_;
122 label nStepsToNextWrite =
max(1, round(nSteps));
124 scalar newDeltaT = timeToNextWrite/nStepsToNextWrite;
146 const word startFrom = controlDict_.getOrDefault<
word>
152 if (startFrom ==
"startTime")
154 controlDict_.readEntry(
"startTime", startTime_);
161 const label nTimes = timeDirs.size();
163 if (startFrom ==
"firstTime")
165 if (nTimes > 1 && timeDirs.first().name() ==
constant())
167 startTime_ = timeDirs[1].value();
171 startTime_ = timeDirs.first().value();
174 else if (startFrom ==
"latestTime")
178 startTime_ = timeDirs.last().value();
184 <<
"expected startTime, firstTime or latestTime"
185 <<
" found '" << startFrom <<
"'"
193 deltaTSave_ = deltaT_;
202 int oldPrecision = precision_;
203 int requiredPrecision = -1;
208 precision_ = maxPrecision_;
209 precision_ > oldPrecision;
226 found = !dirName.empty();
230 requiredPrecision = precision_;
234 if (requiredPrecision > 0)
237 precision_ = requiredPrecision;
243 <<
"Increasing the timePrecision from " << oldPrecision
244 <<
" to " << precision_
245 <<
" to support the formatting of the current time directory "
251 precision_ = oldPrecision;
260 scalar sumStartTime = startTime_;
269 <<
"Start time is not the same for all processors" <<
nl
291 if (controlDict_.getOrDefault(
"adjustTimeStep",
false))
295 deltaTSave_ = deltaT_;
304 timeIndex_ = startTimeIndex_;
311 bool checkValue =
true;
313 string storedTimeName;
328 scalar storedTimeValue;
336 <<
"Time read from time dictionary " << storedTimeName
337 <<
" differs from actual time " <<
timeName() <<
'.' <<
nl
338 <<
" This may cause unexpected database behaviour."
339 <<
" If you are not interested" <<
nl
340 <<
" in preserving time state delete"
341 <<
" the time dictionary."
400 if (runTimeModifiable_)
407 controlDict_.files().clear();
415 const word& ctrlDictName,
418 const word& systemName,
419 const word& constantName,
420 const bool enableFunctionObjects,
421 const bool enableLibs
434 loopProfiling_(
nullptr),
455 writeControl_(wcTimeStep),
456 writeInterval_(GREAT),
460 sigWriteNow_(*
this,
true),
461 sigStopAtWriteNow_(*
this,
true),
464 runTimeModifiable_(
false),
465 functionObjects_(*
this,
false)
467 if (enableFunctionObjects)
469 functionObjects_.on();
474 libs_.open(
"libs", controlDict_);
488 const word& ctrlDictName,
490 const word& systemName,
491 const word& constantName,
492 const bool enableFunctionObjects,
493 const bool enableLibs
500 loopProfiling_(
nullptr),
521 writeControl_(wcTimeStep),
522 writeInterval_(GREAT),
526 sigWriteNow_(*
this,
true),
527 sigStopAtWriteNow_(*
this,
true),
530 runTimeModifiable_(
false),
531 functionObjects_(*
this,
false)
547 if (enableFunctionObjects)
549 functionObjects_.on();
556 if (enableLibs && !
args.
found(
"no-libs"))
558 libs_.open(
"libs", controlDict_);
577 const word& systemName,
578 const word& constantName,
579 const bool enableFunctionObjects,
580 const bool enableLibs
593 loopProfiling_(
nullptr),
615 writeControl_(wcTimeStep),
616 writeInterval_(GREAT),
620 sigWriteNow_(*
this,
true),
621 sigStopAtWriteNow_(*
this,
true),
624 runTimeModifiable_(
false),
625 functionObjects_(*
this,
false)
627 if (enableFunctionObjects)
629 functionObjects_.on();
634 libs_.open(
"libs", controlDict_);
654 const word& systemName,
655 const word& constantName,
656 const bool enableFunctionObjects,
657 const bool enableLibs
670 loopProfiling_(
nullptr),
691 writeControl_(wcTimeStep),
692 writeInterval_(GREAT),
698 runTimeModifiable_(
false),
699 functionObjects_(*
this,
false)
701 if (enableFunctionObjects)
703 functionObjects_.on();
708 libs_.open(
"libs", controlDict_);
760 loopProfiling_.reset(
nullptr);
768 functionObjects_.clear();
782 std::ostringstream buf;
783 buf.setf(ios_base::fmtflags(format_), ios_base::floatfield);
784 buf.precision(precision);
801 const word& stopInstance
845 if (t.
equal(timeDirs[i].value()))
847 return timeDirs[i].name();
857 return findInstancePath(
path(), t);
863 return startTimeIndex_;
887 loopProfiling_.reset(
nullptr);
889 bool isRunning = value() < (endTime_ - 0.5*deltaT_);
895 if (!isRunning && timeIndex_ != startTimeIndex_)
901 functionObjects_.execute();
905 functionObjects_.end();
916 if (timeIndex_ == startTimeIndex_)
918 addProfiling(functionObjects,
"functionObjects.start()");
919 functionObjects_.start();
923 addProfiling(functionObjects,
"functionObjects.execute()");
924 functionObjects_.execute();
933 if (functionObjects_.filesModified())
941 isRunning = value() < (endTime_ - 0.5*deltaT_);
959 const bool isRunning = run();
972 return value() > (endTime_ + 0.5*deltaT_);
978 if (stopCtrl == stopAtControls::saUnknown)
983 const bool changed = (stopAt_ != stopCtrl);
988 if (stopCtrl == stopAtControls::saEndTime)
990 controlDict_.readEntry(
"endTime", endTime_);
999 return controlDict_.getOrDefault(
"adjustTimeStep",
false);
1005 value() = t.
value();
1014 value() = inst.
value();
1016 timeIndex_ = newIndex;
1049 timeIndex_ = newIndex;
1056 setEndTime(endTime.
value());
1072 setDeltaT(deltaT.
value(), adjust);
1079 deltaTchanged_ =
true;
1094 <<
"previous time state already set" <<
nl
1099 prevTimeState_.reset(
new TimeState(*
this));
1102 deltaT_ /= nSubCycles;
1103 deltaT0_ /= nSubCycles;
1104 deltaTSave_ = deltaT0_;
1106 subCycling_ = nSubCycles;
1108 return prevTimeState();
1118 if (subCycling_ && index > 0)
1120 subCycling_ = index;
1129 TimeState::operator=(prevTimeState());
1130 prevTimeState_.reset(
nullptr);
1141 return operator+=(deltaT.
value());
1148 return operator++();
1154 deltaT0_ = deltaTSave_;
1155 deltaTSave_ = deltaT_;
1158 const scalar oldTimeValue = timeToUserTime(value());
1162 setTime(value() + deltaT_, timeIndex_ + 1);
1167 if (
mag(value()) < 10*SMALL*deltaT_)
1172 if (sigStopAtWriteNow_.active() || sigWriteNow_.active())
1178 if (sigStopAtWriteNow_.active() && stopAt_ == saWriteNow)
1182 if (sigWriteNow_.active() && writeOnce_)
1190 stopAt_ = saWriteNow;
1200 switch (writeControl_)
1207 writeTime_ = !(timeIndex_ % label(writeInterval_));
1211 case wcAdjustableRunTime:
1213 const label writeIndex = label
1215 ((value() - startTime_) + 0.5*deltaT_)
1219 if (writeIndex > writeTimeIndex_)
1222 writeTimeIndex_ = writeIndex;
1229 const label writeIndex = label
1234 if (writeIndex > writeTimeIndex_)
1237 writeTimeIndex_ = writeIndex;
1244 const label writeIndex = label
1249 if (writeIndex > writeTimeIndex_)
1252 writeTimeIndex_ = writeIndex;
1262 if (stopAt_ == saNoWriteNow)
1266 else if (stopAt_ == saWriteNow)
1271 else if (stopAt_ == saNextWrite && writeTime_ ==
true)
1288 const scalar timeTol =
1289 max(
min(
pow(10.0, -precision_), 0.1*deltaT_), SMALL);
1292 const scalar userDeltaT = timeToUserTime(deltaT_);
1295 scalar timeNameValue = -VGREAT;
1302 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1305 int oldPrecision = precision_;
1308 precision_ < maxPrecision_
1310 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1317 if (precision_ != oldPrecision)
1320 <<
"Increased the timePrecision from " << oldPrecision
1321 <<
" to " << precision_
1322 <<
" to distinguish between timeNames at time "
1326 if (precision_ == maxPrecision_)
1332 <<
" The maximum time precision has been reached"
1333 " which might result in overwriting previous"
1339 scalar oldTimeNameValue = -VGREAT;
1342 readScalar(oldTimeName, oldTimeNameValue)
1344 sign(timeNameValue - oldTimeNameValue)
1351 <<
" is set to an instance prior to the "
1353 << oldTimeName <<
nl
1354 <<
" This might result in temporal "
1369 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.
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)
const fileName & instance() const noexcept
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 /)
static const Enum< writeControls > writeControlNames
Names for writeControls.
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.
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 Type & 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.
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.
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.
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()
const word & name() const noexcept
Return name.
word findInstancePath(const fileName &directory, const instant &t) const
void readModifiedObjects()
Read the objects that have been modified.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Triggers for starting/stopping code profiling.
static int printExecutionFormat_
Style for "ExecutionTime = " output.
static int myProcNo(const label communicator=worldComm)
Number of this process (starting from masterNo() = 0)
static bool & parRun() noexcept
Test if this a parallel run.
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.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
#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.
static label nProcs(const label communicator=worldComm)
Number of processes in parallel run, and 1 for serial run.
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.