Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
Merge #1928
Browse files Browse the repository at this point in the history
1928: Add thermo mixing ratio functions r=charleskawczynski a=charleskawczynski

Add thermo method `shum_to_mixing_ratio` for computing mixing ratios (needed for radiation). I've also added a convenience method, `mixing_ratios`, which accepts a `PhasePartition`, and returns a `PhasePartition` of mixing ratios.

Co-authored-by: Charles Kawczynski <kawczynski.charles@gmail.com>
  • Loading branch information
2 people authored and yairchn committed Jan 15, 2021
2 parents ac78879 + e8c46a4 commit eb15711
Show file tree
Hide file tree
Showing 11 changed files with 290 additions and 44 deletions.
2 changes: 2 additions & 0 deletions docs/src/APIs/Common/Thermodynamics.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ liquid_fraction
liquid_ice_pottemp
liquid_ice_pottemp_sat
liquid_specific_humidity
mixing_ratios
moist_static_energy
q_vap_saturation
q_vap_saturation_liquid
Expand All @@ -74,6 +75,7 @@ saturation_adjustment
saturation_excess
saturation_vapor_pressure
soundspeed_air
shum_to_mixing_ratio
specific_enthalpy
specific_volume
supersaturation
Expand Down
40 changes: 40 additions & 0 deletions src/Common/Thermodynamics/relations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export liquid_fraction, PhasePartition_equil
export dry_pottemp
export virtual_pottemp
export exner
export shum_to_mixing_ratio
export mixing_ratios
export liquid_ice_pottemp
export liquid_ice_pottemp_sat
export relative_humidity
Expand Down Expand Up @@ -2185,6 +2187,44 @@ exner(ts::ThermodynamicState) = exner(
PhasePartition(ts),
)

"""
shum_to_mixing_ratio(q, q_tot)
Mixing ratio, from specific humidity
- `q` specific humidity
- `q_tot` total specific humidity
"""
function shum_to_mixing_ratio(q::FT, q_tot::FT) where {FT <: Real}
return q / (1 - q_tot)
end

"""
mixing_ratios(q::PhasePartition)
Mixing ratios
- `r.tot` total mixing ratio
- `r.liq` liquid mixing ratio
- `r.ice` ice mixing ratio
given a phase partition, `q`.
"""
function mixing_ratios(q::PhasePartition{FT}) where {FT <: Real}
return PhasePartition(
shum_to_mixing_ratio(q.tot, q.tot),
shum_to_mixing_ratio(q.liq, q.tot),
shum_to_mixing_ratio(q.ice, q.tot),
)
end

"""
mixing_ratios(ts::ThermodynamicState)
Mixing ratios stored, in a phase partition, for
- total specific humidity
- liquid specific humidity
- ice specific humidity
"""
mixing_ratios(ts::ThermodynamicState) = mixing_ratios(PhasePartition(ts))

"""
relative_humidity(param_set, T, p, phase_type, q::PhasePartition)
Expand Down
8 changes: 7 additions & 1 deletion test/Atmos/EDMF/closures/entr_detr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ function entr_detr(
lim_amp = entr.lim_amp
w_min = entr.w_min
# precompute vars
w_up_i = fix_void_up(up[i].ρa, up[i].ρaw / up[i].ρa)
w_up_i = fix_void_up(
m.turbconv,
up[i].ρa*ρ_inv,
up[i].ρaw / up[i].ρa,
gm.ρu[3],
gm.ρu[3],
)
sqrt_tke = sqrt(max(en.ρatke, 0) * ρ_inv / env.a)
# ensure far from zero
Δw = filter_w(w_up_i - env.w, w_min)
Expand Down
2 changes: 1 addition & 1 deletion test/Atmos/EDMF/closures/mixing_length.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function mixing_length(
b = FT(0)
a_up = vuntuple(i -> up[i].ρa * ρinv, N_up)
w_up = vuntuple(N_up) do i
fix_void_up(up[i].ρa, up[i].ρaw / up[i].ρa)
fix_void_up(m.turbconv, up[i].ρa/gm.ρ, up[i].ρaw / up[i].ρa)
end
b = sum(
ntuple(N_up) do i
Expand Down
8 changes: 7 additions & 1 deletion test/Atmos/EDMF/closures/pressure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ function perturbation_pressure(
up_aux = aux.turbconv.updraft
up_dif = diffusive.turbconv.updraft

w_up_i = fix_void_up(up[i].ρa, up[i].ρaw / up[i].ρa)
w_up_i = fix_void_up(
m.turbconv,
up[i].ρa/state.ρ,
up[i].ρaw / up[i].ρa,
state.ρu[3],
state.ρu[3],
)

nh_press_buoy = press.α_b * buoy.up[i]
nh_pressure_adv = -press.α_a * w_up_i * up_dif[i].∇w[3]
Expand Down
Loading

0 comments on commit eb15711

Please sign in to comment.