-
Notifications
You must be signed in to change notification settings - Fork 1
/
erk.jl
522 lines (406 loc) · 13 KB
/
erk.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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
reference(::Val{:ExplicitEuler}) = """
Reference:
Leonhard Euler.
Institutiones calculi differentialis cum eius vsu in analysi finitorum ac doctrina serierum.
Imp. Acad. Imper. Scient. Petropolitanae, Opera Omnia, Vol.X, [I.6], 1755.
In: Opera Omnia, 1st Series, Volume 11, Institutiones Calculi Integralis. Teubner, Leipzig, Pages 424-434, 1913.
Sectio secunda. Caput VII. De integratione aequationum differentialium per approximationem. Problema 85.
"""
"""
Tableau of one-stage, 1st order explicit (forward) Euler method
```julia
TableauExplicitEuler(::Type{T}=Float64) where {T}
```
The constructor takes one optional argument, that is the element type of the tableau.
$(reference(Val(:ExplicitEuler)))
"""
function TableauExplicitEuler(::Type{T}=Float64) where {T}
a = zeros(BigFloat, 1, 1)
b = ones(BigFloat, 1)
c = zeros(BigFloat, 1)
o = 1
Tableau{T}(:ExplicitEuler, o, a, b, c; R∞=Inf)
end
"Alias for [`TableauExplicitEuler`](@ref)"
const TableauForwardEuler = TableauExplicitEuler
reference(::Val{:ForwardEuler}) = reference(Val(:ExplicitEuler))
reference(::Val{:ExplicitMidpoint}) = """
Reference:
Carl Runge.
Über die numerische Auflösung von Differentialgleichungen.
Mathematische Annalen, Volume 46, Pages 167-178, 1895.
doi: 10.1007/BF01446807.
Equation (2)
"""
"""
Tableau of explicit two-stage, 2nd order midpoint method
```julia
TableauExplicitMidpoint(::Type{T}=Float64) where {T}
```
The constructor takes one optional argument, that is the element type of the tableau.
$(reference(Val(:ExplicitMidpoint)))
"""
function TableauExplicitMidpoint(::Type{T}=Float64) where {T}
a = @big [[ 0 0 ]
[ 1//2 0 ]]
b = @big [ 0, 1 ]
c = @big [ 0, 1//2 ]
o = 2
Tableau{T}(:ExplicitMidpoint, o, a, b, c)
end
reference(::Val{:Heun2}) = """
Reference:
Karl Heun.
Neue Methoden zur approximativen Integration der Differentialgleichungen einer unabhängigen Veränderlichen.
Zeitschrift für Mathematik und Physik, Volume 45, Pages 23-38, 1900.
Algorithm II.
"""
"""
Tableau of Heun's two-stage, 2nd order method
```julia
TableauHeun2(::Type{T}=Float64) where {T}
```
The constructor takes one optional argument, that is the element type of the tableau.
$(reference(Val(:Heun2)))
"""
function TableauHeun2(::Type{T}=Float64) where {T}
a = @big [[ 0 0 ]
[ 1 0 ]]
b = @big [ 1//2, 1//2 ]
c = @big [ 0, 1 ]
o = 2
Tableau{T}(:Heun2, o, a, b, c)
end
"""
Alias for [`TableauHeun2`](@ref)
according to
John C. Butcher
Numerical Methods for Ordinary Differential Equations. Wiley, 2016.
Page 99
"""
const TableauRK21 = TableauHeun2
reference(::Val{:RK21}) = reference(Val(:Heun2))
reference(::Val{:Heun3}) = """
Reference:
Karl Heun.
Neue Methoden zur approximativen Integration der Differentialgleichungen einer unabhängigen Veränderlichen.
Zeitschrift für Mathematik und Physik, Volume 45, Pages 23-38, 1900.
Algorithm VI.
"""
"""
Tableau of Heun's three-stage, 3rd order method
```julia
TableauHeun3(::Type{T}=Float64) where {T}
```
The constructor takes one optional argument, that is the element type of the tableau.
$(reference(Val(:Heun3)))
"""
function TableauHeun3(::Type{T}=Float64) where {T}
a = @big [[ 0 0 0 ]
[ 1//3 0 0 ]
[ 0 2//3 0 ]]
b = @big [ 1//4, 0, 3//4 ]
c = @big [ 0, 1//3, 2//3 ]
o = 3
Tableau{T}(:Heun3, o, a, b, c)
end
reference(::Val{:Ralston2}) = """
Reference:
Anthony Ralston.
Runge-Kutta Methods with Minimum Error Bounds.
Mathematics of Computation, Volume 16, Pages 431-437, 1962.
doi: 10.1090/S0025-5718-1962-0150954-0.
Equation (3.5)
"""
"""
Tableau of Ralston's two-stage, 2nd order method
```julia
TableauRalston2(::Type{T}=Float64) where {T}
```
The constructor takes one optional argument, that is the element type of the tableau.
$(reference(Val(:Ralston2)))
"""
function TableauRalston2(::Type{T}=Float64) where {T}
a = @big [[ 0 0 ]
[ 2//3 0 ]]
b = @big [ 1//4, 3//4 ]
c = @big [ 0, 2//3 ]
o = 2
Tableau{T}(:Ralston2, o, a, b, c)
end
reference(::Val{:Ralston3}) = """
Reference:
Anthony Ralston.
Runge-Kutta Methods with Minimum Error Bounds.
Mathematics of Computation, Volume 16, Pages 431-437, 1962.
doi: 10.1090/S0025-5718-1962-0150954-0.
Equation (4.10)
"""
"""
Tableau of Ralston's three-stage, 3rd order method
```julia
TableauRalston3(::Type{T}=Float64) where {T}
```
The constructor takes one optional argument, that is the element type of the tableau.
$(reference(Val(:Ralston3)))
"""
function TableauRalston3(::Type{T}=Float64) where {T}
a = @big [[ 0 0 0 ]
[ 1//2 0 0 ]
[ 0 3//4 0 ]]
b = @big [ 2//9, 3//9, 4//9 ]
c = @big [ 0, 1//2, 3//4 ]
o = 3
Tableau{T}(:Ralston3, o, a, b, c)
end
reference(::Val{:Runge}) = """
Reference:
Carl Runge
Über die numerische Auflösung von Differentialgleichungen.
Mathematische Annalen, Volume 46, Pages 167-178, 1895.
doi: 10.1007/BF01446807.
Equation (3)
"""
"""
Tableau of Runge's two-stage, 2nd order method
```julia
TableauRunge(::Type{T}=Float64) where {T}
```
The constructor takes one optional argument, that is the element type of the tableau.
$(reference(Val(:Runge)))
"""
function TableauRunge(::Type{T}=Float64) where {T}
a = @big [[ 0 0 ]
[ 1//2 0 ]]
b = @big [ 0, 1 ]
c = @big [ 0, 1//2 ]
o = 2
Tableau{T}(:Runge, o, a, b, c)
end
"Alias for [`TableauRunge`](@ref)"
const TableauRunge2 = TableauRunge
reference(::Val{:Runge2}) = reference(Val(:Runge))
"""
Alias for [`TableauRunge`](@ref)
according to
John C. Butcher
Numerical Methods for Ordinary Differential Equations. Wiley, 2016.
Page 99
"""
const TableauRK22 = TableauRunge
reference(::Val{:RK22}) = reference(Val(:Runge))
reference(::Val{:Kutta}) = """
Reference:
Wilhelm Kutta
Beitrag zur Näherungsweisen Integration totaler Differentialgleichungen
Zeitschrift für Mathematik und Physik, Volume 46, Pages 435-453, 1901.
Page 440
"""
"""
Tableau of Kutta's three-stage, 3rd order method
```julia
TableauKutta(::Type{T}=Float64) where {T}
```
The constructor takes one optional argument, that is the element type of the tableau.
$(reference(Val(:Kutta)))
"""
function TableauKutta(::Type{T}=Float64) where {T}
a = @big [[ 0 0 0 ]
[ 1//2 0 0 ]
[-1 2 0 ]]
b = @big [ 1//6, 4//6, 1//6 ]
c = @big [ 0, 1//2, 1 ]
o = 3
Tableau{T}(:Kutta, o, a, b, c)
end
"Alias for [`TableauKutta`](@ref)"
const TableauKutta3 = TableauKutta
reference(::Val{:Kutta3}) = reference(Val(:Kutta))
"""
Alias for [`TableauKutta`](@ref) according to
John C. Butcher
Numerical Methods for Ordinary Differential Equations. Wiley, 2016.
Page 99
"""
const TableauRK32 = TableauKutta
reference(::Val{:RK32}) = reference(Val(:Kutta))
reference(::Val{:RK31}) = """
Reference:
John C. Butcher
Numerical Methods for Ordinary Differential Equations. Wiley, 2016.
Page 99
"""
"""
Tableau of a three-stage, 3rd order method
```julia
TableauKutta(::Type{T}=Float64) where {T}
```
The constructor takes one optional argument, that is the element type of the tableau.
$(reference(Val(:RK31)))
"""
function TableauRK31(::Type{T}=Float64) where {T}
a = @big [[ 0 0 0 ]
[ 2//3 0 0 ]
[ 1//3 1//3 0 ]]
b = @big [ 1//4, 0, 3//4 ]
c = @big [ 0, 2//3, 2//3 ]
o = 3
Tableau{T}(:RK31, o, a, b, c)
end
reference(::Val{:RK416}) = """
Reference:
Wilhelm Kutta
Beitrag zur Näherungsweisen Integration totaler Differentialgleichungen
Zeitschrift für Mathematik und Physik, Volume 46, Pages 435-453, 1901.
Page 443
"""
"""
Tableau of explicit Runge-Kutta method of order four (1/6 rule)
```julia
TableauRK416(::Type{T}=Float64) where {T}
```
The constructor takes one optional argument, that is the element type of the tableau.
$(reference(Val(:RK416)))
"""
function TableauRK416(::Type{T}=Float64) where {T}
a = @big [[ 0 0 0 0 ]
[ 1//2 0 0 0 ]
[ 0 1//2 0 0 ]
[ 0 0 1 0 ]]
b = @big [ 1//6, 1//3, 1//3, 1//6 ]
c = @big [ 0, 1//2, 1//2, 1 ]
o = 4
Tableau{T}(:RK416, o, a, b, c)
end
"""
Alias for [`TableauRK416`](@ref) according to
John C. Butcher
Numerical Methods for Ordinary Differential Equations. Wiley, 2016.
Page 102
"""
const TableauRK41 = TableauRK416
reference(::Val{:RK41}) = reference(Val(:RK416))
"Alias for [`TableauRK416`](@ref)"
const TableauRK4 = TableauRK416
reference(::Val{:RK4}) = reference(Val(:RK416))
reference(::Val{:RK42}) = """
Reference:
John C. Butcher
Numerical Methods for Ordinary Differential Equations. Wiley, 2016.
Page 102
"""
"""
Tableau of explicit Runge-Kutta method of order four with four stages
```julia
TableauRK42(::Type{T}=Float64) where {T}
```
The constructor takes one optional argument, that is the element type of the tableau.
$(reference(Val(:RK42)))
"""
function TableauRK42(::Type{T}=Float64) where {T}
a = @big [[ 0 0 0 0 ]
[ 1//4 0 0 0 ]
[ 0 1//2 0 0 ]
[ 1 -2 1 0 ]]
b = @big [ 1//6, 0, 2//3, 1//6 ]
c = @big [ 0, 1//4, 1//2, 1 ]
o = 4
Tableau{T}(:RK42, o, a, b, c)
end
reference(::Val{:RK438}) = """
Reference:
Wilhelm Kutta
Beitrag zur Näherungsweisen Integration totaler Differentialgleichungen
Zeitschrift für Mathematik und Physik, Volume 46, Pages 435-453, 1901.
Page 441
"""
"""
Tableau of explicit Runge-Kutta method of order four (3/8 rule)
```julia
TableauRK438(::Type{T}=Float64) where {T}
```
The constructor takes one optional argument, that is the element type of the tableau.
$(reference(Val(:RK438)))
"""
function TableauRK438(::Type{T}=Float64) where {T}
a = @big [[ 0 0 0 0 ]
[ 1//3 0 0 0 ]
[-1//3 1 0 0 ]
[ 1 -1 1 0 ]]
b = @big [ 1//8, 3//8, 3//8, 1//8 ]
c = @big [ 0, 1//3, 2//3, 1 ]
o = 4
Tableau{T}(:RK438, o, a, b, c)
end
reference(::Val{:RK5}) = """
Reference:
John C. Butcher
Numerical Methods for Ordinary Differential Equations. Wiley, 2016.
Page 103
"""
"""
Tableau of explicit Runge-Kutta method of order five with six stages
```julia
TableauRK5(::Type{T}=Float64) where {T}
```
The constructor takes one optional argument, that is the element type of the tableau.
$(reference(Val(:RK5)))
"""
function TableauRK5(::Type{T}=Float64) where {T}
a = @big [[ 0 0 0 0 0 0 ]
[ 1//4 0 0 0 0 0 ]
[ 1//8 1//8 0 0 0 0 ]
[ 0 0 1//2 0 0 0 ]
[ 3//16 -3//8 3//8 9//16 0 0 ]
[-3//7 8//7 6//7 -12//7 8//7 0 ]]
b = @big [ 7//90, 0, 32//90, 12//90, 32//90, 7//90]
c = @big [ 0, 1//4, 1//4, 1//2, 3//4, 1 ]
o = 5
Tableau{T}(:RK5, o, a, b, c)
end
reference(::Val{:SSPRK2}) = """
Reference:
Chi-Wang Shu, Stanley Osher.
Efficient implementation of essentially non-oscillatory shock-capturing schemes.
Journal of Computational Physics, Volume 77, Issue 2, Pages 439-471, 1988.
doi: 10.1016/0021-9991(88)90177-5.
Equation (2.16)
"""
"""
Tableau of 2rd order Strong Stability Preserving method with two stages and CFL ≤ 1
```julia
TableauSSPRK2(::Type{T}=Float64) where {T}
```
The constructor takes one optional argument, that is the element type of the tableau.
This is the same tableau as [`TableauHeun2`](@ref).
$(reference(Val(:SSPRK2)))
"""
function TableauSSPRK2(args...)
tab = TableauHeun2(args...)
Tableau(:SSPRK2, tab.o, tab.a, tab.b, tab.c)
end
reference(::Val{:SSPRK3}) = """
Reference:
Chi-Wang Shu, Stanley Osher.
Efficient implementation of essentially non-oscillatory shock-capturing schemes.
Journal of Computational Physics, Volume 77, Issue 2, Pages 439-471, 1988.
doi: 10.1016/0021-9991(88)90177-5.
Equation (2.18)
"""
"""
Tableau of 3rd order Strong Stability Preserving method with three stages and CFL ≤ 1
```julia
TableauSSPRK3(::Type{T}=Float64) where {T}
```
The constructor takes one optional argument, that is the element type of the tableau.
$(reference(Val(:SSPRK3)))
"""
function TableauSSPRK3(::Type{T}=Float64) where {T}
a = @big [[ 0 0 0 ]
[ 1 0 0 ]
[ 1//4 1//4 0 ]]
b = @big [ 1//6, 1//6, 4//6 ]
c = @big [ 0, 1, 1//2 ]
o = 3
Tableau{T}(:SSPRK3, o, a, b, c)
end