Skip to content

Commit

Permalink
Merge #140
Browse files Browse the repository at this point in the history
140: Use RelativeSolutionTolerance r=charleskawczynski a=charleskawczynski

This PR addresses one of the check boxes in #134, by changing from `SolutionTolerance` to `RelativeSolutionTolerance`.

One downside of this, unfortunately, is that it's a breaking change, but I think it's fine if we know that this is what we want in the long run.

Alternatively, we could require users to pass in `::RootSolvers.AbstractTolerance`, which would make the interface less likely to be breaking, however this means that our interface would be tied to using `RootSolvers`, so it's not a complete win to do that.

It looks like all the tests pass with these changes.

Co-authored-by: Charles Kawczynski <[email protected]>
  • Loading branch information
bors[bot] and charleskawczynski authored Oct 26, 2022
2 parents d7d03c0 + e57d9af commit cdf2408
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
env:
JULIA_VERSION: "1.8.1"
JULIA_VERSION: "1.8.2"
OPENBLAS_NUM_THREADS: 1
CUDA_VERSION: "10.2"
JULIA_PKG_SERVER: ""
Expand Down
2 changes: 1 addition & 1 deletion .dev/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"

[compat]
JuliaFormatter = "0.22"
JuliaFormatter = "1"
2 changes: 1 addition & 1 deletion .github/workflows/CodeCov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Julia
uses: julia-actions/setup-julia@latest
with:
version: 1.6.0
version: 1.8

- name: Test with coverage
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/JuliaFormatter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- uses: julia-actions/setup-julia@latest
if: steps.filter.outputs.julia_file_change == 'true'
with:
version: 1.8.1
version: 1.8

- name: Apply JuliaFormatter
if: steps.filter.outputs.julia_file_change == 'true'
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ jobs:
fail-fast: false
matrix:
version:
- '1.5'
- '1.6.0'
- '1.6'
- '1.7'
- '1.8'
os:
- ubuntu-latest
- macOS-latest
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Thermodynamics"
uuid = "b60c26fb-14c3-4610-9d3e-2d17fe7ff00c"
authors = ["Climate Modeling Alliance"]
version = "0.9.7"
version = "0.10.0"

[deps]
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
Expand All @@ -13,4 +13,4 @@ RootSolvers = "7181ea78-2dcb-4de3-ab41-2b8ab5a31e74"
DocStringExtensions = "0.8.1, 0.9"
KernelAbstractions = "0.7, 0.8"
RootSolvers = "0.2, 0.3"
julia = "1.5"
julia = "1.6"
15 changes: 9 additions & 6 deletions bors.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
status = [
"buildkite/thermodynamics-ci",
"ci 1.5 - ubuntu-latest",
"ci 1.5 - windows-latest",
"ci 1.5 - macOS-latest",
"ci 1.6.0 - ubuntu-latest",
"ci 1.6.0 - windows-latest",
"ci 1.6.0 - macOS-latest",
"ci 1.6 - ubuntu-latest",
"ci 1.6 - windows-latest",
"ci 1.6 - macOS-latest",
"ci 1.7 - ubuntu-latest",
"ci 1.7 - windows-latest",
"ci 1.7 - macOS-latest",
"ci 1.8 - ubuntu-latest",
"ci 1.8 - windows-latest",
"ci 1.8 - macOS-latest",
"docbuild",
"format",
]
Expand Down
49 changes: 27 additions & 22 deletions src/relations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,7 @@ end
q_tot,
phase_type,
maxiter,
temperature_tol,
relative_temperature_tol,
T_guess,
)
Expand All @@ -1464,7 +1464,7 @@ Compute the temperature that is consistent with
- `q_tot` total specific humidity
- `phase_type` a thermodynamic state type
- `maxiter` maximum iterations for non-linear equation solve
- `temperature_tol` temperature tolerance
- `relative_temperature_tol` relative temperature tolerance
- `T_guess` initial temperature guess
by finding the root of
Expand All @@ -1483,11 +1483,11 @@ function saturation_adjustment(
q_tot::FT,
::Type{phase_type},
maxiter::Int,
temperature_tol::FT,
relative_temperature_tol::FT,
T_guess::Union{FT, Nothing} = nothing,
) where {FT <: Real, sat_adjust_method, phase_type <: PhaseEquil}
_T_min::FT = TP.T_min(param_set)
tol = RS.SolutionTolerance(temperature_tol)
tol = RS.RelativeSolutionTolerance(relative_temperature_tol)

