From b6e5ecc45feba95fc5c2346822996a9cd68a4314 Mon Sep 17 00:00:00 2001 From: Henry <Henry> Date: Sun, 8 Mar 2015 21:02:51 +0000 Subject: [PATCH] Time: Improved tolerance used to test time equivalence from Bruno Resolves bug-report http://www.openfoam.org/mantisbt/view.php?id=815 --- src/OpenFOAM/db/Time/Time.C | 49 ++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/OpenFOAM/db/Time/Time.C b/src/OpenFOAM/db/Time/Time.C index 799ba098c7a..3842ff1045e 100644 --- a/src/OpenFOAM/db/Time/Time.C +++ b/src/OpenFOAM/db/Time/Time.C @@ -1097,45 +1097,50 @@ Foam::Time& Foam::Time::operator++() // Time value obtained by reading timeName - scalar timeNameValue; + 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 // reinterpretation of the word if ( readScalar(dimensionedScalar::name().c_str(), timeNameValue) - && (mag(timeNameValue - oldTimeValue - deltaT_) > 100*SMALL) + && (mag(timeNameValue - oldTimeValue - deltaT_) > timeTol) ) { int oldPrecision = precision_; - do - { - precision_++; - setTime(value(), timeIndex()); - } while ( precision_ < maxPrecision_ && readScalar(dimensionedScalar::name().c_str(), timeNameValue) - && (mag(timeNameValue - oldTimeValue - deltaT_) > 100*SMALL) - ); - - WarningIn("Time::operator++()") - << "Increased the timePrecision from " << oldPrecision - << " to " << precision_ - << " to distinguish between timeNames at time " - << dimensionedScalar::name() - << endl; + && (mag(timeNameValue - oldTimeValue - deltaT_) > timeTol) + ) + { + precision_++; + setTime(value(), timeIndex()); + } - if (precision_ == maxPrecision_ && precision_ != oldPrecision) + if (precision_ != oldPrecision) { - // Reached maxPrecision limit WarningIn("Time::operator++()") - << "Current time name " << dimensionedScalar::name() - << " is the old as the previous one " << oldTimeName - << endl - << " This might result in overwriting old results." + << "Increased the timePrecision from " << oldPrecision + << " to " << precision_ + << " to distinguish between timeNames at time " + << dimensionedScalar::name() << endl; + + if (precision_ == maxPrecision_) + { + // Reached maxPrecision limit + WarningIn("Time::operator++()") + << "Current time name " << dimensionedScalar::name() + << " is the old as the previous one " << oldTimeName + << endl + << " This might result in overwriting old results." + << endl; + } } } -- GitLab