Skip to content

Commit 9a2988b

Browse files
committed
implicit vertical smagorinsky
1 parent dbdca3d commit 9a2988b

File tree

5 files changed

+72
-18
lines changed

5 files changed

+72
-18
lines changed

post_processing/ci_plots.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,7 @@ function make_plots(
13211321
"cl",
13221322
"clw",
13231323
"cli",
1324+
"Dh_smag", "Dv_smag", "dtmaxh_smag", "dtmaxv_smag", "strainrateh_smag", "strainratev_smag"
13241325
]
13251326
short_names = short_names collect(keys(simdirs[1].vars))
13261327

src/cache/precomputed_quantities.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ function precomputed_quantities(Y, atmos)
254254
ᶠS = similar(Y.f, typeof(uvw_vec * uvw_vec')),
255255
ᶜL_h = similar(Y.c, FT), ᶜL_v = similar(Y.c, FT),
256256
ᶜD_h = similar(Y.c, FT), ᶠD_v = similar(Y.f, FT),
257+
ᶜstrain_rate_norm_h = similar(Y.c, FT),
258+
ᶜstrain_rate_norm_v = similar(Y.c, FT),
257259
)
258260
else
259261
(;)

src/diagnostics/core_diagnostics.jl

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,21 +347,59 @@ add_diagnostic_variable!(
347347
# Smagorinski Lilly diffusivity
348348
###
349349
add_diagnostic_variable!(
350-
short_name = "D_smag_h",
350+
short_name = "Dh_smag",
351351
long_name = "Horizontal smagorinski diffusivity",
352352
units = "m^2 s^-1",
353353
compute! = (out, _, cache, _) -> begin
354354
isnothing(out) ? copy(cache.precomputed.ᶜD_h) : (out .= cache.precomputed.ᶜD_h)
355355
end,
356356
)
357357
add_diagnostic_variable!(
358-
short_name = "D_smag_v",
358+
short_name = "Dv_smag",
359359
long_name = "Horizontal smagorinski diffusivity",
360360
units = "m^2 s^-1",
361361
compute! = (out, _, cache, _) -> begin
362362
isnothing(out) ? copy(cache.precomputed.ᶠD_v) : (out .= cache.precomputed.ᶠD_v)
363363
end,
364364
)
365+
add_diagnostic_variable!(
366+
short_name = "dtmaxh_smag",
367+
long_name = "Max horizontal diffusion dt",
368+
units = "s",
369+
compute! = (out, state, cache, _) -> begin
370+
Δh = Spaces.node_horizontal_length_scale(Spaces.horizontal_space(axes(state.f)))
371+
dtmax = @. lazy(Δh^2 / cache.precomputed.ᶜD_h)
372+
isnothing(out) ? copy(dtmax) : (out .= dtmax)
373+
end,
374+
)
375+
add_diagnostic_variable!(
376+
short_name = "dtmaxv_smag",
377+
long_name = "Max diffusion dt",
378+
units = "s",
379+
compute! = (out, state, cache, _) -> begin
380+
ᶜΔ_z = Fields.Δz_field(state.c)
381+
dtmax = @. lazy(ᶠinterp(ᶜΔ_z^2) / cache.precomputed.ᶠD_v)
382+
isnothing(out) ? copy(dtmax) : (out .= dtmax)
383+
end,
384+
)
385+
add_diagnostic_variable!(
386+
short_name = "strainrateh_smag",
387+
long_name = "Strain rate horizontal",
388+
units = "s",
389+
compute! = (out, state, cache, _) -> begin
390+
ᶜstrain_rate_h = cache.precomputed.ᶜstrain_rate_norm_h
391+
isnothing(out) ? copy(ᶜstrain_rate_h) : (out .= ᶜstrain_rate_h)
392+
end,
393+
)
394+
add_diagnostic_variable!(
395+
short_name = "strainratev_smag",
396+
long_name = "Strain rate vertical",
397+
units = "s",
398+
compute! = (out, state, cache, _) -> begin
399+
ᶜstrain_rate_v = cache.precomputed.ᶜstrain_rate_norm_v
400+
isnothing(out) ? copy(ᶜstrain_rate_v) : (out .= ᶜstrain_rate_v)
401+
end,
402+
)
365403

366404
###
367405
# Relative humidity (3d)

src/parameterized_tendencies/les_sgs_models/smagorinsky_lilly.jl

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,33 @@ These quantities are computed for both cell centers and faces, with prefixes `
2626
- `p`: The model parameters, e.g. `AtmosCache`.
2727
"""
2828
function set_smagorinsky_lilly_precomputed_quantities!(Y, p)
29-
# FT = eltype(Y)
29+
FT = eltype(Y)
3030
(; ᶜu, ᶠu, ᶜts, ᶜL_h, ᶜL_v, ᶠS, ᶜS) = p.precomputed
3131
c_smag = CAP.c_smag(p.params)
32-
# grav = CAP.grav(p.params)
33-
# Pr_t = CAP.Prandtl_number_0(CAP.turbconv_params(p.params))
34-
# thermo_params = CAP.thermodynamics_params(p.params)
35-
# (; ᶜtemp_scalar, ᶜtemp_scalar_2) = p.scratch
32+
grav = CAP.grav(p.params)
33+
Pr_t = CAP.Prandtl_number_0(CAP.turbconv_params(p.params))
34+
thermo_params = CAP.thermodynamics_params(p.params)
35+
(; ᶜtemp_scalar, ᶜtemp_scalar_2) = p.scratch
3636

3737
# Precompute full strain rate tensor
3838
compute_strain_rate_center_full!(ᶜS, ᶜu, ᶠu)
3939
compute_strain_rate_face_full!(ᶠS, ᶜu, ᶠu)
4040

4141
# Stratification correction
42-
# ᶜθ_v = @. lazy(TD.virtual_pottemp(thermo_params, ᶜts))
43-
# ᶜ∇ᵥθ = @. ᶜtemp_scalar_2 = Geometry.WVector(ᶜgradᵥ(ᶠinterp(ᶜθ_v))).components.data.:1
44-
# ᶜN² = @. ᶜtemp_scalar = grav / ᶜθ_v * ᶜ∇ᵥθ
45-
# ᶜS_norm = @. ᶜtemp_scalar_2 = √(2 * norm_sqr(ᶜS))
42+
ᶜθ_v = @. lazy(TD.virtual_pottemp(thermo_params, ᶜts))
43+
ᶜ∇ᵥθ = @. ᶜtemp_scalar_2 = Geometry.WVector(ᶜgradᵥ(ᶠinterp(ᶜθ_v))).components.data.:1
44+
ᶜN² = @. ᶜtemp_scalar = grav / ᶜθ_v * ᶜ∇ᵥθ
45+
ᶜS_norm = @. ᶜtemp_scalar_2 = (2 * norm_sqr(ᶜS))
4646

47-
# ᶜRi = @. ᶜtemp_scalar = ᶜN² / (ᶜS_norm^2 + eps(FT)) # Ri = N² / |S|²
48-
# ᶜfb = @. ᶜtemp_scalar = ifelse(ᶜRi ≤ 0, 1, max(0, 1 - ᶜRi / Pr_t)^(1 / 4))
47+
ᶜRi = @. ᶜtemp_scalar = ᶜN² / (ᶜS_norm^2 + eps(FT)) # Ri = N² / |S|²
48+
ᶜfb = @. ᶜtemp_scalar = ifelse(ᶜRi 0, 1, max(0, 1 - ᶜRi / Pr_t)^(1 / 4))
4949

5050
# filter scale
5151
h_space = Spaces.horizontal_space(axes(Y.c))
5252
Δ_h = Spaces.node_horizontal_length_scale(h_space)
5353
ᶜΔ_z = Fields.Δz_field(Y.c)
5454

55-
@. ᶜL_v = c_smag * ᶜΔ_z #* ᶜfb
55+
@. ᶜL_v = c_smag * ᶜΔ_z * ᶜfb
5656
@. ᶜL_h = c_smag * Δ_h
5757

5858
nothing
@@ -61,15 +61,21 @@ end
6161
horizontal_smagorinsky_lilly_tendency!(Yₜ, Y, p, t, ::Nothing) = nothing
6262
vertical_smagorinsky_lilly_tendency!(Yₜ, Y, p, t, ::Nothing) = nothing
6363

64+
function projected_strain_rate_norm(ᶜS, axis)
65+
ᶜS_proj = @. lazy(Geometry.project((axis,), ᶜS, (axis,)))
66+
ᶜS_norm = @. lazy((2 * norm_sqr(ᶜS_proj)))
67+
return ᶜS_norm
68+
end
69+
6470
function horizontal_smagorinsky_lilly_tendency!(Yₜ, Y, p, t, ::SmagorinskyLilly)
6571
(; ᶜts, ᶜL_h, ᶠS, ᶜS) = p.precomputed
6672
(; ᶜtemp_UVWxUVW, ᶠtemp_UVWxUVW, ᶜtemp_scalar, ᶠtemp_scalar) = p.scratch
6773
thermo_params = CAP.thermodynamics_params(p.params)
6874
Pr_t = CAP.Prandtl_number_0(CAP.turbconv_params(p.params))
6975

7076
## Momentum tendencies
71-
ᶜS_h = @. lazy(Geometry.project((Geometry.UVAxis(),), ᶜS, (Geometry.UVAxis(),)))
72-
ᶜS_norm = @. lazy((2 * norm_sqr(ᶜS_h)))
77+
ᶜS_norm = projected_strain_rate_norm(ᶜS, Geometry.UVAxis())
78+
@. p.precomputed.ᶜstrain_rate_norm_h = ᶜS_norm # save to diagnostics
7379

7480
# Smagorinsky eddy viscosity
7581
ᶜνₜ_h = @. lazy(ᶜL_h^2 * ᶜS_norm)
@@ -128,8 +134,8 @@ function vertical_smagorinsky_lilly_tendency!(Yₜ, Y, p, t, ::SmagorinskyLilly)
128134
)
129135

130136
## Momentum tendencies
131-
ᶜS_v = @. lazy(Geometry.project((Geometry.WAxis(),), ᶜS, (Geometry.WAxis(),)))
132-
ᶜS_norm = @. lazy((2 * norm_sqr(ᶜS_v)))
137+
ᶜS_norm = projected_strain_rate_norm(ᶜS, Geometry.WAxis())
138+
@. p.precomputed.ᶜstrain_rate_norm_v = ᶜS_norm # save to diagnostics
133139

134140
# Smagorinsky eddy viscosity
135141
ᶜνₜ_v = @. lazy(ᶜL_v^2 * ᶜS_norm)

src/prognostic_equations/implicit/manual_sparse_jacobian.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,13 @@ function update_jacobian!(alg::ManualSparseJacobian, cache, Y, p, dtγ, t)
591591
elseif vertical_diffusion isa VerticalDiffusion
592592
ᶜK_h = ᶜcompute_eddy_diffusivity_coefficient(Y.c.uₕ, ᶜp, vertical_diffusion)
593593
ᶜK_u = ᶜK_h
594+
elseif p.atmos.smagorinsky_vertical isa SmagorinskyLilly
595+
Pr_t = CAP.Prandtl_number_0(CAP.turbconv_params(p.params))
596+
set_smagorinsky_lilly_precomputed_quantities!(Y, p) # sets (ᶜS, ᶜL_v) in p.precomputed
597+
(; ᶜS, ᶜL_v) = p.precomputed
598+
ᶜS_norm = projected_strain_rate_norm(ᶜS, Geometry.WAxis())
599+
ᶜK_u = @. lazy(ᶜL_v^2 * ᶜS_norm) # Smagorinsky eddy viscosity, ᶜνₜ_v
600+
ᶜK_h = @. lazy(ᶜK_u / Pr_t) # Smagorinsky eddy diffusivity, ᶜD_smag
594601
elseif turbconv_model isa AbstractEDMF
595602
(; ᶜlinear_buoygrad, ᶜstrain_rate_norm) = p.precomputed
596603
ᶜρa⁰ =

0 commit comments

Comments
 (0)