T_1 = max(_T_min, air_temperature(param_set, e_int, PhasePartition(q_tot))) # Assume all vapor
q_v_sat = q_vap_saturation(param_set, T_1, ρ, phase_type)
Expand All @@ -1498,6 +1498,7 @@ function saturation_adjustment(
_T_freeze::FT = TP.T_freeze(param_set)
e_int_sat(T) =
internal_energy_sat(param_set, heavisided(T), ρ, q_tot, phase_type)
temperature_tol = _T_freeze * relative_temperature_tol
e_int_upper = e_int_sat(_T_freeze + temperature_tol / 2) # /2 => resulting interval is `temperature_tol` wide
e_int_lower = e_int_sat(_T_freeze - temperature_tol / 2) # /2 => resulting interval is `temperature_tol` wide
if e_int_lower < e_int < e_int_upper
Expand Down Expand Up @@ -1548,7 +1549,7 @@ end
q_tot,
phase_type,
maxiter,
temperature_tol,
relative_temperature_tol,
T_guess,
)
Expand All @@ -1562,7 +1563,7 @@ Compute the temperature that is consistent with
- `q_tot` total specific humidity
- `phase_type` a thermodynamic state type
- `maxiter` maximum iterations for non-linear equation solve
- `temperature_tol` temperature tolerance
- `relative_temperature_tol` relative temperature tolerance
- `T_guess` initial temperature guess
by finding the root of
Expand All @@ -1583,11 +1584,11 @@ function saturation_adjustment_given_peq(
q_tot::FT,
::Type{phase_type},
maxiter::Int,
temperature_tol::FT,
relative_temperature_tol::FT,
T_guess::Union{FT, Nothing} = nothing,
) where {FT <: Real, sat_adjust_method, phase_type <: PhaseEquil}
_T_min::FT = TP.T_min(param_set)
tol = RS.SolutionTolerance(temperature_tol)
tol = RS.RelativeSolutionTolerance(relative_temperature_tol)

T_1 = max(_T_min, air_temperature(param_set, e_int, PhasePartition(q_tot))) # Assume all vapor
ρ_T(T) = air_density(param_set, T, p, PhasePartition(q_tot))
Expand All @@ -1601,6 +1602,7 @@ function saturation_adjustment_given_peq(
e_int_sat(T) =
internal_energy_sat(param_set, heavisided(T), ρ_T(T), q_tot, phase_type)

temperature_tol = _T_freeze * relative_temperature_tol
e_int_upper = e_int_sat(_T_freeze + temperature_tol / 2) # /2 => resulting interval is `temperature_tol` wide
e_int_lower = e_int_sat(_T_freeze - temperature_tol / 2) # /2 => resulting interval is `temperature_tol` wide
if e_int_lower < e_int < e_int_upper
Expand Down Expand Up @@ -1651,7 +1653,7 @@ end
q_tot,
phase_type,
maxiter,
temperature_tol
relative_temperature_tol
T_guess,
)
Expand All @@ -1665,7 +1667,7 @@ Compute the temperature that is consistent with
- `q_tot` total specific humidity
- `phase_type` a thermodynamic state type
- `maxiter` maximum iterations for non-linear equation solve
- `temperature_tol` temperature tolerance
- `relative_temperature_tol` relative temperature tolerance
- `T_guess` initial temperature guess
by finding the root of
Expand All @@ -1686,11 +1688,11 @@ function saturation_adjustment_given_phq(
q_tot::FT,
::Type{phase_type},
maxiter::Int,
temperature_tol::FT,
relative_temperature_tol::FT,
T_guess::Union{FT, Nothing} = nothing,
) where {FT <: Real, sat_adjust_method, phase_type <: PhaseEquil}
_T_min::FT = TP.T_min(param_set)
tol = RS.SolutionTolerance(temperature_tol)
tol = RS.RelativeSolutionTolerance(relative_temperature_tol)

