Skip to content

Commit 44f015a

Browse files
committed
fix: compute full strain
1 parent 9de2e19 commit 44f015a

File tree

3 files changed

+40
-19
lines changed

3 files changed

+40
-19
lines changed

src/cache/precomputed_quantities.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,12 @@ function precomputed_quantities(Y, atmos)
248248
smagorinsky_quantities =
249249
if atmos.smagorinsky_horizontal isa SmagorinskyLilly ||
250250
atmos.smagorinsky_vertical isa SmagorinskyLilly
251-
(; ᶜL_h = similar(Y.c, FT), ᶜL_v = similar(Y.c, FT))
251+
uvw_vec = UVW(FT(0), FT(0), FT(0))
252+
(;
253+
ᶜS = similar(Y.c, typeof(uvw_vec * uvw_vec')),
254+
ᶠS = similar(Y.f, typeof(uvw_vec * uvw_vec')),
255+
ᶜL_h = similar(Y.c, FT), ᶜL_v = similar(Y.c, FT),
256+
)
252257
else
253258
(;)
254259
end

src/parameterized_tendencies/les_sgs_models/smagorinsky_lilly.jl

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,17 @@ 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)
30-
(; ᶠu, ᶜts, ᶜL_h, ᶜL_v) = p.precomputed
29+
# FT = eltype(Y)
30+
(; ᶜu, ᶠu, ᶜts, ᶜL_h, ᶜL_v, ᶠS, ᶜS) = p.precomputed
3131
c_smag = CAP.c_smag(p.params)
3232
# grav = CAP.grav(p.params)
3333
# Pr_t = CAP.Prandtl_number_0(CAP.turbconv_params(p.params))
3434
# thermo_params = CAP.thermodynamics_params(p.params)
3535
# (; ᶜtemp_scalar, ᶜtemp_scalar_2) = p.scratch
3636

37-
# Strain rate tensor
38-
# ᶜS = compute_strain_rate_center(ᶠu)
37+
# Precompute full strain rate tensor
38+
compute_strain_rate_center_full!(ᶜS, ᶜu, ᶠu)
39+
compute_strain_rate_face_full!(ᶠS, ᶜu, ᶠu)
3940

4041
# Stratification correction
4142
# ᶜθ_v = @. lazy(TD.virtual_pottemp(thermo_params, ᶜts))
@@ -61,14 +62,12 @@ horizontal_smagorinsky_lilly_tendency!(Yₜ, Y, p, t, ::Nothing) = nothing
6162
vertical_smagorinsky_lilly_tendency!(Yₜ, Y, p, t, ::Nothing) = nothing
6263

6364
function horizontal_smagorinsky_lilly_tendency!(Yₜ, Y, p, t, ::SmagorinskyLilly)
64-
(; ᶜu, ᶠu, ᶜts, ᶜL_h) = p.precomputed
65+
(; ᶜts, ᶜL_h, ᶠS, ᶜS) = p.precomputed
6566
(; ᶜtemp_UVWxUVW, ᶠtemp_UVWxUVW, ᶜtemp_scalar, ᶠtemp_scalar) = p.scratch
6667
thermo_params = CAP.thermodynamics_params(p.params)
6768
Pr_t = CAP.Prandtl_number_0(CAP.turbconv_params(p.params))
6869

6970
## Momentum tendencies
70-
ᶜS = compute_strain_rate_center(ᶠu)
71-
ᶠS = compute_strain_rate_face(ᶜu)
7271
ᶜS_h = @. lazy(Geometry.project((Geometry.UVAxis(),), ᶜS, (Geometry.UVAxis(),)))
7372
ᶜS_norm = @. lazy((2 * norm_sqr(ᶜS_h)))
7473

@@ -88,9 +87,8 @@ function horizontal_smagorinsky_lilly_tendency!(Yₜ, Y, p, t, ::SmagorinskyLill
8887
@. Yₜ.f.u₃ -= C3(wdivₕ(ᶠρ * ᶠτ_smag) / ᶠρ)
8988

9089
## Total energy tendency
91-
ᶜh_tot = @. lazy(
92-
TD.total_specific_enthalpy(thermo_params, ᶜts, specific(Y.c.ρe_tot, Y.c.ρ)),
93-
)
90+
ᶜe_tot = @. lazy(specific(Y.c.ρe_tot, Y.c.ρ))
91+
ᶜh_tot = @. lazy(TD.total_specific_enthalpy(thermo_params, ᶜts, ᶜe_tot))
9492
@. Yₜ.c.ρe_tot += wdivₕ(Y.c.ρ * ᶜD_smag * gradₕ(ᶜh_tot))
9593

9694
## Tracer diffusion and associated mass changes
@@ -108,7 +106,7 @@ end
108106

109107
function vertical_smagorinsky_lilly_tendency!(Yₜ, Y, p, t, ::SmagorinskyLilly)
110108
FT = eltype(Y)
111-
(; ᶜu, ᶠu, ᶜts, ᶜL_v) = p.precomputed
109+
(; ᶜts, ᶜL_v, ᶠS, ᶜS) = p.precomputed
112110
(; ᶜtemp_UVWxUVW, ᶠtemp_UVWxUVW, ᶠtemp_scalar, ᶠtemp_scalar_2) = p.scratch
113111
thermo_params = CAP.thermodynamics_params(p.params)
114112
Pr_t = CAP.Prandtl_number_0(CAP.turbconv_params(p.params))
@@ -129,8 +127,6 @@ function vertical_smagorinsky_lilly_tendency!(Yₜ, Y, p, t, ::SmagorinskyLilly)
129127
)
130128

131129
## Momentum tendencies
132-
ᶜS = compute_strain_rate_center(ᶠu)
133-
ᶠS = compute_strain_rate_face(ᶜu)
134130
ᶜS_v = @. lazy(Geometry.project((Geometry.WAxis(),), ᶜS, (Geometry.WAxis(),)))
135131
ᶜS_norm = @. lazy((2 * norm_sqr(ᶜS_v)))
136132

@@ -155,9 +151,8 @@ function vertical_smagorinsky_lilly_tendency!(Yₜ, Y, p, t, ::SmagorinskyLilly)
155151
@. Yₜ.f.u₃ -= C3(ᶠdivᵥ(Y.c.ρ * ᶜτ_smag) / ᶠρ)
156152

157153
## Total energy tendency
158-
ᶜh_tot = @. lazy(
159-
TD.total_specific_enthalpy(thermo_params, ᶜts, specific(Y.c.ρe_tot, Y.c.ρ)),
160-
)
154+
ᶜe_tot = @. lazy(specific(Y.c.ρe_tot, Y.c.ρ))
155+
ᶜh_tot = @. lazy(TD.total_specific_enthalpy(thermo_params, ᶜts, ᶜe_tot))
161156
@. Yₜ.c.ρe_tot -= ᶜdivᵥ_ρe_tot(-(ᶠρ * ᶠD_smag * ᶠgradᵥ(ᶜh_tot)))
162157

163158
## Tracer diffusion and associated mass changes

src/utils/utilities.jl

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ compute_kinetic(Y::Fields.FieldVector) = compute_kinetic(Y.c.uₕ, Y.f.u₃)
8484
"""
8585
ϵ .= compute_strain_rate_center(u::Field)
8686
87-
Compute the strain_rate at cell centers from velocity at cell faces.
87+
Compute the vertical strain_rate at cell centers from velocity at cell faces.
8888
"""
8989
function compute_strain_rate_center(u::Fields.Field)
9090
axis_uvw = Geometry.UVWAxis()
@@ -99,7 +99,7 @@ end
9999
"""
100100
ϵ .= compute_strain_rate_face(u::Field)
101101
102-
Compute the strain_rate at cell faces from velocity at cell centers.
102+
Compute the vertical strain_rate at cell faces from velocity at cell centers.
103103
"""
104104
function compute_strain_rate_face(u::Fields.Field)
105105
@assert eltype(u) <: C123
@@ -118,6 +118,27 @@ function compute_strain_rate_face(u::Fields.Field)
118118
)
119119
end
120120

121+
function compute_strain_rate_center_full!(ε, ᶜu, ᶠu)
122+
axis_uvw = (Geometry.UVWAxis(),)
123+
@. ε = Geometry.project(axis_uvw, ᶜgradᵥ(UVW(ᶠu))) # vertical component
124+
@. ε += Geometry.project(axis_uvw, gradₕ(UVW(ᶜu))) # horizontal component
125+
@. ε =+ adjoint(ε)) / 2
126+
return ε
127+
end
128+
129+
function compute_strain_rate_face_full!(ε, ᶜu, ᶠu)
130+
∇ᵥuvw_boundary = Geometry.outer(Geometry.WVector(0), UVW(0, 0, 0))
131+
ᶠgradᵥ = Operators.GradientC2F(
132+
bottom = Operators.SetGradient(∇ᵥuvw_boundary),
133+
top = Operators.SetGradient(∇ᵥuvw_boundary),
134+
)
135+
axis_uvw = (Geometry.UVWAxis(),)
136+
@. ε = Geometry.project(axis_uvw, ᶠgradᵥ(UVW(ᶜu))) # vertical component
137+
@. ε += Geometry.project(axis_uvw, gradₕ(UVW(ᶠu))) # horizontal component
138+
@. ε =+ adjoint(ε)) / 2
139+
return ε
140+
end
141+
121142
"""
122143
face_density(Y)
123144

0 commit comments

Comments
 (0)