Skip to content

Choose a stable step ​

A scheme's stability region tells which steps keep every mode of your linearised residual bounded: a mode λ is stable when |R(λΔt)|≤1, R the scheme's stability polynomial. SELAH gives the region's ends on the two axes, and the polynomial itself for a spectrum off them. The definitions and the measured bounds: A5.

The axis bounds of every scheme ​

An oscillation of frequency ω (a wave, a gyration) is stable for ωΔt≤βI, the imaginary-axis bound; a decay of rate λ for λΔt≤βR, the real-axis bound. Ask a tableau, a stepper, or a leapfrog filter:

fortran
real(R_P), parameter  :: OMEGA=100._R_P, LAMBDA=1000._R_P   ! your fastest oscillation and fastest decay
type(butcher_tableau) :: bt
type(leapfrog_filter) :: lf
type(stepper)         :: st
real(R_P)             :: bi, br
integer(I4P)          :: s
character(16)         :: label

print '(A)', 'scheme          imag bound  real bound   dt_max, oscillation   dt_max, decay   stepper agrees'
do s=1, size(RK_SCHEMES)                                       ! the free functions, on the tableau
   bt = butcher(trim(RK_SCHEMES(s)))
   bi = imag_axis_bound(bt) ; br = real_axis_bound(bt)
   call st%initialize(trim(RK_SCHEMES(s)), FORM_BUTCHER, lb=[1], ub=[1], components=.false.)
   label = RK_SCHEMES(s)
   print '(A16,2F12.4,ES20.3,ES16.3,L10)', label, bi, br, bi / OMEGA, br / LAMBDA, &
         st%imag_axis_bound() == bi .and. st%real_axis_bound() == br
   call st%destroy
enddo
do s=1, size(LEAPFROG_SCHEMES)                                 ! the leapfrog's bounds are its filter's
   lf = leapfrog(trim(LEAPFROG_SCHEMES(s)))
   bi = leapfrog_imag_axis_bound(lf) ; br = leapfrog_real_axis_bound(lf)
   call st%initialize(trim(LEAPFROG_SCHEMES(s)), FORM_LEAPFROG, lb=[1], ub=[1], components=.false.)
   label = LEAPFROG_SCHEMES(s)
   print '(A16,2F12.4,ES20.3,ES16.3,L10)', label, bi, br, bi / OMEGA, br / LAMBDA, &
         st%imag_axis_bound() == bi .and. st%real_axis_bound() == br
   call st%destroy
enddo
lf = leapfrog_filter(nu=0.1_R_P, alpha=1._R_P)                 ! a filter of your own: Robert–Asselin, nu = 0.1
bi = leapfrog_imag_axis_bound(lf) ; br = leapfrog_real_axis_bound(lf)
call st%initialize(SCHEME_LEAPFROG, FORM_LEAPFROG, lb=[1], ub=[1], components=.false., nu=lf%nu, alpha=lf%alpha)
label = 'RA, nu = 0.1'
print '(A16,2F12.4,ES20.3,ES16.3,L10)', label, bi, br, bi / OMEGA, br / LAMBDA, &
      st%imag_axis_bound() == bi .and. st%real_axis_bound() == br
