Skip to content

Commit d06ecf0

Browse files
author
Thomas Baumann
committed
Added A-stable DIRK34 method
1 parent a6d863a commit d06ecf0

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

pySDC/implementations/sweeper_classes/Runge_Kutta.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,3 +333,24 @@ def __init__(self, params):
333333
matrix[5, :5] = [1631.0 / 55296.0, 175.0 / 512.0, 575.0 / 13824.0, 44275.0 / 110592.0, 253.0 / 4096.0]
334334
params['butcher_tableau'] = ButcherTableauEmbedded(weights, nodes, matrix)
335335
super(Cash_Karp, self).__init__(params)
336+
337+
338+
class DIRK34(RungeKutta):
339+
"""
340+
Embedded A-stable diagonally implicit RK pair of order 3 and 4.
341+
342+
Taken from [here](https://doi.org/10.1007/BF01934920).
343+
"""
344+
345+
def __init__(self, params):
346+
nodes = np.array([5.0 / 6.0, 10.0 / 39.0, 0, 1.0 / 6.0])
347+
weights = np.array(
348+
[[32.0 / 75.0, 169.0 / 300.0, 1.0 / 100.0, 0], [61.0 / 150.0, 2197.0 / 2100.0, 19.0 / 100.0, -9.0 / 14.0]]
349+
)
350+
matrix = np.zeros((4, 4))
351+
matrix[0, 0] = 5.0 / 6.0
352+
matrix[1, :2] = [-15.0 / 26.0, 5.0 / 6.0]
353+
matrix[2, :3] = [215.0 / 54.0, -130.0 / 27.0, 5.0 / 6.0]
354+
matrix[3, :] = [4007.0 / 6075.0, -31031.0 / 24300.0, -133.0 / 2700.0, 5.0 / 6.0]
355+
params['butcher_tableau'] = ButcherTableauEmbedded(weights, nodes, matrix)
356+
super().__init__(params)

pySDC/tests/test_Runge_Kutta_sweeper.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
CrankNicholson,
1010
Cash_Karp,
1111
Heun_Euler,
12+
DIRK34,
1213
)
1314
from pySDC.implementations.convergence_controller_classes.adaptivity import AdaptivityRK
1415
from pySDC.implementations.convergence_controller_classes.estimate_embedded_error import EstimateEmbeddedErrorNonMPI
@@ -131,7 +132,7 @@ def plot_stability_single(sweeper, ax=None, description=None, implicit=True, re=
131132
)
132133

133134
# check if we think the method should be A-stable
134-
Astable_methods = [RK1, CrankNicholson, MidpointMethod] # only the implicit versions are A-stable
135+
Astable_methods = [RK1, CrankNicholson, MidpointMethod, DIRK34] # only the implicit versions are A-stable
135136
assert (
136137
implicit and sweeper in Astable_methods
137138
) == Astable, f"Unexpected region of stability for {sweeper.__name__} sweeper!"
@@ -162,6 +163,8 @@ def test_all_stability():
162163
plot_stability_single(sweepers[j][i], implicit=impl[j], ax=axs[j], re=re, im=im, crosshair=crosshair[i])
163164
axs[j].set_title(titles[j])
164165

166+
plot_stability_single(DIRK34, re=re, im=im)
167+
165168
fig.tight_layout()
166169

167170

@@ -216,7 +219,7 @@ def test_advection():
216219

217220

218221
@pytest.mark.base
219-
@pytest.mark.parametrize("sweeper", [Cash_Karp, Heun_Euler])
222+
@pytest.mark.parametrize("sweeper", [Cash_Karp, Heun_Euler, DIRK34])
220223
def test_embedded_estimate_order(sweeper):
221224
"""
222225
Test the order of embedded Runge-Kutta schemes. They are not run with adaptivity here,
@@ -244,12 +247,18 @@ def test_embedded_estimate_order(sweeper):
244247

245248
custom_controller_params = {'logger_level': 40}
246249

250+
expected_order = {
251+
Cash_Karp: [5],
252+
Heun_Euler: [2],
253+
DIRK34: [4],
254+
}
255+
247256
Tend = 7e-2
248257
dt_list = Tend * 2.0 ** (-np.arange(8))
249258
prob = run_vdp
250259
plot_all_errors(
251260
ax,
252-
[5] if sweeper == Cash_Karp else [2],
261+
expected_order.get(sweeper, None),
253262
True,
254263
Tend_fixed=Tend,
255264
custom_description=description,

0 commit comments

Comments
 (0)