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")
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."
363 profiling::initialize
383 profiling::initialize
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),
462 writeStreamOption_(
IOstream::ASCII),
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),
528 writeStreamOption_(
IOstream::ASCII),
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),
622 writeStreamOption_(
IOstream::ASCII),
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),
696 writeStreamOption_(
IOstream::ASCII),
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
839 if (t.
equal(timeDirs[i].value()))
841 return timeDirs[i].name();
851 return findInstancePath(
path(), t);
857 return startTimeIndex_;
881 loopProfiling_.reset(
nullptr);
883 bool isRunning = value() < (endTime_ - 0.5*deltaT_);
889 if (!isRunning && timeIndex_ != startTimeIndex_)
895 functionObjects_.execute();
899 functionObjects_.end();
910 if (timeIndex_ == startTimeIndex_)
912 addProfiling(functionObjects,
"functionObjects.start()");
913 functionObjects_.start();
917 addProfiling(functionObjects,
"functionObjects.execute()");
918 functionObjects_.execute();
927 if (functionObjects_.filesModified())
935 isRunning = value() < (endTime_ - 0.5*deltaT_);
953 const bool isRunning = run();
966 return value() > (endTime_ + 0.5*deltaT_);
972 if (stopCtrl == stopAtControls::saUnknown)
977 const bool changed = (stopAt_ != stopCtrl);
982 if (stopCtrl == stopAtControls::saEndTime)
984 controlDict_.readEntry(
"endTime", endTime_);
993 return controlDict_.getOrDefault(
"adjustTimeStep",
false);
1008 value() = inst.
value();
1010 timeIndex_ = newIndex;
1043 timeIndex_ = newIndex;
1050 setEndTime(endTime.
value());
1066 setDeltaT(deltaT.
value(), adjust);
1073 deltaTchanged_ =
true;
1088 <<
"previous time state already set" <<
nl
1093 prevTimeState_.reset(
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;
1124 prevTimeState_.reset(
nullptr);
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 userDeltaT =
1283 timeToUserTime(value()) - timeToUserTime(value() - deltaT_);
1286 const scalar timeTol =
1287 max(
min(
pow(scalar(10), -precision_), 0.1*userDeltaT), SMALL);
1290 scalar timeNameValue = -VGREAT;
1297 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1300 int oldPrecision = precision_;
1303 precision_ < maxPrecision_
1305 && (
mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
1312 if (precision_ != oldPrecision)
1315 <<
"Increased the timePrecision from " << oldPrecision
1316 <<
" to " << precision_
1317 <<
" to distinguish between timeNames at time "
1321 if (precision_ == maxPrecision_)
1327 <<
" The maximum time precision has been reached"
1328 " which might result in overwriting previous"
1334 scalar oldTimeNameValue = -VGREAT;
1337 readScalar(oldTimeName, oldTimeNameValue)
1339 sign(timeNameValue - oldTimeNameValue)
1346 <<
" is set to an instance prior to the "
1348 << oldTimeName <<
nl
1349 <<
" This might result in temporal "
1364 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...
Defines the attributes of an object for which implicit objectRegistry management is supported,...
readOption readOpt() const noexcept
The read option.
const fileName & instance() const noexcept
Read access to instance path component.
readOption
Enumeration defining the read options.
An IOstream is an abstract base class for all input/output systems; be they streams,...
scalar value() const noexcept
The value (const access)
const T & name() const noexcept
The name/key (const access)
bool equal(scalar val) const noexcept
True if values are equal (includes SMALL for rounding)
label nProcs() const noexcept
Number of ranks associated with PstreamBuffers.
Address the time paths without using the Time class.
The time value with time-stepping information, user-defined remapping, etc.
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,.
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 autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
writeControls
Write control options.
@ wcAdjustableRunTime
"adjustable" / "adjustableRunTime"
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.
static const int maxPrecision_
Maximum time directory name precision.
word findInstancePath(const fileName &directory, const instant &t) const
word findInstance(const fileName &dir, const word &name=word::null, const IOobject::readOption rOpt=IOobject::MUST_READ, const word &stopInstance=word::null) const
fmtflags
Supported time directory name formats.
static fmtflags format_
Time directory name format.
writeControls writeControl_
void setControls()
Set the controls from the current controlDict.
virtual word timeName() const
Return current time name.
static word controlDictName
The default control dictionary name (normally "controlDict")
virtual void setEndTime(const dimensionedScalar &endTime)
Reset end time.
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.
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,.
void readModifiedObjects()
Read the objects that have been modified.
virtual bool loop()
Return true if run should continue and if so increment time.
virtual dimensionedScalar endTime() const
Return end time.
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,.
virtual Time & operator+=(const dimensionedScalar &deltaT)
Set deltaT to that specified and increment time via operator++()
T & first()
Return the first element of the list.
void size(const label n)
Older name for setAddressableSize.
T & last()
Return the last element of the list.
static bool & parRun() noexcept
Test if this a parallel run.
Extract command arguments and options from the supplied argc and argv parameters.
bool found(const word &optName) const
Return true if the named option is found.
static HashTable< string > validOptions
A list of valid options.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
Find and return a sub-dictionary pointer if present.
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
const scalar & value() const
Return const reference to value.
const word & name() const
Return const reference to name.
Particle-size distribution model wherein random samples are drawn from a given arbitrary probability ...
bool open(bool verbose=true)
void stop()
Stop parsing, freeing the allocated parser.
A class for handling file names.
static std::string path(const std::string &str)
Return directory path name (part before last /)
static std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
virtual void addWatches(regIOobject &, const fileNameList &) const
Helper: add watches for list of regIOobjects.
virtual bool removeWatch(const label) const
Remove watch on a file (using handle)
virtual void setTime(const Time &) const
Callback for time change.
bool adjustTimeStep()
Called at the end of Time::adjustDeltaT() if adjustTime is true.
void on()
Switch the function objects on.
void operator=(const ObukhovLength &)=delete
No copy assignment.
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name.
Registry of regIOobjects.
void clear()
Clear all entries from the registry.
constant condensation/saturation model.
int myProcNo() const noexcept
Return processor number.
Triggers for starting/stopping code profiling.
static bool active()
True if profiling is allowed and is active.
Perform a subCycleTime on a field.
A class for handling words, derived from Foam::string.
static const word null
An empty word.
#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.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
runTimeSource setTime(sourceTimes[sourceTimeIndex], sourceTimeIndex)
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
#define WarningInFunction
Report a warning using Foam::Warning.
int infoSwitch(const char *name, const int deflt=0)
Lookup info switch or add default value.
dictionary & controlDict()
const fileOperation & fileHandler()
Get current file handler.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
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)
dimensionedScalar log10(const dimensionedScalar &ds)
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
Ostream & endl(Ostream &os)
Add newline and flush stream.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce (copy) and return value.
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a)
#define addProfiling(name, descr)
Define profiling trigger with specified name and description string.
#define registerInfoSwitch(Name, Type, SwitchVar)
Foam::argList args(argc, argv)
#define forAllReverse(list, i)
Reverse loop across all elements in list.