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()intoresidual_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 withpreconditioned=.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
| Name | Type | Attributes | Description |
|---|---|---|---|
NK_MAX_RESTART | integer(kind=I4P) | parameter | The longest GMRES cycle m. |
NK_DONE | integer(kind=I4P) | parameter | Converged. |
NK_RESIDUAL | integer(kind=I4P) | parameter | Evaluate R at state_view() into residual_view(). |
NK_REDUCE | integer(kind=I4P) | parameter | Sum sums(1:nsums) over the boxes and ranks. |
NK_PRECONDITION | integer(kind=I4P) | parameter | precondition_out() = M^{-1} precondition_in(). |
Derived Types
newton_krylov
Matrix-free Newton–GMRES on U = E + gamma R(U).
Components
| Name | Type | Attributes | Description |
|---|---|---|---|
m | integer(kind=I4P) | GMRES cycle (restart) length. | |
atol | real(kind=R_P) | Absolute tolerance on ||F||. | |
rtol | real(kind=R_P) | Relative tolerance, of ||U||. | |
forcing | real(kind=R_P) | A cycle stops at forcing ||F||. | |
preconditioned | logical | The caller applies M^{-1}. | |
max_newton | integer(kind=I4P) | Newton steps (cycles) allowed. | |
newton | integer(kind=I4P) | Newton steps of this solve. | |
krylov | integer(kind=I4P) | Krylov iterations of this solve. | |
reductions | integer(kind=I4P) | Reductions asked in the Krylov iterations. | |
reorthogonalisations | integer(kind=I4P) | Second Gram–Schmidt passes. | |
residuals | integer(kind=I4P) | Residuals asked. | |
sums | real(kind=R_P) | The partial sums to reduce. | |
nsums | integer(kind=I4P) | How many. | |
req | integer(kind=I4P) | The pending request. | |
state | integer(kind=I4P) | What the pending request is for. | |
j | integer(kind=I4P) | The Krylov iteration within the cycle. | |
gam | real(kind=R_P) | gamma. | |
beta | real(kind=R_P) | ||F|| at the cycle's start. | |
ynorm | real(kind=R_P) | ||U||. | |
eps | real(kind=R_P) | The difference quotient's step. | |
ww | real(kind=R_P) | w.w of the current iteration. | |
h | real(kind=R_P) | Hessenberg matrix, rotated. | |
g | real(kind=R_P) | The rotated right-hand side. | |
cs | real(kind=R_P) | Givens rotations. | |
sn | real(kind=R_P) | Givens rotations. | |
coef_d | real(kind=R_P) | pointer | Coefficients for the device kernels. |
regs | real(kind=R_P) | pointer | V(1 .. m + 1), Z, U + eps z, R(U + eps z). |
lbr | integer(kind=I4P) | The registers' bounds. | |
ubr | integer(kind=I4P) | The registers' bounds. | |
e | real(kind=R_P) | pointer | E (the stage's). |
y | real(kind=R_P) | pointer | U (the stage state). |
r | real(kind=R_P) | pointer | R(U) (the stage's register). |
Type-Bound Procedures
| Name | Attributes | Description |
|---|---|---|
initialize | pass(self) | Cycle length, tolerances, preconditioning. |
destroy | pass(self) | Free the registers. |
start | pass(self) | A new solve in the stage. |
request | pass(self) | The pending request. |
advance | pass(self) | The request done: on to the next. |
state_view | pass(self) | Where R is evaluated (NK_RESIDUAL). |
residual_view | pass(self) | Where R is written (NK_RESIDUAL). |
precondition_in | pass(self) | M^{-1}'s argument (NK_PRECONDITION). |
precondition_out | pass(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).
subroutine initialize(self, m, atol, rtol, forcing, preconditioned, max_newton)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(newton_krylov) | inout | Solver. | |
m | integer(kind=I4P) | in | optional | Cycle length. |
atol | real(kind=R_P) | in | optional | Tolerances on ||F||. |
rtol | real(kind=R_P) | in | optional | Tolerances on ||F||. |
forcing | real(kind=R_P) | in | optional | A cycle's relative tolerance. |
preconditioned | logical | in | optional | The caller applies M^{-1}. |
max_newton | integer(kind=I4P) | in | optional | Newton steps allowed. |
Call graph
newton_krylov%destroy
Free the registers.
subroutine destroy(self)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(newton_krylov) | inout | Solver. |
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.
subroutine start(self, gam, e, y, r)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(newton_krylov) | inout | Solver. | |
gam | real(kind=R_P) | in | gamma = dt stage_gamma(k). | |
e | real(kind=R_P) | in | pointer | E (the stepper's view, its bounds). |
y | real(kind=R_P) | in | pointer | U. |
r | real(kind=R_P) | in | pointer | R(U). |
newton_krylov%request
The pending request: NK_RESIDUAL, NK_REDUCE, NK_PRECONDITION or NK_DONE.
Attributes: pure
Returns: integer(kind=I4P)
function request(self) result(req)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(newton_krylov) | in | Solver. |
newton_krylov%advance
The pending request done (by the caller): the solver's next step, up to its next request.
subroutine advance(self, bx)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(newton_krylov) | inout | Solver. | |
bx | type(box) | in | Box. |
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)
function state_view(self) result(u)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(newton_krylov) | in | target | Solver. |
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)
function residual_view(self) result(u)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(newton_krylov) | in | target | Solver. |
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)
function precondition_in(self) result(u)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(newton_krylov) | in | target | Solver. |
newton_krylov%precondition_out
M^{-1}'s result: the register Z.
Returns: real(kind=R_P)
function precondition_out(self) result(u)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(newton_krylov) | in | target | Solver. |