Skip to content

Commit

Permalink
Pass subset of ClimaAtmosParameters to detrainment
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskawczynski committed Nov 20, 2024
1 parent 7eb481f commit ef37150
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 33 deletions.
3 changes: 2 additions & 1 deletion src/cache/diagnostic_edmf_precomputed_quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!(

thermo_params = CAP.thermodynamics_params(params)
microphys_params = CAP.microphysics_precipitation_params(params)
tc_params = CAP.turbconv_params(params)

ᶠΦ = p.scratch.ᶠtemp_scalar
@. ᶠΦ = CAP.grav(params) * ᶠz
Expand Down Expand Up @@ -481,7 +482,7 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!(
)

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

Expand Down
6 changes: 4 additions & 2 deletions src/cache/prognostic_edmf_precomputed_quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_closures!(
(; params) = p
(; dt) = p
thermo_params = CAP.thermodynamics_params(params)
tc_params = CAP.turbconv_params(params)

FT = eltype(params)
n = n_mass_flux_subdomains(turbconv_model)
Expand Down Expand Up @@ -240,7 +241,7 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_closures!(
)

@. ᶜturb_entrʲs.:($$j) = turbulent_entrainment(
params,
tc_params,
draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲs.:($$j)),
)

Expand All @@ -251,7 +252,8 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_closures!(
@. ᶜmassflux_vert_div =
ᶜdivᵥ(ᶠinterp(Y.c.sgsʲs.:($$j).ρa) * ᶠu³ʲs.:($$j))
@. ᶜdetrʲs.:($$j) = detrainment(
params,
thermo_params,
tc_params,
ᶜz,
z_sfc,
ᶜp,
Expand Down
4 changes: 2 additions & 2 deletions src/prognostic_equations/edmfx_closures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ end
"""
Return buoyancy on cell centers.
"""
function ᶜphysical_buoyancy(params, ᶜρ_ref, ᶜρ)
function ᶜphysical_buoyancy(thermo_params, ᶜρ_ref, ᶜρ)
# TODO - replace by ᶜgradᵥᶠΦ when we move to deep atmosphere
g = CAP.grav(params)
g = CAP.grav(thermo_params)
return (ᶜρ_ref - ᶜρ) / ᶜρ * g
end
"""
Expand Down
66 changes: 38 additions & 28 deletions src/prognostic_equations/edmfx_entr_detr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
Return entrainment rate [1/s].
Inputs (everything defined on cell centers):
- params set with model parameters
- `thermo_params` thermodynamics parameters
- `tc_params` turbulence convection parameters
- ᶜz, z_sfc, ᶜp, ᶜρ, - grid-scale height, surface height, grid-scale pressure and density
- buoy_flux_surface - buoyancy flux at the surface
- ᶜaʲ, ᶜwʲ, ᶜRHʲ, ᶜbuoyʲ - updraft area, physical vertical velocity,
Expand All @@ -17,7 +18,8 @@
"""

function entrainment(
params,
thermo_params,
tc_params,
ᶜz,
z_sfc,
ᶜp,
Expand All @@ -32,11 +34,12 @@ function entrainment(
ᶜtke⁰,
::NoEntrainment,
)
return zero(eltype(params))
return zero(eltype(thermo_params))
end

function entrainment(
params,
thermo_params,
tc_params,
ᶜz,
z_sfc,
ᶜp,
Expand All @@ -51,14 +54,14 @@ function entrainment(
ᶜtke⁰,
::PiGroupsEntrainment,
)
FT = eltype(params)
FT = eltype(thermo_params)
if ᶜaʲ <= FT(0)
return FT(0)
else
g = CAP.grav(params)
g = CAP.grav(thermo_params)
ref_H = ᶜp / (ᶜρ * g)

entr_param_vec = CAP.entr_param_vec(params)
entr_param_vec = CAP.entr_param_vec(tc_params)

# non-dimensional pi-groups
Π₁ = (ᶜz - z_sfc) * (ᶜbuoyʲ - ᶜbuoy⁰) / ((ᶜwʲ - ᶜw⁰)^2 + eps(FT)) / 100
Expand All @@ -85,7 +88,8 @@ function entrainment(
end

function entrainment(
params,
thermo_params,
tc_params,
ᶜz,
z_sfc,
ᶜp,
Expand All @@ -100,8 +104,8 @@ function entrainment(
ᶜtke⁰,
::GeneralizedEntrainment,
)
FT = eltype(params)
turbconv_params = CAP.turbconv_params(params)
FT = eltype(thermo_params)
turbconv_params = tc_params
entr_inv_tau = CAP.entr_tau(turbconv_params)
entr_coeff = CAP.entr_coeff(turbconv_params)
min_area_limiter_scale = CAP.min_area_limiter_scale(turbconv_params)
Expand All @@ -120,7 +124,8 @@ function entrainment(
end

function detrainment_from_thermo_state(
params,
thermo_params,
tc_params,
z_prev_level,
z_sfc_halflevel,
p_prev_level,
Expand All @@ -139,10 +144,10 @@ function detrainment_from_thermo_state(
tke_prev_level,
edmfx_detr_model,
)
FT = eltype(params)
thermo_params = CAP.thermodynamics_params(params)
FT = eltype(thermo_params)
detrainment(
params,
thermo_params,
tc_params,
z_prev_level,
z_sfc_halflevel,
p_prev_level,
Expand All @@ -151,7 +156,7 @@ function detrainment_from_thermo_state(
draft_area(ρaʲ_prev_level, ρʲ_prev_level),
get_physical_w(u³ʲ_prev_halflevel, local_geometry_prev_halflevel),
TD.relative_humidity(thermo_params, tsʲ_prev_level),
ᶜphysical_buoyancy(params, ρ_prev_level, ρʲ_prev_level),
ᶜphysical_buoyancy(thermo_params, ρ_prev_level, ρʲ_prev_level),
get_physical_w(u³_prev_halflevel, local_geometry_prev_halflevel),
TD.relative_humidity(thermo_params, ts_prev_level),
FT(0),
Expand All @@ -167,7 +172,8 @@ end
Return detrainment rate [1/s].
Inputs (everything defined on cell centers):
- params set with model parameters
- `thermo_params` thermodynamics parameters
- `tc_params` turbulence convection parameters
- ᶜz, z_sfc, ᶜp, ᶜρ, - grid-scale height, surface height, grid-scale pressure and density
- buoy_flux_surface - buoyancy flux at the surface
- ᶜρaʲ, ᶜaʲ, ᶜwʲ, ᶜRHʲ, ᶜbuoyʲ - updraft effective density, updraft area, physical vertical velocity,
Expand All @@ -178,7 +184,8 @@ end
- ᶜvert_div,ᶜmassflux_vert_div - vertical divergence, vertical mass flux divergence
"""
function detrainment(
params,
thermo_params,
tc_params,
ᶜz,
z_sfc,
ᶜp,
Expand All @@ -197,11 +204,12 @@ function detrainment(
ᶜtke⁰,
::NoDetrainment,
)
return zero(eltype(params))
return zero(eltype(thermo_params))
end

function detrainment(
params,
thermo_params,
tc_params,
ᶜz,
z_sfc,
ᶜp,
Expand All @@ -220,14 +228,14 @@ function detrainment(
ᶜtke⁰,
::PiGroupsDetrainment,
)
FT = eltype(params)
FT = eltype(thermo_params)
if ᶜaʲ <= FT(0)
return FT(0)
else
g = CAP.grav(params)
g = CAP.grav(thermo_params)
ref_H = ᶜp / (ᶜρ * g)

entr_param_vec = CAP.entr_param_vec(params)
entr_param_vec = CAP.entr_param_vec(tc_params)

# non-dimensional pi-groups
Π₁ = (ᶜz - z_sfc) * (ᶜbuoyʲ - ᶜbuoy⁰) / ((ᶜwʲ - ᶜw⁰)^2 + eps(FT)) / 100
Expand All @@ -252,7 +260,8 @@ function detrainment(
end

function detrainment(
params,
thermo_params,
tc_params,
ᶜz,
z_sfc,
ᶜp,
Expand All @@ -271,8 +280,8 @@ function detrainment(
ᶜtke⁰,
::GeneralizedDetrainment,
)
FT = eltype(params)
turbconv_params = CAP.turbconv_params(params)
FT = eltype(thermo_params)
turbconv_params = tc_params
detr_inv_tau = CAP.detr_tau(turbconv_params)
detr_coeff = CAP.detr_coeff(turbconv_params)
detr_buoy_coeff = CAP.detr_buoy_coeff(turbconv_params)
Expand Down Expand Up @@ -303,7 +312,8 @@ function detrainment(
end

function detrainment(
params,
thermo_params,
tc_params,
ᶜz,
z_sfc,
ᶜp,
Expand All @@ -325,8 +335,8 @@ function detrainment(
return max(detr, 0)
end

function turbulent_entrainment(params, ᶜaʲ)
turb_entr_param_vec = CAP.turb_entr_param_vec(params)
function turbulent_entrainment(tc_params, ᶜaʲ)
turb_entr_param_vec = CAP.turb_entr_param_vec(tc_params)
return max(turb_entr_param_vec[1] * exp(-turb_entr_param_vec[2] * ᶜaʲ), 0)
end

Expand Down

0 comments on commit ef37150

Please sign in to comment.