public interface DirectSolver
| Modifier and Type | Interface and Description |
|---|---|
static class |
DirectSolver.IterativeMethod
Describes the methods available for
iterativeSolve(double[], double[], double[]), each of
which uses the most recent factorization as a preconditioner. |
| Modifier and Type | Field and Description |
|---|---|
static int |
ANALYZED
Indicates that a matrix has been set and analyzed for this solver.
|
static int |
DEFAULT_ITERATIVE_MAX_SOLVES
Default maximum number of preconditioner solves for iterative solves.
|
static double |
DEFAULT_ITERATIVE_TOLERANCE
Default relative residual tolerance for iterative solves.
|
static int |
FACTORED
Indicates that a matrix has been set, analyzed, and numerically factored
for this solver.
|
static int |
UNSET
Indicates that no matrix is currently set for this solver.
|
| Modifier and Type | Method and Description |
|---|---|
void |
analyze(double[] vals,
int[] colIdxs,
int[] rowOffs,
int size,
int type)
Performs prefactor analysis on a matrix whose structure and values are
supplied in compressed row storage (CRS) format, using 1-based
indices, as described in the documentation for
Matrix.setCRSValues. |
void |
analyze(Matrix M,
int size,
int type)
Performs prefactor analysis on a specified matrix.
|
void |
analyzeAndFactor(Matrix M)
Factors a matrix.
|
void |
dispose()
Releases all internal resources allocated by this solver.
|
void |
factor()
Factors a previously analyzed matrix.
|
void |
factor(double[] vals)
Factors a previously analyzed matrix, using the numeric values supplied
by
vals. |
java.lang.String |
getErrorMessage()
|
default int |
getIterativeMaxSolves()
Queries the maximum number of preconditioner solves allowed for
iterativeSolve(double[], double[], double[]). |
default DirectSolver.IterativeMethod |
getIterativeMethod()
Queries the method used by
iterativeSolve(double[], double[], double[]). |
default double |
getIterativeTolerance()
Queries the tolerance for
iterativeSolve(double[], double[], double[]). |
default double |
getLastIterativeResidual()
Returns the relative residual
||b - M x||/||b|| obtained by the
most recent call to iterativeSolve(double[], double[], double[]), or -1 if this is not
available. |
default int |
getLastIterativeSolves()
Returns the number of preconditioner solves performed by the most recent
call to
iterativeSolve(double[], double[], double[]), or -1 if this is not available. |
default int |
getMaxRefinementSteps()
Returns the maximum number of iterative refinement steps that this solver
will perform after a solve, or 0 if iterative refinement is not
supported.
|
default int |
getNumNegEigenvalues()
If possible, returns the number of negative eigenvalues detected during
the most recent factorization of a symmetric indefinite matrix.
|
long |
getNumNonZerosInFactors()
If possible, returns the number of non-zero elements in the
factorization.
|
default int |
getNumPerturbedPivots()
If possible, returns the number of pivot perturbations that were required
during the most recent numeric factorization (i.e., during the last
factor() call). |
default int |
getNumPosEigenvalues()
If possible, returns the number of positive eigenvalues detected during
the most recent factorization of a symmetric indefinite matrix.
|
int |
getState()
|
default boolean |
hasIterativeSolves()
Returns true if this solver supports iterative solving, using a recent
directly-factored matrix as a preconditioner.
|
default boolean |
hasMultipleRhsSolves()
Returns true if this solver can solve for multiple right hand sides,
using
solve(X,B,nrhs). |
default int |
iterativeSolve(double[] vals,
double[] x,
double[] b)
Solves the system
|
default int |
iterativeSolve(double[] vals,
double[] x,
double[] b,
int tolExp)
Deprecated.
|
static double |
residual(int[] rowOffs,
int[] colIdxs,
double[] vals,
int size,
double[] x,
double[] b,
boolean symmetric)
Computes the norm of the residual
|
default void |
setIterativeMaxSolves(int max)
Sets the maximum number of preconditioner solves allowed for
iterativeSolve(double[], double[], double[]), beyond which it fails. |
default void |
setIterativeMethod(DirectSolver.IterativeMethod method)
Sets the method used by
iterativeSolve(double[], double[], double[]). |
default void |
setIterativeTolerance(double tol)
Sets the tolerance for
iterativeSolve(double[], double[], double[]): the iteration succeeds
when the relative residual ||b - M x||/||b|| is at most
tol. |
default void |
setMaxRefinementSteps(int nsteps)
Sets the maximum number of iterative refinement steps that this solver
should perform after a solve.
|
void |
solve(double[] x,
double[] b)
Solves the system
|
default void |
solve(double[] X,
double[] B,
int nrhs)
Solves the system
|
void |
solve(VectorNd x,
VectorNd b)
Solves the system
|
static final int UNSET
static final int ANALYZED
static final int FACTORED
static final double DEFAULT_ITERATIVE_TOLERANCE
static final int DEFAULT_ITERATIVE_MAX_SOLVES
int getState()
java.lang.String getErrorMessage()
analyze() or factor(), or
null if the method succeeded.long getNumNonZerosInFactors()
analyze(). If the solver does not report this quantity, -1 is returned.void analyze(Matrix M, int size, int type)
factor(). If
size is less than the actual matrix size, then the analysis
is done on the principal submatrix of M defined by the first
size rows and columns.M - matrix to analyzesize - size of the matrix to factor.type - or-ed flags giving information about the matrix type. Typical flags are
SYMMETRIC or
POSITIVE_DEFINITEjava.lang.IllegalArgumentException - if the matrix is not square, or the matrix type is not supported by the
solver.NumericalException - if the analysis failed for numeric reasons.void analyze(double[] vals,
int[] colIdxs,
int[] rowOffs,
int size,
int type)
Matrix.setCRSValues. The number of
non-zero values is given by rowOffs[size]-1. If the matrix type
is symmetric, only the upper triangular portion should be supplied.
Because no matrix object is supplied, factor()
cannot be used after calling this method; use factor(vals) instead. The values supplied here may be used to assist
the analysis but are not used for any numeric factorization.
vals - values of the non-zero matrix elementscolIdxs - 1-based column indices of the non-zero matrix elementsrowOffs - 1-based row start offsets into vals and
colIdxssize - size of the matrix to be analyzedtype - or-ed flags giving information about the matrix type, as
described for analyze(M,size,type)java.lang.IllegalArgumentException - if the CRS data structures are
inconsistent, or the matrix type is not supported by the solverNumericalException - if the analysis failed for numeric reasonsvoid factor()
java.lang.IllegalStateException - if no previous call to analyze has been made.NumericalException - if the factor failed for numeric reasons.void factor(double[] vals)
vals. These must be ordered in the same way as those
supplied to the most recent call to analyze().vals - non-zero matrix element valuesjava.lang.IllegalStateException - if no previous call to analyze has been madejava.lang.IllegalArgumentException - if the number of supplied values is
less than the number of non-zero elements in the analyzed matrixNumericalException - if the factor failed for numeric reasons.void analyzeAndFactor(Matrix M)
analyze (M, M.rowSize(), 0) factor()
M - matrix to factorjava.lang.IllegalArgumentException - if the matrix is not square, or general matrices are not supported by the
solver.NumericalException - if the analysis or factoring failed for numeric reasons.void solve(VectorNd x, VectorNd b)
x - vector in which result is returnedb - right hand vector of matrix equationNumericalException - if the solve failed for numeric reasons.java.lang.IllegalStateException - if no previous call to analyze or
factor has been made.void solve(double[] x,
double[] b)
M x = bwhere the solution and right hand side are supplied using
double[] objects.x - vector in which result is returnedb - right hand vector of matrix equationNumericalException - if the solve failed for numeric reasons.java.lang.IllegalStateException - if the matrix has not been factoreddefault boolean hasIterativeSolves()
DirectSolver.IterativeMethod are available, as are the
settings setIterativeMethod(maspack.solvers.DirectSolver.IterativeMethod), setIterativeMaxSolves(int) and
setIterativeTolerance(double).default void setIterativeMethod(DirectSolver.IterativeMethod method)
iterativeSolve(double[], double[], double[]). The default is DirectSolver.IterativeMethod.GMRES. Has no effect if hasIterativeSolves()
returns false.method - iterative methoddefault DirectSolver.IterativeMethod getIterativeMethod()
iterativeSolve(double[], double[], double[]).default void setIterativeMaxSolves(int max)
iterativeSolve(double[], double[], double[]), beyond which it fails. The default is DEFAULT_ITERATIVE_MAX_SOLVES. Has no effect if hasIterativeSolves() returns false.max - maximum number of preconditioner solvesdefault int getIterativeMaxSolves()
iterativeSolve(double[], double[], double[]).default void setIterativeTolerance(double tol)
iterativeSolve(double[], double[], double[]): the iteration succeeds
when the relative residual ||b - M x||/||b|| is at most
tol. The default is DEFAULT_ITERATIVE_TOLERANCE.
Has no effect if hasIterativeSolves() returns false.tol - relative residual tolerancedefault double getIterativeTolerance()
iterativeSolve(double[], double[], double[]).default int getLastIterativeSolves()
iterativeSolve(double[], double[], double[]), or -1 if this is not available.default double getLastIterativeResidual()
||b - M x||/||b|| obtained by the
most recent call to iterativeSolve(double[], double[], double[]), or -1 if this is not
available.default int iterativeSolve(double[] vals,
double[] x,
double[] b)
M x = biteratively, using the most recent factorization as a preconditioner and the matrix values supplied by
vals. If the current values
are close to those associated with the factorization, this can be
considerably faster than an explicit factor()
and solve(). The method, maximum number
of preconditioner solves and tolerance are set by setIterativeMethod(maspack.solvers.DirectSolver.IterativeMethod), setIterativeMaxSolves(int) and setIterativeTolerance(double).
This method is only available if hasIterativeSolves() returns
true; otherwise, it returns 0 and the caller should fall
back on factoring and solving directly.
vals - current values of the non-zero matrix elements, in the same
ordering as that supplied to analyze()x - vector in which the result is returnedb - right hand vector of the matrix equation<= 0 if the
iterative solve was not performed or did not succeed@Deprecated
default int iterativeSolve(double[] vals,
double[] x,
double[] b,
int tolExp)
setIterativeTolerance(double) and iterativeSolve(double[],double[],double[]) instead10^-tolExp, leaving the tolerance set by setIterativeTolerance(double) unchanged.vals - current values of the non-zero matrix elementsx - vector in which the result is returnedb - right hand vector of the matrix equationtolExp - (negative) exponent of the desired relative residual<= 0 if the
iterative solve was not performed or did not succeeddefault boolean hasMultipleRhsSolves()
solve(X,B,nrhs).default void solve(double[] X,
double[] B,
int nrhs)
M X = Bfor a set of right hand sides B, where the number of right hand sides is given by
nrhs. Both X and B should
be stored in column major order. This method is only available if hasMultipleRhsSolves() returns true.X - returns the solutions, in column major orderB - supplies the right hand sides, in column major ordernrhs - number of right hand sidesjava.lang.UnsupportedOperationException - if multiple right hand sides are
not supportedjava.lang.IllegalStateException - if the matrix has not been factoredNumericalException - if the solve failed for numeric reasonsdefault int getNumNegEigenvalues()
default int getNumPosEigenvalues()
default int getNumPerturbedPivots()
factor() call). Pivot perturbation generally indicates
a singular, or very nearly singular, matrix. If the solver does not
report pivot perturbations, -1 is returned.default int getMaxRefinementSteps()
setMaxRefinementSteps(int)default void setMaxRefinementSteps(int nsteps)
nsteps - maximum number of iterative refinement stepsgetMaxRefinementSteps()static double residual(int[] rowOffs,
int[] colIdxs,
double[] vals,
int size,
double[] x,
double[] b,
boolean symmetric)
M x - bfor given values of M, x, and b, where the values of
M are
given in compressed row storage (CRS) format with 1-based indices.rowOffs - matrix row offsets (CRS format)colIdxs - non-zero element column indices (CRS format)vals - non-zero element values (CRS format)size - size of the matrixx - supplies the solution valueb - supplies the right-hand sidesymmetric - if true, assumes that the arguments define
only the upper triangular portion of a symmetric matrixjava.lang.IllegalArgumentException - if the dimensions of x or
b are incompatible with the matrix size.void dispose()