Skip to content

Commit

Permalink
Merge pull request #193 from CliMA/ck/rm_T_min
Browse files Browse the repository at this point in the history
Use ClimaParameters T_init_min, with new T_min value
  • Loading branch information
trontrytel authored Feb 13, 2024
2 parents 5d3b8e0 + 3fa7fd6 commit b67e7f7
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 34 deletions.
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.11.7"
version = "0.12.0"

[deps]
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
Expand All @@ -23,4 +23,4 @@ KernelAbstractions = "0.9"
Random = "1"
RootSolvers = "0.4"
julia = "1.6"
CLIMAParameters = "0.8"
CLIMAParameters = "0.9"
1 change: 1 addition & 0 deletions ext/CreateParametersExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function ThermodynamicsParameters(toml_dict::CP.AbstractTOMLDict)
:isobaric_specific_heat_liquid => :cp_l,
:latent_heat_vaporization_at_reference => :LH_v0,
:temperature_saturation_adjustment_min => :T_min,
:temperature_saturation_adjustment_init_min => :T_init_min,
:gas_constant => :gas_constant,
:temperature_mean_at_reference => :T_surf_ref,
:gravitational_acceleration => :grav,
Expand Down
2 changes: 1 addition & 1 deletion gpuenv/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Thermodynamics = "b60c26fb-14c3-4610-9d3e-2d17fe7ff00c"

[compat]
CLIMAParameters = "0.8"
CLIMAParameters = "0.9"
CUDA = "3.5, 4, 5"
KernelAbstractions = "0.9"
RootSolvers = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion perf/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Thermodynamics = "b60c26fb-14c3-4610-9d3e-2d17fe7ff00c"

