Skip to content

Commit

Permalink
Pass subset of ClimaAtmosParameters to detrainment
Browse files Browse the repository at this point in the history
Fixes

More fixes

Rename tc_params -> turbconv_params
  • Loading branch information
charleskawczynski committed Nov 21, 2024
1 parent 6fa62ee commit 5f2ba95
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 39 deletions.
11 changes: 7 additions & 4 deletions 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)
turbconv_params = CAP.turbconv_params(params)

ᶠΦ = p.scratch.ᶠtemp_scalar
@. ᶠΦ = CAP.grav(params) * ᶠz
Expand Down Expand Up @@ -458,7 +459,8 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!(
tke_prev_level = Fields.field_values(Fields.level(ᶜtke⁰, i - 1))

@. entrʲ_prev_level = entrainment(
params,
thermo_params,
turbconv_params,
z_prev_level,
z_sfc_halflevel,
p_prev_level,
Expand All @@ -469,7 +471,7 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!(
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,
Expand All @@ -481,7 +483,7 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!(
)

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

Expand Down Expand Up @@ -598,7 +600,8 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!(
) / local_geometry_level.J / ρ_level

@. detrʲ_prev_level = detrainment_from_thermo_state(
params,
thermo_params,
turbconv_params,
z_prev_level,
z_sfc_halflevel,
p_prev_level,
Expand Down
13 changes: 8 additions & 5 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)
turbconv_params = CAP.turbconv_params(params)

FT = eltype(params)
n = n_mass_flux_subdomains(turbconv_model)
Expand Down Expand Up @@ -217,15 +218,16 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_closures!(
for j in 1:n
# entrainment/detrainment
@. ᶜentrʲs.:($$j) = entrainment(
params,
thermo_params,
turbconv_params,
ᶜz,
z_sfc,
ᶜp,
Y.c.ρ,
draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲs.:($$j)),
get_physical_w(ᶜuʲs.:($$j), ᶜlg),
TD.relative_humidity(thermo_params, ᶜtsʲs.:($$j)),
ᶜphysical_buoyancy(params, Y.c.ρ, ᶜρʲs.:($$j)),
ᶜphysical_buoyancy(thermo_params, Y.c.ρ, ᶜρʲs.:($$j)),
get_physical_w(ᶜu, ᶜlg),
TD.relative_humidity(thermo_params, ᶜts⁰),
FT(0),
Expand All @@ -240,7 +242,7 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_closures!(
)

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

Expand All @@ -251,7 +253,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,
turbconv_params,
ᶜz,
z_sfc,
ᶜp,
Expand All @@ -260,7 +263,7 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_closures!(
draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲs.:($$j)),
get_physical_w(ᶜuʲs.:($$j), ᶜlg),
TD.relative_humidity(thermo_params, ᶜtsʲs.:($$j)),
ᶜphysical_buoyancy(params, Y.c.ρ, ᶜρʲs.:($$j)),
ᶜphysical_buoyancy(thermo_params, Y.c.ρ, ᶜρʲs.:($$j)),
get_physical_w(ᶜu, ᶜlg),
TD.relative_humidity(thermo_params, ᶜts⁰),
FT(0),
Expand Down
5 changes: 3 additions & 2 deletions src/prognostic_equations/edmfx_closures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#####

import StaticArrays as SA
import Thermodynamics.Parameters as TDP
import ClimaCore.Geometry as Geometry
import ClimaCore.Fields as Fields

Expand All @@ -16,9 +17,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 = TDP.grav(thermo_params)
return (ᶜρ_ref - ᶜρ) / ᶜρ * g
end
"""
Expand Down
68 changes: 40 additions & 28 deletions src/prognostic_equations/edmfx_entr_detr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
##### EDMF entrainment detrainment
#####

import Thermodynamics.Parameters as TDP

"""
Return entrainment rate [1/s].
Inputs (everything defined on cell centers):
- params set with model parameters
- `thermo_params` thermodynamics parameters
- `turbconv_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 +20,8 @@
"""

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

function entrainment(
params,
thermo_params,
turbconv_params,
ᶜz,
z_sfc,
ᶜp,
Expand All @@ -51,14 +56,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 = TDP.grav(thermo_params)
ref_H = ᶜp / (ᶜρ * g)

entr_param_vec = CAP.entr_param_vec(params)
entr_param_vec = CAP.entr_param_vec(turbconv_params)

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

function entrainment(
params,
thermo_params,
turbconv_params,
ᶜz,
z_sfc,
ᶜp,
Expand All @@ -100,8 +106,8 @@ function entrainment(
ᶜtke⁰,
::GeneralizedEntrainment,
)
FT = eltype(params)
turbconv_params = CAP.turbconv_params(params)
FT = eltype(thermo_params)
turbconv_params = turbconv_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 +126,8 @@ function entrainment(
end

function detrainment_from_thermo_state(
params,
thermo_params,
turbconv_params,
z_prev_level,
z_sfc_halflevel,
p_prev_level,
Expand All @@ -139,10 +146,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,
turbconv_params,
z_prev_level,
z_sfc_halflevel,
p_prev_level,
Expand All @@ -151,7 +158,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 +174,8 @@ end
Return detrainment rate [1/s].
Inputs (everything defined on cell centers):
- params set with model parameters
- `thermo_params` thermodynamics parameters
- `turbconv_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 +186,8 @@ end
- ᶜvert_div,ᶜmassflux_vert_div - vertical divergence, vertical mass flux divergence
"""
function detrainment(
params,
thermo_params,
turbconv_params,
ᶜz,
z_sfc,
ᶜp,
Expand All @@ -197,11 +206,12 @@ function detrainment(
ᶜtke⁰,
::NoDetrainment,
)
return zero(eltype(params))
return zero(eltype(thermo_params))
end

function detrainment(
params,
thermo_params,
turbconv_params,
ᶜz,
z_sfc,
ᶜp,
Expand All @@ -220,14 +230,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 = TDP.grav(thermo_params)
ref_H = ᶜp / (ᶜρ * g)

entr_param_vec = CAP.entr_param_vec(params)
entr_param_vec = CAP.entr_param_vec(turbconv_params)

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

function detrainment(
params,
thermo_params,
turbconv_params,
ᶜz,
z_sfc,
ᶜp,
Expand All @@ -271,8 +282,8 @@ function detrainment(
ᶜtke⁰,
::GeneralizedDetrainment,
)
FT = eltype(params)
turbconv_params = CAP.turbconv_params(params)
FT = eltype(thermo_params)
turbconv_params = turbconv_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 +314,8 @@ function detrainment(
end

function detrainment(
params,
thermo_params,
turbconv_params,
ᶜz,
z_sfc,
ᶜp,
Expand All @@ -325,8 +337,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(turbconv_params, ᶜaʲ)
turb_entr_param_vec = CAP.turb_entr_param_vec(turbconv_params)
return max(turb_entr_param_vec[1] * exp(-turb_entr_param_vec[2] * ᶜaʲ), 0)
end

Expand Down

0 comments on commit 5f2ba95

Please sign in to comment.