CliMA / Thermodynamics.jl

A package containing a library of moist thermodynamic relations.
https://clima.github.io/Thermodynamics.jl/dev/
Apache License 2.0
61 stars 2 forks source link

Add promoting constructors for Dual number support #199

Closed dennisYatunin closed 7 months ago

dennisYatunin commented 7 months ago

This PR adds a method to every user-facing ThermodynamicState constructor, in which all input arguments are promoted to the same number type. In addition, q_vap_saturation_generic is given a new method that promotes its input arguments.

With only three exceptions, every function from Thermodynamics.jl that gets called while computing the precomputed quantities and implicit tendencies of ClimaAtmos.jl only takes two input arguments: a parameter set and a ThermodynamicState. The exceptions are

So, this PR constitutes the minimum set of additions to Thermodynamics.jl that will enable us to use automatic differentiation in ClimaAtmos.jl, which involves replacing values in the prognostic state with numbers of type ForwardDiff.Dual.

This is a simpler alternative to #197, which I'm going to close for now. In the future, we may want to come back to the changes in that PR, since they are much more generalizable. That is, they will not require to continue adding new methods to every function that relies on promotion during automatic differentiation in other repositories. The downside to those changes is that they would allow developers to silently introduce Float32/Float64 type instabilities within internal functions, and we would probably want to add more unit tests to ensure that those are avoided.

codecov[bot] commented 7 months ago

Codecov Report

Attention: 26 lines in your changes are missing coverage. Please review.

Comparison is base (1dc23bb) 93.04% compared to head (eccb2ae) 90.98%.

Files Patch % Lines
src/states.jl 0.00% 25 Missing :warning:
src/relations.jl 0.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #199 +/- ## ========================================== - Coverage 93.04% 90.98% -2.06% ========================================== Files 10 10 Lines 1150 1176 +26 ========================================== Hits 1070 1070 - Misses 80 106 +26 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.