-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tutorial: construction of B-series and average vector field example (#68
) * construct B-series from a given function * add average vector field method to tutorials * format * set version to v0.1.25 * add test * format * fix typo * fix typo * fix typo * fix typo * fix formatting of jldoctest * fix doctest * tutorial on creating B-series * fix formatting of jldoctest * fix tutorial * modified equation of AVF
- Loading branch information
Showing
8 changed files
with
380 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "BSeries" | ||
uuid = "ebb8d67c-85b4-416c-b05f-5f409e808f32" | ||
authors = ["Hendrik Ranocha <[email protected]> and contributors"] | ||
version = "0.1.24" | ||
version = "0.1.25" | ||
|
||
[deps] | ||
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316" | ||
|
@@ -18,5 +18,5 @@ OrderedCollections = "1" | |
Polynomials = "2.0.23, 3" | ||
Reexport = "1" | ||
Requires = "1" | ||
RootedTrees = "2.10.4" | ||
RootedTrees = "2.12" | ||
julia = "1.6" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
# [Creating B-series](@id tutorial-bseries-creation) | ||
|
||
We have already seen some ways of creating B-series in the | ||
[basic tutorial](@ref tutorial-bseries-basics). In this tutorial, we look at | ||
ways to obtain the B-series of different time integration methods. | ||
|
||
|
||
## B-series for Runge-Kutta methods | ||
|
||
[BSeries.jl](https://github.com/ranocha/BSeries.jl) and | ||
[RootedTrees.jl](https://github.com/SciML/RootedTrees.jl) provide | ||
the type `RungeKuttaMethod` as wrapper of Butcher coefficients `A, b, c` of | ||
Runge-Kutta methods. | ||
|
||
```@example ex:RK4 | ||
using BSeries | ||
# classical RK4 | ||
A = [0 0 0 0 | ||
1//2 0 0 0 | ||
0 1//2 0 0 | ||
0 0 1 0] | ||
b = [1 // 6, 1 // 3, 1 // 3, 1 // 6] | ||
rk = RungeKuttaMethod(A, b) | ||
``` | ||
|
||
Instead of passing the Butcher coefficients explicitly | ||
to [`bseries`](@ref), you can also pass the wrapper struct. In fact, this is | ||
the preferred method. | ||
|
||
```@example ex:RK4 | ||
series = bseries(rk, 5) | ||
``` | ||
|
||
We can check that the classical Runge-Kutta method is indeed fourth-order accurate. | ||
|
||
```@example ex:RK4 | ||
series - ExactSolution(series) | ||
``` | ||
|
||
|
||
## B-series for additive Runge-Kutta methods | ||
|
||
[BSeries.jl](https://github.com/ranocha/BSeries.jl) and | ||
[RootedTrees.jl](https://github.com/SciML/RootedTrees.jl) also support additive | ||
Runge-Kutta methods via the wrapper `AdditiveRungeKuttaMethod`. For example, | ||
we can write the Störmer-Verlet method as additive Runge-Kutta method following | ||
Table II.2.1 of Hairer, Lubich, and Wanner (2002). | ||
|
||
```@example ex:SV | ||
using BSeries | ||
As = [ | ||
[0 0; 1//2 1//2], | ||
[1//2 0; 1//2 0], | ||
] | ||
bs = [ | ||
[1 // 2, 1 // 2], | ||
[1 // 2, 1 // 2], | ||
] | ||
ark = AdditiveRungeKuttaMethod(As, bs) | ||
``` | ||
|
||
We can create the B-series as usual, truncated to order 3. | ||
|
||
```@example ex:SV | ||
series = bseries(ark, 3) | ||
``` | ||
|
||
For additive Runge-Kutta methods like this, we use colored rooted trees. | ||
Again, we can check the order of accuracy by comparing the coefficients to | ||
the exact solution. | ||
|
||
```@example ex:SV | ||
series - ExactSolution(series) | ||
``` | ||
|
||
|
||
### References | ||
|
||
- Ernst Hairer, Gerhard Wanner, Christian Lubich. | ||
Geometric numerical integration. | ||
Springer, 2002. | ||
|
||
|
||
## [B-series for the average vector field method](@id tutorial-bseries-creation-AVF) | ||
|
||
Consider the autonomous ODE | ||
|
||
```math | ||
u'(t) = f\bigl( u(t) \bigr). | ||
``` | ||
|
||
The average vector field method | ||
|
||
```math | ||
u^{n+1} = u^{n} + \Delta t \int_0^1 f\bigl(\xi u^{n+1} + (1 - \xi) u^{n}\bigr) \mathrm{d} \xi | ||
``` | ||
|
||
introduced by McLachlan, Quispel, and Robidoux (1999) is a second-order accurate | ||
method. Quispel and McLaren (2008) discovered that it is indeed a B-series method. | ||
Its coefficients are given explicitly as | ||
|
||
```math | ||
\begin{align*} | ||
b(.) &= 1, \\ | ||
b([t_1, ..., t_n]) &= b(t_1)...b(t_n) / (n + 1). | ||
\end{align*} | ||
``` | ||
|
||
by Celledoni, McLachlan, McLaren, Owren, Quispel, and Wright (2009). We can | ||
implement this up to order 5 in BSeries.jl as follows. | ||
|
||
```@example ex:AVF | ||
using BSeries | ||
series = bseries(5) do t, series | ||
if order(t) in (0, 1) | ||
return 1 // 1 | ||
else | ||
v = 1 // 1 | ||
n = 0 | ||
for subtree in SubtreeIterator(t) | ||
v *= series[subtree] | ||
n += 1 | ||
end | ||
return v / (n + 1) | ||
end | ||
end | ||
``` | ||
|
||
We can check that this method is second-order accurate by comparing it to | ||
the B-series of the exact solution, truncated at the same order. | ||
|
||
```@example ex:AVF | ||
series - ExactSolution(series) | ||
``` | ||
|
||
### References | ||
|
||
- Robert I. McLachlan, G. Reinout W. Quispel, and Nicolas Robidoux. | ||
"Geometric integration using discrete gradients." | ||
Philosophical Transactions of the Royal Society of London. | ||
Series A: Mathematical, Physical and Engineering Sciences 357, | ||
no. 1754 (1999): 1021-1045. | ||
[DOI: 10.1098/rsta.1999.0363](https://doi.org/10.1098/rsta.1999.0363) | ||
- G. Reinout W. Quispel, and David Ian McLaren. | ||
"A new class of energy-preserving numerical integration methods." | ||
Journal of Physics A: Mathematical and Theoretical 41, no. 4 (2008): 045206. | ||
[DOI: 10.1088/1751-8113/41/4/045206](https://doi.org/10.1088/1751-8113/41/4/045206) | ||
- Elena Celledoni, Robert I. McLachlan, David I. McLaren, Brynjulf Owren, | ||
G. Reinout W. Quispel, and William M. Wright. | ||
"Energy-preserving Runge-Kutta methods." | ||
ESAIM: Mathematical Modelling and Numerical Analysis 43, no. 4 (2009): 645-649. | ||
[DOI: 10.1051/m2an/2009020](https://doi.org/10.1051/m2an/2009020) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
0c594ba
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
0c594ba
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/65939
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: