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" },
78 IOstreamOption::floatFormat::general
94 "printExecutionFormat",
104 bool adjustTime =
false;
105 scalar timeToNextWrite = VGREAT;
110 timeToNextWrite =
max
119 scalar nSteps = timeToNextWrite/
deltaT_;
125 label nStepsToNextWrite =
max(1, round(nSteps));
127 scalar newDeltaT = timeToNextWrite/nStepsToNextWrite;
149 const word startFrom = controlDict_.getOrDefault<
word>
155 if (startFrom ==
"startTime")
157 controlDict_.readEntry(
"startTime", startTime_);
164 const label nTimes = timeDirs.size();
166 if (startFrom ==
"firstTime")
168 if (nTimes > 1 && timeDirs.front().name() ==
constant())
170 startTime_ = timeDirs[1].value();
174 startTime_ = timeDirs.front().value();
177 else if (startFrom ==
"latestTime")
181 startTime_ = timeDirs.back().value();
187 <<
"expected startTime, firstTime or latestTime"
188 <<
" found '" << startFrom <<
"'"
196 deltaTSave_ = deltaT_;
208 const int oldPrecision = precision_;
209 int requiredPrecision = -1;
213 precision_ = maxPrecision_;
214 precision_ > oldPrecision;
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))
295 if (timeDict.readIfPresent(
"deltaT", deltaT_))
297 deltaTSave_ = deltaT_;
302 timeDict.readIfPresent(
"deltaT0", deltaT0_);
304 if (timeDict.readIfPresent(
"index", startTimeIndex_))
306 timeIndex_ = startTimeIndex_;
313 bool checkValue =
true;
315 string storedTimeName;
316 if (timeDict.readIfPresent(
"name", storedTimeName))
330 scalar storedTimeValue;
331 if (timeDict.readIfPresent(
"value", 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."
383 && profilingDict->getOrDefault(
"active",
true)
404 if (runTimeModifiable_)
413 fileHandler().addWatches(controlDict_, controlDict_.files());
417 controlDict_.files().
clear();
425 const word& ctrlDictName,
428 const word& systemDirName,
429 const word& constantDirName,
430 const bool enableFunctionObjects,
431 const bool enableLibs,
435 TimePaths(rootPath, caseName, systemDirName, constantDirName),
437 loopProfiling_(nullptr),
458 writeControl_(wcTimeStep),
459 writeInterval_(GREAT),
463 sigWriteNow_(*this, true),
464 sigStopAtWriteNow_(*this, true),
467 runTimeModifiable_(false),
468 cacheTemporaryObjects_(true),
469 functionObjects_(*this, false)
471 if (enableFunctionObjects)
473 functionObjects_.
on();
478 libs_.
open(
"libs", controlDict_);
492 const word& ctrlDictName,
494 const word& systemDirName,
495 const word& constantDirName,
496 const bool enableFunctionObjects,
497 const bool enableLibs,
503 loopProfiling_(nullptr),
524 writeControl_(wcTimeStep),
525 writeInterval_(GREAT),
529 sigWriteNow_(*this, true),
530 sigStopAtWriteNow_(*this, true),
533 runTimeModifiable_(false),
534 cacheTemporaryObjects_(true),
535 functionObjects_(*this, false)
542 if (enableFunctionObjects &&
args.allowFunctionObjects())
544 functionObjects_.on();
550 if (enableLibs &&
args.allowLibs())
552 libs_.open(
"libs", controlDict_);
571 const word& systemDirName,
572 const word& constantDirName,
573 const bool enableFunctionObjects,
574 const bool enableLibs,
578 TimePaths(rootPath, caseName, systemDirName, constantDirName),
580 loopProfiling_(nullptr),
588 Time::controlDictName,
603 writeControl_(wcTimeStep),
604 writeInterval_(GREAT),
608 sigWriteNow_(*this, true),
609 sigStopAtWriteNow_(*this, true),
612 runTimeModifiable_(false),
613 cacheTemporaryObjects_(true),
614 functionObjects_(*this, false)
616 if (enableFunctionObjects)
618 functionObjects_.
on();
623 libs_.
open(
"libs", controlDict_);
632 controlDict_.readOpt(rOpt);
643 const word& systemDirName,
644 const word& constantDirName,
645 const bool enableFunctionObjects,
646 const bool enableLibs
649 TimePaths(rootPath, caseName, systemDirName, constantDirName),
651 loopProfiling_(nullptr),
658 Time::controlDictName,
672 writeControl_(wcTimeStep),
673 writeInterval_(GREAT),
679 runTimeModifiable_(false),
680 cacheTemporaryObjects_(true),
681 functionObjects_(*this, false)
683 if (enableFunctionObjects)
685 functionObjects_.
on();
690 libs_.
open(
"libs", controlDict_);
701 loopProfiling_.reset(
nullptr);
705 fileHandler().removeWatch(controlDict_.watchIndices()[i]);
709 functionObjects_.clear();
723 std::ostringstream buf;
724 buf.setf(std::ios_base::fmtflags(
format_), std::ios_base::floatfield);
725 buf.precision(precision);
736 const word& stopInstance,
737 const bool constant_fallback
744 scalar startValue = timeOutputValue();
756 return io.instance();
786 loopProfiling_.reset(
nullptr);
788 bool isRunning = value() < (endTime_ - 0.5*deltaT_);
794 if (!isRunning && timeIndex_ != startTimeIndex_)
800 functionObjects_.execute();
804 functionObjects_.end();
807 if (cacheTemporaryObjects_)
809 cacheTemporaryObjects_ = checkCacheTemporaryObjects();
820 if (timeIndex_ == startTimeIndex_)
823 functionObjects_.start();
828 functionObjects_.execute();
837 if (functionObjects_.filesModified())
842 if (cacheTemporaryObjects_)
844 cacheTemporaryObjects_ = checkCacheTemporaryObjects();
850 isRunning = value() < (endTime_ - 0.5*deltaT_);
868 const bool isRunning = run();
887 if (stopCtrl == stopAtControls::saUnknown)
892 const bool changed = (stopAt_ != stopCtrl);
897 if (stopCtrl == stopAtControls::saEndTime)
908 return controlDict_.getOrDefault(
"adjustTimeStep",
false);
921 resetTimeState(inst.
name(), inst.
value(), newIndex);
938 timeDict.readIfPresent(
"deltaT0",
deltaT0_);
987 deltaTchanged_ =
true;
1002 <<
"previous time state already set" <<
nl
1007 prevTimeState_.reset(
new TimeState(*
this));
1010 deltaT_ /= nSubCycles;
1011 deltaT0_ /= nSubCycles;
1012 deltaTSave_ = deltaT0_;
1037 TimeState::operator=(prevTimeState());
1038 prevTimeState_.reset(
nullptr);
1062 deltaT0_ = deltaTSave_;
1063 deltaTSave_ = deltaT_;
1066 const scalar oldTimeValue = timeToUserTime(value());
1070 setTime(value() + deltaT_, timeIndex_ + 1);
1075 if (
mag(value()) < 10*SMALL*deltaT_)
1080 if (sigStopAtWriteNow_.active() || sigWriteNow_.active())
1086 if (sigStopAtWriteNow_.active() && stopAt_ == saWriteNow)
1090 if (sigWriteNow_.active() && writeOnce_)
1098 stopAt_ = saWriteNow;
1108 switch (writeControl_)
1115 writeTime_ = !(timeIndex_ % label(writeInterval_));
1119 case wcAdjustableRunTime:
1121 const label writeIndex = label
1123 ((value() - startTime_) + 0.5*deltaT_)
1127 if (writeIndex > writeTimeIndex_)
1130 writeTimeIndex_ = writeIndex;
1137 const label writeIndex = label
1142 if (writeIndex > writeTimeIndex_)
1145 writeTimeIndex_ = writeIndex;
1152 const label writeIndex = label
1157 if (writeIndex > writeTimeIndex_)
1160 writeTimeIndex_ = writeIndex;
1170 if (stopAt_ == saNoWriteNow)
1174 else if (stopAt_ == saWriteNow)
1179 else if (stopAt_ == saNextWrite && writeTime_ ==
true)
1196 const scalar userDeltaT =
1197 timeToUserTime(value()) - timeToUserTime(value() - deltaT_);
1200 const scalar timeTol =
1201 max(
min(
pow(scalar(10), -precision_), 0.1*userDeltaT), SMALL);
1204 scalar timeNameValue = -VGREAT;
1211 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1214 int oldPrecision = precision_;
1217 precision_ < maxPrecision_
1219 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1226 if (precision_ != oldPrecision)
1229 <<
"Increased the timePrecision from " << oldPrecision
1230 <<
" to " << precision_
1231 <<
" to distinguish between timeNames at time "
1235 if (precision_ == maxPrecision_)
1241 <<
" The maximum time precision has been reached"
1242 " which might result in overwriting previous"
1248 scalar oldTimeNameValue = -VGREAT;
1251 readScalar(oldTimeName, oldTimeNameValue)
1253 sign(timeNameValue - oldTimeNameValue)
1260 <<
" is set to an instance prior to the "
1262 << oldTimeName <<
nl
1263 <<
" This might result in temporal "
1278 return operator++();
Inter-processor communication reduction functions.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
A simple container of IOobject preferences. Can also be used for general handling of read/no-read/rea...
@ NO_REGISTER
Do not request registration (bool: false).
@ REGISTER
Request registration (bool: true).
readOption readOpt() const noexcept
Get the read option.
readOption
Enumeration defining read preferences.
@ NO_READ
Nothing to be read.
@ LAZY_READ
Reading is optional [identical to READ_IF_PRESENT].
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
@ AUTO_WRITE
Automatically write from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
const word & name() const noexcept
Return the object name.
A simple container for options an IOstream can normally have.
floatFormat
Float formats (eg, time directory name formats).
scalar value() const noexcept
The value (const access).
const T & name() const noexcept
The name/key (const access).
Address the time paths without using the Time class.
const word & system() const noexcept
Return system name.
const word & constant() const noexcept
Return constant name.
static instantList findTimes(const fileName &directory, const word &constantDirName="constant")
Search a given directory for valid time directories.
TimePaths(const bool processorCase, const fileName &rootPath, const bool distributed, const fileName &globalCaseName, const fileName &caseName, const word &systemDirName="system", const word &constantDirName="constant")
Construct from all components.
The time value with time-stepping information, user-defined remapping, etc.
TimeState()
Construct a zero time state, using the current time formatting.
virtual scalar timeToUserTime(const scalar t) const
Convert the real-time (s) into user-time (e.g. CA deg).
scalar timeOutputValue() const
Return the current user-time value. (ie, after applying any timeToUserTime() conversion).
void resetTimeState(const word &newName, const scalar newValue, const label newIndex)
Reset some of TimeState (name, value, index).
label timeIndex() const noexcept
Return the current time index.
dimensionedScalar deltaT() const
Return time step.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
virtual bool isAdjustTimeStep() const
Return true if adjustTimeStep is true.
virtual bool run() const
Return true if run should continue,.
virtual void readDict()
Read the control dictionary and set the write controls etc.
static int precision_
Time directory name precision.
virtual void setDeltaT(const dimensionedScalar &deltaT, const bool adjust=true)
Reset time step, normally also calling adjustDeltaT().
static const Enum< stopAtControls > stopAtControlNames
Names for stopAtControls.
virtual dimensionedScalar startTime() const
Return start time.
static IOstreamOption::floatFormat format_
Format for time directory names (general | fixed | scientific).
writeControls
Write control options.
@ wcAdjustableRunTime
"adjustable" / "adjustableRunTime"
sigStopAtWriteNow sigStopAtWriteNow_
Signal handler for write and clean exit upon signal.
void setMonitoring(const bool forceProfiling=false)
Set file monitoring, profiling, etc.
void adjustDeltaT()
Adjust the time step so that writing occurs at the specified time.
static int printExecutionFormat_
Style for "ExecutionTime = " output.
const fileName & rootPath() const noexcept
The root path.
static const int maxPrecision_
Maximum time directory name precision.
autoPtr< TimeState > prevTimeState_
If time is being sub-cycled this is the previous TimeState.
word findInstance(const fileName &directory, const word &name=word::null, IOobjectOption::readOption rOpt=IOobjectOption::MUST_READ, const word &stopInstance=word::null, const bool constant_fallback=true) const
Return time instance (location) of directory containing the file name (eg, used in reading mesh data)...
stopAtControls
Stop-run control options, which are primarily used when altering the stopAt condition.
@ saNoWriteNow
Adjust endTime to stop immediately w/o writing.
@ saWriteNow
adjust endTime to stop immediately w/ writing
@ saUnknown
Dummy no-op. Do not change current value.
@ saEndTime
Stop when Time reaches prescribed endTime.
@ saNextWrite
stop at the next data write interval
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
writeControls writeControl_
sigWriteNow sigWriteNow_
Signal handler for one-shot writing upon signal.
void setControls()
Set the controls from the current controlDict.
static word controlDictName
The default control dictionary name (normally "controlDict").
virtual void setEndTime(const dimensionedScalar &endTime)
Reset end time.
const functionObjectList & functionObjects() const noexcept
Return the list of function objects.
static const Enum< writeControls > writeControlNames
Names for writeControls.
virtual stopAtControls stopAt() const
Return the stop control information.
virtual label startTimeIndex() const
Return start time index.
label subCycling_
The total number of sub-cycles, the current sub-cycle index, or 0 if time is not being sub-cycled.
virtual void endSubCycle()
Reset time after sub-cycling back to previous TimeState.
virtual void subCycleIndex(const label index)
Adjust the reported sub-cycle index.
virtual Time & operator++()
Prefix increment,.
const TimeState & prevTimeState() const
Return previous TimeState if time is being sub-cycled.
void readModifiedObjects()
Read the objects that have been modified.
fileName timePath() const
Return current time path = path/timeName.
virtual TimeState subCycle(const label nSubCycles)
Set time to sub-cycle for the given number of steps.
virtual bool loop()
Return true if run should continue and if so increment time.
virtual dimensionedScalar endTime() const
Return end time.
const word & timeName() const noexcept
The current time name.
virtual void setTime(const Time &t)
Reset the time and time-index to those of the given time.
virtual ~Time()
Destructor.
virtual bool end() const
Return true if end of run,.
const fileName & caseName() const noexcept
The case name.
virtual Time & operator+=(const dimensionedScalar &deltaT)
Set deltaT to that specified and increment time via operator++().
Time(const word &ctrlDictName, const argList &args, const bool enableFunctionObjects=true, const bool enableLibs=true, IOobjectOption::readOption rOpt=IOobjectOption::READ_MODIFIED)
Construct from argument list, reading from specified control dictionary name.
T & back()
Access last element of the list, position [size()-1].
T & front()
Access first element of the list, position [0].
void size(const label n)
Older name for setAddressableSize.
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Negative if the process is not a...
static bool parRun(const bool on) noexcept
Set as parallel run on/off.
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run.
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
@ broadcast
broadcast [MPI]
Extract command arguments and options from the supplied argc and argv parameters.
double elapsedClockTime() const
Returns wall-clock time since clock instantiation.
double elapsedCpuTime() const
Return CPU time [seconds] from the start.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
const dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary pointer if present (and it is a dictionary) otherwise return nullptr...
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
void clear()
Clear the dictionary.
const word & name() const noexcept
const scalar & value() const noexcept
bool open(bool verbose=true)
Open named, but unopened libraries. These names will normally have been added with push_back().
A class for handling file names.
bool adjustTimeStep()
Called at the end of Time::adjustDeltaT() if adjustTime is true.
void on()
Switch the function objects on.
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name.
Registry of regIOobjects.
bool checkCacheTemporaryObjects() const
Check that all objects specified in the cacheTemporaryObjects were also cached.
void clear()
Clear all entries from the registry.
Triggers for starting/stopping code profiling.
static bool active() noexcept
True if profiling is allowed and is active.
static void stop(const Time &owner)
Stop profiling, cleanup pool if possible.
static void initialize(const IOobject &ioObj, const Time &owner)
Singleton to initialize profiling pool, everything enabled.
virtual fileName filePath() const
Return complete path + object name if the file exists.
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
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()
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
runTimeSource setTime(sourceTimes[sourceTimeIndex], sourceTimeIndex)
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
#define WarningInFunction
Report a warning using Foam::Warning.
Different types of constants.
int infoSwitch(const char *name, const int deflt=0)
Lookup info switch or add default value.
dictionary & controlDict()
The central control dictionary, the contents of which are either taken directly from the FOAM_CONTROL...
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
bool returnReduceOr(const bool value, const int communicator=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
dimensionedScalar sign(const dimensionedScalar &ds)
int system(const std::string &command, const bool bg=false)
Execute the specified command via the shell.
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler().
dimensionedScalar log10(const dimensionedScalar &ds)
List< instant > instantList
List of instants.
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
T returnReduce(const T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
Ostream & endl(Ostream &os)
Add newline and flush stream.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
void reduce(T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce).
bool returnReduceAnd(const bool value, const int communicator=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a).
#define addProfiling(Name,...)
Define profiling trigger with specified name and description string. The description is generated by ...
#define registerInfoSwitch(Name, Type, SwitchVar)
Foam::argList args(argc, argv)
#define forAllReverse(list, i)
Reverse loop across all elements in list.