Skip to content

selah_newton_krylov ​

SELAH, L1: matrix-free Newton–GMRES for an implicit stage whose stiff part couples the cells.

The implicit stage solves F(U) = U - E - gamma R(U) = 0. When the stiff part of R couples the cells (diffusion, a pressure), its Jacobian is a sparse operator SELAH never sees: Newton's step J d = -F is solved by restarted GMRES (Saad & Schultz 1986) on products J z = z - gamma (R(U + eps z) - R(U)) / eps, one residual of the caller's per Krylov iteration (Knoll & Keyes 2004, eps = sqrt(eps_mach) (1 + ||U||) / ||z||). Each GMRES cycle of at most m iterations (m <= 16) is one Newton step: then the true F at the new iterate is evaluated, and a cycle stops early when its residual estimate is below forcing times ||F||. On a linear R this is restarted GMRES itself.

The orthogonalisation is classical Gram–Schmidt, the j + 1 inner products of the new vector w with the basis and w.w one fused reduction per iteration; the new vector's norm follows from Pythagoras, and when it kept less than a tenth of ||w|| (where Pythagoras loses two digits) a second pass, one more reduction, reorthogonalises it. A right preconditioner M is the caller's: GMRES solves J M^{-1} y = -F, and d = M^{-1} V y.

