Skip to content

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 ​

NameTypeAttributesDescription
NYSTROM_SCHEMEScharacter(len=*)parameterThe catalogue.
STORMER_MAX_STEPSinteger(kind=I4P)parameterStormer and Cowell schemes: k = 1 .. 16.

Derived Types ​

nystrom_tableau ​

A Runge-Kutta-Nystrom scheme for y'' = f(t, y).

Components

NameTypeAttributesDescription
sinteger(kind=I4P)Stages (0: unknown name).
orderinteger(kind=I4P)Order (position and velocity).
embedded_orderinteger(kind=I4P)The embedded pair's order (0: none).
creal(kind=R_P)allocatableAbscissae.
abarreal(kind=R_P)allocatableThe stages' weights of the forces (strictly lower).
bbarreal(kind=R_P)allocatableThe position's weights.
breal(kind=R_P)allocatableThe velocity's weights.
bbar_hatreal(kind=R_P)allocatableThe embedded position's weights.
b_hatreal(kind=R_P)allocatableThe embedded velocity's weights.

nystrom_stepper ​

A Runge-Kutta-Nystrom scheme driven stage by stage.

Components

NameTypeAttributesDescription
nttype(nystrom_tableau)The scheme.
regsreal(kind=R_P)pointerThe stage state, then the s forces.
at_dreal(kind=R_P)pointerabar transposed (column k: stage k's row), device.
w_dreal(kind=R_P)pointerbbar, b, bbar - bbar_hat, b - b_hat (columns), device.
lbinteger(kind=I4P)The field's bounds.
ubinteger(kind=I4P)The field's bounds.
k_activeinteger(kind=I4P)The active stage.

Type-Bound Procedures

NameAttributesDescription
initializepass(self)The scheme and the field's bounds.
destroypass(self)Free the registers.
stagespass(self)Stages per step.
begin_steppass(self)A step begins.
begin_stagepass(self)Stage k's state.
end_stagepass(self)Stage k done.
finish_steppass(self)The update of q and p.
step_errorpass(self)The embedded pair's error estimate.
stage_statepass(self)The active stage's state (rank-5 view).
rhs_registerpass(self)Where the caller writes the active stage's force.
stage_timepass(self)c_k.

nystrom_stepper%initialize ​

The scheme (NYSTROM_SCHEMES) and the field's bounds (rank 5, ghosts included): s + 1 registers.

fortran
subroutine initialize(self, scheme, lb, ub)

Arguments

NameTypeIntentAttributesDescription
selfclass(nystrom_stepper)inoutStepper.
schemecharacter(len=*)inScheme name.
lbinteger(kind=I4P)inLower bounds.
ubinteger(kind=I4P)inUpper bounds.

Call graph

nystrom_stepper%destroy ​

Free the registers.

fortran
subroutine destroy(self)

Arguments

NameTypeIntentAttributesDescription
selfclass(nystrom_stepper)inoutStepper.

nystrom_stepper%stages ​

Stages (force evaluations) per step.

Attributes: pure

Returns: integer(kind=I4P)

fortran
function stages(self) result(s)

Arguments

NameTypeIntentAttributesDescription
selfclass(nystrom_stepper)inStepper.

nystrom_stepper%begin_step ​

A step begins (stage 1 next).

fortran
subroutine begin_step(self)

Arguments

NameTypeIntentAttributesDescription
selfclass(nystrom_stepper)inoutStepper.

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.

fortran
subroutine begin_stage(self, k, bx, h, q, p)

Arguments

NameTypeIntentAttributesDescription
selfclass(nystrom_stepper)inoutStepper.
kinteger(kind=I4P)inStage.
bxtype(box)inBox.
hreal(kind=R_P)inStep.
qreal(kind=R_P)inPosition.
preal(kind=R_P)inVelocity.

Call graph

nystrom_stepper%end_stage ​

Stage k done (its force written).

fortran
subroutine end_stage(self, k)

Arguments

NameTypeIntentAttributesDescription
selfclass(nystrom_stepper)inoutStepper.
kinteger(kind=I4P)inStage.

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.

fortran
subroutine finish_step(self, bx, h, q, p)

Arguments

NameTypeIntentAttributesDescription
selfclass(nystrom_stepper)inoutStepper.
bxtype(box)inBox.
hreal(kind=R_P)inStep.
qreal(kind=R_P)inoutPosition.
preal(kind=R_P)inoutVelocity.

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.

fortran
subroutine step_error(self, bx, h, q, p, atol, rtol, emax, esum, ncells)

Arguments

NameTypeIntentAttributesDescription
selfclass(nystrom_stepper)inoutStepper.
bxtype(box)inBox.
hreal(kind=R_P)inStep.
qreal(kind=R_P)inPosition.
preal(kind=R_P)inVelocity.
atolreal(kind=R_P)inTolerances.
rtolreal(kind=R_P)inTolerances.
emaxreal(kind=R_P)outLargest scaled error, sum of the squares.
esumreal(kind=R_P)outLargest scaled error, sum of the squares.
ncellsinteger(kind=I8P)outValues counted.

Call graph

nystrom_stepper%stage_state ​

The active stage's state, with the field's bounds.

Returns: real(kind=R_P)

fortran
function stage_state(self) result(u)

Arguments

NameTypeIntentAttributesDescription
selfclass(nystrom_stepper)inStepper.

nystrom_stepper%rhs_register ​

Where the caller writes the active stage's force, with the field's bounds.

Returns: real(kind=R_P)

fortran
function rhs_register(self) result(r)

Arguments

NameTypeIntentAttributesDescription
selfclass(nystrom_stepper)inStepper.

nystrom_stepper%stage_time ​

Stage k's time, as a fraction of the step (c_k).

Attributes: pure

Returns: real(kind=R_P)

fortran
function stage_time(self, k) result(c)

Arguments

NameTypeIntentAttributesDescription
selfclass(nystrom_stepper)inStepper.
kinteger(kind=I4P)inStage.

stormer_stepper ​

A Stormer (explicit) or Cowell (implicit) k-step scheme for y'' = f(t, y), driven stage by stage.

Components

NameTypeAttributesDescription
namecharacter(len=16)stormer-k or cowell-k.
implicitlogicalCowell.
kinteger(kind=I4P)Steps.
orderinteger(kind=I4P)Order.
minteger(kind=I4P)Stages per step (Stormer 1; Cowell 2 or more).
wreal(kind=R_P)allocatableThe weights, w(0:k-1) (Stormer) or w(0:k) (Cowell).
coef_dreal(kind=R_P)pointerThe weights by ring slot (device).
regsreal(kind=R_P)pointery_{n-1}, the k forces (a ring), the state, E, R.
headinteger(kind=I4P)The ring slot of f_n (1 .. k).
lbinteger(kind=I4P)The field's bounds.
ubinteger(kind=I4P)The field's bounds.
k_activeinteger(kind=I4P)The active stage.
readylogicalThe history is written (resume).

Type-Bound Procedures

NameAttributesDescription
initializepass(self)The scheme, the field's bounds, the stages.
destroypass(self)Free the registers.
stagespass(self)Stages per step.
historypass(self)A history level: 0 y_{n-1}, j f_{n-j}.
resumepass(self)The history is written.
begin_steppass(self)A step begins.
begin_stagepass(self)Stage k's state.
stage_state_is_qpass(self)Stage 1's state is q itself.
stage_statepass(self)The active stage's state (stages >= 2).
rhs_registerpass(self)Where the caller writes the stage's force.
stage_gammapass(self)Cowell: w_0 for the stages >= 2.
explicit_partpass(self)Cowell: E (begin_stage(2) to finish_step).
end_stagepass(self)Stage k done.
finish_steppass(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).

fortran
subroutine s_initialize(self, scheme, lb, ub, stages)

Arguments

NameTypeIntentAttributesDescription
selfclass(stormer_stepper)inoutStepper.
schemecharacter(len=*)inScheme name.
lbinteger(kind=I4P)inLower bounds.
ubinteger(kind=I4P)inUpper bounds.
stagesinteger(kind=I4P)inoptionalStages per step (Cowell, >= 2).

Call graph

stormer_stepper%destroy ​

Free the registers.

fortran
subroutine s_destroy(self)

Arguments

NameTypeIntentAttributesDescription
selfclass(stormer_stepper)inoutStepper.

stormer_stepper%stages ​

Stages per step.

Attributes: pure

Returns: integer(kind=I4P)

fortran
function s_stages(self) result(s)

Arguments

NameTypeIntentAttributesDescription
selfclass(stormer_stepper)inStepper.

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)

