Skip to content

Commit

Permalink
Merge pull request #2906 from CliMA/zs/gm_bgrad_strain
Browse files Browse the repository at this point in the history
move buoyancy gradient and strain rate norm to grid-mean cache
  • Loading branch information
szy21 authored Apr 15, 2024
2 parents 0180920 + 3478420 commit 5e31be2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 65 deletions.
6 changes: 2 additions & 4 deletions src/cache/precomputed_quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ function precomputed_quantities(Y, atmos)
ᶜp = similar(Y.c, FT),
ᶜh_tot = similar(Y.c, FT),
ᶜmixing_length = similar(Y.c, FT),
ᶜlinear_buoygrad = similar(Y.c, FT),
ᶜstrain_rate_norm = similar(Y.c, FT),
sfc_conditions = Fields.Field(SCT, Spaces.level(axes(Y.f), half)),
)
cloud_diagnostics = (; ᶜcloud_fraction = similar(Y.c, FT),)
Expand Down Expand Up @@ -83,8 +85,6 @@ function precomputed_quantities(Y, atmos)
ᶜq_tot⁰ = similar(Y.c, FT),
ᶜts⁰ = similar(Y.c, TST),
ᶜρ⁰ = similar(Y.c, FT),
ᶜlinear_buoygrad = similar(Y.c, FT),
ᶜstrain_rate_norm = similar(Y.c, FT),
ᶜK_u = similar(Y.c, FT),
ᶜK_h = similar(Y.c, FT),
ρatke_flux = similar(Fields.level(Y.f, half), C3{FT}),
Expand Down Expand Up @@ -123,8 +123,6 @@ function precomputed_quantities(Y, atmos)
ᶜu⁰ = similar(Y.c, C123{FT}),
ᶜK⁰ = similar(Y.c, FT),
ᶜtke⁰ = similar(Y.c, FT),
ᶜlinear_buoygrad = similar(Y.c, FT),
ᶜstrain_rate_norm = similar(Y.c, FT),
ᶜK_u = similar(Y.c, FT),
ᶜK_h = similar(Y.c, FT),
ρatke_flux = similar(Fields.level(Y.f, half), C3{FT}),
Expand Down
32 changes: 32 additions & 0 deletions src/diagnostics/core_diagnostics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,38 @@ add_diagnostic_variable!(
end,
)

###
# Buoyancy gradient (3d)
###
add_diagnostic_variable!(
short_name = "bgrad",
long_name = "Linearized Buoyancy Gradient",
units = "s^-2",
compute! = (out, state, cache, time) -> begin
if isnothing(out)
return copy(cache.precomputed.ᶜlinear_buoygrad)
else
out .= cache.precomputed.ᶜlinear_buoygrad
end
end,
)

###
# Strain rate magnitude (3d)
###
add_diagnostic_variable!(
short_name = "strain",
long_name = "String Rate Magnitude",
units = "s^-2",
compute! = (out, state, cache, time) -> begin
if isnothing(out)
return copy(cache.precomputed.ᶜstrain_rate_norm)
else
out .= cache.precomputed.ᶜstrain_rate_norm
end
end,
)

###
# Relative humidity (3d)
###
Expand Down
58 changes: 0 additions & 58 deletions src/diagnostics/edmfx_diagnostics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -882,64 +882,6 @@ add_diagnostic_variable!(
compute! = compute_tke!,
)

###
# Buoyancy gradient (3d)
###
compute_bgrad!(out, state, cache, time) =
compute_bgrad!(out, state, cache, time, cache.atmos.turbconv_model)
compute_bgrad!(_, _, _, _, turbconv_model::T) where {T} =
error_diagnostic_variable("bgrad", turbconv_model)

function compute_bgrad!(
out,
state,
cache,
time,
turbconv_model::Union{PrognosticEDMFX, DiagnosticEDMFX},
)
if isnothing(out)
return copy(cache.precomputed.ᶜlinear_buoygrad)
else
out .= cache.precomputed.ᶜlinear_buoygrad
end
end

add_diagnostic_variable!(
short_name = "bgrad",
long_name = "Linearized Buoyancy Gradient",
units = "s^-2",
compute! = compute_bgrad!,
)

###
# Strain rate magnitude (3d)
###
compute_strain!(out, state, cache, time) =
compute_strain!(out, state, cache, time, cache.atmos.turbconv_model)
compute_strain!(_, _, _, _, turbconv_model::T) where {T} =
error_diagnostic_variable("strain", turbconv_model)

function compute_strain!(
out,
state,
cache,
time,
turbconv_model::Union{PrognosticEDMFX, DiagnosticEDMFX},
)
if isnothing(out)
return copy(cache.precomputed.ᶜstrain_rate_norm)
else
out .= cache.precomputed.ᶜstrain_rate_norm
end
end

add_diagnostic_variable!(
short_name = "strain",
long_name = "String Rate Magnitude",
units = "s^-2",
compute! = compute_strain!,
)

###
# Diffusivity of heat (3d)
###
Expand Down
6 changes: 3 additions & 3 deletions src/prognostic_equations/gm_sgs_closures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ NVTX.@annotate function compute_gm_mixing_length!(ᶜmixing_length, Y, p)

ᶜdz = Fields.Δz_field(axes(Y.c))
ᶜlg = Fields.local_geometry_field(Y.c)
(; ᶜts, ᶜp, ᶠu³) = p.precomputed
(; ᶜts, ᶠu³, ᶜlinear_buoygrad, ᶜstrain_rate_norm) = p.precomputed
(; obukhov_length) = p.precomputed.sfc_conditions

ᶜlinear_buoygrad = p.scratch.ᶜtemp_scalar
@. ᶜlinear_buoygrad = buoyancy_gradients(
BuoyGradMean(),
thermo_params,
Expand All @@ -53,13 +52,14 @@ NVTX.@annotate function compute_gm_mixing_length!(ᶜmixing_length, Y, p)
@. ᶠu = C123(ᶠinterp(Y.c.uₕ)) + C123(ᶠu³)
ᶜstrain_rate = p.scratch.ᶜtemp_UVWxUVW
compute_strain_rate_center!(ᶜstrain_rate, ᶠu)
@. ᶜstrain_rate_norm = norm_sqr(ᶜstrain_rate)

ᶜprandtl_nvec = p.scratch.ᶜtemp_scalar_2
@. ᶜprandtl_nvec = turbulent_prandtl_number(
params,
obukhov_length,
ᶜlinear_buoygrad,
norm_sqr(ᶜstrain_rate),
ᶜstrain_rate_norm,
)

@. ᶜmixing_length = smagorinsky_lilly_length(
Expand Down

0 comments on commit 5e31be2

Please sign in to comment.