call st%destroy
text
$ cookbook_stable_step bounds
scheme          imag bound  real bound   dt_max, oscillation   dt_max, decay   stepper agrees
euler                 0.0000      2.0000           0.000E+00       2.000E-03         T
ssp-22                0.0000      2.0000           0.000E+00       2.000E-03         T
ssp-33                1.7321      2.5127           1.732E-02       2.513E-03         T
ssp-54                3.2784      5.3315           3.278E-02       5.331E-03         T
ssp-104               4.9215     13.9170           4.921E-02       1.392E-02         T
rk4                   2.8284      2.7853           2.828E-02       2.785E-03         T
lsrk-33               1.7321      2.5127           1.732E-02       2.513E-03         T
lsrk-54               3.3407      4.6568           3.341E-02       4.657E-03         T
lsrk-64               4.8948      3.2289           4.895E-02       3.229E-03         T
lsrk-74               5.6770      3.9575           5.677E-02       3.957E-03         T
lsrk-124             10.9538      4.0465           1.095E-01       4.047E-03         T
lsrk-134              6.5491     10.9262           6.549E-02       1.093E-02         T
lsrk-144              6.0793     18.5215           6.079E-02       1.852E-02         T
heun-euler-21         0.0000      2.0000           0.000E+00       2.000E-03         T
cash-karp-54          0.0000      3.7344           0.000E+00       3.734E-03         T
dopri-54              0.9972      3.3066           9.972E-03       3.307E-03         T
calvo-65              2.6093      4.4634           2.609E-02       4.463E-03         T
feagin-108            1.1540      2.5279           1.154E-02       2.528E-03         T
runge-2               0.0000      2.0000           0.000E+00       2.000E-03         T
heun-2                0.0000      2.0000           0.000E+00       2.000E-03         T
kutta-3               1.7321      2.5127           1.732E-02       2.513E-03         T
ralston-4             2.8284      2.7853           2.828E-02       2.785E-03         T
shanks-4              2.8284      2.7853           2.828E-02       2.785E-03         T
butcher-6             0.0000      2.8561           0.000E+00       2.856E-03         T
ssp-53                2.6952      6.2136           2.695E-02       6.214E-03         T
jiang-shu-4           2.8284      2.7853           2.828E-02       2.785E-03         T
ssp-43                2.1562      5.1495           2.156E-02       5.149E-03         T
shanks-7              1.9484      4.4731           1.948E-02       4.473E-03         T
shanks-7b             2.8616      4.0507           2.862E-02       4.051E-03         T
shanks-8              0.0000      3.3820           0.000E+00       3.382E-03         T
cooper-verner-8       3.0018      3.7154           3.002E-02       3.715E-03         T
tmy-7s                2.4708      7.1767           2.471E-02       7.177E-03         T
stepanov-10           0.0000      4.4293           0.000E+00       4.429E-03         T
zhang-10              0.0000      4.7241           0.000E+00       4.724E-03         T
bs-32                 1.7321      2.5127           1.732E-02       2.513E-03         T
fehlberg-45           0.0000      3.0200           0.000E+00       3.020E-03         T
tsitouras-54          0.4780      3.5068           4.780E-03       3.507E-03         T
stepanov-54           0.5256      3.4965           5.256E-03       3.497E-03         T
pp-54a                0.3720      3.5257           3.720E-03       3.526E-03         T
pp-54b                0.0000      3.6848           0.000E+00       3.685E-03         T
dopri-65              1.7644      3.9541           1.764E-02       3.954E-03         T
tsit-pap-64           1.7644      3.9541           1.764E-02       3.954E-03         T
verner-65a            1.3068      4.0648           1.307E-02       4.065E-03         T
verner-65r            0.0000      4.3240           0.000E+00       4.324E-03         T
tsit-pap-75           0.0000      4.5025           0.000E+00       4.503E-03         T
verner-76e            0.0000      4.6400           0.000E+00       4.640E-03         T
verner-76r            0.0000      4.6355           0.000E+00       4.635E-03         T
sharp-smart-76        3.9069      3.8995           3.907E-02       3.899E-03         T
fehlberg-78           1.8824      5.0362           1.882E-02       5.036E-03         T
verner-78a            4.0838      5.5383           4.084E-02       5.538E-03         T
tsit-pap-86           2.9149      5.9069           2.915E-02       5.907E-03         T
dopri-87              0.0000      5.1666           0.000E+00       5.167E-03         T
verner-87e            0.0000      5.8641           0.000E+00       5.864E-03         T
verner-87r            2.5913      4.8198           2.591E-02       4.820E-03         T
enright-ver-87        3.0015      5.6426           3.002E-02       5.643E-03         T
fehlberg-89           0.0000      2.8457           0.000E+00       2.846E-03         T
verner-89             0.1944      4.1562           1.944E-03       4.156E-03         T
tsitouras-98          2.6896      4.5013           2.690E-02       4.501E-03         T
verner-98e            2.7570      4.4762           2.757E-02       4.476E-03         T
verner-98r            2.7022      4.5214           2.702E-02       4.521E-03         T
sharp-98              0.0000      5.1917           0.000E+00       5.192E-03         T
dopri-853             5.9604      6.3937           5.960E-02       6.394E-03         T
bs-54                 1.6643      3.9879           1.664E-02       3.988E-03         T
leapfrog              1.0000      0.0000           1.000E-02       0.000E+00         T
leapfrog-raw          0.4371      0.1988           4.371E-03       1.988E-04         T
RA, nu = 0.1          0.9512      0.0952           9.512E-03       9.524E-05         T
  • imag_axis_bound(bt) and real_axis_bound(bt) take any explicit tableau, your own included (Coefficient forms). The stepper's methods give the same numbers for its scheme, the last column says so.
  • euler and ssp-22 have no imaginary-axis interval: an undamped oscillation grows at any step.
  • The leapfrog's bounds are its filter's, leapfrog_imag_axis_bound(lf) and leapfrog_real_axis_bound(lf). The unfiltered leapfrog has no real-axis interval (on a decay its computational root has modulus x+1+x2>1, x=λΔt), and a filter trades imaginary-axis range for a real-axis one. A filter of your own is a leapfrog_filter(nu, alpha); pass the same nu= and alpha= to the stepper's initialize. The row RA, nu = 0.1 is the Robert–Asselin filter (α=1).

