Skip to content

Commit 5180cc1

Browse files
Remove coriolis forces from the cache
1 parent 002b4f3 commit 5180cc1

File tree

3 files changed

+69
-43
lines changed

3 files changed

+69
-43
lines changed

src/cache/cache.jl

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ function build_cache(Y, atmos, params, surface_setup, sim_info, aerosol_names)
115115
ᶜΦ = grav .* ᶜcoord.z
116116
ᶠΦ = grav .* ᶠcoord.z
117117

118-
(; ᶜf³, ᶠf¹²) = compute_coriolis(ᶜcoord, ᶠcoord, params)
119-
120118
quadrature_style =
121119
Spaces.quadrature_style(Spaces.horizontal_space(axes(Y.c)))
122120
do_dss = quadrature_style isa Quadratures.GLL
@@ -150,8 +148,6 @@ function build_cache(Y, atmos, params, surface_setup, sim_info, aerosol_names)
150148
ᶜΦ,
151149
ᶠgradᵥ_ᶜΦ = ᶠgradᵥ.(ᶜΦ),
152150
ᶜgradᵥ_ᶠΦ = ᶜgradᵥ.(ᶠΦ),
153-
ᶜf³,
154-
ᶠf¹²,
155151
# Used by diagnostics such as hfres, evspblw
156152
surface_ct3_unit = CT3.(
157153
unit_basis_vector_data.(CT3, sfc_local_geometry)
@@ -219,31 +215,55 @@ function build_cache(Y, atmos, params, surface_setup, sim_info, aerosol_names)
219215
return AtmosCache{map(typeof, args)...}(args...)
220216
end
221217

218+
function (
219+
coord::Geometry.LatLongZPoint,
220+
global_geom::Geometry.DeepSphericalGlobalGeometry,
221+
params,
222+
)
223+
Ω = CAP.Omega(params)
224+
CT3(
225+
CT123(
226+
Geometry.LocalVector(
227+
Geometry.Cartesian123Vector(zero(Ω), zero(Ω), 2 * Ω),
228+
global_geom,
229+
coord,
230+
),
231+
),
232+
)
233+
end
222234

223-
function compute_coriolis(ᶜcoord, ᶠcoord, params)
224-
if eltype(ᶜcoord) <: Geometry.LatLongZPoint
225-
Ω = CAP.Omega(params)
226-
global_geom = Spaces.global_geometry(axes(ᶜcoord))
227-
if global_geom isa Geometry.DeepSphericalGlobalGeometry
228-
@info "using deep atmosphere"
229-
coriolis_deep(coord::Geometry.LatLongZPoint) = Geometry.LocalVector(
235+
function f¹²(
236+
coord::Geometry.LatLongZPoint,
237+
global_geom::Geometry.DeepSphericalGlobalGeometry,
238+
params,
239+
)
240+
Ω = CAP.Omega(params)
241+
CT12(
242+
CT123(
243+
Geometry.LocalVector(
230244
Geometry.Cartesian123Vector(zero(Ω), zero(Ω), 2 * Ω),
231245
global_geom,
232246
coord,
233-
)
234-
ᶜf³ = @. CT3(CT123(coriolis_deep(ᶜcoord)))
235-
ᶠf¹² = @. CT12(CT123(coriolis_deep(ᶠcoord)))
236-
else
237-
coriolis_shallow(coord::Geometry.LatLongZPoint) =
238-
Geometry.WVector(2 * Ω * sind(coord.lat))
239-
ᶜf³ = @. CT3(coriolis_shallow(ᶜcoord))
240-
ᶠf¹² = nothing
241-
end
242-
else
243-
f = CAP.f_plane_coriolis_frequency(params)
244-
coriolis_f_plane(coord) = Geometry.WVector(f)
245-
ᶜf³ = @. CT3(coriolis_f_plane(ᶜcoord))
246-
ᶠf¹² = nothing
247-
end
248-
return (; ᶜf³, ᶠf¹²)
247+
),
248+
),
249+
)
250+
end
251+
252+
# Shallow sphere
253+
function (coord::Geometry.LatLongZPoint, global_geom, params)
254+
Ω = CAP.Omega(params)
255+
CT3(Geometry.WVector(2 * Ω * sind(coord.lat)))
249256
end
257+
258+
# Shallow cartesian
259+
function (coord, global_geom, params)
260+
f = CAP.f_plane_coriolis_frequency(params)
261+
CT3(Geometry.WVector(f))
262+
end
263+
264+
f¹²(coord::Geometry.LatLongZPoint, global_geom, params) =
265+
error("Not supported for $coord, $global_geom.")
266+
f¹²(coord, global_geom, p::CartesianCoriolisParams) =
267+
error("Not supported for $coord, $global_geom.")
268+
269+
Φ(g, ᶠz) = g * z

src/cache/diagnostic_edmf_precomputed_quantities.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,12 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!(
327327
microphys_params = CAP.microphysics_precipitation_params(params)
328328
turbconv_params = CAP.turbconv_params(params)
329329

330-
ᶠΦ = p.scratch.ᶠtemp_scalar
331-
@. ᶠΦ = CAP.grav(params) * ᶠz
330+
g = CAP.grav(params)
332331
ᶜ∇Φ³ = p.scratch.ᶜtemp_CT3
333-
@. ᶜ∇Φ³ = CT3(ᶜgradᵥ(ᶠΦ))
332+
@. ᶜ∇Φ₃ = ᶜgradᵥ(Φ(g, ᶠz))
333+
@. ᶜ∇Φ³ = CT3(ᶜ∇Φ₃)
334334
@. ᶜ∇Φ³ += CT3(gradₕ(ᶜΦ))
335335
ᶜ∇Φ₃ = p.scratch.ᶜtemp_C3
336-
@. ᶜ∇Φ₃ = ᶜgradᵥ(ᶠΦ)
337336

338337
z_sfc_halflevel =
339338
Fields.field_values(Fields.level(Fields.coordinate_field(Y.f).z, half))

src/prognostic_equations/advection.jl

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,14 @@ NVTX.@annotate function explicit_vertical_advection_tendency!(Yₜ, Y, p, t)
7373
point_type = eltype(Fields.coordinate_field(Y.c))
7474
(; dt) = p
7575
ᶜJ = Fields.local_geometry_field(Y.c).J
76-
(; ᶜf³, ᶠf¹², ᶜΦ) = p.core
7776
(; ᶜu, ᶠu³, ᶜK) = p.precomputed
7877
(; edmfx_upwinding) = n > 0 || advect_tke ? p.atmos.numerics : all_nothing
7978
(; ᶜuʲs, ᶜKʲs, ᶠKᵥʲs) = n > 0 ? p.precomputed : all_nothing
8079
(; ᶠu³⁰) = advect_tke ? p.precomputed : all_nothing
8180
(; energy_upwinding, tracer_upwinding) = p.atmos.numerics
8281
(; ᶜspecific) = p.precomputed
82+
ᶜcoords = Fields.coordinate_field(Y.c)
83+
global_geom = Spaces.global_geometry(axes(ᶜcoord))
8384

8485
ᶜρa⁰ = advect_tke ? (n > 0 ? p.precomputed.ᶜρa⁰ : Y.c.ρ) : nothing
8586
ᶜρ⁰ = advect_tke ? (n > 0 ? p.precomputed.ᶜρ⁰ : Y.c.ρ) : nothing
@@ -129,26 +130,32 @@ NVTX.@annotate function explicit_vertical_advection_tendency!(Yₜ, Y, p, t)
129130
end
130131
end
131132

132-
if isnothing(ᶠf¹²)
133-
# shallow atmosphere
133+
if global_geom isa Geometry.DeepSphericalGlobalGeometry
134+
# deep atmosphere
134135
@. Yₜ.c.uₕ -=
135-
ᶜinterp(ᶠω¹² × (ᶠinterp(Y.c.ρ * ᶜJ) * ᶠu³)) / (Y.c.ρ * ᶜJ) +
136-
(ᶜf³ + ᶜω³) × CT12(ᶜu)
137-
@. Yₜ.f.u₃ -= ᶠω¹² × ᶠinterp(CT12(ᶜu)) + ᶠgradᵥ(ᶜK)
136+
ᶜinterp(
137+
(f¹²(ᶠcoords, global_geom, params) + ᶠω¹²) ×
138+
(ᶠinterp(Y.c.ρ * ᶜJ) * ᶠu³),
139+
) / (Y.c.ρ * ᶜJ) +
140+
((ᶜcoords, global_geom, params) + ᶜω³) × CT12(ᶜu)
141+
@. Yₜ.f.u₃ -=
142+
(f¹²(ᶠcoords, global_geom, params) + ᶠω¹²) × ᶠinterp(CT12(ᶜu)) +
143+
ᶠgradᵥ(ᶜK)
138144
for j in 1:n
139145
@. Yₜ.f.sgsʲs.:($$j).u₃ -=
140-
ᶠω¹²ʲs.:($$j) × ᶠinterp(CT12(ᶜuʲs.:($$j))) +
146+
(f¹²(ᶠcoords, global_geom, params) + ᶠω¹²ʲs.:($$j)) ×
147+
ᶠinterp(CT12(ᶜuʲs.:($$j))) +
141148
ᶠgradᵥ(ᶜKʲs.:($$j) - ᶜinterp(ᶠKᵥʲs.:($$j)))
142149
end
143150
else
144-
# deep atmosphere
151+
# shallow atmosphere
145152
@. Yₜ.c.uₕ -=
146-
ᶜinterp((ᶠf¹² + ᶠω¹²) × (ᶠinterp(Y.c.ρ * ᶜJ) * ᶠu³)) /
147-
(Y.c.ρ * ᶜJ) + (ᶜf³ + ᶜω³) × CT12(ᶜu)
148-
@. Yₜ.f.u₃ -= (ᶠf¹² + ᶠω¹²) × ᶠinterp(CT12(ᶜu)) + ᶠgradᵥ(ᶜK)
153+
ᶜinterp(ᶠω¹² × (ᶠinterp(Y.c.ρ * ᶜJ) * ᶠu³)) / (Y.c.ρ * ᶜJ) +
154+
((ᶜcoords, global_geom, params) + ᶜω³) × CT12(ᶜu)
155+
@. Yₜ.f.u₃ -= ᶠω¹² × ᶠinterp(CT12(ᶜu)) + ᶠgradᵥ(ᶜK)
149156
for j in 1:n
150157
@. Yₜ.f.sgsʲs.:($$j).u₃ -=
151-
(ᶠf¹² + ᶠω¹²ʲs.:($$j)) × ᶠinterp(CT12(ᶜuʲs.:($$j))) +
158+
ᶠω¹²ʲs.:($$j) × ᶠinterp(CT12(ᶜuʲs.:($$j))) +
152159
ᶠgradᵥ(ᶜKʲs.:($$j) - ᶜinterp(ᶠKᵥʲs.:($$j)))
153160
end
154161
end

0 commit comments

Comments
 (0)