-
Notifications
You must be signed in to change notification settings - Fork 98
/
TableausEX.jl
334 lines (291 loc) · 6.31 KB
/
TableausEX.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
###########
# 1 stage #
###########
function EXRK11(::Type{T}) where {T}
matrix = T[0;;]
weights = T[1]
order = 1
GenericTableau(matrix, weights, order)
end
"""
EXRK_Euler_1_1
"""
struct EXRK_Euler_1_1 <: TableauName end
function ButcherTableau(::EXRK_Euler_1_1, ::Type{T}=Float64) where {T}
EXRK11(T)
end
############
# 2 stages #
############
function EXRK22(α::Real, ::Type{T}=Float64) where {T}
a = 1 // 2 / α
matrix = T[
0 0
α 0
]
weights = T[1-a, a]
order = 2
GenericTableau(matrix, weights, order)
end
"""
EXRK_Midpoint_2_2
"""
struct EXRK_Midpoint_2_2 <: TableauName end
function ButcherTableau(::EXRK_Midpoint_2_2, ::Type{T}=Float64) where {T}
EXRK22(1 // 2, T)
end
"""
EXRK_SSP_2_2
EXRK_Heun_2_2
"""
struct EXRK_SSP_2_2 <: TableauName end
function ButcherTableau(::EXRK_SSP_2_2, ::Type{T}=Float64) where {T}
tableau = EXRK22(1, T)
emb_weights = T[1, 0]
emb_order = 1
EmbeddedTableau(tableau, emb_weights, emb_order)
end
struct EXRK_Heun_2_2 <: TableauName end
function ButcherTableau(::EXRK_Heun_2_2, ::Type{T}=Float64) where {T}
ButcherTableau(EXRK_SSP_2_2(), T)
end
"""
EXRK_Ralston_2_2
"""
struct EXRK_Ralston_2_2 <: TableauName end
function ButcherTableau(::EXRK_Ralston_2_2, ::Type{T}=Float64) where {T}
EXRK22(2 // 3, T)
end
############
# 3 stages #
############
function EXRK33(α::Real, β::Real, ::Type{T}=Float64) where {T}
b = β * (β - α) / α / (2 - 3 * α)
c = β - b
d = (3 * β - 2) // 6 / α / (β - α)
e = (2 - 3 * α) // 6 / β / (β - α)
matrix = T[
0 0 0
α 0 0
c b 0
]
weights = T[1-d-e, d, e]
order = 3
GenericTableau(matrix, weights, order)
end
function EXRK33_1(α::Real, ::Type{T}=Float64) where {T}
a = 2 // 3
b = 1 // 4 / α
c = 2 // 3 - b
d = 1 // 4
matrix = T[
0 0 0
a 0 0
c b 0
]
weights = T[d, 1-α-d, α]
order = 3
GenericTableau(matrix, weights, order)
end
function EXRK33_2(α::Real, ::Type{T}=Float64) where {T}
a = 2 // 3
b = 1 // 4 / α
c = -b
d = 3 // 4
matrix = T[
0 0 0
a 0 0
c b 0
]
weights = T[1-α-d, d, α]
order = 3
GenericTableau(matrix, weights, order)
end
"""
EXRK_Kutta_3_3
"""
struct EXRK_Kutta_3_3 <: TableauName end
function ButcherTableau(::EXRK_Kutta_3_3, ::Type{T}=Float64) where {T}
EXRK33(1 // 2, 1, T)
end
"""
EXRK_Heun_3_3
"""
struct EXRK_Heun_3_3 <: TableauName end
function ButcherTableau(::EXRK_Heun_3_3, ::Type{T}=Float64) where {T}
EXRK33(1 // 3, 2 // 3, T)
end
"""
EXRK_Wray_3_3
EXRK_VanDerHouwen_3_3
"""
struct EXRK_Wray_3_3 <: TableauName end
function ButcherTableau(::EXRK_Wray_3_3, ::Type{T}=Float64) where {T}
EXRK33(8 // 15, 2 // 3, T)
end
struct EXRK_VanDerHouwen_3_3 <: TableauName end
function ButcherTableau(::EXRK_VanDerHouwen_3_3, ::Type{T}=Float64) where {T}
ButcherTableau(EXRK_Wray_3_3(), T)
end
"""
EXRK_Ralston_3_3
"""
struct EXRK_Ralston_3_3 <: TableauName end
function ButcherTableau(::EXRK_Ralston_3_3, ::Type{T}=Float64) where {T}
EXRK33(1 // 2, 3 // 4, T)
end
"""
EXRK_SSP_3_3
"""
struct EXRK_SSP_3_3 <: TableauName end
function ButcherTableau(::EXRK_SSP_3_3, ::Type{T}=Float64) where {T}
EXRK33(1, 1 // 2, T)
end
"""
EXRK_SSP_3_2
"""
struct EXRK_SSP_3_2 <: TableauName end
function ButcherTableau(::EXRK_SSP_3_2, ::Type{T}=Float64) where {T}
a = 1 // 2
b = 1 // 3
matrix = T[
0 0 0
a 0 0
a a 0
]
weights = T[b, b, b]
order = 2
GenericTableau(matrix, weights, order)
end
"""
EXRK_Fehlberg_3_2
"""
struct EXRK_Fehlberg_3_2 <: TableauName end
function ButcherTableau(::EXRK_Fehlberg_3_2, ::Type{T}=Float64) where {T}
a = 1 // 2
b = 1 // 256
c = 255 // 256
d = 1 // 512
matrix = T[
0 0 0
a 0 0
b c 0
]
weights = T[d, c, d]
order = 2
tableau = GenericTableau(matrix, weights, order)
emb_weights = T[b, c, 0]
emb_order = 1
EmbeddedTableau(tableau, emb_weights, emb_order)
end
############
# 4 stages #
############
"""
EXRK_RungeKutta_4_4
"""
struct EXRK_RungeKutta_4_4 <: TableauName end
function ButcherTableau(::EXRK_RungeKutta_4_4, ::Type{T}=Float64) where {T}
a = 1 // 2
b = 1 // 6
c = 1 // 3
matrix = T[
0 0 0 0
a 0 0 0
0 a 0 0
0 0 1 0
]
weights = T[b, c, c, b]
order = 4
GenericTableau(matrix, weights, order)
end
"""
EXRK_Simpson_4_4
"""
struct EXRK_Simpson_4_4 <: TableauName end
function ButcherTableau(::EXRK_Simpson_4_4, ::Type{T}=Float64) where {T}
a = 1 // 3
b = -1 // 3
c = -1
d = 1 // 8
e = 3 // 8
matrix = T[
0 0 0 0
a 0 0 0
b 1 0 0
1 c 1 0
]
weights = T[d, e, e, d]
order = 4
GenericTableau(matrix, weights, order)
end
"""
EXRK_Ralston_4_4
"""
struct EXRK_Ralston_4_4 <: TableauName end
function ButcherTableau(::EXRK_Ralston_4_4, ::Type{T}=Float64) where {T}
α = 2 // 5
β = 7 // 8 - 3 * sqrt(5) / 16
a = β * (β - α) / 2 / α / (1 - 2 * α)
b = β - a
c = (1 - α) * (α + β - 1 - (2 * β - 1)^2) / 2 / α / (β - α) / (6 * α * β - 4 * (α + β) + 3)
d = (1 - 2 * α) * (1 - α) * (1 - β) / β / (β - α) / (6 * α * β - 4 * (α + β) + 3)
e = 1 - c - d
f = 1 // 2 + (1 - 2 * (α + β)) / 12 / α / β
g = (2 * β - 1) / 12 / α / (β - α) / (1 - α)
h = (1 - 2 * α) / 12 / β / (β - α) / (1 - β)
i = 1 // 2 + (2 * (α + β) - 3) / 12 / (1 - α) / (1 - β)
matrix = T[
0 0 0 0
α 0 0 0
b a 0 0
e c d 0
]
weights = T[f, g, h, i]
order = 4
GenericTableau(matrix, weights, order)
end
"""
EXRK_SSP_4_3
"""
struct EXRK_SSP_4_3 <: TableauName end
function ButcherTableau(::EXRK_SSP_4_3, ::Type{T}=Float64) where {T}
a = 1 // 2
b = 1 // 6
c = 1 // 4
matrix = T[
0 0 0 0
a 0 0 0
a a 0 0
b b b 0
]
weights = T[b, b, b, a]
order = 3
tableau = GenericTableau(matrix, weights, order)
emb_weights = T[c, c, c, c]
emb_order = 2
EmbeddedTableau(tableau, emb_weights, emb_order)
end
"""
EXRK_BogackiShampine_4_3
"""
struct EXRK_BogackiShampine_4_3 <: TableauName end
function ButcherTableau(::EXRK_BogackiShampine_4_3, ::Type{T}=Float64) where {T}
a = 1 // 2
b = 3 // 4
c = 2 // 9
d = 1 // 3
e = 4 // 9
matrix = T[
0 0 0 0
a 0 0 0
0 b 0 0
c d e 0
]
weights = T[c, d, e, 0]
order = 3
tableau = GenericTableau(matrix, weights, order)
emb_weights = T[0, a, b, 1]
emb_order = 2
EmbeddedTableau(tableau, emb_weights, emb_order)
end