The stability regions of the Runge–Kutta schemes by family, from the library's own tableaux

The regions the axis bounds above are read from (A5); each family's alone: Schemes.

A spectrum off the axes ​

The axis bounds hold for modes on the axes. An advection-diffusion residual has modes with both parts: with central differences on a periodic grid, λ(θ)=−2νΔx2(1−cos⁡θ)−iaΔxsin⁡θ, an ellipse; here a=1, ν=4⋅10−3, Δx=1/64, where the two axis limits are of the same size. Compare the step that each axis bound allows on its own with the largest step that keeps the whole ellipse inside the region, from stability_polynomial(bt):

fortran
type(butcher_tableau) :: bt
real(R_P)             :: dt_axes, dt_true
integer(I4P)          :: s

print '(A)', 'scheme          dt from the axis bounds   largest stable dt   ratio'
do s=1, size(RK_SCHEMES)
   bt = butcher(trim(RK_SCHEMES(s)))
   dt_axes = min(imag_axis_bound(bt) * DX / A, real_axis_bound(bt) * DX**2 / (4 * NU)) ! each axis on its own
   dt_true = largest_stable_dt(stability_polynomial(bt))                              ! the whole ellipse
   print '(A16,ES20.4,ES20.4,F8.3)', RK_SCHEMES(s), dt_axes, dt_true, dt_axes / dt_true
enddo
fortran
function largest_stable_dt(g) result(dt)
!< The largest dt with |R(dt lambda(theta))| <= 1 at every theta: a scan by DX/1000, then bisection.
real(R_P), intent(in) :: g(0:)                               ! R(z) = sum_k g(k) z^k
real(R_P)             :: dt, lo, hi
integer(I4P)          :: it

dt = 0._R_P
do while (stable(g, dt + 1.e-3_R_P * DX))
   dt = dt + 1.e-3_R_P * DX
enddo
lo = dt ; hi = dt + 1.e-3_R_P * DX
do it=1, 60
   dt = 0.5_R_P * (lo + hi)
   if (stable(g, dt)) then ; lo = dt ; else ; hi = dt ; endif
enddo
dt = lo
endfunction largest_stable_dt

logical function stable(g, dt)
!< |R(dt lambda(theta))| <= 1 at 1024 angles theta in (0, pi] (the ellipse is symmetric about the real axis).
real(R_P), intent(in) :: g(0:), dt
complex(R_P)          :: z, r
integer(I4P)          :: j, k

stable = .true.
do j=1, 1024
   z = dt * cmplx(-2 * NU / DX**2 * (1 - cos(j * acos(-1._R_P) / 1024)), &
                  -A / DX * sin(j * acos(-1._R_P) / 1024), R_P)
   r = g(ubound(g, 1))
   do k=ubound(g, 1) - 1, 0, -1                              ! Horner
      r = r * z + g(k)
   enddo
   if (abs(r) > 1._R_P + 1.e-12_R_P) then
      stable = .false.
      return
   endif
