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.
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 dtAn adaptive step runs this loop.
The controllers
With
| Name | Constant | Reference | ||
|---|---|---|---|---|
elementary | CONTROL_ELEMENTARY | the classical rule | ||
pi | CONTROL_PI | Gustafsson, Lundh & Söderlind (1988); Hairer & Wanner, Solving ODEs II, IV.2 | ||
h211b | CONTROL_H211B | Söderlind (2003), | ||
pi42 | CONTROL_PI42 | Söderlind (2003), PI.4.2 | ||
custom | CONTROL_CUSTOM | beta= | alpha= | yours |
CONTROLLERS lists the five names.
- The limits. The ratio
stays in ( fac_min, default 0.2;fac_max, default 5), and infor the step after a rejection: no growth right after a failure. The step stays in ( dt_min, default 0;dt_max, default huge). - A rejected step is redone with the elementary rule,
limited to , and leaves the filter's history as it was. When that step would fall below dt_min, the controller proposesdt_minand setsstalled: 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
as , as Hairer's DOPRI5 does: a step whose error vanished must not make piorpi42, whosehas a positive exponent, shrink the next. - A restart.
reset()forgets the history (a discontinuity, a regrid, a step the controller did not propose); the countersacceptedandrejectedare kept. - FOODIE's rule.
embedded_step_size(dt, err, tol, embedded_order)stays as it was: it only shrinks the step.
Which controller
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$ cookbook_step_control
controller accepted rejected
elementary 304 21
pi 307 0
h211b 306 28
pi42 306 0
custom 306 0
foodie 2001 0piat 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.piandpi42damp the oscillation: above,dopri-54on, , rtol = atol = ( customis PI.4.2 written out). FOODIE's rule never grows the step from itsstart. h211bfor smooth steps. It filters the step sequence itself (its), at the cost of a slower response. - Any of them in the asymptotic range. The global error follows the tolerance: with
dopri-54on the logistic equation,, the largest global error against tol 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 dt_min and dt_max. The stepper measures the norms in the Butcher form; the controller applies the rule:
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)$ 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,
, written into stage 2's register. is stage 1's residual of the first step: begin_stepbegins that step again and keeps it (stage_needs_residual(1)is false). - Two reductions.
initial_step_normsgives the parts ofand (the largest and the sum of squares of each, over ncells),initial_step_differencethose of, as step_errordoes: 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 am-<p-1> or bdf-<p>, computed from SELAH's own coefficients) and
select(sums, accept, h_next, q_next) turns the reduced sums into RMS norms. The step is accepted when finish_step or reject_step, then set_order and set_step.
The stability cap. Given the largest set_spectral_radius(rho) (an advection's stability_bound(p) the imaginary-axis bound of the order-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:
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$ 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 9selah_test_nordsieck: the oscillator's error at
Procedures
| Procedure | What 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 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 |
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):
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