time handling in single precision#3161
Open
wiersema1 wants to merge 2 commits into
Open
Conversation
…le precision. When compiling in single precision, the time step and current time were float32, which could lead to some unintended behavior when the number of time steps is large. For 6 hour Bomex simulations with fixed_dt=0.3, the actual dt is 0.29980469 until time 16384, after which dt=0.30078125. This causes the single precision run to reach 6 hrs in 20 less time steps relative to the double precision run.
…rue elapsed time due to representation of the time step as float32. This change assigns t_new[0] using the double cur_time after each time step, which avoids the accumulation of float32 quantization error. The correct timestamp is now provided to physics routines and the plt and chk Header files. There should be no change when compiled in double precision since t_new[0] is already a double, so the static_cast<Real> does nothing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When compiled in single precision, small rounding errors in the time step and current time can accumulate. For Bomex (6 hours with dt=0.3) the single precision run completes 20 time steps (6 seconds) earlier than the double precision run. This PR changes some times to doubles when in single precision and also syncs the current time after each time step so that it does not drift for the I/O and physics routines. These changes shouldn't change anything when compiled in double precision.
Tested by compiling in single and double precision and running Bomex. No change to behavior of the double precision simulation. Single precision simulation now tracks and reports time identical to the double precision simulation.