[compat]
CLIMAParameters = "0.8"
CLIMAParameters = "0.9"
KernelAbstractions = "0.9"
RootSolvers = "0.4"
julia = "1.7"
1 change: 1 addition & 0 deletions src/Parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Base.@kwdef struct ThermodynamicsParameters{FT}
T_freeze::FT
T_min::FT
T_max::FT
T_init_min::FT
entropy_reference_temperature::FT
entropy_dry_air::FT
entropy_water_vapor::FT
Expand Down
57 changes: 33 additions & 24 deletions src/config_numerical_method.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ end
::Type{phase_type},
T_guess::Union{FT, Nothing},
) where {FT, NM <: RS.NewtonsMethod, phase_type <: PhaseEquil}
T_min = TP.T_min(param_set)
T_init_min = TP.T_init_min(param_set)
T_init = if T_guess isa Nothing
max(T_min, air_temperature(param_set, e_int, PhasePartition(q_tot))) # Assume all vapor
max(T_init_min, air_temperature(param_set, e_int, PhasePartition(q_tot))) # Assume all vapor
else
T_guess
end
Expand All @@ -73,9 +73,9 @@ end
::Type{phase_type},
T_guess::FT,
) where {FT, NM <: RS.NewtonsMethodAD, phase_type <: PhaseEquil}
T_min = TP.T_min(param_set)
T_init_min = TP.T_init_min(param_set)
T_init = if T_guess isa Nothing
max(T_min, air_temperature(param_set, e_int, PhasePartition(q_tot))) # Assume all vapor
max(T_init_min, air_temperature(param_set, e_int, PhasePartition(q_tot))) # Assume all vapor
else
T_guess
end
Expand All @@ -91,10 +91,13 @@ end
::Type{phase_type},
T_guess::Union{FT, Nothing},
) where {FT, NM <: RS.SecantMethod, phase_type <: PhaseEquil}
T_min = TP.T_min(param_set)
T_init_min = TP.T_init_min(param_set)
q_pt = PhasePartition(q_tot, FT(0), q_tot) # Assume all ice
T_2 = air_temperature(param_set, e_int, q_pt)
T_1 = max(T_min, air_temperature(param_set, e_int, PhasePartition(q_tot))) # Assume all vapor
T_1 = max(
T_init_min,
air_temperature(param_set, e_int, PhasePartition(q_tot)),
) # Assume all vapor
T_2 = bound_upper_temperature(T_1, T_2)
return RS.SecantMethod(T_1, T_2)
end
Expand All @@ -108,10 +111,13 @@ end
::Type{phase_type},
T_guess::Union{FT, Nothing},
) where {FT, NM <: RS.RegulaFalsiMethod, phase_type <: PhaseEquil}
T_min = TP.T_min(param_set)
T_init_min = TP.T_init_min(param_set)
q_pt = PhasePartition(q_tot, FT(0), q_tot) # Assume all ice
T_2 = air_temperature(param_set, e_int, q_pt)
T_1 = max(T_min, air_temperature(param_set, e_int, PhasePartition(q_tot))) # Assume all vapor
T_1 = max(
T_init_min,
air_temperature(param_set, e_int, PhasePartition(q_tot)),
) # Assume all vapor
T_2 = bound_upper_temperature(T_1, T_2)
return RS.RegulaFalsiMethod(T_1, T_2)
end
Expand Down Expand Up @@ -166,9 +172,9 @@ end
::Type{phase_type},
T_guess::Union{FT, Nothing},
) where {FT, NM <: RS.NewtonsMethodAD, phase_type <: PhaseEquil}
T_min = TP.T_min(param_set)
T_init_min = TP.T_init_min(param_set)
T_init = if T_guess isa Nothing
max(T_min, air_temperature(param_set, e_int, PhasePartition(q_tot))) # Assume all vapor
max(T_init_min, air_temperature(param_set, e_int, PhasePartition(q_tot))) # Assume all vapor
else
T_guess
end
Expand All @@ -184,10 +190,13 @@ end
::Type{phase_type},
T_guess::Union{FT, Nothing},
) where {FT, NM <: RS.SecantMethod, phase_type <: PhaseEquil}
T_min = TP.T_min(param_set)
T_init_min = TP.T_init_min(param_set)
q_pt = PhasePartition(q_tot, FT(0), q_tot) # Assume all ice
T_2 = air_temperature(param_set, e_int, q_pt)
T_1 = max(T_min, air_temperature(param_set, e_int, PhasePartition(q_tot))) # Assume all vapor
T_1 = max(
T_init_min,
air_temperature(param_set, e_int, PhasePartition(q_tot)),
) # Assume all vapor
T_2 = bound_upper_temperature(T_1, T_2)
return RS.SecantMethod(T_1, T_2)
end
Expand All @@ -205,10 +214,10 @@ end
::Type{phase_type},
T_guess::Union{FT, Nothing},
) where {FT, NM <: RS.NewtonsMethodAD, phase_type <: PhaseEquil}
T_min = TP.T_min(param_set)
T_init_min = TP.T_init_min(param_set)
T_init = if T_guess isa Nothing # Assume all vapor
max(
T_min,
T_init_min,
air_temperature_from_enthalpy(param_set, h, PhasePartition(q_tot)),
)
else
Expand All @@ -226,11 +235,11 @@ end
::Type{phase_type},
T_guess::Union{FT, Nothing},
) where {FT, NM <: RS.SecantMethod, phase_type <: PhaseEquil}
T_min = TP.T_min(param_set)
T_init_min = TP.T_init_min(param_set)
q_pt = PhasePartition(q_tot, FT(0), q_tot) # Assume all ice
T_2 = air_temperature_from_enthalpy(param_set, h, q_pt)
T_1 = max(
T_min,
T_init_min,
air_temperature_from_enthalpy(param_set, h, PhasePartition(q_tot)),
) # Assume all vapor
T_2 = bound_upper_temperature(T_1, T_2)
Expand All @@ -246,11 +255,11 @@ end
::Type{phase_type},
T_guess::Union{FT, Nothing},
) where {FT, NM <: RS.RegulaFalsiMethod, phase_type <: PhaseEquil}
T_min = TP.T_min(param_set)
T_init_min = TP.T_init_min(param_set)
q_pt = PhasePartition(q_tot, FT(0), q_tot) # Assume all ice
T_2 = air_temperature_from_enthalpy(param_set, h, q_pt)
T_1 = max(
T_min,
T_init_min,
air_temperature_from_enthalpy(param_set, h, PhasePartition(q_tot)),
) # Assume all vapor
T_2 = bound_upper_temperature(T_1, T_2)
Expand All @@ -270,10 +279,10 @@ end
::Type{phase_type},
T_guess::Union{FT, Nothing},
) where {FT, NM <: RS.RegulaFalsiMethod, phase_type <: PhaseEquil}
_T_min = TP.T_min(param_set)
_T_init_min = TP.T_init_min(param_set)
_T_max = TP.T_max(param_set)
@inline air_temp(q) = air_temperature_given_pθq(param_set, p, θ_liq_ice, q)
T_1 = max(_T_min, air_temp(PhasePartition(q_tot))) # Assume all vapor
T_1 = max(_T_init_min, air_temp(PhasePartition(q_tot))) # Assume all vapor
T_2 = T_1 + 10
T_1 = T_1 - 10
return RS.RegulaFalsiMethod(T_1, T_2)
Expand All @@ -288,9 +297,9 @@ end
::Type{phase_type},
T_guess::Union{FT, Nothing},
) where {FT, NM <: RS.SecantMethod, phase_type <: PhaseEquil}
_T_min = TP.T_min(param_set)
_T_init_min = TP.T_init_min(param_set)
@inline air_temp(q) = air_temperature_given_pθq(param_set, p, θ_liq_ice, q)
T_1 = max(_T_min, air_temp(PhasePartition(q_tot))) # Assume all vapor
T_1 = max(_T_init_min, air_temp(PhasePartition(q_tot))) # Assume all vapor
T_2 = air_temp(PhasePartition(q_tot, FT(0), q_tot)) # Assume all ice
T_2 = bound_upper_temperature(T_1, T_2)
return RS.SecantMethod(T_1, T_2)
Expand All @@ -305,10 +314,10 @@ end
::Type{phase_type},
T_guess::Union{FT, Nothing},
) where {FT, NM <: RS.NewtonsMethodAD, phase_type <: PhaseEquil}
T_min = TP.T_min(param_set)
T_init_min = TP.T_init_min(param_set)
@inline air_temp(q) = air_temperature_given_pθq(param_set, p, θ_liq_ice, q)
T_init = if T_guess isa Nothing
max(T_min, air_temp(PhasePartition(q_tot))) # Assume all vapor
max(T_init_min, air_temp(PhasePartition(q_tot))) # Assume all vapor
else
T_guess
end
Expand Down
11 changes: 6 additions & 5 deletions src/relations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2044,6 +2044,7 @@ See also [`saturation_adjustment`](@ref).
T_guess::Union{FT, Nothing} = nothing,
) where {FT <: Real, phase_type <: PhaseEquil}
_T_min = TP.T_min(param_set)
T_init_min = TP.T_init_min(param_set)
@inline air_temp(q) = air_temperature_given_ρθq(param_set, ρ, θ_liq_ice, q)
T_1 = max(_T_min, air_temp(PhasePartition(q_tot))) # Assume all vapor
q_v_sat = q_vap_saturation(param_set, T_1, ρ, phase_type)
Expand All @@ -2058,7 +2059,7 @@ See also [`saturation_adjustment`](@ref).
θ_liq_ice
sol = RS.find_zero(
roots,
RS.SecantMethod(T_1, T_2),
RS.SecantMethod(T_init_min, T_2),
RS.CompactSolution(),
tol,
maxiter,
Expand Down Expand Up @@ -2368,13 +2369,13 @@ The air temperature and `q_tot` where
tol::RS.AbstractTolerance = RS.ResidualTolerance{FT}(sqrt(eps(FT))),
) where {FT <: Real, phase_type <: ThermodynamicState}