newton_krylov is driven by its caller inside the implicit stage (reverse communication, D1 of #11): start takes the stage's views (E, the iterate U: the stage state, the stage's residual register); then, while request() is not NK_DONE, the caller does what it asks and calls advance:

  • NK_RESIDUAL: R at state_view() into residual_view() (the stage state and register, or the perturbed state and the solver's own register);
  • NK_REDUCE: sum sums(1:nsums) over the boxes and ranks (nothing to do with one box on one rank);
  • NK_PRECONDITION: precondition_out() = M^{-1} precondition_in() (asked only with preconditioned=.true.).

At NK_DONE ||F(U)|| <= atol + rtol ||U|| (2-norms over the field): the stage state is U, the stage's register R(U), and the stepper's update E + gamma R(U) returns U. Its registers (m + 4 of the field's size, on the device in a device build) are allocated at the first start, from the field's bounds.

Source: src/lib/selah_newton_krylov.F90

Dependencies

Contents ​

Variables ​

NameTypeAttributesDescription
NK_MAX_RESTARTinteger(kind=I4P)parameterThe longest GMRES cycle m.
NK_DONEinteger(kind=I4P)parameterConverged.
NK_RESIDUALinteger(kind=I4P)parameterEvaluate R at state_view() into residual_view().
NK_REDUCEinteger(kind=I4P)parameterSum sums(1:nsums) over the boxes and ranks.
NK_PRECONDITIONinteger(kind=I4P)parameterprecondition_out() = M^{-1} precondition_in().

Derived Types ​

newton_krylov ​

Matrix-free Newton–GMRES on U = E + gamma R(U).

Components

NameTypeAttributesDescription
minteger(kind=I4P)GMRES cycle (restart) length.
atolreal(kind=R_P)Absolute tolerance on ||F||.
rtolreal(kind=R_P)Relative tolerance, of ||U||.
forcingreal(kind=R_P)A cycle stops at forcing ||F||.
preconditionedlogicalThe caller applies M^{-1}.
max_newtoninteger(kind=I4P)Newton steps (cycles) allowed.
newtoninteger(kind=I4P)Newton steps of this solve.
krylovinteger(kind=I4P)Krylov iterations of this solve.
reductionsinteger(kind=I4P)Reductions asked in the Krylov iterations.
reorthogonalisationsinteger(kind=I4P)Second Gram–Schmidt passes.
residualsinteger(kind=I4P)Residuals asked.
sumsreal(kind=R_P)The partial sums to reduce.
nsumsinteger(kind=I4P)How many.
reqinteger(kind=I4P)The pending request.
stateinteger(kind=I4P)What the pending request is for.
jinteger(kind=I4P)The Krylov iteration within the cycle.
gamreal(kind=R_P)gamma.
betareal(kind=R_P)||F|| at the cycle's start.
ynormreal(kind=R_P)||U||.
epsreal(kind=R_P)The difference quotient's step.
wwreal(kind=R_P)w.w of the current iteration.
hreal(kind=R_P)Hessenberg matrix, rotated.
greal(kind=R_P)The rotated right-hand side.
csreal(kind=R_P)Givens rotations.
snreal(kind=R_P)Givens rotations.
coef_dreal(kind=R_P)pointerCoefficients for the device kernels.
regsreal(kind=R_P)pointerV(1 .. m + 1), Z, U + eps z, R(U + eps z).
lbrinteger(kind=I4P)The registers' bounds.
ubrinteger(kind=I4P)The registers' bounds.
ereal(kind=R_P)pointerE (the stage's).
yreal(kind=R_P)pointerU (the stage state).
rreal(kind=R_P)pointerR(U) (the stage's register).

Type-Bound Procedures

NameAttributesDescription
initializepass(self)Cycle length, tolerances, preconditioning.
destroypass(self)Free the registers.
startpass(self)A new solve in the stage.
requestpass(self)The pending request.
advancepass(self)The request done: on to the next.
state_viewpass(self)Where R is evaluated (NK_RESIDUAL).
residual_viewpass(self)Where R is written (NK_RESIDUAL).
precondition_inpass(self)M^{-1}'s argument (NK_PRECONDITION).
precondition_outpass(self)M^{-1}'s result (NK_PRECONDITION).

newton_krylov%initialize ​

GMRES cycle m (1 .. NK_MAX_RESTART, default 16); tolerances (defaults: atol 0, rtol 1e-10, forcing 1e-4); preconditioned (default .false.); Newton steps allowed (default 50).

fortran
subroutine initialize(self, m, atol, rtol, forcing, preconditioned, max_newton)

Arguments

NameTypeIntentAttributesDescription
selfclass(newton_krylov)inoutSolver.
minteger(kind=I4P)inoptionalCycle length.
atolreal(kind=R_P)inoptionalTolerances on ||F||.
rtolreal(kind=R_P)inoptionalTolerances on ||F||.
forcingreal(kind=R_P)inoptionalA cycle's relative tolerance.
preconditionedlogicalinoptionalThe caller applies M^{-1}.
max_newtoninteger(kind=I4P)inoptionalNewton steps allowed.

Call graph

newton_krylov%destroy ​

Free the registers.

fortran
subroutine destroy(self)

Arguments

NameTypeIntentAttributesDescription
selfclass(newton_krylov)inoutSolver.

newton_krylov%start ​

A new solve of U = e + gam R(U) from the iterate in y (the stage state), r the stage's residual register: the first request is R(U) into r.

fortran
subroutine start(self, gam, e, y, r)

Arguments

NameTypeIntentAttributesDescription
selfclass(newton_krylov)inoutSolver.
gamreal(kind=R_P)ingamma = dt stage_gamma(k).
ereal(kind=R_P)inpointerE (the stepper's view, its bounds).
yreal(kind=R_P)inpointerU.
rreal(kind=R_P)inpointerR(U).

newton_krylov%request ​

The pending request: NK_RESIDUAL, NK_REDUCE, NK_PRECONDITION or NK_DONE.

Attributes: pure

Returns: integer(kind=I4P)

fortran
function request(self) result(req)

Arguments

NameTypeIntentAttributesDescription
selfclass(newton_krylov)inSolver.

newton_krylov%advance ​

The pending request done (by the caller): the solver's next step, up to its next request.

fortran
subroutine advance(self, bx)

Arguments

NameTypeIntentAttributesDescription
selfclass(newton_krylov)inoutSolver.
bxtype(box)inBox.

Call graph

newton_krylov%state_view ​

Where NK_RESIDUAL evaluates R: the iterate U (the stage state) or the perturbed state U + eps z.

Returns: real(kind=R_P)

fortran
function state_view(self) result(u)

Arguments

NameTypeIntentAttributesDescription
selfclass(newton_krylov)intargetSolver.

newton_krylov%residual_view ​

Where NK_RESIDUAL writes R: the stage's register, or the solver's own for the perturbed state.

Returns: real(kind=R_P)

fortran
function residual_view(self) result(u)

Arguments

NameTypeIntentAttributesDescription
selfclass(newton_krylov)intargetSolver.

newton_krylov%precondition_in ​

M^{-1}'s argument: the basis vector v_j, or the cycle's combination V y.

Returns: real(kind=R_P)

fortran
function precondition_in(self) result(u)

Arguments

NameTypeIntentAttributesDescription
selfclass(newton_krylov)intargetSolver.

newton_krylov%precondition_out ​

M^{-1}'s result: the register Z.

Returns: real(kind=R_P)

fortran
function precondition_out(self) result(u)

Arguments

NameTypeIntentAttributesDescription
selfclass(newton_krylov)intargetSolver.