maspack.solvers
Class CGSolver

java.lang.Object
  extended by maspack.solvers.CGSolver
All Implemented Interfaces:
IterativeSolver

public class CGSolver
extends java.lang.Object
implements IterativeSolver

Solves linear systems using the conjugate gradient algorithm


Nested Class Summary
 
Nested classes/interfaces inherited from interface maspack.solvers.IterativeSolver
IterativeSolver.ToleranceType
 
Field Summary
 boolean debug
           
 
Constructor Summary
CGSolver()
           
 
Method Summary
 int getMaxIterations()
           
 int getNumIterations()
          Returns the number of iterations associated with the last call to solve.
 double getRelativeResidual()
          Returns the relative residual ||A x - b||/||b|| at the end of the last call to solve.
 double getTolerance()
           
 IterativeSolver.ToleranceType getToleranceType()
           
 boolean isCompatible(int matrixType)
           
 void setMaxIterations(int max)
           
 void setTolerance(double tol)
           
 void setToleranceType(IterativeSolver.ToleranceType type)
           
 boolean solve(VectorNd x, LinearTransformNd A, VectorNd b)
          Solves a linear system A x = b using the conjugate gradient method.
 boolean solve(VectorNd x, LinearTransformNd A, VectorNd b, double tol, int maxIter)
          Solves a linear system A x = b using the conjugate gradient method.
 boolean solve(VectorNd x, LinearTransformNd A, VectorNd b, double tol, int maxIter, LinearTransformNd P)
          Solves a linear system A x = b using the conjugate gradient method with a preconditioner.
 boolean solveTransformed(VectorNd x, SparseMatrixNd A, VectorNd b, double tol, int maxIter, IncompleteCholeskyDecomposition icd)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

public boolean debug
Constructor Detail

CGSolver

public CGSolver()
Method Detail

getTolerance

public double getTolerance()
Specified by:
getTolerance in interface IterativeSolver

setTolerance

public void setTolerance(double tol)
Specified by:
setTolerance in interface IterativeSolver

getToleranceType

public IterativeSolver.ToleranceType getToleranceType()
Specified by:
getToleranceType in interface IterativeSolver

setToleranceType

public void setToleranceType(IterativeSolver.ToleranceType type)
Specified by:
setToleranceType in interface IterativeSolver

getMaxIterations

public int getMaxIterations()
Specified by:
getMaxIterations in interface IterativeSolver

setMaxIterations

public void setMaxIterations(int max)
Specified by:
setMaxIterations in interface IterativeSolver

solve

public boolean solve(VectorNd x,
                     LinearTransformNd A,
                     VectorNd b)
Solves a linear system A x = b using the conjugate gradient method. The matrix associated with the linear system is represented implicitly by a LinearTransformNd. The method will iterate while relative residual ||A x - b||/||b|| is greater than a supplied tolerance and the number of iterations is less than a specified maximum.

Specified by:
solve in interface IterativeSolver
Parameters:
x - result vector, as well as initial guess of the solution
A - linear transform for the system to be solved
b - input vector
Returns:
true if a solution was found within the specified tolerance

solve

public boolean solve(VectorNd x,
                     LinearTransformNd A,
                     VectorNd b,
                     double tol,
                     int maxIter)
Solves a linear system A x = b using the conjugate gradient method. The matrix associated with the linear system is represented implicitly by a LinearTransformNd. The method will iterate while relative residual ||A x - b||/||b|| is greater than a supplied tolerance and the number of iterations is less than a specified maximum.

Parameters:
x - result vector, as well as initial guess of the solution
A - linear transform for the system to be solved
b - input vector
tol - solution tolerance
maxIter - maximum number of iferations
Returns:
true if a solution was found within the specified tolerance

solve

public boolean solve(VectorNd x,
                     LinearTransformNd A,
                     VectorNd b,
                     double tol,
                     int maxIter,
                     LinearTransformNd P)
Solves a linear system A x = b using the conjugate gradient method with a preconditioner. The matrix associated with the linear system and the preconditioner are each represented implicitly by a LinearTransformNd. The mul method of the preconditioner should implement the transformation y = inv(M) x, where M is a a preconditioning matrix that approximates A. The method will iterate while relative residual ||A x - b||/||b|| is greater than a supplied tolerance and the number of iterations is less than a specified maximum.

Parameters:
x - result vector, as well as initial guess of the solution
A - linear transform for the system to be solved
b - input vector
tol - solution tolerance
maxIter - maximum number of iferations
P - preconditioner (optional, may be specified as null)
Returns:
true if a solution was found within the specified tolerance

getNumIterations

public int getNumIterations()
Returns the number of iterations associated with the last call to solve.

Specified by:
getNumIterations in interface IterativeSolver
Returns:
number of iterations

getRelativeResidual

public double getRelativeResidual()
Returns the relative residual ||A x - b||/||b|| at the end of the last call to solve.

Specified by:
getRelativeResidual in interface IterativeSolver
Returns:
last relative residual

isCompatible

public boolean isCompatible(int matrixType)
Specified by:
isCompatible in interface IterativeSolver

solveTransformed

public boolean solveTransformed(VectorNd x,
                                SparseMatrixNd A,
                                VectorNd b,
                                double tol,
                                int maxIter,
                                IncompleteCholeskyDecomposition icd)