Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use LazyBroadcast for edmf coriolis #3580

Merged
merged 1 commit into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/cache/cache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ struct AtmosCache{
PR,
LSAD,
EXTFORCING,
EDMFCOR,
NONGW,
ORGW,
RAD,
Expand Down Expand Up @@ -56,7 +55,6 @@ struct AtmosCache{
precipitation::PR
large_scale_advection::LSAD
external_forcing::EXTFORCING
edmf_coriolis::EDMFCOR
non_orographic_gravity_wave::NONGW
orographic_gravity_wave::ORGW
radiation::RAD
Expand Down Expand Up @@ -160,7 +158,6 @@ function build_cache(Y, atmos, params, surface_setup, sim_info, aerosol_names)
precipitation = precipitation_cache(Y, atmos)
large_scale_advection = large_scale_advection_cache(Y, atmos)
external_forcing = external_forcing_cache(Y, atmos, params)
edmf_coriolis = edmf_coriolis_cache(Y, atmos)
non_orographic_gravity_wave = non_orographic_gravity_wave_cache(Y, atmos)
orographic_gravity_wave = orographic_gravity_wave_cache(Y, atmos)
radiation = radiation_model_cache(Y, atmos, radiation_args...)
Expand All @@ -180,7 +177,6 @@ function build_cache(Y, atmos, params, surface_setup, sim_info, aerosol_names)
precipitation,
large_scale_advection,
external_forcing,
edmf_coriolis,
non_orographic_gravity_wave,
orographic_gravity_wave,
radiation,
Expand Down
32 changes: 11 additions & 21 deletions src/prognostic_equations/edmf_coriolis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,21 @@
import ClimaCore.Geometry as Geometry
import ClimaCore.Fields as Fields

edmf_coriolis_cache(Y, atmos::AtmosModel) =
edmf_coriolis_cache(Y, atmos.edmf_coriolis)

edmf_coriolis_cache(Y, edmf_coriolis::Nothing) = (;)
function edmf_coriolis_cache(Y, edmf_coriolis::EDMFCoriolis)
function edmf_coriolis_tendency_uₕ(ᶜuₕ, edmf_coriolis)
edmf_coriolis isa EDMFCoriolis || return NullBroadcasted()
(; prof_ug, prof_vg) = edmf_coriolis
ᶜspace = axes(ᶜuₕ)
ᶜz = Fields.coordinate_field(ᶜspace).z
(; coriolis_param) = edmf_coriolis
coords = Fields.coordinate_field(axes(Y.c.ρ))
coords = Fields.coordinate_field(ᶜspace)
coriolis_fn(coord) = Geometry.WVector(coriolis_param)
ᶜf_coriolis = @. Geometry.Contravariant3Vector(coriolis_fn(coords))
return (; ᶜuₕ_g = similar(Y.c.uₕ), ᶜf_coriolis)
end

edmf_coriolis_tendency!(Yₜ, Y, p, t, ::Nothing) = nothing
function edmf_coriolis_tendency!(Yₜ, Y, p, t, edmf_coriolis::EDMFCoriolis)
(; prof_ug, prof_vg) = edmf_coriolis
ᶜf_coriolis = p.edmf_coriolis.ᶜf_coriolis
ᶜuₕ_g = p.edmf_coriolis.ᶜuₕ_g
z = Fields.coordinate_field(axes(ᶜuₕ_g)).z
@. ᶜuₕ_g =
Geometry.Covariant12Vector(Geometry.UVVector(prof_ug(z), prof_vg(z)))
ᶜf_coriolis = @lazy @. Geometry.Contravariant3Vector(coriolis_fn(coords))
ᶜuₕ_g = @lazy @. Geometry.Covariant12Vector(
Geometry.UVVector(prof_ug(ᶜz), prof_vg(ᶜz)),
)

# Coriolis
C123 = Geometry.Covariant123Vector
C12 = Geometry.Contravariant12Vector
@. Yₜ.c.uₕ -= ᶜf_coriolis × (C12(C123(Y.c.uₕ)) - C12(C123(ᶜuₕ_g)))

return nothing
return @lazy @. - ᶜf_coriolis × (C12(C123(ᶜuₕ)) - C12(C123(ᶜuₕ_g)))
end
6 changes: 5 additions & 1 deletion src/prognostic_equations/remaining_tendency.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ NVTX.@annotate function additional_tendency!(Yₜ, Y, p, t)
ᶠu₃ = Yₜ.f.u₃
ᶜρ = Y.c.ρ
(; forcing_type, moisture_model, rayleigh_sponge, viscous_sponge) = p.atmos
(; edmf_coriolis) = p.atmos
(; params) = p
(; ᶜp, sfc_conditions) = p.precomputed

Expand All @@ -51,6 +52,7 @@ NVTX.@annotate function additional_tendency!(Yₜ, Y, p, t)
hs_args = (ᶜuₕ, ᶜp, params, sfc_conditions.ts, moisture_model, forcing_type)
hs_tendency_uₕ = held_suarez_forcing_tendency_uₕ(hs_args...)
hs_tendency_ρe_tot = held_suarez_forcing_tendency_ρe_tot(ᶜρ, hs_args...)
edmf_cor_tend_uₕ = edmf_coriolis_tendency_uₕ(ᶜuₕ, edmf_coriolis)

# TODO: fuse, once we fix
# https://github.com/CliMA/ClimaCore.jl/issues/2165
Expand All @@ -74,7 +76,9 @@ NVTX.@annotate function additional_tendency!(Yₜ, Y, p, t)
@. Yₜ.c.ρe_tot += hs_tendency_ρe_tot

subsidence_tendency!(Yₜ, Y, p, t, p.atmos.subsidence)
edmf_coriolis_tendency!(Yₜ, Y, p, t, p.atmos.edmf_coriolis)

@. Yₜ.c.uₕ += edmf_cor_tend_uₕ

large_scale_advection_tendency!(Yₜ, Y, p, t, p.atmos.ls_adv)
external_forcing_tendency!(Yₜ, Y, p, t, p.atmos.external_forcing)

Expand Down
1 change: 0 additions & 1 deletion test/coupler_compatibility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ const T2 = 290
p.precipitation,
p.large_scale_advection,
p.external_forcing,
p.edmf_coriolis,
p.non_orographic_gravity_wave,
p.orographic_gravity_wave,
p.radiation,
Expand Down
Loading