Skip to content

Commit

Permalink
Merge #208
Browse files Browse the repository at this point in the history
208: Define AbstractClimaODEFunction r=charleskawczynski a=charleskawczynski

This PR defines `AbstractClimaODEFunction`, so that we can, from ClimaAtmos, define our own `AtmosODEFunction` with custom hooks (post stage callback etc.) and rearrange them in a custom `step_u!`.

Co-authored-by: Charles Kawczynski <[email protected]>
  • Loading branch information
bors[bot] and charleskawczynski authored Sep 27, 2023
2 parents 270d06a + fb34440 commit 585daa1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ClimaTimeSteppers"
uuid = "595c0a79-7f3d-439a-bc5a-b232dc3bde79"
authors = ["Climate Modeling Alliance"]
version = "0.7.8"
version = "0.7.9"

[deps]
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/plotting_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using PrettyTables: pretty_table, ft_printf
Return the predicted convergence order of the algorithm for the given ODE
function (assuming that the algorithm converges).
"""
function predicted_convergence_order(algorithm_name::AbstractAlgorithmName, ode_function::ClimaODEFunction)
function predicted_convergence_order(algorithm_name::AbstractAlgorithmName, ode_function::AbstractClimaODEFunction)
(imp_order, exp_order, combined_order) = imex_convergence_orders(algorithm_name)
has_imp = !isnothing(ode_function.T_imp!)
has_exp = !isnothing(ode_function.T_exp!) || !isnothing(ode_function.T_lim!)
Expand Down
11 changes: 7 additions & 4 deletions src/functions.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import DiffEqBase
export AbstractClimaODEFunction
export ClimaODEFunction, ForwardEulerODEFunction

Base.@kwdef struct ClimaODEFunction{TL, TE, TI, L, D, PE, PI} <: DiffEqBase.AbstractODEFunction{true}
abstract type AbstractClimaODEFunction <: DiffEqBase.AbstractODEFunction{true} end

Base.@kwdef struct ClimaODEFunction{TL, TE, TI, L, D, PE, PI} <: AbstractClimaODEFunction
T_lim!::TL = nothing # nothing or (uₜ, u, p, t) -> ...
T_exp!::TE = nothing # nothing or (uₜ, u, p, t) -> ...
T_imp!::TI = nothing # nothing or (uₜ, u, p, t) -> ...
Expand All @@ -11,9 +14,9 @@ Base.@kwdef struct ClimaODEFunction{TL, TE, TI, L, D, PE, PI} <: DiffEqBase.Abst
post_implicit!::PI = (u, p, t) -> nothing
end

# Don't wrap a ClimaODEFunction in an ODEFunction (makes ODEProblem work).
DiffEqBase.ODEFunction{iip}(f::ClimaODEFunction) where {iip} = f
DiffEqBase.ODEFunction(f::ClimaODEFunction) = f
# Don't wrap a AbstractClimaODEFunction in an ODEFunction (makes ODEProblem work).
DiffEqBase.ODEFunction{iip}(f::AbstractClimaODEFunction) where {iip} = f
DiffEqBase.ODEFunction(f::AbstractClimaODEFunction) = f

"""
ForwardEulerODEFunction(f; jac_prototype, Wfact, tgrad)
Expand Down
7 changes: 3 additions & 4 deletions src/solvers/imex_ark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@ function init_cache(prob::DiffEqBase.AbstractODEProblem, alg::IMEXAlgorithm{Unco
return IMEXARKCache(U, T_lim, T_exp, T_imp, temp, γ, newtons_method_cache)
end

step_u!(integrator, cache::IMEXARKCache) = step_u!(integrator, cache, integrator.alg.name)
step_u!(integrator, cache::IMEXARKCache) = step_u!(integrator, cache, integrator.sol.prob.f, integrator.alg.name)

include("hard_coded_ars343.jl")
# generic fallback
function step_u!(integrator, cache::IMEXARKCache, name)
(; u, p, t, dt, sol, alg) = integrator
(; f) = sol.prob
function step_u!(integrator, cache::IMEXARKCache, f, name)
(; u, p, t, dt, alg) = integrator
(; T_lim!, T_exp!, T_imp!, lim!, dss!) = f
(; tableau, newtons_method) = alg
(; a_exp, b_exp, a_imp, b_imp, c_exp, c_imp) = tableau
Expand Down
7 changes: 3 additions & 4 deletions src/solvers/imex_ssprk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ function init_cache(prob::DiffEqBase.AbstractODEProblem, alg::IMEXAlgorithm{SSP}
return IMEXSSPRKCache(U, U_exp, U_lim, T_lim, T_exp, T_imp, temp, β, γ, newtons_method_cache)
end

step_u!(integrator, cache::IMEXSSPRKCache) = step_u!(integrator, cache, integrator.alg.name)
step_u!(integrator, cache::IMEXSSPRKCache) = step_u!(integrator, cache, integrator.sol.prob.f, integrator.alg.name)

function step_u!(integrator, cache::IMEXSSPRKCache, name)
(; u, p, t, dt, sol, alg) = integrator
(; f) = sol.prob
function step_u!(integrator, cache::IMEXSSPRKCache, f, name)
(; u, p, t, dt, alg) = integrator
(; T_lim!, T_exp!, T_imp!, lim!, dss!) = f
(; tableau, newtons_method) = alg
(; a_imp, b_imp, c_exp, c_imp) = tableau
Expand Down

2 comments on commit 585daa1

@charleskawczynski
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/91462

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.9 -m "<description of version>" 585daa18647ab27fd848d425adfc3cd23d2756a2
git push origin v0.7.9

Please sign in to comment.