JFNK-Hookstep
October 8, 2024 · View on GitHub
Jacobian-Free Newton-Krylov solver with Hookstep-trust-region approach.
This is a solver for systems in the form , where the dimension (length) of the vector can be either large or small. The trust-region approach enlarges the basin of attraction of a solution by automatically adjusting the size of each step in the Newton iteration, while the Hookstep optimises the direction of the step to accelerate convergence.
The method is 'Jacobian-Free' in the sense that the user only need supply a function that evaluates for a given . The user need not supply a Jacobian matrix, despite that the Jacobian appears in the Newton iteration formula. The Newton iteration formula is solved via the GMRES(m) algorithm, the implementation of which may be supplied a preconditioner. (Further details of the method are given below.)
I hope that you will find that the code is simply written, and that it can be bolted on to any existing code that evaluates (a potentially complicated) , for example, where is the result of timestepping \{\bf x}. The template solves for periodic orbits of the Lorenz equations, (dimension of the system + unknown period), while the same code has been used without modification to compute nonlinear equilibria of pipe flow, 10^{6}, via parallel (MPI) simulations.
The JFNK solver and GMRES codes are available in both MATLAB/Fortran90 versions, and are easily integrated with codes developed in other languages: if your code doesn't already, edit it a little so that it loads a state from disk, calculates and saves the result to disk. The MATLAB/Fortran code then only need save to disk, execute your existing code via a terminal/system command, then load the result.
The MATLAB version of this code will run under the free alternative Octave.
Developed as part of www.openpipeflow.org
FURTHER DETAILS ON THE METHOD: See below or at https://doi.org/10.48550/arXiv.1908.06730
CITATION: https://doi.org/10.48550/arXiv.1908.06730 or https://doi.org/10.1016/j.softx.2017.05.003
AUTHOR: Ashley P. Willis, Applied Mathematics, School of Mathematical and Physical Sciences, University of Sheffield. https://www.sheffield.ac.uk/mps/research/fluid-dynamics
THANKS: Rich Kerswell, Predrag Cvitanovi'c (chaosbook.org), John Gibson (channelflow.org), Marc Avila and many others for their generous support in many forms. Developed under EPSRC grants EP/K03636X/1, EP/P000959/1.
Download
With git:
$ git clone https://github.com/apwillis1/JFNK-Hookstep.git
Manually:
- click on 'MATLAB' or 'Fortran90' above,
- click on a code file,
- click on 'Raw',
- Ctrl+S, or use browser option 'Save page as...'
Using the code
Tutorial and Adapting the code for your own use.
Method overview
The codes implement the 'Jacobian-free Newton-Krylov (JFNK) method' for solving where and are -vectors, supplemented with a Hookstep--Trust-region approach.
This is a powerful method that can solve for for a complicated nonlinear . For example, to find an ''equilibrium'' solution or a ''periodic orbit'', let , where is the result of time integration of an initial condition .
Newton-Raphson method
To find the roots of a function in one dimension, given an initial guess , the Newton-Raphson method generates improvements using the iteration , where the dash denotes the derivative. The iteration can be re-expressed as The extension of Newton's method to an -dimensional system is then The Jacobian matrix is evaluated at . In order to apply the update , the linear system needs to be solved for the unknown .
Jacobian-Free Newton method
The Jacobian matrix is usually difficult to evaluate. However, the problem is in the form , which can be solved using the Krylov-subspace method GMRES(m). The GMRES algorithm does not need to know the matrix itself, only the result of multiplying a vector by . For a given starting vector , e.g. , the method seeks solutions for in , but uses Gram-Schmidt orthogonalisation to improve the numerical suitability of this basis set. The set of orthogonalised vectors is called the Krylov-subspace, and m is the maximum number of vectors stored.
Iterations of the GMRES algorithm for the problem involve calculating products of the Jacobian with given , which may be approximated, e.g. for some small value . (Try such that .) The important point is that we do not need to know the Jacobian; only a routine for evaluating is required.
Note that provided that each step of the Newton method, , is essentially in the correct direction, the method is expected to converge. Therefore the tolerance specified in the accuracy of the solution for in each Newton step (calculated via the GMRES method) typically need not be so stringent as the tolerance placed on the Newton method itself for the solution . For example, we might seek a relative error for the Newton solution , but a relative error for the GMRES steps is likely to be sufficient for calculation of the steps .
Hookstep approach
To improve the domain of convergence of the Newton method, it is commonplace to limit the size of the step taken. One approach is simply to take a 'damped' step in the direction of the solution to , i.e. step by , where .
In the hookstep approach, we minimise subject to the condition that the magnitude of the Newton step is limited, where is the size of the 'trust region'
Given the minimisation, the hookstep is expected to produce a better result than a simple damped step of the same size. It is also expected to perform much better in 'valleys', where it produces a bent/hooked step to a point along the valley, rather than jumping from one side of the valley to the other.
The hookstep can be calculated with little extra work to the GMRES method, provided that the size of Krylov-subspace, m, is chosen sufficiently large to solve to the desired accuracy within m GMRES iterations.
For a given , the reduction in error predicted by the minimisation can be compared with the actual reduction in . According to the accuracy of the prediction, the size of the trust region can be adjusted automatically.
Preconditioning
The GMRES implementations can be supplied with a preconditioner routine (see GMRES subroutine), but is unlikely to be necessary when the method is combined with time integration.
Further details
Extended overview https://doi.org/10.48550/arXiv.1908.06730 . See section 4 for a Tutorial and Adapting the code for your own use
Further details on the method at channelflow.org.