Peano
Loading...
Searching...
No Matches
test_rungekutta_butcher_tableau.py
Go to the documentation of this file.
1import pytest
2
4
5
6def _dot(u, v):
7 return sum(a * b for a, b in zip(u, v))
8
9
10def _times(matrix, v):
11 return [_dot(row, v) for row in matrix]
12
13
14def _elementwise(u, v):
15 return [a * b for a, b in zip(u, v)]
16
17
18@pytest.mark.parametrize("order", [1, 2, 3, 4])
21 a = tableau.weight_matrix()
22 c = tableau.relative_time_step_sizes()
23 b = tableau.final_estimate_weights()
24
25 assert tableau.number_of_stages == order
26 assert len(a) == order and all(len(row) == order for row in a)
27 assert len(b) == order and len(c) == order
28 for k in range(order):
29 assert all(a[k][j] == 0.0 for j in range(k, order)), "not explicit"
30 assert sum(a[k]) == pytest.approx(c[k])
31 assert sum(b) == pytest.approx(1.0)
32
33
34@pytest.mark.parametrize("order", [1, 2, 3, 4])
37 a = tableau.weight_matrix()
38 c = tableau.relative_time_step_sizes()
39 b = tableau.final_estimate_weights()
40
41 # One entry per rooted tree, up to order four
42 conditions = {
43 2: [(_dot(b, c), 1 / 2)],
44 3: [
45 (_dot(b, _elementwise(c, c)), 1 / 3),
46 (_dot(b, _times(a, c)), 1 / 6),
47 ],
48 4: [
49 (_dot(b, _elementwise(c, _elementwise(c, c))), 1 / 4),
50 (_dot(b, _elementwise(c, _times(a, c))), 1 / 8),
51 (_dot(b, _times(a, _elementwise(c, c))), 1 / 12),
52 (_dot(b, _times(a, _times(a, c))), 1 / 24),
53 ],
54 }
55 for p in range(2, order + 1):
56 for value, expected in conditions[p]:
57 assert value == pytest.approx(expected)
58
59
60@pytest.mark.parametrize("order", [0, 5])
62 with pytest.raises(ValueError):
Butcher tableau of an explicit Runge-Kutta scheme.
Runge-Kutta time integration tools which do not depend on the discretisation in space,...
Definition __init__.py:1