SpeedyWeather / SpeedyWeather.jl

Play atmospheric modelling like it's LEGO.
https://speedyweather.github.io/SpeedyWeather.jl/dev
MIT License
437 stars 27 forks source link

Use Celsius instead of Kelvin to avoid rounding errors at low-precision #85

Open white-alistair opened 2 years ago

white-alistair commented 2 years ago

Copying @milankl's comment from PR #82:

I mean rewriting the entire model such that temperature uses ˚C instead of Kelvin. I expect everything to work very similar, instead of probably radiation, where somewhere the Stefan-Boltzmann ~T^4 should appear. We could then convert from ˚C to Kelvin therein. But from a precision point-of-view using Kelvin is awful as you'll hit massive rounding errors in the time integration, e.g. T = 300K, tendency dT = 0.1K

julia> T = Float16(300)
Float16(300.0)

julia> dT = Float16(0.1)
Float16(0.1)

julia> T+dT
Float16(300.0)

julia> T2 = Float16(300-273.15)
Float16(26.84)

julia> T2+dT
Float16(26.94)

In Kelvin you can't resolve the increment, but in ˚C you can.

Having said that, we obviously do the time stepping in spectral space, meaning that we'd only have that problem on the l=m=0 mode which we could also solve with compensated summation, but I think in general, we should try to use ˚C if possible. If it turns out that ˚C is a bad idea then we can still revert back.

milankl commented 2 years ago

With #123 this should become much easier as we can define tempC and tempK for a given column and use both within the parametrizations. Given that the tendencies in ˚C and Kelvin are the same, we then are left with the question whether we can carry temperature in ˚C around in the dynamics...

milankl commented 1 year ago

Most parts in the dynamical core now use the temperature anomaly anyway, so maybe less of an issue. Hoskins and Burridge 1975 normalise temperature by $a^2\Omega^2/R$ ($a$ radius, $R$ gas constant) which might be another option

milankl commented 1 year ago

Btw, IFS uses virtual temperature as prognostic variable, maybe that's a good idea too