Skip to content

Commit ee821f9

Browse files
authored
Merge pull request #66 from SciML/myb/rootedtrees
Add 4-th order Ralston and RootedTrees.jl integration
2 parents bf369d9 + 0c2bd6a commit ee821f9

File tree

6 files changed

+55
-5
lines changed

6 files changed

+55
-5
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DiffEqDevTools"
22
uuid = "f3b72e0c-5b89-59e1-b016-84e28bfd966d"
33
authors = ["Chris Rackauckas <[email protected]>"]
4-
version = "2.22.0"
4+
version = "2.23.0"
55

66
[deps]
77
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
@@ -12,6 +12,7 @@ Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
1212
NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56"
1313
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
1414
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
15+
RootedTrees = "47965b36-3f3e-11e9-0dcf-4570dfd42a8c"
1516
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1617

1718
[compat]
@@ -22,6 +23,7 @@ DiffEqProblemLibrary = "4.5"
2223
NLsolve = "4.2"
2324
RecipesBase = "0.7, 0.8, 1.0"
2425
RecursiveArrayTools = "2"
26+
RootedTrees = "1"
2527
julia = "1"
2628

2729
[extras]

src/DiffEqDevTools.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export test_convergence, analyticless_test_convergence, appxtrue!, appxtrue
4040
export get_sample_errors
4141

4242
#Plot Functions
43-
export stability_region
43+
export stability_region, residual_order_condition
4444

4545
#Tableaus
4646
export deduce_Butcher_tableau
@@ -51,7 +51,7 @@ export constructEuler, constructKutta3, constructRK4, constructRK438Rule,
5151
constructLobattoIIICStar4, constructLobattoIIID2, constructLobattoIIID4,
5252
constructRadauIA3, constructRadauIA5,
5353
constructRadauIIA3, constructRadauIIA5,
54-
constructRalston, constructHeun, constructRKF5, constructBogakiShampine3,
54+
constructRalston, constructRalston4, constructHeun, constructRKF5, constructBogakiShampine3,
5555
constructCashKarp, constructRKF8, constructDormandPrince8,
5656
constructMSRI1,constructFeagin10, constructFeagin12, constructFeagin14,
5757
constructDormandPrince8_64bit, constructRKF5, constructRungeFirst5,

src/ode_tableaus.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,35 @@ function constructRK438Rule(T::Type = Float64)
231231
return(ExplicitRKTableau(A,c,α,4))
232232
end
233233

234+
"""
235+
Ralston's Order 4 method with minimum truncation error.
236+
"""
237+
function constructRalston4(T::Type = Float64)
238+
sqrt5 = sqrt(convert(T, 5))
239+
a21 = 4//10
240+
a31 = (-2889 + 1428 * sqrt5) / 1024
241+
a32 = (3785 - 1620 * sqrt5) / 1024
242+
a41 = (-3365 + 2094 * sqrt5) / 6040
243+
a42 = (-975 - 3046 * sqrt5) / 2552
244+
a43 = (467040 + 203968 * sqrt5) / 240845
245+
A = [0 0 0 0
246+
a21 0 0 0
247+
a31 a32 0 0
248+
a41 a42 a43 0]
249+
b2 = 4//10
250+
b3 = (14 - 3 * sqrt5) / 16
251+
c = [0, b2, b3, 1]
252+
b1 = (263 + 24 * sqrt5) / 1812
253+
b2 = (125 - 1000 * sqrt5) / 3828
254+
b3 = 1024 * (3346 + 1623 * sqrt5) / 5924787
255+
b4 = (30 - 4 * sqrt5) / 123
256+
α = [b1, b2, b3, b4]
257+
A = map(T,A)
258+
α = map(T,α)
259+
c = map(T,c)
260+
return ExplicitRKTableau(A,c,α,4)
261+
end
262+
234263
"""
235264
Explicit SSP method of order 2 using 2 stages.
236265
"""

src/tableau_info.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using NLsolve, LinearAlgebra
1+
using NLsolve, LinearAlgebra, RootedTrees
22
"""
33
`Base.length(tab::ODERKTableau)`
44
@@ -29,3 +29,16 @@ function stability_region(tab::ODERKTableau; initial_guess=-3.0)
2929
sol = nlsolve(residual!, [initial_guess])
3030
sol.zero[1]
3131
end
32+
33+
function RootedTrees.residual_order_condition(tab::ODERKTableau, order::Int, reducer=nothing, mapper=x->x^2)
34+
if reducer === nothing
35+
resid = map(RootedTreeIterator(order)) do t
36+
residual_order_condition(t, tab.A, tab.α, tab.c)
37+
end
38+
else
39+
resid = mapreduce(reducer, RootedTreeIterator(order)) do t
40+
mapper(residual_order_condition(t, tab.A, tab.α, tab.c))
41+
end
42+
end
43+
return resid
44+
end

test/analyticless_convergence_tests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using OrdinaryDiffEq, ParameterizedFunctions, Test, Random
2-
2+
using ParameterizedFunctions.ModelingToolkit # macro hygiene
33
f = @ode_def LotkaVolterra begin
44
dx = 1.5x - x*y
55
dy = -3y + x*y

test/ode_tableau_convergence_tests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ dts = 1 .//2 .^(8:-1:4)
1818
testTol = 0.3
1919
superduperbool = Vector{Bool}(undef, 2)
2020

21+
@test all(i -> residual_order_condition(constructRalston4(), i, +, abs) < 10eps(1.0), 1:4)
22+
2123
for i = 1:2 # 1 = num, 2 = ExplicitRK
2224
global dts
2325
if i>1
@@ -63,6 +65,10 @@ for i = 1:2 # 1 = num, 2 = ExplicitRK
6365
sim = test_convergence(dts,prob,tabalg)
6466
@test abs(sim.𝒪est[:l∞]-4) < testTol
6567

68+
tabalg = ExplicitRK(tableau=constructRalston4())
69+
sim = test_convergence(dts,prob,tabalg)
70+
@test abs(sim.𝒪est[:l∞]-4) < testTol
71+
6672
tabalg = ExplicitRK(tableau=constructSSPRK104())
6773
sim = test_convergence(dts,prob,tabalg)
6874
@test abs(sim.𝒪est[:l∞]-4) < testTol

0 commit comments

Comments
 (0)