Skip to content

Commit

Permalink
ensure limit turbulent entrainment is positive
Browse files Browse the repository at this point in the history
  • Loading branch information
costachris committed Sep 22, 2024
1 parent 835f2e4 commit 939e23c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
30 changes: 15 additions & 15 deletions src/cache/diagnostic_edmf_precomputed_quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!(
p.atmos.edmfx_model.entr_model,
)

@. turb_entrʲ_prev_level = turbulent_entrainment(
params,
draft_area(ρaʲ_prev_level, ρʲ_prev_level),
)

# We don't have an upper limit to entrainment for the first level
# (calculated at i=2), as the vertical velocity at the first level is zero
if i > 2
Expand All @@ -418,28 +423,23 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!(
),
dz_prev_level,
)

@. turb_entrʲ_prev_level = limit_turb_entrainment(
entrʲ_prev_level,
turb_entrʲ_prev_level,
get_physical_w(
u³ʲ_prev_halflevel,
local_geometry_prev_halflevel,
),
dz_prev_level,
)
end
@. entrʲ_prev_level = limit_entrainment(
entrʲ_prev_level,
draft_area(ρaʲ_prev_level, ρʲ_prev_level),
dt,
)

@. turb_entrʲ_prev_level = turbulent_entrainment(
params,
draft_area(ρaʲ_prev_level, ρʲ_prev_level),
)

@. turb_entrʲ_prev_level = limit_turb_entrainment(
entrʲ_prev_level,
turb_entrʲ_prev_level,
get_physical_w(
u³ʲ_prev_halflevel,
local_geometry_prev_halflevel,
),
dz_prev_level,
)

# TODO: use updraft top instead of scale height
if p.atmos.edmfx_model.nh_pressure isa Val{true}
@. nh_pressure³ʲ_prev_halflevel = ᶠupdraft_nh_pressure(
Expand Down
4 changes: 2 additions & 2 deletions src/prognostic_equations/edmfx_entr_detr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ limit_detrainment(detr::FT, a, dt) where {FT} =
max(min(detr, FT(0.9) * 1 / dt), 0)

function limit_turb_entrainment(dyn_entr::FT, turb_entr::FT, dt) where {FT}
return min((FT(0.9) * 1 / dt) - dyn_entr, turb_entr)
return max(min((FT(0.9) * 1 / dt) - dyn_entr, turb_entr), 0)
end

# limit entrainment and detrainment rates for diagnostic EDMF
Expand All @@ -379,5 +379,5 @@ limit_detrainment(detr::FT, a, w, dz) where {FT} =
max(min(detr, FT(0.9) * w / dz), 0)

function limit_turb_entrainment(dyn_entr::FT, turb_entr::FT, w, dz) where {FT}
return min((FT(0.9) * w / dz) - dyn_entr, turb_entr)
return max(min((FT(0.9) * w / dz) - dyn_entr, turb_entr), 0)
end

0 comments on commit 939e23c

Please sign in to comment.