Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Floating point roundoff errors in model time #76

Open
szy21 opened this issue Oct 14, 2022 · 1 comment
Open

Floating point roundoff errors in model time #76

szy21 opened this issue Oct 14, 2022 · 1 comment

Comments

@szy21
Copy link
Member

szy21 commented Oct 14, 2022

When using float32, there may be roundoff errors in model time, which could cause problems. For example:

julia> t=Float32(390*24*60*60)
3.3696f7

julia> tt = t+150
3.369615f7

julia> tt-t
152.0f0

Potential solution:
use a different mechanism for internally storing current time, either

  • a higher-precision Float64
  • an integer, either number of time steps or number of seconds (or equivalently using a DateTime object, which internally uses milliseconds since an epoch)

From Tapio: Standard solution is to use an integer step counter j, then write output every n steps. Of course, this only works with constant dt, but every climate model I know has that anyway.

@tapios
Copy link

tapios commented Oct 14, 2022

Standard solution: Specify start time tstart (in seconds since epoch, e.g., obtained from DateTime object), end time tend, and timestep dt. Calculate number of integer time steps needed to get from tstart to tend. Write output every n steps. Increment step counter jstep and calculate time at jstep as tstart + jstep * dt.

@simonbyrne simonbyrne transferred this issue from CliMA/ClimaAtmos.jl Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants