Skip to content

Commit

Permalink
add mass flux divergence to detrainment
Browse files Browse the repository at this point in the history
  • Loading branch information
szy21 committed Mar 14, 2024
1 parent ee2f72a commit cba48eb
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 107 deletions.
2 changes: 1 addition & 1 deletion config/model_configs/prognostic_edmfx_bomex_box.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ y_elem: 2
z_elem: 60
z_stretch: false
perturb_initstate: false
dt: "20secs"
dt: "10secs"
t_end: "6hours"
dt_save_state_to_disk: "30mins"
toml: [toml/prognostic_edmfx_bomex_box.toml]
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[deps]
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
ClimaParams = "5c42b081-d73a-476f-9059-fd94b934656c"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
ClimaAtmos = "b2c96348-7fb7-4fe0-8da9-78d88439e717"
ClimaParams = "5c42b081-d73a-476f-9059-fd94b934656c"
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DocumenterCitations = "daee34ce-89f3-4625-b898-19384cb65244"
Expand Down
2 changes: 1 addition & 1 deletion perf/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ ArtifactWrappers = "a14bc488-3040-4b00-9dc1-f6467924858a"
AtmosphericProfilesLibrary = "86bc3604-9858-485a-bdbe-831ec50de11d"
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
ClimaParams = "5c42b081-d73a-476f-9059-fd94b934656c"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
ClimaAnalysis = "29b5916a-a76c-4e73-9657-3c8fd22e65e6"
Expand All @@ -17,6 +16,7 @@ ClimaCorePlots = "cf7c7e5a-b407-4c48-9047-11a94a308626"
ClimaCoreSpectra = "c2caaa1d-32ae-4754-ba0d-80e7561362e9"
ClimaCoreTempestRemap = "d934ef94-cdd4-4710-83d6-720549644b70"
ClimaCoreVTK = "c8b6d40d-e815-466f-95ae-c48aefa668fa"
ClimaParams = "5c42b081-d73a-476f-9059-fd94b934656c"
ClimaTimeSteppers = "595c0a79-7f3d-439a-bc5a-b232dc3bde79"
CloudMicrophysics = "6a9e3e04-43cd-43ba-94b9-e8782df3c71b"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Expand Down
2 changes: 2 additions & 0 deletions src/cache/diagnostic_edmf_precomputed_quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ function set_diagnostic_edmf_precomputed_quantities_do_integral!(Y, p, t)
p_prev_level,
ρ_prev_level,
buoyancy_flux_sfc_halflevel,
ρaʲ_prev_level,
draft_area(ρaʲ_prev_level, ρʲ_prev_level),
get_physical_w(
u³ʲ_prev_halflevel,
Expand All @@ -498,6 +499,7 @@ function set_diagnostic_edmf_precomputed_quantities_do_integral!(Y, p, t)
FT(0),
entrʲ_prev_level,
vert_div_level,
FT(0), # mass flux divergence is not implemented for diagnostic edmf
p.atmos.edmfx_detr_model,
)

