Skip to content

Commit 282423b

Browse files
Make user-facing types
1 parent 597b82b commit 282423b

File tree

12 files changed

+333
-237
lines changed

12 files changed

+333
-237
lines changed

docs/src/algorithms.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ForwardEulerODEFunction
1616

1717
```@docs
1818
IMEXARKAlgorithm
19-
make_IMEXARKAlgorithm
19+
make_IMEXARKTableau
2020
```
2121

2222
The convergence orders of the provided methods are verified using test cases from [ARKode](http://runge.math.smu.edu/ARKode_example.pdf). Plots of the solutions to these test cases, the errors of these solutions, and the convergence orders with respect to `dt` are shown below.

perf/flame.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ elseif problem_str=="fe"
3030
else
3131
error("Bad option")
3232
end
33-
algorithm = ARS343(NewtonsMethod(; max_iters = 2))
33+
algorithm = CTS.IMEXARKAlgorithm(ARS343(), NewtonsMethod(; max_iters = 2))
3434
dt = 0.01
3535
integrator = DiffEqBase.init(prob, algorithm; dt)
3636
not_generated_cache = CTS.not_generated_cache(prob, algorithm)

perf/jet.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ end
1515
cts = joinpath(dirname(@__DIR__));
1616
include(joinpath(cts, "test", "problems.jl"))
1717
function config_integrators(problem)
18-
algorithm = ARS343(NewtonsMethod(; linsolve = linsolve_direct, max_iters = 2))
18+
algorithm = CTS.IMEXARKAlgorithm(ARS343(), NewtonsMethod(; linsolve = linsolve_direct, max_iters = 2))
1919
dt = 0.01
2020
integrator = DiffEqBase.init(problem, algorithm; dt)
2121
not_generated_integrator = DiffEqBase.init(problem, algorithm; dt)

src/ClimaTimeSteppers.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,24 @@ include("algorithms.jl")
6666

6767
abstract type DistributedODEAlgorithm <: DiffEqBase.AbstractODEAlgorithm end
6868

69+
abstract type AbstractIMEXARKAlgorithm <: DistributedODEAlgorithm end
70+
abstract type AbstractIMEXARKTableau end
71+
72+
"""
73+
tableau(::DistributedODEAlgorithm)
74+
75+
Returns the tableau for a particular algorithm.
76+
"""
77+
function tableau end
78+
6979
"""
7080
theoretical_convergence_order
7181
7282
Returns the theoretical convergence order of an ODE algorithm
7383
"""
7484
function theoretical_convergence_order end
75-
theoretical_convergence_order(alg::DistributedODEAlgorithm) =
76-
error("No convergence order found for algo $alg, please open an issue or PR.")
85+
theoretical_convergence_order(tab) =
86+
error("No convergence order found for tableau $tab, please open an issue or PR.")
7787

7888
SciMLBase.allowscomplex(alg::DistributedODEAlgorithm) = true
7989
include("integrators.jl")

src/convergence_orders.jl

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,53 @@
22
##### 1st order
33
#####
44

5-
const first_order_methods = [
6-
# ARS111,
7-
# ARS121,
5+
# TODO: is it better to use `first_order_tableau = Union{ARS111,ARS121}`? to
6+
# reduce the number of methods?
7+
const first_order_tableau = [
8+
ARS111,
9+
ARS121,
810
]
911

1012
#####
1113
##### 2nd order
1214
#####
1315

14-
const second_order_methods = [
15-
# ARS122,
16-
# ARS232,
17-
# ARS222,
18-
# IMKG232a,
19-
# IMKG232b,
20-
# IMKG242a,
21-
# IMKG242b,
22-
# IMKG252a,
23-
# IMKG252b,
24-
# IMKG253a,
25-
# IMKG253b,
26-
# IMKG254a,
27-
# IMKG254b,
28-
# IMKG254c,
29-
# HOMMEM1,
16+
const second_order_tableau = [
17+
ARS122,
18+
ARS232,
19+
ARS222,
20+
IMKG232a,
21+
IMKG232b,
22+
IMKG242a,
23+
IMKG242b,
24+
IMKG252a,
25+
IMKG252b,
26+
IMKG253a,
27+
IMKG253b,
28+
IMKG254a,
29+
IMKG254b,
30+
IMKG254c,
31+
HOMMEM1,
3032
]
3133

3234
#####
3335
##### 3rd order
3436
#####
35-
const third_order_methods = [
36-
# ARS233,
37-
# ARS343,
38-
# ARS443,
39-
# IMKG342a,
40-
# IMKG343a,
41-
# DBM453,
37+
const third_order_tableau = [
38+
ARS233,
39+
ARS343,
40+
ARS443,
41+
IMKG342a,
42+
IMKG343a,
43+
DBM453,
4244
]
4345

44-
for m in first_order_methods
46+
for m in first_order_tableau
4547
@eval theoretical_convergence_order(::$m) = 1
4648
end
47-
for m in second_order_methods
49+
for m in second_order_tableau
4850
@eval theoretical_convergence_order(::$m) = 2
4951
end
50-
for m in third_order_methods
52+
for m in third_order_tableau
5153
@eval theoretical_convergence_order(::$m) = 3
5254
end

src/integrators.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function tstops_and_saveat_heaps(t0, tf, tstops, saveat)
5050
tstops = DataStructures.BinaryHeap{FT, ordering}(tstops)
5151

5252
if isnothing(saveat)
53-
saveat = [t0, tf]
53+
saveat = [t0, tf]
5454
elseif saveat isa Number
5555
saveat > zero(saveat) || error("saveat value must be positive")
5656
saveat = tf > t0 ? saveat : -saveat
@@ -101,7 +101,7 @@ function DiffEqBase.__init(
101101
callback = DiffEqBase.CallbackSet(callback, saving_callback)
102102
isempty(callback.continuous_callbacks) ||
103103
error("Continuous callbacks are not supported")
104-
104+
105105
integrator = DistributedODEIntegrator(
106106
alg,
107107
u0,

src/solvers/imex_ark.jl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Is this too messy to do in the general case?
112112
113113
Don't forget about the possible memory optimizations!
114114
=#
115-
export IMEXARKAlgorithm, make_IMEXARKAlgorithm
115+
export IMEXARKAlgorithm, make_IMEXARKTableau
116116

117117
using Base: broadcasted, materialize!
118118
using StaticArrays: SMatrix, SVector
@@ -124,23 +124,32 @@ A generic implementation of an IMEX ARK algorithm that can handle arbitrary
124124
Butcher tableaus and problems specified using either `ForwardEulerODEFunction`s
125125
or regular `ODEFunction`s.
126126
"""
127-
struct IMEXARKAlgorithm{as, cs, N} <: DistributedODEAlgorithm
127+
struct IMEXARKAlgorithm{as, cs, N} <: AbstractIMEXARKAlgorithm
128128
newtons_method::N
129129
end
130130

131131
IMEXARKAlgorithm{as, cs}(newtons_method::N) where {as, cs, N} =
132132
IMEXARKAlgorithm{as, cs, N}(newtons_method)
133133

134134
"""
135-
make_IMEXARKAlgorithm(; a_exp, b_exp, c_exp, a_imp, b_imp, c_imp)
135+
IMEXARKAlgorithm(::AbstractIMEXARKAlgorithm, newtons_method)
136+
137+
Returns the imex ARK algorithm for a particular algorithm.
138+
"""
139+
function IMEXARKAlgorithm(tab::AbstractIMEXARKTableau, newtons_method)
140+
tableau(tab)(newtons_method)
141+
end
142+
143+
"""
144+
make_IMEXARKTableau(; a_exp, b_exp, c_exp, a_imp, b_imp, c_imp)
136145
137146
Generates an `IMEXARKAlgorithm` type from an IMEX ARK Butcher tableau. Only
138147
`a_exp` and `a_imp` are required arguments; the default values for `b_exp` and
139148
`b_imp` assume that the algorithm is FSAL (first same as last), and the default
140149
values for `c_exp` and `c_imp` assume that the algorithm is internally
141150
consistent.
142151
"""
143-
function make_IMEXARKAlgorithm(;
152+
function make_IMEXARKTableau(;
144153
a_exp::SMatrix{s, s},
145154
b_exp::SVector{s} = vec(a_exp[end, :]),
146155
c_exp::SVector{s} = vec(sum(a_exp; dims = 2)),

0 commit comments

Comments
 (0)