Skip to content

selah_step_control ​

SELAH, L0: step-size control for an embedded pair, a scalar object on the host.

The caller's loop owns the step: after step_error it reduces the scaled error to one norm err (the step is accepted when err <= 1, see stepper%step_error) and asks a step_controller for the next step. The controller keeps the earlier errors and step ratios the filters need; it touches no field and calls nothing back.

With k = p_hat + 1 (the power of dt in the estimate of a pair whose embedded order is p_hat), the proposed step after an accepted one is the digital filter of Söderlind (2003):

( \Delta t_{n+1} = \Delta t_n , s, e_n^{-\beta_1/k} e_{n-1}^{-\beta_2/k} e_{n-2}^{-\beta_3/k} \rho_{n-1}^{-\alpha_2} \rho_{n-2}^{-\alpha_3} ), ( \rho_{n-1} = \Delta t_n / \Delta t_{n-1} ), the ratios of the accepted steps (those the caller took, which may differ from the proposals: the last step of a run, a step of an output time),

s the safety factor, the ratio Delta t_{n+1}/Delta t_n then limited to [fac_min, fac_max] (to [fac_min, 1] for the step after a rejection) and the step to [dt_min, dt_max]. A rejected step is redone with the elementary rule s e_n^{-1/k}, limited to [fac_min, 1), and leaves the filter's history as it was. The controllers:

  • elementary (CONTROL_ELEMENTARY): beta = (1, 0, 0), alpha = 0, the classical rule;
  • PI (CONTROL_PI): beta = (0.7, -0.4, 0), the PI controller of Gustafsson, Lundh & Söderlind (1988) (Hairer & Wanner, Solving ODEs II, IV.2), which damps the oscillation of the step at the stability boundary;
  • H211b (CONTROL_H211B): beta = (1/4, 1/4, 0), alpha2 = 1/4, Söderlind (2003), b = 4;
  • PI.4.2 (CONTROL_PI42): beta = (3/5, -1/5, 0), Söderlind (2003);
  • custom (CONTROL_CUSTOM): the caller's beta and alpha.

Before a filter has its earlier errors and ratios, the missing ones count as 1 (an error at the tolerance, an unchanged step). An error of 0 is replaced by tiny(1._R_P)**(1/2): the ratio is then fac_max.

The starting step (Hairer, Nørsett & Wanner, Solving ODEs I, II.4, after Gladwell, Shampine & Brankin 1987), from three norms the caller reduces (stepper%initial_step_norms and initial_step_difference give their parts), all scaled by atol + rtol |q^0|: d0 = ||q^0||, d1 = ||F(t^0, q^0)||, d2 = ||F(t^0 + h0, q^0 + h0 F^0) - F^0|| / h0. initial_probe(d0, d1) gives the probe's step h0 = 0.01 d0/d1 (1e-6 when d0 or d1 is below 1e-5); initial_step(h0, d1, d2) the first step min(100 h0, (0.01/max(d1, d2))^(1/k)) (max(1e-6, 1e-3 h0) when both are below 1e-15), within [dt_min, dt_max]. The history keeps an error below 1e-4 as 1e-4 (Hairer's DOPRI5 does the same): a step whose error vanished must not make a PI or PI.4.2 controller, whose e_{n-1} has a positive exponent, shrink the next.

Source: src/lib/selah_step_control.F90

Dependencies

Contents ​

Variables ​

NameTypeAttributesDescription
CONTROL_NAME_LENinteger(kind=I4P)parameterLength of a controller's name.
CONTROL_ELEMENTARYcharacter(len=*)parameterThe elementary (I) controller.
CONTROL_PIcharacter(len=*)parameterGustafsson, Lundh & Söderlind's PI controller.
CONTROL_H211Bcharacter(len=*)parameterSöderlind's H211b filter (b = 4).
CONTROL_PI42character(len=*)parameterSöderlind's PI.4.2 filter.
CONTROL_CUSTOMcharacter(len=*)parameterThe caller's beta and alpha.
CONTROLLERScharacter(len=CONTROL_NAME_LEN)parameterEvery controller.

Derived Types ​

step_controller ​

Step-size controller of an embedded pair: the filter, its limits and its history.

Components

NameTypeAttributesDescription
namecharacter(len=CONTROL_NAME_LEN)The controller (CONTROL_*).
kreal(kind=R_P)Power of dt in the error estimate, p_hat + 1.
betareal(kind=R_P)Exponents of e_n, e_{n-1}, e_{n-2} (times 1/k).
alphareal(kind=R_P)Exponents of rho_{n-1}, rho_{n-2}.
safetyreal(kind=R_P)Safety factor.
fac_minreal(kind=R_P)Smallest ratio of two steps.
fac_maxreal(kind=R_P)Largest ratio of two steps.
dt_minreal(kind=R_P)Smallest step.
dt_maxreal(kind=R_P)Largest step.
ereal(kind=R_P)e_{n-1}, e_{n-2}: earlier accepted errors.
dt_oldreal(kind=R_P)Delta t_{n-1}, Delta t_{n-2}: earlier accepted steps.
after_rejectlogicalThe last step was rejected.
stalledlogicalA rejection asked for a step below dt_min.
acceptedinteger(kind=I4P)Accepted steps.
rejectedinteger(kind=I4P)Rejected steps.

