Skip to content

Commit

Permalink
Merge pull request #222 from CliMA/zs/temperature_tol
Browse files Browse the repository at this point in the history
Change temperature tolerance of all PhaseEquil constructor to 1e-4
  • Loading branch information
szy21 authored Jul 20, 2024
2 parents 3b450bb + fdd3336 commit ffbbe72
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Thermodynamics.jl Release Notes
========================

main
-------
- ![][badge-🤖precisionΔ] Change the tolerance of PhaseEquil constructor to 1e-4

v0.12.7
-------
- ![][badge-🔥behavioralΔ] Change the upper limit of saturation specific humidity

v0.12.4
-------
- Upgraded to use ClimaParams.jl
Expand Down
2 changes: 1 addition & 1 deletion src/relations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,7 @@ See also [`saturation_adjustment`](@ref).
q_tot::FT,
::Type{phase_type},
maxiter::Int,
relative_temperature_tol::Real = sqrt(eps(FT)),
relative_temperature_tol::Real,
T_guess::Union{FT, Nothing} = nothing,
) where {FT <: Real, sat_adjust_method, phase_type <: PhaseEquil}
tol = RS.RelativeSolutionTolerance(relative_temperature_tol)
Expand Down
20 changes: 10 additions & 10 deletions src/states.jl
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,6 @@ end
Base.convert(::Type{PhaseEquil{FT}}, ts::PhaseEquil) where {FT} =
PhaseEquil{FT}(ts.ρ, ts.p, ts.e_int, ts.q_tot, ts.T)

@inline ifnothing(x, y) = x
@inline ifnothing(x::Nothing, y) = y

"""
PhaseEquil_ρeq(param_set, ρ, e_int, q_tot[, maxiter, relative_temperature_tol, sat_adjust_method, T_guess])
Expand All @@ -333,8 +330,9 @@ and, optionally
::Type{sat_adjust_method} = RS.NewtonsMethod,
T_guess::Union{FT, Nothing} = nothing,
) where {FT <: Real, sat_adjust_method, IT <: ITERTYPE, TT <: TOLTYPE}
maxiter = ifnothing(maxiter, 8)
relative_temperature_tol = ifnothing(relative_temperature_tol, FT(1e-4))
maxiter === nothing && (maxiter = 8)
relative_temperature_tol === nothing &&
(relative_temperature_tol = FT(1e-4))
phase_type = PhaseEquil{FT}
q_tot_safe = clamp(q_tot, FT(0), FT(1))
T = saturation_adjustment(
Expand Down Expand Up @@ -403,7 +401,7 @@ Constructs a [`PhaseEquil`](@ref) thermodynamic state from:
) where {FT <: Real, IT <: ITERTYPE, TT <: TOLTYPE}
maxiter === nothing && (maxiter = 36)
relative_temperature_tol === nothing &&
(relative_temperature_tol = FT(1e-5))
(relative_temperature_tol = FT(1e-4))
phase_type = PhaseEquil{FT}
tol = RS.RelativeSolutionTolerance(relative_temperature_tol)
T = saturation_adjustment_given_ρθq(
Expand Down Expand Up @@ -590,12 +588,14 @@ TODO: change input argument order: perform_sat_adjust is
p::FT,
q_tot::FT,
perform_sat_adjust = false,
maxiter::Int = 5,
relative_temperature_tol::Real = FT(sqrt(eps(FT))),
maxiter::IT = nothing,
relative_temperature_tol::TT = nothing,
::Type{sat_adjust_method} = RS.NewtonsMethodAD,
T_guess::Union{FT, Nothing} = nothing,
) where {FT <: Real, sat_adjust_method}

) where {FT <: Real, sat_adjust_method, IT <: ITERTYPE, TT <: TOLTYPE}
maxiter === nothing && (maxiter = 5)
relative_temperature_tol === nothing &&
(relative_temperature_tol = FT(1e-4))
phase_type = PhaseEquil{FT}
if perform_sat_adjust
T = saturation_adjustment_ρpq(
Expand Down

0 comments on commit ffbbe72

Please sign in to comment.