Mismatch between user and physical time when adapting the time precision
Summary
I am developing a new solver in which I derive from Foam::Time and override the virtual functions Foam::TimeState::userTimeToTime, etc. While doing this, I noticed that OpenFOAM unexpectedly increases the write precision, which seems to be due to mismatches between user- and physical time in OpenFOAM's time classes. See the proposed source of problem below.
Steps to reproduce
This bug is not related to any specific usage of the code.
Environment information
- OpenFOAM version : v2112
- Operating system : Ubuntu 20.04
- Hardware info : Intel 64 bit
- Compiler : Gcc 8.2
Possible fixes
After some debugging, I think I found the issue. At Time.C:1287
// Tolerance used when testing time equivalence
const scalar timeTol =
max(min(pow(10.0, -precision_), 0.1*deltaT_), SMALL);
Here the physical time is used to define the tolerance for increasing the time precision, but a few lines down (1302) this is compared against the user time. This mismatch causes the precision to unexpectedly increase.
A second issue I noted is that, on line 1292, userDeltaT is determined using the function timeToUserTime
. This is only correct if the user time is a linear function of the physical time. It would be better to calculate this as:
const scalar userDeltaT = timeToUserTime(value()) - timeToUserTime(value() - deltaT_);