Time: Increase the precision the value entry is written in uniform/time

Add check for round-off error causing time reversal
Resolves bug-report http://www.openfoam.org/mantisbt/view.php?id=815
This commit is contained in:
Henry
2015-03-14 20:33:51 +00:00
parent e20e69992d
commit b169f09cd3
3 changed files with 26 additions and 5 deletions

View File

@ -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;
}
}
}

View File

@ -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;

View File

@ -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_));