Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ClimaParameters T_init_min, with new T_min value #193

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
::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 @@
::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)

Check warning on line 76 in src/config_numerical_method.jl

View check run for this annotation

Codecov / codecov/patch

src/config_numerical_method.jl#L76

Added line #L76 was not covered by tests
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

Check warning on line 78 in src/config_numerical_method.jl

View check run for this annotation

Codecov / codecov/patch

src/config_numerical_method.jl#L78

Added line #L78 was not covered by tests
else
T_guess
end
Expand All @@ -91,10 +91,13 @@
::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 @@
::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)

Check warning on line 114 in src/config_numerical_method.jl

View check run for this annotation

Codecov / codecov/patch

src/config_numerical_method.jl#L114

Added line #L114 was not covered by tests
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(

Check warning on line 117 in src/config_numerical_method.jl

View check run for this annotation

Codecov / codecov/patch

src/config_numerical_method.jl#L117

Added line #L117 was not covered by tests
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 @@
::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)

Check warning on line 175 in src/config_numerical_method.jl

View check run for this annotation

Codecov / codecov/patch

src/config_numerical_method.jl#L175

Added line #L175 was not covered by tests
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

Check warning on line 177 in src/config_numerical_method.jl

View check run for this annotation

Codecov / codecov/patch

src/config_numerical_method.jl#L177

Added line #L177 was not covered by tests
else
T_guess
end
Expand All @@ -184,10 +190,13 @@
::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 @@
::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)

Check warning on line 217 in src/config_numerical_method.jl

View check run for this annotation

Codecov / codecov/patch

src/config_numerical_method.jl#L217

Added line #L217 was not covered by tests
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 @@
::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 @@
::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)

Check warning on line 258 in src/config_numerical_method.jl

View check run for this annotation

Codecov / codecov/patch

src/config_numerical_method.jl#L258

Added line #L258 was not covered by tests
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 @@
::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 @@
::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 @@
::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"
Loading