Class GenMinRes
- All Implemented Interfaces:
Serializable
GenMinRes implements restarted GMRES to generate an approximate
solution to \( Ax = b \). It is based on GMRES by Homer Walker (1988).
The GMRES method begins with an approximate solution \(x_0\) and an initial residual \(r_0 = b-Ax_0\). At iteration m, a correction \(z_m\) is determined in the Krylov subspace $$ {\kappa}_m (\nu)=\rm{span}(\nu,A\nu,\ldots,A^{m-1}\nu ) $$ \(\nu = r_0 \) which solves the least squares problem $$\min_{z \in \kappa_m(r_0)}{\Vert b-A(x_0 + z) \Vert}_2$$ Then at iteration m, \( x_m = x_0 + z_m \).
There are four distinct GMRES implementations, selectable through method setMethod.
The first Gram-Schmidt implementation is essentially the original algorithm by Saad and Schultz (1986).
The second Gram-Schmidt implementation, developed by Homer Walker and Lou Zhou, is
simpler than the first implementation. The least squares problem is constructed
in upper-triangular form and the residual vector updating at the end of a GMRES
cycle is cheaper. The first Householder implementation is algorithm 2.2 of Walker (1988),
but with more efficient correction accumulation at the end of each GMRES cycle.
The second Householder implementation is algorithm 3.1 of Walker (1988). The products of Householder
transformations are expanded as sums, allowing most work to be formulated as large scale
matrix-vector operations.
The Gram-Schmidt implementations are less expensive than the Householder, the latter requiring about twice as many computations beyond the coefficient matrix/vector products. However, the Householder implementations may be more reliable near the limits of residual reduction. See Walker (1988) for details. Issues such as the cost of coefficient matrix/vector products, availability of effective preconditioners, and features of particular computing environments may serve to mitigate the extra expense of the Householder implementations.
Note that one can use the JAVA Logging API to generate intermediate output for the solver.
Accumulated levels of detail correspond to JAVA's FINE and FINER logging levels with
FINE yielding the smallest amount of information and FINER yielding the most. The levels of output
yield the following:
| Level | Output |
FINE |
A summary report is printed upon completion. |
FINER |
Lines of intermediate results giving the most important data for each step are printed after each step. A summary report is printed upon completion. |
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDeprecated.static interfacePublic interface for the user supplied function toGenMinRes.static interfacePublic interface for the user supplied function to theGenMinResobject used for the norm \( \Vert X \Vert \) when the Gram-Schmidt implementation is used.static interfacePublic interface for the user supplied function toGenMinResused for preconditioning.static classMaximum number of iterations exceeded.static interfacePublic interface for the user supplied function to theGenMinResobject used for the inner product when the Gram-Schmidt implementation is used. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intIndicates residual updating is to be done by direct evaluation upon restarting and at termination.static final intIndicates residual updating is to be done by direct evaluation upon restarting only.static final intIndicates the first Gram-Schmidt implementation method is to be used.static final intIndicates the first Householder implementation method is to be used.static final intIndicates residual updating is to be done by linear combination upon restarting and at termination.static final intIndicates residual updating is to be done by linear combination upon restarting only.static final intIndicates the second Gram-Schmidt implementation method is to be used.static final intIndicates the second Householder implementation method is to be used. -
Constructor Summary
ConstructorsConstructorDescriptionGenMinRes(int n, GenMinRes.Function argF) GMRES linear system solver constructor. -
Method Summary
Modifier and TypeMethodDescriptiondouble[]getGuess()Returns the initial guess of the solution.intReturns the actual number of GMRES iterations used.Returns the logger object.intReturns the maximum number of iterations allowed.intReturns the maximum Krylov subspace dimension, i.e., the maximum allowable number of GMRES iterations allowed before restarting.intReturns the implementation method to be used.intReturns the total number of GMRES right preconditioner solves.intReturns the total number of GMRES matrix-vector products used.doubleReturns the stopping tolerance.doubleReturns the final residual norm, \({\Vert b-Ax \Vert}_2\) .intReturns the residual updating method to be used.Returns the user-supplied functions for the inner product and, optionally, the norm used in the Gram-Schmidt implementations.voidsetGuess(double[] xguess) Set the initial guess of the solution.voidsetMaxIterations(int maxIterations) Set the maximum number of iterations allowed.voidsetMaxKrylovDim(int kdmax) Set the maximum Krylov subspace dimension, i.e., the maximum allowable number of GMRES iterations allowed before restarting.voidsetMethod(int iMethod) Set the implementation method to be used.voidsetRelativeError(double tolerance) Set the stopping tolerance.voidsetResidualUpdating(int rMethod) Set the residual updating method to be used.voidSets the user-supplied functions for the inner product and, optionally, the norm to be used in the Gram-Schmidt implementations.double[]solve(double[] b) Generate an approximate solution to \(Ax=b\) using the Generalized Residual Method.
-
Field Details
-
FIRST_GRAM_SCHMIDT
public static final int FIRST_GRAM_SCHMIDTIndicates the first Gram-Schmidt implementation method is to be used.- See Also:
-
SECOND_GRAM_SCHMIDT
public static final int SECOND_GRAM_SCHMIDTIndicates the second Gram-Schmidt implementation method is to be used.- See Also:
-
FIRST_HOUSEHOLDER
public static final int FIRST_HOUSEHOLDERIndicates the first Householder implementation method is to be used.- See Also:
-
SECOND_HOUSEHOLDER
public static final int SECOND_HOUSEHOLDERIndicates the second Householder implementation method is to be used.- See Also:
-
LINEAR_AT_RESTART_ONLY
public static final int LINEAR_AT_RESTART_ONLYIndicates residual updating is to be done by linear combination upon restarting only.- See Also:
-
LINEAR_AT_RESTART_AND_TERMINATION
public static final int LINEAR_AT_RESTART_AND_TERMINATIONIndicates residual updating is to be done by linear combination upon restarting and at termination.- See Also:
-
DIRECT_AT_RESTART_ONLY
public static final int DIRECT_AT_RESTART_ONLYIndicates residual updating is to be done by direct evaluation upon restarting only.- See Also:
-
DIRECT_AT_RESTART_AND_TERMINATION
public static final int DIRECT_AT_RESTART_AND_TERMINATIONIndicates residual updating is to be done by direct evaluation upon restarting and at termination.- See Also:
-
-
Constructor Details
-
GenMinRes
GMRES linear system solver constructor.- Parameters:
n- Anintscalar value which defines the order of the system to be solvedargF- aFunctionthat defines the user-supplied function which computes \( z = Ap \). IfargFimplementsPreconditionerthen right preconditioning is performed using this user supplied function. Otherwise, no preconditioning is performed. Note thatargFcan be used to act upon the coefficients of matrix A stored in different storage modes. See the examples.
-
-
Method Details
-
solve
public double[] solve(double[] b) throws SingularMatrixException, GenMinRes.TooManyIterationsException Generate an approximate solution to \(Ax=b\) using the Generalized Residual Method.- Parameters:
b- adoublearray which defines the right-hand side of the linear system.- Returns:
- a
doublearray containing the solution of the linear system. - Throws:
IllegalArgumentException- is thrown if if the length ofbis not consistent withn.SingularMatrixExceptionGenMinRes.TooManyIterationsException
-
setGuess
public void setGuess(double[] xguess) Set the initial guess of the solution. If this member function is not called, the elements of this array are set to 0.0.- Parameters:
xguess- adoublearray of lengthnspecifying the initial guess of the solution.
-
getGuess
public double[] getGuess()Returns the initial guess of the solution.- Returns:
- a
doublearray of lengthncontaining the initial guess of the solution.
-
setRelativeError
public void setRelativeError(double tolerance) Set the stopping tolerance. The algorithm attempts to generatexsuch that \({\Vert b-Ax \Vert}_2 \le t {\Vert b \Vert}_2\), where t = tolerance. If this member function is not called,toleranceis set to 1.4901161193847656e-08.- Parameters:
tolerance- adoublescalar value specifying the stopping tolerance. By default,tolerance= 1.49e-08.- Throws:
IllegalArgumentException- is thrown iftoleranceis less than or equal to 0.0
-
getRelativeError
public double getRelativeError()Returns the stopping tolerance. The algorithm attempts to generatexsuch that \({\Vert b-Ax \Vert}_2 \le t {\Vert b \Vert}_2\), where t = tolerance.- Returns:
- a
doublescalar value specifying the stopping tolerance.
-
getResidualNorm
public double getResidualNorm()Returns the final residual norm, \({\Vert b-Ax \Vert}_2\) .- Returns:
- a
doublescalar value specifying the final residual norm.
-
setMaxKrylovDim
public void setMaxKrylovDim(int kdmax) Set the maximum Krylov subspace dimension, i.e., the maximum allowable number of GMRES iterations allowed before restarting. If this member function is not called,kdmaxis set to the minimum ofnand 20.- Throws:
IllegalArgumentException- is thrown ifkdmaxis less than 1 or greater thann.
-
getMaxKrylovDim
public int getMaxKrylovDim()Returns the maximum Krylov subspace dimension, i.e., the maximum allowable number of GMRES iterations allowed before restarting.- Returns:
- An
intscalar representing the maximum Krylov subspace dimension, i.e., the maximum allowable number of GMRES iterations allowed before restarting.
-
setMethod
public void setMethod(int iMethod) Set the implementation method to be used.- Parameters:
iMethod- anintscalar value specifying the implementation method to be used. If this member function is not called,iMethodis set toFIRST_GRAM_SCHMIDT.iMethodDescription FIRST_GRAM_SCHMIDTUse the first Gram-Schmidt implementation. This is the default value used. SECOND_GRAM_SCHMIDTUse the second Gram-Schmidt implementation. FIRST_HOUSEHOLDERUse the first Householder implementation. SECOND_HOUSEHOLDERUse the second Householder implementation. - Throws:
IllegalArgumentException- is thrown ifiMethodis less than 1 or greater than 4.
-
getMethod
public int getMethod()Returns the implementation method to be used.- Returns:
- an
intscalar value specifying the implementation method to be used.Return Value Method 1 = FIRST_GRAM_SCHMIDTUse the first Gram-Schmidt implementation. This is the default value used. 2 = SECOND_GRAM_SCHMIDTUse the second Gram-Schmidt implementation. 3 = FIRST_HOUSEHOLDERUse the first Householder implementation. 4 = SECOND_HOUSEHOLDERUse the second Householder implementation.
-
setResidualUpdating
public void setResidualUpdating(int rMethod) Set the residual updating method to be used.- Parameters:
rMethod- anintscalar value specifying the residual updating method to be used. If this member function is not called,rMethodis set toLINEAR_AT_RESTART_ONLY.rMethodDescription LINEAR_AT_RESTART_ONLYUpdate by linear combination upon restarting only. This is the default value used. LINEAR_AT_RESTART_AND_TERMINATIONUpdate by linear combination upon restarting and at termination. DIRECT_AT_RESTART_ONLYUpdate by direct evaluation upon restarting only. DIRECT_AT_RESTART_AND_TERMINATIONUpdate by direct evaluation upon restarting and at termination. - Throws:
IllegalArgumentException- is thrown ifrMethodis less than 1 or greater than 4.
-
getResidualUpdating
public int getResidualUpdating()Returns the residual updating method to be used.- Returns:
- an
intscalar value specifying the residual updating method to be used.Return Value Method 1 = LINEAR_AT_RESTART_ONLYUpdate by linear combination upon restarting only. This is the default value used. 2 = LINEAR_AT_RESTART_AND_TERMINATIONUpdate by linear combination upon restarting and at termination. 3 = DIRECT_AT_RESTART_ONLYUpdate by direct evaluation upon restarting only. 4 = DIRECT_AT_RESTART_AND_TERMINATIONUpdate by direct evaluation upon restarting and at termination.
-
getIterations
public int getIterations()Returns the actual number of GMRES iterations used.- Returns:
- an
intscalar representing the number of iterations used.
-
getProducts
public int getProducts()Returns the total number of GMRES matrix-vector products used.- Returns:
- An
intrepresenting the number of GMRES matrix-vector products used.
-
getPreconditionerSolves
public int getPreconditionerSolves()Returns the total number of GMRES right preconditioner solves.- Returns:
- An
intrepresenting the number of GMRES right preconditioner solves.
-
setMaxIterations
public void setMaxIterations(int maxIterations) Set the maximum number of iterations allowed.- Parameters:
maxIterations- anintspecifying the maximum number of iterations allowed. By default,maxIterations= 1000.- Throws:
IllegalArgumentException- is thrown ifmaxIterationsis less than or equal to 0.
-
getMaxIterations
public int getMaxIterations()Returns the maximum number of iterations allowed.- Returns:
- an
intspecifying the maximum number of iterations allowed.
-
setVectorProducts
Sets the user-supplied functions for the inner product and, optionally, the norm to be used in the Gram-Schmidt implementations.- Parameters:
argP- aVectorProductspecifying the user-defined function for the inner product and, optionally, the norm in the Gram-Schmidt implementations. If this member function is not called, the dot product will be used for the inner product and the \( L_2 \) norm will be used for the norm.
-
getVectorProducts
Returns the user-supplied functions for the inner product and, optionally, the norm used in the Gram-Schmidt implementations.- Returns:
- a
VectorProductsthat defines the user-supplied functions for the inner product and, optionally, the norm used in the Gram-Schmidt implementations.
-
getLogger
Returns the logger object.- Returns:
- the logger object, if present, or null.
-
IMSLFormatterinstead.