enddo
endfunction stable
text
$ cookbook_stable_step spectrum
scheme          dt from the axis bounds   largest stable dt   ratio
euler                     0.0000E+00          8.0000E-03   0.000
ssp-22                    0.0000E+00          2.6770E-02   0.000
ssp-33                    2.7063E-02          3.2324E-02   0.837
ssp-54                    5.1224E-02          4.3125E-02   1.188
ssp-104                   7.6898E-02          8.0584E-02   0.954
rk4                       4.2500E-02          3.5185E-02   1.208
lsrk-33                   2.7063E-02          3.2324E-02   0.837
lsrk-54                   5.2199E-02          4.3799E-02   1.192
lsrk-64                   4.9269E-02          4.5724E-02   1.078
lsrk-74                   6.0386E-02          5.2741E-02   1.145
lsrk-124                  6.1745E-02          6.1507E-02   1.004
lsrk-134                  1.0233E-01          1.5106E-01   0.677
lsrk-144                  9.4990E-02          1.4089E-01   0.674
heun-euler-21             0.0000E+00          2.6770E-02   0.000
cash-karp-54              0.0000E+00          4.9429E-02   0.000
dopri-54                  1.5581E-02          4.4831E-02   0.348
calvo-65                  4.0770E-02          5.5025E-02   0.741
feagin-108                1.8032E-02          3.4338E-02   0.525
runge-2                   0.0000E+00          2.6770E-02   0.000
heun-2                    0.0000E+00          2.6770E-02   0.000
kutta-3                   2.7063E-02          3.2324E-02   0.837
ralston-4                 4.2500E-02          3.5185E-02   1.208
shanks-4                  4.2500E-02          3.5185E-02   1.208
butcher-6                 0.0000E+00          3.8814E-02   0.000
ssp-53                    4.2112E-02          5.0007E-02   0.842
jiang-shu-4               4.2500E-02          3.5185E-02   1.208
ssp-43                    3.3690E-02          4.1084E-02   0.820
shanks-7                  3.0444E-02          5.2543E-02   0.579
shanks-7b                 4.4713E-02          5.4881E-02   0.815
shanks-8                  0.0000E+00          4.6105E-02   0.000
cooper-verner-8           4.6903E-02          4.2243E-02   1.110
tmy-7s                    3.8607E-02          6.6872E-02   0.577
stepanov-10               0.0000E+00          5.1395E-02   0.000
zhang-10                  0.0000E+00          5.8926E-02   0.000
bs-32                     2.7063E-02          3.2324E-02   0.837
fehlberg-45               0.0000E+00          3.9596E-02   0.000
tsitouras-54              7.4684E-03          4.7312E-02   0.158
stepanov-54               8.2120E-03          4.7194E-02   0.174
pp-54a                    5.8128E-03          4.7524E-02   0.122
pp-54b                    0.0000E+00          4.9063E-02   0.000
dopri-65                  2.7569E-02          5.1752E-02   0.533
tsit-pap-64               2.7569E-02          5.1752E-02   0.533
verner-65a                2.0418E-02          5.2855E-02   0.386
verner-65r                0.0000E+00          6.0471E-02   0.000
tsit-pap-75               0.0000E+00          6.0396E-02   0.000
verner-76e                0.0000E+00          6.1807E-02   0.000
verner-76r                0.0000E+00          6.1762E-02   0.000
sharp-smart-76            5.9501E-02          5.3341E-02   1.115
fehlberg-78               2.9413E-02          6.2044E-02   0.474
verner-78a                6.3810E-02          6.7421E-02   0.946
tsit-pap-86               4.5545E-02          7.5440E-02   0.604
dopri-87                  0.0000E+00          7.1120E-02   0.000
verner-87e                0.0000E+00          7.6683E-02   0.000
verner-87r                4.0490E-02          6.2363E-02   0.649
enright-ver-87            4.6899E-02          7.4848E-02   0.627
fehlberg-89               0.0000E+00          3.8471E-02   0.000
verner-89                 3.0377E-03          4.5610E-02   0.067
tsitouras-98              4.2025E-02          5.9867E-02   0.702
verner-98e                4.3078E-02          5.9655E-02   0.722
verner-98r                4.2222E-02          6.0236E-02   0.701
sharp-98                  0.0000E+00          6.7619E-02   0.000
dopri-853                 9.3131E-02          8.8458E-02   1.053
bs-54                     2.6005E-02          5.2038E-02   0.500
  • The two axis bounds together are not a stability test: for ssp-54, rk4 and lsrk-54 (ratio above 1) the step they allow is unstable on this spectrum.
  • For euler and ssp-22 they allow no step at all, while the diffusion makes a positive step stable.
  • stability_polynomial(bt) returns g0,…,gs of R(z)=∑kgkzk, so evaluate R on your own spectrum, as above, whenever its modes are not on an axis.

A stiff decay that sets λΔt far beyond βR, in a layer or a source term, need not set the step: see An absorbing layer.