Time: Correct precision adjustment for user-time

This commit is contained in:
Henry
2015-05-20 12:43:54 +01:00
parent 295a357a02
commit 36ca836f28

View File

@ -1086,7 +1086,7 @@ Foam::Time& Foam::Time::operator++()
deltaTSave_ = deltaT_; deltaTSave_ = deltaT_;
// Save old time value and name // Save old time value and name
const scalar oldTimeValue = value(); const scalar oldTimeValue = timeToUserTime(value());
const word oldTimeName = dimensionedScalar::name(); const word oldTimeName = dimensionedScalar::name();
// Increment time // Increment time
@ -1276,19 +1276,22 @@ Foam::Time& Foam::Time::operator++()
// Adjust the precision of the time directory name if necessary // Adjust the precision of the time directory name if necessary
if (outputTime_) if (outputTime_)
{ {
// Tolerance used when testing time equivalence
const scalar timeTol =
max(min(pow(10.0, -precision_), 0.1*deltaT_), SMALL);
// User-time equivalent of deltaT
const scalar userDeltaT = timeToUserTime(deltaT_);
// Time value obtained by reading timeName // Time value obtained by reading timeName
scalar timeNameValue = -VGREAT; scalar timeNameValue = -VGREAT;
// Tolerance used when testing time equivalence
scalar timeTol =
max(min(pow(10.0, -precision_), 0.1*deltaT_), SMALL);
// Check that new time representation differs from old one // Check that new time representation differs from old one
// reinterpretation of the word // reinterpretation of the word
if if
( (
readScalar(dimensionedScalar::name().c_str(), timeNameValue) readScalar(dimensionedScalar::name().c_str(), timeNameValue)
&& (mag(timeNameValue - oldTimeValue - deltaT_) > timeTol) && (mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
) )
{ {
int oldPrecision = precision_; int oldPrecision = precision_;
@ -1296,7 +1299,7 @@ Foam::Time& Foam::Time::operator++()
( (
precision_ < maxPrecision_ precision_ < maxPrecision_
&& readScalar(dimensionedScalar::name().c_str(), timeNameValue) && readScalar(dimensionedScalar::name().c_str(), timeNameValue)
&& (mag(timeNameValue - oldTimeValue - deltaT_) > timeTol) && (mag(timeNameValue - oldTimeValue - userDeltaT) > timeTol)
) )
{ {
precision_++; precision_++;