diff --git a/src/OpenFOAM/db/Time/Time.C b/src/OpenFOAM/db/Time/Time.C index 3842ff1045ec0d4defef8a6f6b93e4a69da1f198..420da6123da963766a11694234490ffd09bb0b84 100644 --- a/src/OpenFOAM/db/Time/Time.C +++ b/src/OpenFOAM/db/Time/Time.C @@ -732,11 +732,11 @@ void Foam::Time::setUnmodified(const label watchFd) const } -Foam::word Foam::Time::timeName(const scalar t) +Foam::word Foam::Time::timeName(const scalar t, const int precision) { std::ostringstream buf; buf.setf(ios_base::fmtflags(format_), ios_base::floatfield); - buf.precision(precision_); + buf.precision(precision); buf << t; return buf.str(); } @@ -1137,10 +1137,26 @@ Foam::Time& Foam::Time::operator++() WarningIn("Time::operator++()") << "Current time name " << dimensionedScalar::name() << " is the old as the previous one " << oldTimeName - << endl + << nl << " This might result in overwriting old results." << endl; } + + // Check if round-off error caused time-reversal + scalar oldTimeNameValue = -VGREAT; + if + ( + readScalar(oldTimeName.c_str(), oldTimeNameValue) + && (sign(timeNameValue - oldTimeNameValue) != sign(deltaT_)) + ) + { + WarningIn("Time::operator++()") + << "Current time name " << dimensionedScalar::name() + << " is set to an instance prior to the previous one " + << oldTimeName << nl + << " This might result in temporal discontinuities." + << endl; + } } } diff --git a/src/OpenFOAM/db/Time/Time.H b/src/OpenFOAM/db/Time/Time.H index f9e0afe1fbac867c7d9508d038c0e874b1b46837..c2d60b47077606fca8f1241acca220f20466a60a 100644 --- a/src/OpenFOAM/db/Time/Time.H +++ b/src/OpenFOAM/db/Time/Time.H @@ -406,7 +406,12 @@ public: // Access //- Return time name of given scalar time - static word timeName(const scalar); + // formatted with given precision + static word timeName + ( + const scalar, + const int precision = precision_ + ); //- Return current time name virtual word timeName() const; diff --git a/src/OpenFOAM/db/Time/TimeIO.C b/src/OpenFOAM/db/Time/TimeIO.C index c9134d6530ef56bfda8a03f0b208fcf1692ec6ff..79a1659a8d5c1ddbca01cf6b7cb546720ee5cfb2 100644 --- a/src/OpenFOAM/db/Time/TimeIO.C +++ b/src/OpenFOAM/db/Time/TimeIO.C @@ -508,7 +508,7 @@ bool Foam::Time::writeObject ) ); - timeDict.add("value", timeToUserTime(value())); + timeDict.add("value", timeName(timeToUserTime(value()), maxPrecision_)); timeDict.add("name", string(tmName)); timeDict.add("index", timeIndex_); timeDict.add("deltaT", timeToUserTime(deltaT_));