_T_min = TP.T_min(param_set)
T_init_min = TP.T_init_min(param_set)
_T_max = T_virt
@inline roots(T) =
T_virt - virt_temp_from_RH(param_set, heavisided(T), ρ, RH, phase_type)
sol = RS.find_zero(
roots,
RS.SecantMethod(_T_min, _T_max),
RS.SecantMethod(T_init_min, _T_max),
RS.CompactSolution(),
tol,
maxiter,
Expand Down Expand Up @@ -2464,7 +2465,7 @@ by finding the root of
tol::RS.AbstractTolerance,
q::PhasePartition{FT} = q_pt_0(FT),
) where {FT <: Real}
_T_min = TP.T_min(param_set)
T_init_min = TP.T_init_min(param_set)
_T_max = TP.T_max(param_set)
@inline roots(T) =
T - air_temperature_given_pθq(
Expand All @@ -2475,7 +2476,7 @@ by finding the root of
)
sol = RS.find_zero(
roots,
RS.SecantMethod(_T_min, _T_max),
RS.SecantMethod(T_init_min, _T_max),
RS.CompactSolution(),
tol,
maxiter,
Expand Down
2 changes: 1 addition & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Thermodynamics = "b60c26fb-14c3-4610-9d3e-2d17fe7ff00c"

[compat]
CLIMAParameters = "0.8"
CLIMAParameters = "0.9"
KernelAbstractions = "0.9"
RootSolvers = "0.4"
julia = "1.7"

2 comments on commit b67e7f7

@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/100814

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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.12.0 -m "<description of version>" b67e7f78a3b74d507f518ece96a25490e15d64dd
git push origin v0.12.0

Please sign in to comment.