Type-Bound Procedures

NameAttributesDescription
initializepass(self)Choose the controller, the order and the limits.
proposepass(self)Accept or reject a step, and propose the next one.
resetpass(self)Forget the history (a restart, a discontinuity).
initial_probepass(self)The probe's step of the starting-step rule.
initial_steppass(self)The first step of the starting-step rule.

step_controller%initialize ​

Choose the controller, the order and the limits; the history is reset. Unknown names stop with an error.

fortran
subroutine initialize(self, name, embedded_order, safety, fac_min, fac_max, dt_min, dt_max, beta, alpha)

Arguments

NameTypeIntentAttributesDescription
selfclass(step_controller)inoutThe controller.
namecharacter(len=*)inCONTROL_*.
embedded_orderinteger(kind=I4P)inp_hat: min(bt%order, bt%embedded_order).
safetyreal(kind=R_P)inoptionalSafety factor (default 0.9).
fac_minreal(kind=R_P)inoptionalSmallest ratio of two steps (default 0.2).
fac_maxreal(kind=R_P)inoptionalLargest ratio of two steps (default 5).
dt_minreal(kind=R_P)inoptionalSmallest step (default 0).
dt_maxreal(kind=R_P)inoptionalLargest step (default huge).
betareal(kind=R_P)inoptionalCONTROL_CUSTOM: beta_1, beta_2, beta_3.
alphareal(kind=R_P)inoptional

Call graph

step_controller%propose ​

The step dt just tried had the scaled error err (accepted when err <= 1): say whether it is accepted, and give the step to try next (the step to redo it with, after a rejection). An accepted step updates the history.

fortran
subroutine propose(self, dt, err, dt_next, accept)

Arguments

NameTypeIntentAttributesDescription
selfclass(step_controller)inoutThe controller.
dtreal(kind=R_P)inThe step just tried.
errreal(kind=R_P)inIts scaled error norm.
dt_nextreal(kind=R_P)outThe step to try next.
acceptlogicaloutThe step is accepted.

step_controller%reset ​

Forget the history: the next accepted step uses the controller as at the start (a restart, a discontinuity, a change of dt the controller did not propose). The counters are kept.

Attributes: elemental

fortran
subroutine reset(self)

Arguments

NameTypeIntentAttributesDescription
selfclass(step_controller)inoutThe controller.

step_controller%initial_probe ​

The probe's step of the starting-step rule: 0.01 d0/d1, or 1e-6 when d0 or d1 is below 1e-5 (d0 = ||q^0||, d1 = ||F^0||, scaled by atol + rtol |q^0|).

Attributes: pure

Returns: real(kind=R_P)

fortran
function initial_probe(self, d0, d1) result(h0)

Arguments

NameTypeIntentAttributesDescription
selfclass(step_controller)inThe controller.
d0real(kind=R_P)in||q^0||.
d1real(kind=R_P)in||F(t^0, q^0)||.

step_controller%initial_step ​

The first step of the starting-step rule: min(100 h0, (0.01/max(d1, d2))^(1/k)), or max(1e-6, 1e-3 h0) when d1 and d2 are below 1e-15 (d2 = ||F(t^0 + h0, q^0 + h0 F^0) - F^0|| / h0), within [dt_min, dt_max].

Attributes: pure

Returns: real(kind=R_P)

fortran
function initial_step(self, h0, d1, d2) result(dt)

Arguments

NameTypeIntentAttributesDescription
selfclass(step_controller)inThe controller.
h0real(kind=R_P)inThe probe's step.
d1real(kind=R_P)in||F(t^0, q^0)||.
d2real(kind=R_P)in||F(t^0 + h0, q^0 + h0 F^0) - F^0|| / h0.

Functions ​

dop853_error ​

The error norm of the Dormand–Prince 8(5,3) pair (dopri-853) from the sums of squares of its two estimates, the fifth-order one (esum, step_error) and the third-order one (esum2, step_error(second=.true.)), each already reduced over the boxes and ranks: err = esum / sqrt(ncells (esum + 0.01 esum2)), the combination of Hairer's DOP853 code (Hairer, Nørsett & Wanner, Solving ODEs I), 1 at the tolerance. The 1e-2 weight lets the third-order estimate guard the fifth-order one where that is accidentally small; when both sums are 0 the error is 0.

Attributes: elemental

Returns: real(kind=R_P)

fortran
function dop853_error(esum, esum2, ncells) result(err)

Arguments

NameTypeIntentAttributesDescription
esumreal(kind=R_P)inSum of the squared scaled errors of the fifth-order estimate.
esum2real(kind=R_P)inThe same of the third-order estimate.
ncellsinteger(kind=I8P)inCells the sums run over.