Skip to content

Commit f039fc9

Browse files
wip
1 parent 7aa534c commit f039fc9

File tree

7 files changed

+292
-62
lines changed

7 files changed

+292
-62
lines changed

.buildkite/ci_driver.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ redirect_stderr(IOContext(stderr, :stacktrace_types_limited => Ref(false)))
99
# To load in the precompiled methods, run `using PrecompileCI` before loading ClimaAtmos.
1010
# To see what methods are precompiled, open julia: `julia --project=.buildkite/PrecompileCI`
1111
# and run `using PrecompileTools; PrecompileTools.verbose[] = true; include(".buildkite/PrecompileCI/src/PrecompileCI.jl")`
12+
13+
# Todo: move this to NullBroadcasts, or is there a better way?
14+
import NullBroadcasts
15+
# This makes the following pattern easier:
16+
# ∑tendencies = lazy.(∑tendencies .+ viscous_sponge_tendency_uₕ(ᶜuₕ, viscous_sponge))
17+
Base.broadcasted(::typeof(+), ::NullBroadcasts.NullBroadcasted, x) = x
18+
Base.broadcasted(::typeof(+), x, ::NullBroadcasts.NullBroadcasted) = x
19+
# Base.broadcasted(::typeof(-), ::NullBroadcasts.NullBroadcasted, x) = x
20+
Base.broadcasted(::typeof(-), x, ::NullBroadcasts.NullBroadcasted) = x
21+
1222
using PrecompileCI
1323
import ClimaComms
1424
ClimaComms.@import_required_backends

examples/hybrid/driver.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ import ClimaAtmos as CA
1010
import Random
1111
Random.seed!(1234)
1212

13+
# Todo: move this to NullBroadcasts, or is there a better way?
14+
import NullBroadcasts
15+
# This makes the following pattern easier:
16+
# ∑tendencies = lazy.(∑tendencies .+ viscous_sponge_tendency_uₕ(ᶜuₕ, viscous_sponge))
17+
Base.broadcasted(::typeof(+), ::NullBroadcasts.NullBroadcasted, x) = x
18+
Base.broadcasted(::typeof(+), x, ::NullBroadcasts.NullBroadcasted) = x
19+
# Base.broadcasted(::typeof(-), ::NullBroadcasts.NullBroadcasted, x) = x
20+
Base.broadcasted(::typeof(-), x, ::NullBroadcasts.NullBroadcasted) = x
21+
1322
if !(@isdefined config)
1423
(; config_file, job_id) = CA.commandline_kwargs()
1524
config = CA.AtmosConfig(config_file; job_id)

