selah_nystrom
SELAH, L2: the Nystrom form, Runge-Kutta-Nystrom schemes for second-order systems y'' = f(t, y).
A second-order system y'' = f(t, y) whose force does not depend on y' (decision D6 of #11: a wave equation, the forces of an N-body or a molecular-dynamics system) needs no stage for the velocity. A Runge-Kutta-Nystrom (RKN) scheme of s stages advances the position q and the velocity p together:
Y_k = q + c_k h p + h^2 sum_{j<k} abar_kj F_j, F_k = f(t + c_k h, Y_k),
q <- q + h p + h^2 sum_k bbar_k F_k, p <- p + h sum_k b_k F_k.
nystrom_stepper runs it with the stepper's stage contract (the caller evaluates F at stage_state() into rhs_register() for each stage, as the forms of stepper): s + 1 registers of the field's size (the stage state and the s forces), the stage state and the update each one kernel. The catalogue (NYSTROM_SCHEMES): rkn-4, Nystrom's method of order 4 in 3 stages (as Hairer, Norsett & Wanner I, II.14, give it); rkn-64, Dormand, El-Mikkawy & Prince's RKN6(4)6FM (1987), 6 stages, an embedded pair of order 4; rkn-1210, their RKN12(10)17M (1987), 17 stages, an embedded pair of order 10. notes/nystrom-check.py checks every order condition of each, tree by tree in 60 digits (notes/methods/rkn/, a JSON file per scheme: its coefficients and their sources). step_error estimates the embedded pair's error of the position and the velocity.
Stormer and Cowell (stormer_stepper): the k-step schemes y_{n+1} - 2 y_n + y_{n-1} = h^2 sum_j w_j f_{n-j} (stormer-k, explicit, order k; k = 1 is Verlet's, order 2 by symmetry) and h^2 sum_j w_j f_{n+1-j} (cowell-k, implicit, order k + 1; k = 2 is Numerov's, order 4 by symmetry), k = 1 .. 16 at a constant step (stormer_weights: the weights, exact rationals by notes/stormer-check.py, 40 digits). The history, y_{n-1} and the forces f_{n-1} .. f_{n-k+1}, is the caller's (history(level), then resume); a step evaluates f_n at q (stage 1) into the ring of forces; a Cowell step's implicit stage, y = E + gamma f(y), gamma = h^2 w_0, is a fixed-point stage (stage_gamma, explicit_part: a solver of the caller's in stage 2, as for the implicit multistep schemes).
Fields of rank 5 (lower ranks through their rank-5 view); every array device resident in a device build.
Source: src/lib/selah_nystrom.F90
Dependencies
Contents
Variables
| Name | Type | Attributes | Description |
|---|---|---|---|
NYSTROM_SCHEMES | character(len=*) | parameter | The catalogue. |
STORMER_MAX_STEPS | integer(kind=I4P) | parameter | Stormer and Cowell schemes: k = 1 .. 16. |
Derived Types
nystrom_tableau
A Runge-Kutta-Nystrom scheme for y'' = f(t, y).
Components
| Name | Type | Attributes | Description |
|---|---|---|---|
s | integer(kind=I4P) | Stages (0: unknown name). | |
order | integer(kind=I4P) | Order (position and velocity). | |
embedded_order | integer(kind=I4P) | The embedded pair's order (0: none). | |
c | real(kind=R_P) | allocatable | Abscissae. |
abar | real(kind=R_P) | allocatable | The stages' weights of the forces (strictly lower). |
bbar | real(kind=R_P) | allocatable | The position's weights. |
b | real(kind=R_P) | allocatable | The velocity's weights. |
bbar_hat | real(kind=R_P) | allocatable | The embedded position's weights. |
b_hat | real(kind=R_P) | allocatable | The embedded velocity's weights. |
nystrom_stepper
A Runge-Kutta-Nystrom scheme driven stage by stage.
Components
| Name | Type | Attributes | Description |
|---|---|---|---|
nt | type(nystrom_tableau) | The scheme. | |
regs | real(kind=R_P) | pointer | The stage state, then the s forces. |
at_d | real(kind=R_P) | pointer | abar transposed (column k: stage k's row), device. |
w_d | real(kind=R_P) | pointer | bbar, b, bbar - bbar_hat, b - b_hat (columns), device. |
lb | integer(kind=I4P) | The field's bounds. | |
ub | integer(kind=I4P) | The field's bounds. | |
k_active | integer(kind=I4P) | The active stage. |
Type-Bound Procedures
| Name | Attributes | Description |
|---|---|---|
initialize | pass(self) | The scheme and the field's bounds. |
destroy | pass(self) | Free the registers. |
stages | pass(self) | Stages per step. |
begin_step | pass(self) | A step begins. |
begin_stage | pass(self) | Stage k's state. |
end_stage | pass(self) | Stage k done. |
finish_step | pass(self) | The update of q and p. |
step_error | pass(self) | The embedded pair's error estimate. |
stage_state | pass(self) | The active stage's state (rank-5 view). |
rhs_register | pass(self) | Where the caller writes the active stage's force. |
stage_time | pass(self) | c_k. |
nystrom_stepper%initialize
The scheme (NYSTROM_SCHEMES) and the field's bounds (rank 5, ghosts included): s + 1 registers.
subroutine initialize(self, scheme, lb, ub)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(nystrom_stepper) | inout | Stepper. | |
scheme | character(len=*) | in | Scheme name. | |
lb | integer(kind=I4P) | in | Lower bounds. | |
ub | integer(kind=I4P) | in | Upper bounds. |
Call graph
nystrom_stepper%destroy
Free the registers.
subroutine destroy(self)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(nystrom_stepper) | inout | Stepper. |
nystrom_stepper%stages
Stages (force evaluations) per step.
Attributes: pure
Returns: integer(kind=I4P)
function stages(self) result(s)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(nystrom_stepper) | in | Stepper. |
nystrom_stepper%begin_step
A step begins (stage 1 next).
subroutine begin_step(self)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(nystrom_stepper) | inout | Stepper. |
nystrom_stepper%begin_stage
Stage k's state, Y_k = q + c_k h p + h^2 sum_{j<k} abar_kj F_j, into the stage-state register.
subroutine begin_stage(self, k, bx, h, q, p)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(nystrom_stepper) | inout | Stepper. | |
k | integer(kind=I4P) | in | Stage. | |
bx | type(box) | in | Box. | |
h | real(kind=R_P) | in | Step. | |
q | real(kind=R_P) | in | Position. | |
p | real(kind=R_P) | in | Velocity. |
Call graph
nystrom_stepper%end_stage
Stage k done (its force written).
subroutine end_stage(self, k)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(nystrom_stepper) | inout | Stepper. | |
k | integer(kind=I4P) | in | Stage. |
nystrom_stepper%finish_step
q <- q + h p + h^2 sum bbar_k F_k, p <- p + h sum b_k F_k, after the last stage.
subroutine finish_step(self, bx, h, q, p)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(nystrom_stepper) | inout | Stepper. | |
bx | type(box) | in | Box. | |
h | real(kind=R_P) | in | Step. | |
q | real(kind=R_P) | inout | Position. | |
p | real(kind=R_P) | inout | Velocity. |
Call graph
nystrom_stepper%step_error
After the last stage, before finish_step: the embedded pair's error of the position, h^2 sum (bbar - bbar_hat)_k F_k, and of the velocity, h sum (b - b_hat)_k F_k, each scaled by atol + rtol |its value| (q^n, p^n): the largest, the sum of the squares and the values counted (both quantities), for the caller to reduce.
subroutine step_error(self, bx, h, q, p, atol, rtol, emax, esum, ncells)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(nystrom_stepper) | inout | Stepper. | |
bx | type(box) | in | Box. | |
h | real(kind=R_P) | in | Step. | |
q | real(kind=R_P) | in | Position. | |
p | real(kind=R_P) | in | Velocity. | |
atol | real(kind=R_P) | in | Tolerances. | |
rtol | real(kind=R_P) | in | Tolerances. | |
emax | real(kind=R_P) | out | Largest scaled error, sum of the squares. | |
esum | real(kind=R_P) | out | Largest scaled error, sum of the squares. | |
ncells | integer(kind=I8P) | out | Values counted. |
Call graph
nystrom_stepper%stage_state
The active stage's state, with the field's bounds.
Returns: real(kind=R_P)
function stage_state(self) result(u)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(nystrom_stepper) | in | Stepper. |
nystrom_stepper%rhs_register
Where the caller writes the active stage's force, with the field's bounds.
Returns: real(kind=R_P)
function rhs_register(self) result(r)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(nystrom_stepper) | in | Stepper. |
nystrom_stepper%stage_time
Stage k's time, as a fraction of the step (c_k).
Attributes: pure
Returns: real(kind=R_P)
function stage_time(self, k) result(c)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(nystrom_stepper) | in | Stepper. | |
k | integer(kind=I4P) | in | Stage. |
stormer_stepper
A Stormer (explicit) or Cowell (implicit) k-step scheme for y'' = f(t, y), driven stage by stage.
Components
| Name | Type | Attributes | Description |
|---|---|---|---|
name | character(len=16) | stormer-k or cowell-k. | |
implicit | logical | Cowell. | |
k | integer(kind=I4P) | Steps. | |
order | integer(kind=I4P) | Order. | |
m | integer(kind=I4P) | Stages per step (Stormer 1; Cowell 2 or more). | |
w | real(kind=R_P) | allocatable | The weights, w(0:k-1) (Stormer) or w(0:k) (Cowell). |
coef_d | real(kind=R_P) | pointer | The weights by ring slot (device). |
regs | real(kind=R_P) | pointer | y_{n-1}, the k forces (a ring), the state, E, R. |
head | integer(kind=I4P) | The ring slot of f_n (1 .. k). | |
lb | integer(kind=I4P) | The field's bounds. | |
ub | integer(kind=I4P) | The field's bounds. | |
k_active | integer(kind=I4P) | The active stage. | |
ready | logical | The history is written (resume). |
Type-Bound Procedures
| Name | Attributes | Description |
|---|---|---|
initialize | pass(self) | The scheme, the field's bounds, the stages. |
destroy | pass(self) | Free the registers. |
stages | pass(self) | Stages per step. |
history | pass(self) | A history level: 0 y_{n-1}, j f_{n-j}. |
resume | pass(self) | The history is written. |
begin_step | pass(self) | A step begins. |
begin_stage | pass(self) | Stage k's state. |
stage_state_is_q | pass(self) | Stage 1's state is q itself. |
stage_state | pass(self) | The active stage's state (stages >= 2). |
rhs_register | pass(self) | Where the caller writes the stage's force. |
stage_gamma | pass(self) | Cowell: w_0 for the stages >= 2. |
explicit_part | pass(self) | Cowell: E (begin_stage(2) to finish_step). |
end_stage | pass(self) | Stage k done. |
finish_step | pass(self) | The new q; y_{n-1} and the ring advance. |
stormer_stepper%initialize
stormer-k or cowell-k, the field's bounds (rank 5), the stages (Cowell: default 2, the fixed point's).
subroutine s_initialize(self, scheme, lb, ub, stages)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stormer_stepper) | inout | Stepper. | |
scheme | character(len=*) | in | Scheme name. | |
lb | integer(kind=I4P) | in | Lower bounds. | |
ub | integer(kind=I4P) | in | Upper bounds. | |
stages | integer(kind=I4P) | in | optional | Stages per step (Cowell, >= 2). |
Call graph
stormer_stepper%destroy
Free the registers.
subroutine s_destroy(self)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stormer_stepper) | inout | Stepper. |
stormer_stepper%stages
Stages per step.
Attributes: pure
Returns: integer(kind=I4P)
function s_stages(self) result(s)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stormer_stepper) | in | Stepper. |
stormer_stepper%history
A history level, with the field's bounds: 0, y_{n-1}; j = 1 .. k - 1, f_{n-j}. Written by the caller before the first step (then resume); afterwards the scheme's own.
Returns: real(kind=R_P)
function s_history(self, level) result(h)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stormer_stepper) | in | Stepper. | |
level | integer(kind=I4P) | in | Level. |
Call graph
stormer_stepper%resume
The history is written: steps may begin.
subroutine s_resume(self)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stormer_stepper) | inout | Stepper. |
stormer_stepper%begin_step
A step begins (stage 1, on q, next).
subroutine s_begin_step(self)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stormer_stepper) | inout | Stepper. |
stormer_stepper%begin_stage
Stage k: 1, on q (its force f_n into the ring); Cowell k = 2, E = 2 q - y_{n-1} + h^2 sum_{j>=1} w_j f_{n+1-j} and the first iterate E + gamma f_n; k > 2, E + gamma R(the previous state), in place.
subroutine s_begin_stage(self, k, bx, h, q)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stormer_stepper) | inout | Stepper. | |
k | integer(kind=I4P) | in | Stage. | |
bx | type(box) | in | Box. | |
h | real(kind=R_P) | in | Step. | |
q | real(kind=R_P) | inout | Solution, y_n. |
Call graph
stormer_stepper%stage_state_is_q
Stage 1's state is q.
Attributes: pure
Returns: logical
function s_stage_state_is_q(self, k) result(yes)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stormer_stepper) | in | Stepper. | |
k | integer(kind=I4P) | in | Stage. |
stormer_stepper%stage_state
The state of a stage >= 2 (Cowell), with the field's bounds.
Returns: real(kind=R_P)
function s_stage_state(self) result(u)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stormer_stepper) | in | Stepper. |
stormer_stepper%rhs_register
Where the caller writes the active stage's force: stage 1, f_n (the ring's head); later stages, their own.
Returns: real(kind=R_P)
function s_rhs_register(self) result(r)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stormer_stepper) | in | Stepper. |
stormer_stepper%stage_gamma
Cowell: w_0 for the stages >= 2 (the implicit stage is y = E + gamma f(y), gamma = h^2 w_0); 0 otherwise.
Attributes: pure
Returns: real(kind=R_P)
function s_stage_gamma(self, k) result(g)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stormer_stepper) | in | Stepper. | |
k | integer(kind=I4P) | in | Stage. |
stormer_stepper%explicit_part
Cowell: E, from begin_stage(2) to finish_step, with the field's bounds.
Returns: real(kind=R_P)
function s_explicit_part(self) result(e)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stormer_stepper) | in | Stepper. |
stormer_stepper%end_stage
Stage k done.
subroutine s_end_stage(self, k)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stormer_stepper) | inout | Stepper. | |
k | integer(kind=I4P) | in | Stage. |
stormer_stepper%finish_step
old q and the ring advances (f_n becomes f_{n-1}).
subroutine s_finish_step(self, bx, h, q)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(stormer_stepper) | inout | Stepper. | |
bx | type(box) | in | Box. | |
h | real(kind=R_P) | in | Step. | |
q | real(kind=R_P) | inout | Solution. |
Call graph
Subroutines
stormer_weights
The weights of stormer-k (w(0:k-1)) or cowell-k (w(0:k)), k = 1 .. 16, and the order; w unallocated for any other name. Generated by notes/stormer-check.py --fortran (exact rationals, 40 digits).
subroutine stormer_weights(name, w, order)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
name | character(len=*) | in | Scheme name. | |
w | real(kind=R_P) | out | allocatable | Weights. |
order | integer(kind=I4P) | out | Order. |
Functions
nystrom
The scheme of the catalogue named name (nt%s = 0 if unknown).
Returns: type(nystrom_tableau)
function nystrom(name) result(nt)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
name | character(len=*) | in | Scheme name. |
Call graph