Commit 5c210513 authored by Henry's avatar Henry
Browse files

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
parent 67e8bd8b
......@@ -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;
}
}
}
......
......@@ -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;
......
......@@ -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_));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment