Skip to content

Commit

Permalink
Dont assume that MSLP and theta ref pressure are the same
Browse files Browse the repository at this point in the history
  • Loading branch information
trontrytel committed Aug 29, 2023
1 parent f7d5775 commit 3e94218
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/Parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ param_set = TP.ThermodynamicsParameters{FT}(; param_pairs...);
Base.@kwdef struct ThermodynamicsParameters{FT}
T_0::FT
MSLP::FT
p_ref_theta::FT
cp_v::FT
cp_l::FT
cp_i::FT
Expand Down
8 changes: 4 additions & 4 deletions src/isentropic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ function air_pressure_given_θ(
Φ::FT,
::DryAdiabaticProcess,
) where {FT <: AbstractFloat}
MSLP::FT = TP.MSLP(param_set)
p0::FT = TP.p_ref_theta(param_set)
_R_d::FT = TP.R_d(param_set)
_cp_d::FT = TP.cp_d(param_set)
return MSLP * (1 - Φ /* _cp_d))^(_cp_d / _R_d)
return p0 * (1 - Φ /* _cp_d))^(_cp_d / _R_d)
end

"""
Expand Down Expand Up @@ -72,6 +72,6 @@ function air_temperature(
) where {FT <: AbstractFloat}
_R_d::FT = TP.R_d(param_set)
_cp_d::FT = TP.cp_d(param_set)
MSLP::FT = TP.MSLP(param_set)
return (p / MSLP)^(_R_d / _cp_d) * θ
p0::FT = TP.p_ref_theta(param_set)
return (p / p0)^(_R_d / _cp_d) * θ
end
10 changes: 5 additions & 5 deletions src/relations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2293,12 +2293,12 @@ function air_temperature_given_ρθq(
q::PhasePartition{FT} = q_pt_0(FT),
) where {FT <: Real}

MSLP::FT = TP.MSLP(param_set)
p0::FT = TP.p_ref_theta(param_set)
cvm = cv_m(param_set, q)
cpm = cp_m(param_set, q)
R_m = gas_constant_air(param_set, q)
κ = 1 - cvm / cpm
T_u =* R_m * θ_liq_ice / MSLP)^(R_m / cvm) * θ_liq_ice
T_u =* R_m * θ_liq_ice / p0)^(R_m / cvm) * θ_liq_ice
T_1 = latent_heat_liq_ice(param_set, q) / cvm
T_2 = -κ / (2 * T_u) * (latent_heat_liq_ice(param_set, q) / cvm)^2
return T_u + T_1 + T_2
Expand Down Expand Up @@ -2545,13 +2545,13 @@ function exner_given_pressure(
p::FT,
q::PhasePartition{FT} = q_pt_0(FT),
) where {FT <: Real}
MSLP::FT = TP.MSLP(param_set)
p0::FT = TP.p_ref_theta(param_set)
# gas constant and isobaric specific heat of moist air
_R_m = gas_constant_air(param_set, q)
_cp_m = cp_m(param_set, q)

# return (p / MSLP)^(_R_m / _cp_m)
return pow_hack(p / MSLP, _R_m / _cp_m)
# return (p / p0)^(_R_m / _cp_m)
return pow_hack(p / p0, _R_m / _cp_m)
end

"""
Expand Down
20 changes: 11 additions & 9 deletions test/relations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ compare_moisture(param_set, ts::PhaseNonEquil, q_pt::PhasePartition) = all((
_T_triple = FT(TP.T_triple(param_set))
_T_freeze = FT(TP.T_freeze(param_set))
_T_min = FT(TP.T_min(param_set))
_MSLP = FT(TP.MSLP(param_set))
_p_ref_theta = FT(TP.p_ref_theta(param_set))
_T_max = FT(TP.T_max(param_set))
_kappa_d = FT(TP.kappa_d(param_set))

Expand All @@ -105,13 +105,13 @@ compare_moisture(param_set, ts::PhaseNonEquil, q_pt::PhasePartition) = all((
# TODO: Use reasonable values for ambient temperature/pressure
T∞, p∞ = T .* perturbation, p .* perturbation
@test air_temperature.(param_set, p, θ_liq_ice, DryAdiabaticProcess())
(p ./ _MSLP) .^ (_R_d / _cp_d) .* θ_liq_ice
(p ./ _p_ref_theta) .^ (_R_d / _cp_d) .* θ_liq_ice
@test TD.air_pressure_given_θ.(
param_set,
θ_liq_ice,
Φ,
DryAdiabaticProcess(),
) _MSLP .* (1 .- Φ ./ (θ_liq_ice .* _cp_d)) .^ (_cp_d / _R_d)
) _p_ref_theta .* (1 .- Φ ./ (θ_liq_ice .* _cp_d)) .^ (_cp_d / _R_d)
@test air_pressure.(param_set, T, T∞, p∞, DryAdiabaticProcess())
p∞ .* (T ./ T∞) .^ (FT(1) / _kappa_d)
end
Expand Down Expand Up @@ -142,7 +142,7 @@ end
_T_triple = FT(TP.T_triple(param_set))
_T_freeze = FT(TP.T_freeze(param_set))
_T_min = FT(TP.T_min(param_set))
_MSLP = FT(TP.MSLP(param_set))
_p_ref_theta = FT(TP.p_ref_theta(param_set))
_T_max = FT(TP.T_max(param_set))
_kappa_d = FT(TP.kappa_d(param_set))
_T_icenuc = FT(TP.T_icenuc(param_set))
Expand Down Expand Up @@ -446,13 +446,16 @@ end

# potential temperatures
T = FT(300)
@test TD.liquid_ice_pottemp_given_pressure(param_set, T, _MSLP) === T
@test TD.liquid_ice_pottemp_given_pressure(param_set, T, _MSLP / 10)
T * 10^(_R_d / _cp_d)
@test TD.liquid_ice_pottemp_given_pressure(param_set, T, _p_ref_theta) === T
@test TD.liquid_ice_pottemp_given_pressure(
param_set,
T,
_MSLP / 10,
_p_ref_theta / 10,
) T * 10^(_R_d / _cp_d)
@test TD.liquid_ice_pottemp_given_pressure(
param_set,
T,
_p_ref_theta / 10,
PhasePartition(FT(1)),
) T * 10^(_R_v / _cp_v)

Expand Down Expand Up @@ -992,7 +995,6 @@ end
for ArrayType in array_types
FT = eltype(ArrayType)
param_set = parameter_set(FT)
_MSLP = FT(TP.MSLP(param_set))

profiles = TestedProfiles.PhaseDryProfiles(param_set, ArrayType)
@unpack T, p, e_int, h, ρ, θ_liq_ice, phase_type = profiles
Expand Down

0 comments on commit 3e94218

Please sign in to comment.