Skip to content

Commit 0149e6d

Browse files
Optionally accept climacomms context, and define T_exp-T_lim compute function
1 parent 7a2e03e commit 0149e6d

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

src/functions.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ export ClimaODEFunction, ForwardEulerODEFunction
44

55
abstract type AbstractClimaODEFunction <: DiffEqBase.AbstractODEFunction{true} end
66

7-
Base.@kwdef struct ClimaODEFunction{TL, TE, TI, L, D, PE, PI} <: AbstractClimaODEFunction
7+
Base.@kwdef struct ClimaODEFunction{TL, TE, TI, L, D, PE, PI, CC} <: AbstractClimaODEFunction
88
T_lim!::TL = nothing # nothing or (uₜ, u, p, t) -> ...
99
T_exp!::TE = nothing # nothing or (uₜ, u, p, t) -> ...
1010
T_imp!::TI = nothing # nothing or (uₜ, u, p, t) -> ...
1111
lim!::L = (u, p, t, u_ref) -> nothing
1212
dss!::D = (u, p, t) -> nothing
1313
post_explicit!::PE = (u, p, t) -> nothing
1414
post_implicit!::PI = (u, p, t) -> nothing
15+
comms_context::CC = nothing
1516
end
1617

1718
# Don't wrap a AbstractClimaODEFunction in an ODEFunction (makes ODEProblem work).

src/solvers/imex_ark.jl

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,28 @@ end
169169
end
170170

171171
if !all(iszero, a_exp[:, i]) || !iszero(b_exp[i])
172-
isnothing(T_lim!) || T_lim!(T_lim[i], U, p, t_exp)
173-
isnothing(T_exp!) || T_exp!(T_exp[i], U, p, t_exp)
172+
if !isnothing!(T_lim!) && !isnothing(T_exp!)
173+
(; comms_context) = f
174+
compute_T_exp_T_lim!(T_lim[i], T_exp[i], U, p, t, T_exp!, T_lim!, comms_context)
175+
else
176+
isnothing(T_lim!) || T_lim!(T_lim[i], U, p, t_exp)
177+
isnothing(T_exp!) || T_exp!(T_exp[i], U, p, t_exp)
178+
end
174179
end
175180

176181
return nothing
177182
end
183+
184+
function compute_T_exp_T_lim!(
185+
T_lim,
186+
T_exp,
187+
U,
188+
p,
189+
t,
190+
T_exp!,
191+
T_lim!,
192+
comms_context::Union{Nothing, ClimaComms.AbstractCommsContext},
193+
)
194+
T_lim!(T_lim, U, p, t)
195+
T_exp!(T_exp, U, p, t)
196+
end

src/solvers/imex_ssprk.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,12 @@ function step_u!(integrator, cache::IMEXSSPRKCache)
153153
end
154154

155155
if !iszero(β[i])
156-
if !isnothing(T_lim!)
157-
T_lim!(T_lim, U, p, t_exp)
158-
end
159-
if !isnothing(T_exp!)
160-
T_exp!(T_exp, U, p, t_exp)
156+
if !isnothing!(T_lim!) && !isnothing(T_exp!)
157+
(; comms_context) = f
158+
compute_T_exp_T_lim!(T_lim[i], T_exp[i], U, p, t, T_exp!, T_lim!, comms_context)
159+
else
160+
isnothing(T_lim!) || T_lim!(T_lim[i], U, p, t_exp)
161+
isnothing(T_exp!) || T_exp!(T_exp[i], U, p, t_exp)
161162
end
162163
end
163164
end

0 commit comments

Comments
 (0)