Skip to content

Step control ​

An embedded pair estimates the error of each step (Stepper: procedures, step_error); the time loop, and with it the decision, stays yours. A step_controller turns the error of each step into that decision: accept or reject, and the step to try next. It is a scalar object on the host. It keeps the earlier errors and steps its filter needs, touches no field and calls nothing back, so every rank holding the same reduced error takes the same decision.

fortran
type(step_controller) :: ctl
type(butcher_tableau)  :: bt

bt = butcher(SCHEME_DOPRI_54)
call ctl%initialize(CONTROL_PI, bt%embedded_order)
! ... every step: the stages, then step_error, then your norm err of the scaled error (reduced over boxes and ranks)
call ctl%propose(dt_try, err, dt, accept)   ! accept: finish_step; otherwise q is still q^n: redo it with dt

An adaptive step runs this loop.

The controllers ​

With k=p^+1, the power of Δt in the estimate of a pair whose embedded order is p^, the step after an accepted one is Söderlind's digital filter (Söderlind 2003):

Δtn+1=Δtnsen−β1/ken−1−β2/ken−2−β3/kρn−1−α2ρn−2−α3,ρn−1=ΔtnΔtn−1,

en the scaled error of the step (accepted when en≤1), s the safety factor, and the ratios ρ those of the steps you took, which may differ from the proposals (the last step of a run, a step cut at an output time).

NameConstantβ1,β2,β3α2,α3Reference
elementaryCONTROL_ELEMENTARY1,0,00,0the classical rule
piCONTROL_PI0.7,−0.4,00,0Gustafsson, Lundh & Söderlind (1988); Hairer & Wanner, Solving ODEs II, IV.2
h211bCONTROL_H211B1/4,1/4,01/4,0Söderlind (2003), b=4
pi42CONTROL_PI423/5,−1/5,00,0Söderlind (2003), PI.4.2
customCONTROL_CUSTOMbeta=alpha=yours

CONTROLLERS lists the five names.

  • The limits. The ratio Δtn+1/Δtn stays in [fmin,fmax] (fac_min, default 0.2; fac_max, default 5), and in [fmin,1] for the step after a rejection: no growth right after a failure. The step stays in [Δtmin,Δtmax] (dt_min, default 0; dt_max, default huge).
  • A rejected step is redone with the elementary rule, sen−1/k limited to [fmin,1], and leaves the filter's history as it was. When that step would fall below dt_min, the controller proposes dt_min and sets stalled: the tolerance cannot be met there, and what to do is your decision.
  • The start. Before a filter has its earlier errors and steps, the missing ones count as 1 (an error at the tolerance, an unchanged step). The history keeps an error below 10−4 as 10−4, as Hairer's DOPRI5 does: a step whose error vanished must not make pi or pi42, whose en−1 has a positive exponent, shrink the next.
  • A restart. reset() forgets the history (a discontinuity, a regrid, a step the controller did not propose); the counters accepted and rejected are kept.
  • FOODIE's rule. embedded_step_size(dt, err, tol, embedded_order) stays as it was: it only shrinks the step.

Which controller ​

fortran
do c=1, size(CONTROLLERS)
   name = CONTROLLERS(c)
   call run(name, accepted, rejected)
   print '(A12,2I10)', trim(name), accepted, rejected
enddo
call run('foodie', accepted, rejected)                       ! embedded_step_size: it only shrinks the step
print '(A12,2I10)', 'foodie', accepted, rejected
text
$ cookbook_step_control
  controller  accepted  rejected
  elementary       304        21
          pi       307         0
       h211b       306        28
        pi42       306         0
      custom       306         0
      foodie      2001         0
  • pi at the stability boundary. When the step is limited by stability rather than accuracy (a stiff term, a CFL limit), the elementary rule makes the step oscillate around the boundary, with a rejection every few steps. pi and pi42 damp the oscillation: above, dopri-54 on y′=−500(y−cos⁡t)−sin⁡t, t≤2, rtol = atol = 10−4 (custom is PI.4.2 written out). FOODIE's rule never grows the step from its 10−3 start.
  • h211b for smooth steps. It filters the step sequence itself (its α2), at the cost of a slower response.
  • Any of them in the asymptotic range. The global error follows the tolerance: with dopri-54 on the logistic equation, t≤10, the largest global error against tol =10−4…10−10 has slope 0.97 (elementary), 0.90 (pi), 0.99 (h211b, pi42).

The starting step ​