Expand Down
7 changes: 5 additions & 2 deletions src/cache/prognostic_edmf_precomputed_quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ function set_prognostic_edmf_precomputed_quantities_draft_and_bc!(Y, p, ᶠuₕ
(; ᶜspecific, ᶜp, ᶜh_tot, ᶜK) = p.precomputed
(; ᶜuʲs, ᶠu³ʲs, ᶜKʲs, ᶠKᵥʲs, ᶜtsʲs, ᶜρʲs) = p.precomputed
(; ustar, obukhov_length, buoyancy_flux) = p.precomputed.sfc_conditions
ᶜinterp_lb = Operators.LeftBiasedF2C()
ᶜinterp_rb = Operators.RightBiasedF2C()

for j in 1:n
ᶜuʲ = ᶜuʲs.:($j)
Expand Down Expand Up @@ -195,6 +193,7 @@ function set_prognostic_edmf_precomputed_quantities_closures!(Y, p, t)
ᶜlg = Fields.local_geometry_field(Y.c)

ᶜvert_div = p.scratch.ᶜtemp_scalar
ᶜmassflux_vert_div = p.scratch.ᶜtemp_scalar_2
for j in 1:n
# entrainment/detrainment
@. ᶜentrʲs.:($$j) = entrainment(
Expand All @@ -219,13 +218,16 @@ function set_prognostic_edmf_precomputed_quantities_closures!(Y, p, t)
dt,
)
@. ᶜvert_div = ᶜdivᵥ(ᶠinterp(ᶜρʲs.:($$j)) * ᶠu³ʲs.:($$j)) / ᶜρʲs.:($$j)
@. ᶜmassflux_vert_div =
ᶜdivᵥ(ᶠinterp(Y.c.sgsʲs.:($$j).ρa) * ᶠu³ʲs.:($$j))
@. ᶜdetrʲs.:($$j) = detrainment(
params,
ᶜz,
z_sfc,
ᶜp,
Y.c.ρ,
buoyancy_flux,
Y.c.sgsʲs.:($$j).ρa,
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)),
Expand All @@ -235,6 +237,7 @@ function set_prognostic_edmf_precomputed_quantities_closures!(Y, p, t)
FT(0),
ᶜentrʲs.:($$j),
ᶜvert_div,
ᶜmassflux_vert_div,
p.atmos.edmfx_detr_model,
)
@. ᶜdetrʲs.:($$j) = limit_detrainment(
Expand Down
1 change: 1 addition & 0 deletions src/parameters/Parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Base.@kwdef struct TurbulenceConvectionParameters{FT} <: ATCP
detr_coeff::FT
detr_buoy_coeff::FT
detr_vertdiv_coeff::FT
detr_massflux_vertdiv_coeff::FT
min_area_limiter_scale::FT
min_area_limiter_power::FT
max_area_limiter_scale::FT
Expand Down
1 change: 1 addition & 0 deletions src/parameters/create_parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function TurbulenceConvectionParameters(toml_dict::CP.AbstractTOMLDict)
:mixing_length_smin_ub => :smin_ub,
:EDMF_min_area => :min_area,
:detr_vertdiv_coeff => :detr_vertdiv_coeff,
:detr_massflux_vertdiv_coeff => :detr_massflux_vertdiv_coeff,
:max_area_limiter_power => :max_area_limiter_power,
:min_area_limiter_power => :min_area_limiter_power,
:pressure_normalmode_drag_coeff => :pressure_normalmode_drag_coeff,
Expand Down
105 changes: 25 additions & 80 deletions src/prognostic_equations/edmfx_entr_detr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,50 +114,19 @@ function entrainment(
return entr
end

function entrainment(
params,
ᶜz::FT,
z_sfc::FT,
ᶜp::FT,
ᶜρ::FT,
buoy_flux_surface::FT,
ᶜaʲ::FT,
ᶜwʲ::FT,
ᶜRHʲ::FT,
ᶜbuoyʲ::FT,
ᶜw⁰::FT,
ᶜRH⁰::FT,
ᶜbuoy⁰::FT,
::GeneralizedHarmonicsEntrainment,
) where {FT}
turbconv_params = CAP.turbconv_params(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)
min_area_limiter_power = CAP.min_area_limiter_power(turbconv_params)
a_min = CAP.min_area(turbconv_params)

min_area_limiter =
min_area_limiter_scale *
exp(-min_area_limiter_power * (max(ᶜaʲ, 0) - a_min))
entr =
entr_inv_tau + entr_coeff * abs(ᶜwʲ) / (ᶜz - z_sfc) + min_area_limiter

return entr * FT(2) * hm_limiter(ᶜaʲ)
end

"""
Return detrainment rate [1/s].
Inputs (everything defined on cell centers):
- params set with model 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,
- ᶜρaʲ, ᶜaʲ, ᶜwʲ, ᶜRHʲ, ᶜbuoyʲ - updraft effective density, updraft area, physical vertical velocity,
relative humidity and buoyancy
- ᶜw⁰, ᶜRH⁰, ᶜbuoy⁰ - environment physical vertical velocity,
relative humidity and buoyancy
- dt - timestep
- ᶜentr - entrainment rate
- ᶜvert_div,ᶜmassflux_vert_div - vertical divergence, vertical mass flux divergence
"""
function detrainment(
params,
Expand All @@ -166,6 +135,7 @@ function detrainment(
ᶜp::FT,
ᶜρ::FT,
buoy_flux_surface::FT,
ᶜρaʲ::FT,
ᶜaʲ::FT,
ᶜwʲ::FT,
ᶜRHʲ::FT,
Expand All @@ -175,6 +145,7 @@ function detrainment(
ᶜbuoy⁰::FT,
ᶜentr::FT,
ᶜvert_div::FT,
ᶜmassflux_vert_div::FT,
::NoDetrainment,
) where {FT}
return FT(0)
Expand All @@ -187,6 +158,7 @@ function detrainment(
ᶜp::FT,
ᶜρ::FT,
buoy_flux_surface::FT,
ᶜρaʲ::FT,
ᶜaʲ::FT,
ᶜwʲ::FT,
ᶜRHʲ::FT,
Expand All @@ -196,6 +168,7 @@ function detrainment(
ᶜbuoy⁰::FT,
ᶜentr::FT,
ᶜvert_div::FT,
ᶜmassflux_vert_div::FT,
::PiGroupsDetrainment,
) where {FT}

Expand Down Expand Up @@ -236,6 +209,7 @@ function detrainment(
ᶜp::FT,
ᶜρ::FT,
buoy_flux_surface::FT,
ᶜρaʲ::FT,
ᶜaʲ::FT,
ᶜwʲ::FT,
ᶜRHʲ::FT,
Expand All @@ -245,68 +219,37 @@ function detrainment(
ᶜbuoy⁰::FT,
ᶜentr::FT,
ᶜvert_div::FT,
ᶜmassflux_vert_div::FT,
::GeneralizedDetrainment,
) where {FT}
turbconv_params = CAP.turbconv_params(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)
detr_vertdiv_coeff = CAP.detr_vertdiv_coeff(turbconv_params)
detr_massflux_vertdiv_coeff =
CAP.detr_massflux_vertdiv_coeff(turbconv_params)
max_area_limiter_scale = CAP.max_area_limiter_scale(turbconv_params)
max_area_limiter_power = CAP.max_area_limiter_power(turbconv_params)
a_max = CAP.max_area(turbconv_params)

max_area_limiter =
max_area_limiter_scale *
exp(-max_area_limiter_power * (a_max - min(ᶜaʲ, 1)))
detr =
detr_inv_tau +
detr_coeff * abs(ᶜwʲ) +
detr_buoy_coeff * abs(min(ᶜbuoyʲ - ᶜbuoy⁰, 0)) /
max(eps(FT), abs(ᶜwʲ - ᶜw⁰)) - detr_vertdiv_coeff * ᶜvert_div +
max_area_limiter

return detr
end

function detrainment(
params,
ᶜz::FT,
z_sfc::FT,
ᶜp::FT,
ᶜρ::FT,
buoy_flux_surface::FT,
ᶜaʲ::FT,
ᶜwʲ::FT,
ᶜRHʲ::FT,
ᶜbuoyʲ::FT,
ᶜw⁰::FT,
ᶜRH⁰::FT,
ᶜbuoy⁰::FT,
ᶜentr::FT,
ᶜvert_div::FT,
::GeneralizedHarmonicsDetrainment,
) where {FT}
turbconv_params = CAP.turbconv_params(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)
detr_vertdiv_coeff = CAP.detr_vertdiv_coeff(turbconv_params)
max_area_limiter_scale = CAP.max_area_limiter_scale(turbconv_params)
max_area_limiter_power = CAP.max_area_limiter_power(turbconv_params)
a_max = CAP.max_area(turbconv_params)

max_area_limiter =
max_area_limiter_scale *
exp(-max_area_limiter_power * (a_max - min(ᶜaʲ, 1)))
detr =
detr_inv_tau +
detr_coeff * abs(ᶜwʲ) +
detr_buoy_coeff * abs(min(ᶜbuoyʲ - ᶜbuoy⁰, 0)) /
max(eps(FT), abs(ᶜwʲ - ᶜw⁰)) - detr_vertdiv_coeff * ᶜvert_div +
max_area_limiter
if ᶜρaʲ <= 0
detr = 0
else
detr =
detr_inv_tau +
detr_coeff * abs(ᶜwʲ) +
detr_buoy_coeff * abs(min(ᶜbuoyʲ - ᶜbuoy⁰, 0)) /
max(eps(FT), abs(ᶜwʲ - ᶜw⁰)) - detr_vertdiv_coeff * ᶜvert_div -
detr_massflux_vertdiv_coeff * min(ᶜmassflux_vert_div, 0) / ᶜρaʲ +
max_area_limiter
end

return detr * FT(2) * hm_limiter(ᶜaʲ)
return detr
end

function detrainment(
Expand All @@ -316,6 +259,7 @@ function detrainment(
ᶜp::FT,
ᶜρ::FT,
buoy_flux_surface::FT,
ᶜρaʲ::FT,
ᶜaʲ::FT,
ᶜwʲ::FT,
ᶜRHʲ::FT,
Expand All @@ -325,6 +269,7 @@ function detrainment(
ᶜbuoy⁰::FT,
ᶜentr::FT,
ᶜvert_div::FT,
ᶜmassflux_vert_div::FT,
::ConstantAreaDetrainment,
) where {FT}
detr = ᶜentr - ᶜvert_div
Expand Down
17 changes: 10 additions & 7 deletions toml/prognostic_edmfx_bomex_box.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ value = 1.0e-5
value = 0.7

[entr_inv_tau]
value = 0
value = 0.0002

[entr_coeff]
value = 0.1
value = 0.2

[min_area_limiter_scale]
value = 0.001
value = 0

[min_area_limiter_power]
value = 10
Expand All @@ -23,13 +23,16 @@ value = 10
value = 0

[detr_coeff]
value = 2e-3
value = 0

[detr_buoy_coeff]
value = 0.3
value = 0

[detr_vertdiv_coeff]
value = 0.6
value = 0

[detr_massflux_vertdiv_coeff]
value = 1

[max_area_limiter_scale]
value = 0.01
value = 0
3 changes: 3 additions & 0 deletions toml/prognostic_edmfx_dycoms_rf01_box.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ value = 1e-3
value = 0.3

[detr_vertdiv_coeff]
value = 0

[detr_massflux_vertdiv_coeff]
value = 0.5

[max_area_limiter_scale]
Expand Down
Loading

0 comments on commit cba48eb

Please sign in to comment.