fortran
function s_history(self, level) result(h)

Arguments

NameTypeIntentAttributesDescription
selfclass(stormer_stepper)inStepper.
levelinteger(kind=I4P)inLevel.

Call graph

stormer_stepper%resume ​

The history is written: steps may begin.

fortran
subroutine s_resume(self)

Arguments

NameTypeIntentAttributesDescription
selfclass(stormer_stepper)inoutStepper.

stormer_stepper%begin_step ​

A step begins (stage 1, on q, next).

fortran
subroutine s_begin_step(self)

Arguments

NameTypeIntentAttributesDescription
selfclass(stormer_stepper)inoutStepper.

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.

fortran
subroutine s_begin_stage(self, k, bx, h, q)

Arguments

NameTypeIntentAttributesDescription
selfclass(stormer_stepper)inoutStepper.
kinteger(kind=I4P)inStage.
bxtype(box)inBox.
hreal(kind=R_P)inStep.
qreal(kind=R_P)inoutSolution, y_n.

Call graph

stormer_stepper%stage_state_is_q ​

Stage 1's state is q.

Attributes: pure

Returns: logical

fortran
function s_stage_state_is_q(self, k) result(yes)

Arguments

NameTypeIntentAttributesDescription
selfclass(stormer_stepper)inStepper.
kinteger(kind=I4P)inStage.