The first step has no earlier error to learn from. The rule of Hairer, Nørsett & Wanner (Solving ODEs I, II.4, after Gladwell, Shampine & Brankin 1987) estimates it from three norms, scaled by atol+rtol|q0|: d0=∥q0∥, d1=∥F0∥ and d2=∥F1−F0∥/h0, F1 the residual of the probe q0+h0F0. The probe's step is h0=0.01d0/d1 (10−6 when d0 or d1 is below 10−5), and the first step min(100h0,(0.01/max(d1,d2))1/k) (max(10−6,10−3h0) when d1 and d2 are below 10−15), within dt_min and dt_max. The stepper measures the norms in the Butcher form; the controller applies the rule:

fortran
call st%begin_step(bx, u)                                    ! stage 1 of the first step: its residual F^0
call st%begin_stage(1_I4P, bx, 0._R_P, u)
call st%stage_state_view(us) ; call st%rhs_register_view(r)
r = us * (1._R_P - us)
call st%end_stage(1_I4P, bx, 0._R_P, u)
call st%initial_step_norms(bx, u, TOL, TOL, parts, ncells)  ! reduce parts and ncells over boxes and ranks here
d0 = sqrt(parts(2) / ncells) ; d1 = sqrt(parts(4) / ncells) ! ||q^0||, ||F^0|| (RMS)
h0 = ctl%initial_probe(d0, d1)
call st%initial_step_probe(bx, h0, u)                        ! the probe q^0 + h0 F^0: its residual F^1
call st%stage_state_view(us) ; call st%rhs_register_view(r)
r = us * (1._R_P - us)
call st%initial_step_difference(bx, h0, u, TOL, TOL, dmax, dsum, ncells)
d2 = sqrt(dsum / ncells)                                     ! ||F^1 - F^0|| / h0
dt = ctl%initial_step(h0, d1, d2)
text
$ cookbook_initial_step
d0, d1, d2:   3.35E+05  1.39E+05  5.31E+04
probe step   2.40E-02, first step   3.73E-02
its scaled error (RMS)   8.39E-07, accepted T
  • One residual more. The probe costs one residual, F1, written into stage 2's register. F0 is stage 1's residual of the first step: begin_step begins that step again and keeps it (stage_needs_residual(1) is false).
  • Two reductions. initial_step_norms gives the parts of d0 and d1 (the largest and the sum of squares of each, over ncells), initial_step_difference those of d2, as step_error does: reduce them over your boxes and ranks, then take the max norm or the RMS.
  • Conservative by design. The rule aims at an error of 0.01 from the first two derivatives. For a fifth-order pair the step it gives is 10 to 20 times below the largest first step accepted (selah_test_step_control); the controller grows it in the next steps.

Order and step in the Nordsieck form ​

The Nordsieck form (nordsieck_stepper, Schemes) chooses its order as well as its step. After the stages of a step, error_sums(bx, q, atol, rtol, sums) returns the box's sums of the squared local error estimates at the orders q−1, q and q+1, each scaled by atol+rtol|y| (y the corrected value), the count, and the squared residual (BDF's stability-limit detection, Schemes): one reduction for the caller. With Cp+1 the error constant of the order-p method (its am-<p-1> or bdf-<p>, computed from SELAH's own coefficients) and hq+1y(q+1)≈q!lqΔ, the estimates are

eq−1=Cqq!zq,eq=Cq+1q!lqΔ,eq+1=Cq+2q!lq(Δ−Δn−1).

select(sums, accept, h_next, q_next) turns the reduced sums into RMS norms. The step is accepted when eq≤1. After q+1 accepted steps at an order it compares the steps each order allows, ηp=1/(bpep1/(p+1)) with the biases b = 1.3, 1.2, 1.4 (at most 10 times the step), keeps the largest, and changes the step only when it grows by 10 % or must shrink: the fixed coefficients interpolate the array at every change, and frequent changes cost the high orders their digits (the Nordsieck form). A rejection shrinks the step by 0.2 to 0.9, and the order after three in a row. The caller applies the choice between steps: finish_step or reject_step, then set_order and set_step.

The stability cap. Given the largest |λ| of the residual's Jacobian on the imaginary axis, set_spectral_radius(rho) (an advection's a/Δx) caps the step of each order at 0.9βp/ρ, with βp = stability_bound(p) the imaginary-axis bound of the order-p step: for Adams, the step its stages make from the predictor, as fixed_point_imag_axis_bound of Schemes computes it; for BDF, the scheme's own. The order with the largest capped step wins, so a CFL-limited run stays at the orders that allow the largest stable step, and an order with no interval on the imaginary axis (Adams 3, 4, 7, 8, 11, 12 with two stages) is never chosen. Without the cap the error estimate alone lets the step grow past the bound, and instability drives the rejections:

