Skip to content

Commit de6d9fc

Browse files
Start using columnwise
1 parent 660894d commit de6d9fc

File tree

1 file changed

+116
-1
lines changed

1 file changed

+116
-1
lines changed

src/prognostic_equations/remaining_tendency.jl

Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,124 @@ NVTX.@annotate function hyperdiffusion_tendency!(Yₜ, Yₜ_lim, Y, p, t)
1010
apply_hyperdiffusion_tendency!(Yₜ, Y, p, t)
1111
end
1212

13+
function prognostic_nt(::Val{names}; tends...) where {names}
14+
nt_ordered = NamedTuple{names}(rzero(values(tends)))
15+
nt_values = NamedTuple{keys(tends)}(values(tends))
16+
return merge(nt_ordered, nt_values)
17+
end
18+
19+
function ᶜremaining_tendency(ᶜY, ᶠY, p, t)
20+
names = propertynames(ᶜY)
21+
tends = (;
22+
ᶜremaining_tendency_ρ(ᶜY, ᶠY, p, t)...,
23+
ᶜremaining_tendency_uₕ(ᶜY, ᶠY, p, t)...,
24+
ᶜremaining_tendency_ρe_tot(ᶜY, ᶠY, p, t)...,
25+
ᶜremaining_tendency_ρq_tot(ᶜY, ᶠY, p, t)...,
26+
ᶜremaining_tendency_ρq_liq(ᶜY, ᶠY, p, t)...,
27+
ᶜremaining_tendency_ρq_ice(ᶜY, ᶠY, p, t)...,
28+
ᶜremaining_tendency_ρq_rai(ᶜY, ᶠY, p, t)...,
29+
ᶜremaining_tendency_ρq_sno(ᶜY, ᶠY, p, t)...,
30+
ᶜremaining_tendency_sgs⁰(ᶜY, ᶠY, p, t)...,
31+
ᶜremaining_tendency_sgsʲs(ᶜY, ᶠY, p, t)...,
32+
)
33+
return lazy.(prognostic_nt.(Val(names); tends...))
34+
end
35+
function ᶠremaining_tendency(ᶜY, ᶠY, p, t)
36+
names = propertynames(ᶠY)
37+
tends = (;
38+
ᶠremaining_tendency_u₃(ᶜY, ᶠY, p, t)...,
39+
ᶠremaining_tendency_sgsʲs(ᶜY, ᶠY, p, t)...,
40+
)
41+
return lazy.(prognostic_nt.(Val(names); tends...))
42+
end
43+
using ClimaCore.RecursiveApply: rzero
44+
function ᶜremaining_tendency_ρ(ᶜY, ᶠY, p, t)
45+
in propertynames(ᶜY) || return ()
46+
∑tendencies = zero(eltype(ᶜY.ρ))
47+
return (; ρ = ∑tendencies)
48+
end
49+
function ᶜremaining_tendency_uₕ(ᶜY, ᶠY, p, t)
50+
:uₕ in propertynames(ᶜY) || return ()
51+
∑tendencies = zero(eltype(ᶜY.uₕ))
52+
return (; uₕ = ∑tendencies)
53+
end
54+
function ᶜremaining_tendency_ρe_tot(ᶜY, ᶠY, p, t)
55+
:ρe_tot in propertynames(ᶜY) || return ()
56+
∑tendencies = zero(eltype(ᶜY.ρe_tot))
57+
return (; ρe_tot = ∑tendencies)
58+
end
59+
function ᶜremaining_tendency_ρq_tot(ᶜY, ᶠY, p, t)
60+
:ρq_tot in propertynames(ᶜY) || return ()
61+
∑tendencies = zero(eltype(ᶜY.ρq_tot))
62+
return (; ρq_tot = ∑tendencies)
63+
end
64+
function ᶜremaining_tendency_ρq_liq(ᶜY, ᶠY, p, t)
65+
:ρq_liq in propertynames(ᶜY) || return ()
66+
∑tendencies = zero(eltype(ᶜY.ρq_liq))
67+
return (; ρq_liq = ∑tendencies)
68+
end
69+
function ᶜremaining_tendency_ρq_ice(ᶜY, ᶠY, p, t)
70+
:ρq_ice in propertynames(ᶜY) || return ()
71+
∑tendencies = zero(eltype(ᶜY.ρq_ice))
72+
return (; ρq_ice = ∑tendencies)
73+
end
74+
function ᶜremaining_tendency_ρq_rai(ᶜY, ᶠY, p, t)
75+
:ρq_rai in propertynames(ᶜY) || return ()
76+
∑tendencies = zero(eltype(ᶜY.ρq_rai))
77+
return (; ρq_rai = ∑tendencies)
78+
end
79+
function ᶜremaining_tendency_ρq_sno(ᶜY, ᶠY, p, t)
80+
:ρq_sno in propertynames(ᶜY) || return ()
81+
∑tendencies = zero(eltype(ᶜY.ρq_sno))
82+
return (; ρq_sno = ∑tendencies)
83+
end
84+
function ᶜremaining_tendency_sgsʲs(ᶜY, ᶠY, p, t)
85+
:sgsʲs in propertynames(ᶜY) || return ()
86+
∑tendencies = rzero(eltype(ᶜY.sgsʲs))
87+
return (; sgsʲs = ∑tendencies)
88+
end
89+
function ᶜremaining_tendency_sgs⁰(ᶜY, ᶠY, p, t)
90+
:sgs⁰ in propertynames(ᶜY) || return ()
91+
∑tendencies = rzero(eltype(ᶜY.sgs⁰))
92+
return (; sgs⁰ = ∑tendencies)
93+
end
94+
function ᶠremaining_tendency_u₃(ᶜY, ᶠY, p, t)
95+
:u₃ in propertynames(ᶠY) || return ()
96+
∑tendencies = zero(eltype(ᶠY.u₃))
97+
return (; u₃ = ∑tendencies)
98+
end
99+
function ᶠremaining_tendency_sgsʲs(ᶜY, ᶠY, p, t)
100+
:sgsʲs in propertynames(ᶠY) || return ()
101+
∑tendencies = rzero(eltype(ᶠY.sgsʲs))
102+
return (; sgsʲs = ∑tendencies)
103+
end
104+
105+
13106
NVTX.@annotate function remaining_tendency!(Yₜ, Yₜ_lim, Y, p, t)
14107
Yₜ_lim .= zero(eltype(Yₜ_lim))
15-
Yₜ .= zero(eltype(Yₜ))
108+
device = ClimaComms.device(axes(Y.c))
109+
(localmem_lg, localmem_state) = if device isa ClimaComms.CUDADevice
110+
Val(false), Val(true)
111+
else
112+
Val(false), Val(false)
113+
end
114+
p_kernel = (;)
115+
if :sfc in propertynames(Y) # columnwise! does not yet handle .sfc
116+
parent(Yₜ.sfc) .= zero(Spaces.undertype(axes(Y.c)))
117+
end
118+
Operators.columnwise!(
119+
device,
120+
ᶜremaining_tendency,
121+
ᶠremaining_tendency,
122+
Yₜ.c,
123+
Yₜ.f,
124+
Y.c,
125+
Y.f,
126+
p_kernel,
127+
t,
128+
localmem_lg,
129+
localmem_state,
130+
)
16131
horizontal_tracer_advection_tendency!(Yₜ_lim, Y, p, t)
17132
fill_with_nans!(p)
18133
horizontal_advection_tendency!(Yₜ, Y, p, t)

0 commit comments

Comments
 (0)