@@ -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"""
2828function 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
6161horizontal_smagorinsky_lilly_tendency! (Yₜ, Y, p, t, :: Nothing ) = nothing
6262vertical_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+
6470function 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)
0 commit comments