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
| Name | Type | Attributes | Description |
|---|---|---|---|
CONTROL_NAME_LEN | integer(kind=I4P) | parameter | Length of a controller's name. |
CONTROL_ELEMENTARY | character(len=*) | parameter | The elementary (I) controller. |
CONTROL_PI | character(len=*) | parameter | Gustafsson, Lundh & Söderlind's PI controller. |
CONTROL_H211B | character(len=*) | parameter | Söderlind's H211b filter (b = 4). |
CONTROL_PI42 | character(len=*) | parameter | Söderlind's PI.4.2 filter. |
CONTROL_CUSTOM | character(len=*) | parameter | The caller's beta and alpha. |
CONTROLLERS | character(len=CONTROL_NAME_LEN) | parameter | Every controller. |
Derived Types
step_controller
Step-size controller of an embedded pair: the filter, its limits and its history.
Components
| Name | Type | Attributes | Description |
|---|---|---|---|
name | character(len=CONTROL_NAME_LEN) | The controller (CONTROL_*). | |
k | real(kind=R_P) | Power of dt in the error estimate, p_hat + 1. | |
beta | real(kind=R_P) | Exponents of e_n, e_{n-1}, e_{n-2} (times 1/k). | |
alpha | real(kind=R_P) | Exponents of rho_{n-1}, rho_{n-2}. | |
safety | real(kind=R_P) | Safety factor. | |
fac_min | real(kind=R_P) | Smallest ratio of two steps. | |
fac_max | real(kind=R_P) | Largest ratio of two steps. | |
dt_min | real(kind=R_P) | Smallest step. | |
dt_max | real(kind=R_P) | Largest step. | |
e | real(kind=R_P) | e_{n-1}, e_{n-2}: earlier accepted errors. | |
dt_old | real(kind=R_P) | Delta t_{n-1}, Delta t_{n-2}: earlier accepted steps. | |
after_reject | logical | The last step was rejected. | |
stalled | logical | A rejection asked for a step below dt_min. | |
accepted | integer(kind=I4P) | Accepted steps. | |
rejected | integer(kind=I4P) | Rejected steps. |
Type-Bound Procedures
| Name | Attributes | Description |
|---|---|---|
initialize | pass(self) | Choose the controller, the order and the limits. |
propose | pass(self) | Accept or reject a step, and propose the next one. |
reset | pass(self) | Forget the history (a restart, a discontinuity). |
initial_probe | pass(self) | The probe's step of the starting-step rule. |
initial_step | pass(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.
subroutine initialize(self, name, embedded_order, safety, fac_min, fac_max, dt_min, dt_max, beta, alpha)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(step_controller) | inout | The controller. | |
name | character(len=*) | in | CONTROL_*. | |
embedded_order | integer(kind=I4P) | in | p_hat: min(bt%order, bt%embedded_order). | |
safety | real(kind=R_P) | in | optional | Safety factor (default 0.9). |
fac_min | real(kind=R_P) | in | optional | Smallest ratio of two steps (default 0.2). |
fac_max | real(kind=R_P) | in | optional | Largest ratio of two steps (default 5). |
dt_min | real(kind=R_P) | in | optional | Smallest step (default 0). |
dt_max | real(kind=R_P) | in | optional | Largest step (default huge). |
beta | real(kind=R_P) | in | optional | CONTROL_CUSTOM: beta_1, beta_2, beta_3. |
alpha | real(kind=R_P) | in | optional |
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.
subroutine propose(self, dt, err, dt_next, accept)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(step_controller) | inout | The controller. | |
dt | real(kind=R_P) | in | The step just tried. | |
err | real(kind=R_P) | in | Its scaled error norm. | |
dt_next | real(kind=R_P) | out | The step to try next. | |
accept | logical | out | The 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
subroutine reset(self)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(step_controller) | inout | The 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)
function initial_probe(self, d0, d1) result(h0)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(step_controller) | in | The controller. | |
d0 | real(kind=R_P) | in | ||q^0||. | |
d1 | real(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)
function initial_step(self, h0, d1, d2) result(dt)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(step_controller) | in | The controller. | |
h0 | real(kind=R_P) | in | The probe's step. | |
d1 | real(kind=R_P) | in | ||F(t^0, q^0)||. | |
d2 | real(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)
function dop853_error(esum, esum2, ncells) result(err)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
esum | real(kind=R_P) | in | Sum of the squared scaled errors of the fifth-order estimate. | |
esum2 | real(kind=R_P) | in | The same of the third-order estimate. | |
ncells | integer(kind=I8P) | in | Cells the sums run over. |