stormer_stepper%stage_state ​

The state of a stage >= 2 (Cowell), with the field's bounds.

Returns: real(kind=R_P)

fortran
function s_stage_state(self) result(u)

Arguments

NameTypeIntentAttributesDescription
selfclass(stormer_stepper)inStepper.

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)

fortran
function s_rhs_register(self) result(r)

Arguments

NameTypeIntentAttributesDescription
selfclass(stormer_stepper)inStepper.

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)

fortran
function s_stage_gamma(self, k) result(g)

Arguments

NameTypeIntentAttributesDescription
selfclass(stormer_stepper)inStepper.
kinteger(kind=I4P)inStage.

stormer_stepper%explicit_part ​

Cowell: E, from begin_stage(2) to finish_step, with the field's bounds.

Returns: real(kind=R_P)

fortran
function s_explicit_part(self) result(e)

Arguments

NameTypeIntentAttributesDescription
selfclass(stormer_stepper)inStepper.

stormer_stepper%end_stage ​

Stage k done.

fortran
subroutine s_end_stage(self, k)

Arguments

NameTypeIntentAttributesDescription
selfclass(stormer_stepper)inoutStepper.
kinteger(kind=I4P)inStage.

stormer_stepper%finish_step ​

old q and the ring advances (f_n becomes f_{n-1}).

fortran
subroutine s_finish_step(self, bx, h, q)

Arguments

NameTypeIntentAttributesDescription
selfclass(stormer_stepper)inoutStepper.
bxtype(box)inBox.
hreal(kind=R_P)inStep.
qreal(kind=R_P)inoutSolution.

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).

fortran
subroutine stormer_weights(name, w, order)

Arguments

NameTypeIntentAttributesDescription
namecharacter(len=*)inScheme name.
wreal(kind=R_P)outallocatableWeights.
orderinteger(kind=I4P)outOrder.

Functions ​

nystrom ​

The scheme of the catalogue named name (nt%s = 0 if unknown).

Returns: type(nystrom_tableau)

fortran
function nystrom(name) result(nt)

Arguments

NameTypeIntentAttributesDescription
namecharacter(len=*)inScheme name.

Call graph