src/cache/precipitation_precomputed_quantities.jl

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,76 @@ function set_precipitation_velocities!(
9898
return nothing
9999
end
100100

101+
function compute_precip_velocities(ᶜY, ᶠY, p, t)
102+
cmc = CAP.microphysics_cloud_params(p.params)
103+
cmp = CAP.microphysics_1m_params(p.params)
104+
105+
# compute the precipitation terminal velocity [m/s]
106+
ᶜwᵣ = CM1.terminal_velocity(
107+
cmp.pr,
108+
cmp.tv.rain,
109+
ᶜY.ρ,
110+
max(zero(ᶜY.ρ), ᶜY.ρq_rai / ᶜY.ρ),
111+
)
112+
ᶜwₛ = CM1.terminal_velocity(
113+
cmp.ps,
114+
cmp.tv.snow,
115+
ᶜY.ρ,
116+
max(zero(ᶜY.ρ), ᶜY.ρq_sno / ᶜY.ρ),
117+
)
118+
# compute sedimentation velocity for cloud condensate [m/s]
119+
ᶜwₗ = CMNe.terminal_velocity(
120+
cmc.liquid,
121+
cmc.Ch2022.rain,
122+
ᶜY.ρ,
123+
max(zero(ᶜY.ρ), ᶜY.ρq_liq / ᶜY.ρ),
124+
)
125+
ᶜwᵢ = CMNe.terminal_velocity(
126+
cmc.ice,
127+
cmc.Ch2022.small_ice,
128+
ᶜY.ρ,
129+
max(zero(ᶜY.ρ), ᶜY.ρq_ice / ᶜY.ρ),
130+
)
131+
return (ᶜwᵣ, ᶜwₛ, ᶜwₗ, ᶜwᵢ)
132+
end
133+
134+
135+
compute_ᶜwₜqₜ(ᶜY, ᶠY, p, t) =
136+
compute_ᶜwₜqₜ(ᶜY, ᶠY, p, t, p.atmos.moisture_model, p.atmos.precip_model)
137+
compute_ᶜwₜqₜ(ᶜY, ᶠY, p, t, moisture_model, precip_model) = zero(ᶜY.ρ)
138+
139+
function compute_ᶜwₜqₜ(ᶜY, ᶠY, p, t,
140+
::NonEquilMoistModel,
141+
::Microphysics1Moment,
142+
)
143+
(ᶜwᵣ, ᶜwₛ, ᶜwₗ, ᶜwᵢ) = compute_precip_velocities(ᶜY, ᶠY, p, t)
144+
# compute their contributions to energy and total water advection
145+
return Geometry.WVector(
146+
ᶜwₗ * ᶜY.ρq_liq +
147+
ᶜwᵢ * ᶜY.ρq_ice +
148+
ᶜwᵣ * ᶜY.ρq_rai +
149+
ᶜwₛ * ᶜY.ρq_sno,
150+
) / ᶜY.ρ
151+
end
152+
153+
compute_ᶜwₕhₜ(ᶜY, ᶠY, p, t) =
154+
compute_ᶜwₕhₜ(ᶜY, ᶠY, p, t, p.atmos.moisture_model, p.atmos.precip_model)
155+
156+
compute_ᶜwₕhₜ(ᶜY, ᶠY, p, t, moisture_model, precip_model) = zero(ᶜY.ρ)
157+
158+
function compute_ᶜwₕhₜ(ᶜY, ᶠY, p, t, ::NonEquilMoistModel, ::Microphysics1Moment)
159+
thp = CAP.thermodynamics_params(p.params)
160+
ᶜts = compute_ᶜts(ᶜY, ᶠY, p, t)
161+
(ᶜwᵣ, ᶜwₛ, ᶜwₗ, ᶜwᵢ) = compute_precip_velocities(ᶜY, ᶠY, p, t)
162+
# compute their contributions to energy and total water advection
163+
return @. lazy(Geometry.WVector(
164+
ᶜwₗ * ᶜY.ρq_liq * (Iₗ(thp, ᶜts) + ᶜΦ + $(Kin(ᶜwₗ, ᶜY.ᶜu))) +
165+
ᶜwᵢ * ᶜY.ρq_ice * (Iᵢ(thp, ᶜts) + ᶜΦ + $(Kin(ᶜwᵢ, ᶜY.ᶜu))) +
166+
ᶜwᵣ * ᶜY.ρq_rai * (Iₗ(thp, ᶜts) + ᶜΦ + $(Kin(ᶜwᵣ, ᶜY.ᶜu))) +
167+
ᶜwₛ * ᶜY.ρq_sno * (Iᵢ(thp, ᶜts) + ᶜΦ + $(Kin(ᶜwₛ, ᶜY.ᶜu))),
168+
) / ᶜY.ρ)
169+
end
170+
101171
"""
102172
set_precipitation_cache!(Y, p, precip_model, turbconv_model)
103173

src/prognostic_equations/advection.jl

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,6 @@ NVTX.@annotate function explicit_vertical_advection_tendency!(Yₜ, Y, p, t)
139139
end
140140
# ... and upwinding correction of energy and total water.
141141
# (The central advection of energy and total water is done implicitly.)
142-
if energy_upwinding != Val(:none)
143-
(; ᶜh_tot) = p.precomputed
144-
vtt = vertical_transport(ᶜρ, ᶠu³, ᶜh_tot, float(dt), energy_upwinding)
145-
vtt_central = vertical_transport(ᶜρ, ᶠu³, ᶜh_tot, float(dt), Val(:none))
146-
@. Yₜ.c.ρe_tot += vtt - vtt_central
147-
end
148-
149-
if !(p.atmos.moisture_model isa DryModel) && tracer_upwinding != Val(:none)
150-
ᶜq_tot = ᶜspecific.q_tot
151-
vtt = vertical_transport(ᶜρ, ᶠu³, ᶜq_tot, float(dt), tracer_upwinding)
152-
vtt_central = vertical_transport(ᶜρ, ᶠu³, ᶜq_tot, float(dt), Val(:none))
153-
@. Yₜ.c.ρq_tot += vtt - vtt_central
154-
end
155-
156142
if isnothing(ᶠf¹²)
157143
# shallow atmosphere
158144
@. Yₜ.c.uₕ -=

0 commit comments

Comments
 (0)