mirror of
https://github.com/OpenFOAM/OpenFOAM-6.git
synced 2025-12-08 06:57:46 +00:00
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:
@ -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;
|
std::ostringstream buf;
|
||||||
buf.setf(ios_base::fmtflags(format_), ios_base::floatfield);
|
buf.setf(ios_base::fmtflags(format_), ios_base::floatfield);
|
||||||
buf.precision(precision_);
|
buf.precision(precision);
|
||||||
buf << t;
|
buf << t;
|
||||||
return buf.str();
|
return buf.str();
|
||||||
}
|
}
|
||||||
@ -1137,10 +1137,26 @@ Foam::Time& Foam::Time::operator++()
|
|||||||
WarningIn("Time::operator++()")
|
WarningIn("Time::operator++()")
|
||||||
<< "Current time name " << dimensionedScalar::name()
|
<< "Current time name " << dimensionedScalar::name()
|
||||||
<< " is the old as the previous one " << oldTimeName
|
<< " is the old as the previous one " << oldTimeName
|
||||||
<< endl
|
<< nl
|
||||||
<< " This might result in overwriting old results."
|
<< " This might result in overwriting old results."
|
||||||
<< endl;
|
<< 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
|
// Access
|
||||||
|
|
||||||
//- Return time name of given scalar time
|
//- 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
|
//- Return current time name
|
||||||
virtual word timeName() const;
|
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("name", string(tmName));
|
||||||
timeDict.add("index", timeIndex_);
|
timeDict.add("index", timeIndex_);
|
||||||
timeDict.add("deltaT", timeToUserTime(deltaT_));
|
timeDict.add("deltaT", timeToUserTime(deltaT_));
|
||||||
|
|||||||
Reference in New Issue
Block a user