Skip to content

Dense output ​

A step of a Runge–Kutta scheme evaluates residuals inside the step. A scheme with a continuous extension combines them with other weights, bi(θ), into the solution at any tn+θΔt, 0≤θ≤1: output at given times, the interpolation a subcycled level needs, and the trial points of an event, without shortening the step.

fortran
do while (t < 1._R_P)
   call st%begin_step(bx, u)
   do k=1, st%stages()
      call st%begin_stage(k, bx, DT, u)
      if (st%stage_state_is_q(k)) then ; us => u ; else ; call st%stage_state_view(us) ; endif
      call st%rhs_register_view(r)
      r = -us**2                                             ! the caller's residual
      call st%end_stage(k, bx, DT, u)
   enddo
   call st%finish_step(bx, DT, u)                            ! u is u^{n+1}; the residuals are kept until begin_step
   do while (i <= size(T_OUT))                               ! every output time inside this step
      if (T_OUT(i) > t + DT) exit
      theta = (T_OUT(i) - t) / DT
      call st%dense_output(theta, bx, DT, u, out)            ! out = the solution at t + theta DT
      print '(F6.2,ES16.2)', T_OUT(i), maxval(abs(out - u0 / (1._R_P + u0 * T_OUT(i))))
      i = i + 1
   enddo
   t = t + DT
enddo
text
$ cookbook_dense_output
dopri-54: a continuous extension of order 4; its weights at theta = 1/2:
  0.10013  0.00000  0.39183 -0.02982  0.05893 -0.04498  0.02390
   t      largest error of the output
  0.10        6.87E-04
  0.30        1.89E-03
  0.35        1.66E-03
  0.60        1.09E-03
  0.90        6.84E-04
  • After finish_step. dense_output(theta, bx, dt, q, u) reads the residuals of the step just finished, still in their registers until the next begin_step, and q=qn+1: u=qn+1+Δt∑i(bi(θ)−bi)Ri, one pass of the stage-state kernel, no register of its own. At θ=1 it is qn+1, at θ=0 qn to rounding.
  • The schemes. butcher_tableau%b_dense holds bi(θ)=∑jdijθj and dense_order its order; dense_weights(bt, theta) evaluates them. dopri-54 carries Dormand and Prince's extension of order 4 (1986), as Hairer's DOPRI5 code forms it, with no extra stage: notes/dense-check.py derives its dij in exact rationals and checks every condition to order 4 for every θ.
  • Its accuracy. The output's error is the step's, plus the extension's local error, of order dense_order + 1 (selah_test_dense: 4.9 observed for dopri-54).
  • Butcher form only. The low-storage forms keep no residuals.

Hermite's cubic, for any scheme ​

hermite_output(theta, bx, dt, q, u [, r_end]) interpolates the step of any scheme of the Butcher form by the cubic through qn, qn+1 and the residuals at both ends. qn=qn+1−Δt∑ibiRi and R(tn,qn), stage 1's, come from the registers. The residual at tn+1 is the last stage's for a first-same-as-last scheme (dopri-54, calvo-65, the FSAL pairs of #11). For any other scheme you pass it as r_end: you need it anyway, as the next step's first residual. Its order is 3, its local error of order 4 (selah_test_dense: every scheme of order 3 or more):

fortran
do while (t < 1._R_P)
   call st%begin_step(bx, u)
   do k=1, st%stages()
      call st%begin_stage(k, bx, DT, u)
      if (st%stage_state_is_q(k)) then ; us => u ; else ; call st%stage_state_view(us) ; endif
      call st%rhs_register_view(r)
      r = -us**2
      call st%end_stage(k, bx, DT, u)
   enddo
   call st%finish_step(bx, DT, u)
   r_end = -u**2                                          ! F(t^{n+1}, q^{n+1}): the next step's first residual
   do while (i <= size(T_OUT))
      if (T_OUT(i) > t + DT) exit
      call st%hermite_output((T_OUT(i) - t) / DT, bx, DT, u, out, r_end=r_end)
      print '(F6.2,ES16.2)', T_OUT(i), maxval(abs(out - u0 / (1._R_P + u0 * T_OUT(i))))
      i = i + 1
   enddo
   t = t + DT
enddo
text
$ cookbook_dense_output hermite
   t      largest error of rk4's Hermite output
  0.10        2.66E-03
  0.30        1.99E-04
  0.35        4.37E-04
  0.60        7.80E-05
  0.90        1.57E-05

The multistep form ​

In the multistep form, dense_output of ab-k interpolates the residual history the scheme already keeps: u(θ)=qn+1+Δt∑j(βj(θ)−βj(1))Rn+1−j, βj(θ) the integral from 0 to θ of the Lagrange polynomial of the node 1−j over 0,−1,…,1−k, so that βj(1) are ab-k's own weights. Its order is k; it reproduces u=tk to rounding. A subcycled level's ghost cells at an intermediate time (Adaptive mesh refinement) take it, or Hermite's cubic, instead of a linear interpolation in time.