T_1 = max(
_T_min,
Expand All @@ -1712,6 +1714,7 @@ function saturation_adjustment_given_phq(
phase_type,
)

temperature_tol = _T_freeze * relative_temperature_tol
h_upper = h_sat(_T_freeze + temperature_tol / 2) # /2 => resulting interval is `temperature_tol` wide
h_lower = h_sat(_T_freeze - temperature_tol / 2) # /2 => resulting interval is `temperature_tol` wide
if h_lower < h < h_upper
Expand Down Expand Up @@ -1761,7 +1764,7 @@ end
q_tot,
phase_type,
maxiter,
temperature_tol,
relative_temperature_tol,
T_guess,
)
Compute the temperature that is consistent with
Expand All @@ -1773,7 +1776,7 @@ Compute the temperature that is consistent with
- `q_tot` total specific humidity
- `phase_type` a thermodynamic state type
- `maxiter` maximum iterations for non-linear equation solve
- `temperature_tol` temperature tolerance
- `relative_temperature_tol` relative temperature tolerance
- `T_guess` initial temperature guess
by finding the root of
Expand All @@ -1796,10 +1799,10 @@ function saturation_adjustment_ρpq(
q_tot::FT,
::Type{phase_type},
maxiter::Int,
temperature_tol::FT = sqrt(eps(FT)),
relative_temperature_tol::FT = sqrt(eps(FT)),
T_guess::Union{FT, Nothing} = nothing,
) where {FT <: Real, sat_adjust_method, phase_type <: PhaseEquil}
tol = RS.SolutionTolerance(temperature_tol)
tol = RS.RelativeSolutionTolerance(relative_temperature_tol)
# Use `oftype` to preserve diagonalized type signatures:
sol = RS.find_zero(
T ->
Expand Down Expand Up @@ -1894,8 +1897,9 @@ Compute the temperature `T` that is consistent with
- `phase_type` a thermodynamic state type
- `maxiter` maximum iterations for non-linear equation solve
- `tol` absolute tolerance for saturation adjustment iterations. Can be one of:
- `SolutionTolerance()` to stop when `|x_2 - x_1| < tol`
- `RelativeSolutionTolerance()` to stop when `|x_2 - x_1| < tol`
- `ResidualTolerance()` to stop when `|f(x)| < tol`
- `RelativeRelativeSolutionTolerance()` to stop when `|x_2 - x_1|/x_1 < tol`
- `T_guess` initial temperature guess
by finding the root of
Expand Down Expand Up @@ -1966,7 +1970,7 @@ end
q_tot,
phase_type,
maxiter,
temperature_tol,
relative_temperature_tol,
T_guess
)
Expand All @@ -1977,7 +1981,7 @@ Compute the temperature `T` that is consistent with
- `θ_liq_ice` liquid-ice potential temperature
- `q_tot` total specific humidity
- `phase_type` a thermodynamic state type
- `temperature_tol` temperature tolerance
- `relative_temperature_tol` relative temperature tolerance
- `maxiter` maximum iterations for non-linear equation solve
- `sat_adjust_method` the numerical method to use.
- `T_guess` initial temperature guess
Expand All @@ -1996,10 +2000,10 @@ function saturation_adjustment_given_pθq(
q_tot::FT,
::Type{phase_type},
maxiter::Int,
temperature_tol::FT,
relative_temperature_tol::FT,
T_guess::Union{FT, Nothing} = nothing,
) where {FT <: Real, sat_adjust_method, phase_type <: PhaseEquil}
tol = RS.ResidualTolerance(temperature_tol)
tol = RS.RelativeSolutionTolerance(relative_temperature_tol)
T_min::FT = TP.T_min(param_set)
T_freeze::FT = TP.T_freeze(param_set)
cp_d::FT = TP.cp_d(param_set)
Expand Down Expand Up @@ -2028,6 +2032,7 @@ function saturation_adjustment_given_pθq(
if unsaturated && T_1 > T_min
return T_1
end
temperature_tol = T_freeze * relative_temperature_tol
θ_liq_ice_upper = θ_liq_ice_closure(T_freeze + temperature_tol / 2) # /2 => resulting interval is `temperature_tol` wide
θ_liq_ice_lower = θ_liq_ice_closure(T_freeze - temperature_tol / 2) # /2 => resulting interval is `temperature_tol` wide
if θ_liq_ice_lower < θ_liq_ice < θ_liq_ice_upper
Expand Down Expand Up @@ -2308,7 +2313,7 @@ Computes temperature `T` given
- `θ_liq_ice` liquid-ice potential temperature
- `ρ` (moist-)air density
- `tol` absolute tolerance for non-linear equation iterations. Can be one of:
- `SolutionTolerance()` to stop when `|x_2 - x_1| < tol`
- `RelativeSolutionTolerance()` to stop when `|x_2 - x_1|/x_1 < tol`
- `ResidualTolerance()` to stop when `|f(x)| < tol`
- `maxiter` maximum iterations for non-linear equation solve
and, optionally,
Expand Down
Loading

2 comments on commit cdf2408

@charleskawczynski
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/71143

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.10.0 -m "<description of version>" cdf24081e5eac639d99f02ff9668e82556e5ece2
git push origin v0.10.0

Please sign in to comment.