fortran
type(nordsieck_stepper) :: ns
type(box)               :: bx
real(R_P), allocatable, target :: q(:,:,:,:,:), hf(:,:,:,:,:)
real(R_P), pointer      :: y(:,:,:,:,:), r(:,:,:,:,:)
real(R_P)               :: t, tol, sums(5), h_next, err
integer(I4P)            :: k, it, q_next, qhi
logical                 :: accept

bx = box_interior(LAYOUT_V_FIRST, 2_I4P, 1_I4P, 1_I4P, 1_I4P, 0_I4P, 1_I4P) ! (y, v) on one cell
allocate(q(2,1,1,1,1), hf(2,1,1,1,1))
print '(A)', '   tol      error at t = 10   steps  rejected  highest order'
do it=1, 3
   tol = 10._R_P**(-2 * it - 2)
   q(:,1,1,1,1) = [1._R_P, 0._R_P] ; hf(:,1,1,1,1) = 1.e-4_R_P * [0._R_P, -1._R_P] ! h (v, -y)
   call ns%initialize(NORDSIECK_ADAMS, lb=bx%lb, ub=bx%hi)
   call ns%start(bx, 1.e-4_R_P, hf)
   t = 0._R_P ; qhi = 1
   do while (t < 10._R_P - 1.e-12_R_P)
      if (t + ns%h > 10._R_P) call ns%set_step(bx, 10._R_P - t)
      call ns%begin_step(bx, q)
      do k=1, ns%stages()
         call ns%begin_stage(k, bx)
         y => ns%stage_state() ; r => ns%rhs_register()
         r(1,:,:,:,:) = y(2,:,:,:,:) ; r(2,:,:,:,:) = -y(1,:,:,:,:)
         call ns%end_stage(k)
      enddo
      call ns%error_sums(bx, q, tol, tol, sums)     ! with MPI: sums reduced (summed) over the ranks first
      call ns%select(sums, accept, h_next, q_next)  ! accept? and the next step and order
      if (accept) then
         t = t + ns%h
         call ns%finish_step(bx, q)
         qhi = max(qhi, ns%q)
      else
         call ns%reject_step(bx)
      endif
      if (q_next /= ns%q) call ns%set_order(bx, q_next)
      call ns%set_step(bx, h_next)
   enddo
   err = max(abs(q(1,1,1,1,1) - cos(t)), abs(q(2,1,1,1,1) + sin(t)))
   print '(ES8.1,ES14.2,I11,I9,I12)', tol, err, ns%accepted, ns%rejected, qhi
   call ns%destroy
enddo
text
$ cookbook_nordsieck adaptive
   tol      error at t = 10   steps  rejected  highest order
 1.0E-04      1.13E-03         36        0           6
 1.0E-06      2.61E-06         53        0           8
 1.0E-08      9.46E-08         75        0           9

selah_test_nordsieck: the oscillator's error at t=10 follows the tolerance with a slope of 0.94 over 10−4 to 10−10, and the order reaches 9; the advection of 64 cells at a tolerance of 10−3 takes 1000 steps with 1 rejection with the cap, 18 without it, where its maximum grows to 1.0067. Its steps stay accuracy-limited, at most 0.71 of the cap; the cap's value itself is checked on error sums that allow any step: the next step is exactly 0.9βq/ρ.

Procedures ​

ProcedureWhat it does
initialize(name, embedded_order [, safety] [, fac_min] [, fac_max] [, dt_min] [, dt_max] [, beta] [, alpha])chooses the controller and its limits; resets the history and the counters. embedded_order is the order p^ of the estimate's lower-order solution: min(bt%order, bt%embedded_order), which is bt%embedded_order except for a pair that advances with its lower-order weights (fehlberg-45: 4)
propose(dt, err, dt_next, accept)accept = err <= 1; dt_next the step to try next (to redo the step with, after a rejection)
reset()forgets the history
initial_probe(d0, d1)the starting step's probe step h0
initial_step(h0, d1, d2)the first step

The components accepted, rejected, stalled and after_reject can be read.

dop853_error(esum, esum2, ncells), a function of the module, is the error norm of dopri-853 from the sums of its two estimates (step_error and step_error(second=.true.), reduced): esum/n(esum+0.01esum2), as Hairer's DOP853 forms it (An adaptive step: two estimates).

Verification ​

selah_test_step_control: each controller's proposals on a scripted sequence of accepted, rejected and shortened steps equal the filter written out with its published coefficients within 4 ε; the limits, stalled, the counters and reset; the stability-boundary and tolerance-proportionality runs above (R8P); the starting-step rule against its formulas, and through the stepper on y′=−y, u′=tu2 from t=1/2 and the logistic equation: the first step accepted, within a factor 20 of the largest first step accepted, s+1 residuals for the probe and the first step; u′=tu2 from t=0 (F0=0): the rule's branch.