Teuchos - Trilinos Tools Package Version of the Day
Teuchos::SerialDenseSolver< OrdinalType, ScalarType > Class Template Reference

A class for solving dense linear problems. More...

#include <Teuchos_SerialDenseSolver.hpp>

Inheritance diagram for Teuchos::SerialDenseSolver< OrdinalType, ScalarType >:
Teuchos::CompObject Teuchos::Object Teuchos::BLAS< OrdinalType, ScalarType > Teuchos::LAPACK< OrdinalType, ScalarType > Teuchos::DefaultBLASImpl< OrdinalType, ScalarType >

List of all members.

Public Member Functions

Constructor/Destructor Methods
 SerialDenseSolver ()
 Default constructor; matrix should be set using setMatrix(), LHS and RHS set with setVectors().
virtual ~SerialDenseSolver ()
 SerialDenseSolver destructor.
Set Methods
int setMatrix (const RCP< SerialDenseMatrix< OrdinalType, ScalarType > > &A)
 Sets the pointers for coefficient matrix.
int setVectors (const RCP< SerialDenseMatrix< OrdinalType, ScalarType > > &X, const RCP< SerialDenseMatrix< OrdinalType, ScalarType > > &B)
 Sets the pointers for left and right hand side vector(s).
Strategy Modifying Methods
void factorWithEquilibration (bool flag)
 Causes equilibration to be called just before the matrix factorization as part of the call to factor.
void solveWithTranspose (bool flag)
 If flag is true, causes all subsequent function calls to work with the transpose of this matrix, otherwise not.
void solveToRefinedSolution (bool flag)
 Causes all solves to compute solution to best ability using iterative refinement.
void estimateSolutionErrors (bool flag)
 Causes all solves to estimate the forward and backward solution error.
Factor/Solve/Invert Methods
int factor ()
 Computes the in-place LU factorization of the matrix using the LAPACK routine _GETRF.
int solve ()
 Computes the solution X to AX = B for the this matrix and the B provided to SetVectors()..
int invert ()
 Inverts the this matrix.
int computeEquilibrateScaling ()
 Computes the scaling vector S(i) = 1/sqrt(A(i,i)) of the this matrix.
int equilibrateMatrix ()
 Equilibrates the this matrix.
int equilibrateRHS ()
 Equilibrates the current RHS.
int applyRefinement ()
 Apply Iterative Refinement.
int unequilibrateLHS ()
 Unscales the solution vectors if equilibration was used to solve the system.
int reciprocalConditionEstimate (MagnitudeType &Value)
 Returns the reciprocal of the 1-norm condition number of the this matrix.
Query methods
bool transpose ()
 Returns true if transpose of this matrix has and will be used.
bool factored ()
 Returns true if matrix is factored (factor available via AF() and LDAF()).
bool equilibratedA ()
 Returns true if factor is equilibrated (factor available via AF() and LDAF()).
bool equilibratedB ()
 Returns true if RHS is equilibrated (RHS available via B() and LDB()).
bool shouldEquilibrate ()
 Returns true if the LAPACK general rules for equilibration suggest you should equilibrate the system.
bool solutionErrorsEstimated ()
 Returns true if forward and backward error estimated have been computed (available via FERR() and BERR()).
bool inverted ()
 Returns true if matrix inverse has been computed (inverse available via AF() and LDAF()).
bool reciprocalConditionEstimated ()
 Returns true if the condition number of the this matrix has been computed (value available via ReciprocalConditionEstimate()).
bool solved ()
 Returns true if the current set of vectors has been solved.
bool solutionRefined ()
 Returns true if the current set of vectors has been refined.
Data Accessor methods
RCP< SerialDenseMatrix
< OrdinalType, ScalarType > > 
getMatrix () const
 Returns pointer to current matrix.
RCP< SerialDenseMatrix
< OrdinalType, ScalarType > > 
getFactoredMatrix () const
 Returns pointer to factored matrix (assuming factorization has been performed).
RCP< SerialDenseMatrix
< OrdinalType, ScalarType > > 
getLHS () const
 Returns pointer to current LHS.
RCP< SerialDenseMatrix
< OrdinalType, ScalarType > > 
getRHS () const
 Returns pointer to current RHS.
OrdinalType numRows () const
 Returns row dimension of system.
OrdinalType numCols () const
 Returns column dimension of system.
std::vector< OrdinalType > IPIV () const
 Returns pointer to pivot vector (if factorization has been computed), zero otherwise.
MagnitudeType ANORM () const
 Returns the 1-Norm of the this matrix (returns -1 if not yet computed).
MagnitudeType RCOND () const
 Returns the reciprocal of the condition number of the this matrix (returns -1 if not yet computed).
MagnitudeType ROWCND () const
 Ratio of smallest to largest row scale factors for the this matrix (returns -1 if not yet computed).
MagnitudeType COLCND () const
 Ratio of smallest to largest column scale factors for the this matrix (returns -1 if not yet computed).
MagnitudeType AMAX () const
 Returns the absolute value of the largest entry of the this matrix (returns -1 if not yet computed).
std::vector< MagnitudeType > FERR () const
 Returns a pointer to the forward error estimates computed by LAPACK.
std::vector< MagnitudeType > BERR () const
 Returns a pointer to the backward error estimates computed by LAPACK.
std::vector< MagnitudeType > R () const
 Returns a pointer to the row scaling vector used for equilibration.
std::vector< MagnitudeType > C () const
 Returns a pointer to the column scale vector used for equilibration.
I/O methods
void Print (std::ostream &os) const
 Print service methods; defines behavior of ostream << operator.

Detailed Description

template<typename OrdinalType, typename ScalarType>
class Teuchos::SerialDenseSolver< OrdinalType, ScalarType >

A class for solving dense linear problems.

The Teuchos::SerialDenseSolver class enables the definition, in terms of Teuchos::SerialDenseMatrix and Teuchos::SerialDenseVector objects, of a dense linear problem, followed by the solution of that problem via the most sophisticated techniques available in LAPACK.

The Teuchos::SerialDenseSolver class is intended to provide full-featured support for solving linear problems for general dense rectangular (or square) matrices. It is written on top of BLAS and LAPACK and thus has excellent performance and numerical capabilities. Using this class, one can either perform simple factorizations and solves or apply all the tricks available in LAPACK to get the best possible solution for very ill-conditioned problems.

Teuchos::SerialDenseSolver vs. Teuchos::LAPACK

The Teuchos::LAPACK class provides access to most of the same functionality as Teuchos::SerialDenseSolver. The primary difference is that Teuchos::LAPACK is a "thin" layer on top of LAPACK and Teuchos::SerialDenseSolver attempts to provide easy access to the more sophisticated aspects of solving dense linear and eigensystems.

Constructing Teuchos::SerialDenseSolver Objects

There is a single Teuchos::SerialDenseSolver constructor. However, the matrix, right hand side and solution vectors must be set prior to executing most methods in this class.

Setting vectors used for linear solves

The matrix A, the left hand side X and the right hand side B (when solving AX = B, for X), can be set by appropriate set methods. Each of these three objects must be an Teuchos::SerialDenseMatrix or and Teuchos::SerialDenseVector object. The set methods are as follows:

Vector and Utility Functions

Once a Teuchos::SerialDenseSolver is constructed, several mathematical functions can be applied to the object. Specifically:

Strategies for Solving Linear Systems In many cases, linear systems can be accurately solved by simply computing the LU factorization of the matrix and then performing a forward back solve with a given set of right hand side vectors. However, in some instances, the factorization may be very poorly conditioned and this simple approach may not work. In these situations, equilibration and iterative refinement may improve the accuracy, or prevent a breakdown in the factorization.

Teuchos::SerialDenseSolver will use equilibration with the factorization if, once the object is constructed and before it is factored, you call the function factorWithEquilibration(true) to force equilibration to be used. If you are uncertain if equilibration should be used, you may call the function shouldEquilibrate() which will return true if equilibration could possibly help. shouldEquilibrate() uses guidelines specified in the LAPACK User Guide, namely if SCOND < 0.1 and AMAX < Underflow or AMAX > Overflow, to determine if equilibration might be useful.

Teuchos::SerialDenseSolver will use iterative refinement after a forward/back solve if you call solveToRefinedSolution(true). It will also compute forward and backward error estimates if you call estimateSolutionErrors(true). Access to the forward (back) error estimates is available via FERR() (BERR()).

Examples using Teuchos::SerialDenseSolver can be found in the Teuchos test directories.

Examples:

DenseMatrix/cxx_main.cpp.

Definition at line 132 of file Teuchos_SerialDenseSolver.hpp.


Constructor & Destructor Documentation

template<typename OrdinalType , typename ScalarType >
Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::SerialDenseSolver ( )

Default constructor; matrix should be set using setMatrix(), LHS and RHS set with setVectors().

Definition at line 405 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::~SerialDenseSolver ( ) [virtual]

SerialDenseSolver destructor.

Definition at line 442 of file Teuchos_SerialDenseSolver.hpp.


Member Function Documentation

template<typename OrdinalType , typename ScalarType >
int Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::setMatrix ( const RCP< SerialDenseMatrix< OrdinalType, ScalarType > > &  A)

Sets the pointers for coefficient matrix.

Definition at line 487 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
int Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::setVectors ( const RCP< SerialDenseMatrix< OrdinalType, ScalarType > > &  X,
const RCP< SerialDenseMatrix< OrdinalType, ScalarType > > &  B 
)

Sets the pointers for left and right hand side vector(s).

Row dimension of X must match column dimension of matrix A, row dimension of B must match row dimension of A. X and B must have the same dimensions.

Definition at line 504 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
void Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::factorWithEquilibration ( bool  flag) [inline]

Causes equilibration to be called just before the matrix factorization as part of the call to factor.

This function must be called before the factorization is performed.

Definition at line 169 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
void Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::solveWithTranspose ( bool  flag) [inline]

If flag is true, causes all subsequent function calls to work with the transpose of this matrix, otherwise not.

Definition at line 172 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
void Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::solveToRefinedSolution ( bool  flag) [inline]

Causes all solves to compute solution to best ability using iterative refinement.

Definition at line 175 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
void Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::estimateSolutionErrors ( bool  flag)

Causes all solves to estimate the forward and backward solution error.

Error estimates will be in the arrays FERR and BERR, resp, after the solve step is complete. These arrays are accessible via the FERR() and BERR() access functions.

Definition at line 527 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
int Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::factor ( )

Computes the in-place LU factorization of the matrix using the LAPACK routine _GETRF.

Returns:
Integer error code, set to 0 if successful.

Definition at line 537 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
int Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::solve ( )

Computes the solution X to AX = B for the this matrix and the B provided to SetVectors()..

Returns:
Integer error code, set to 0 if successful.

Definition at line 574 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
int Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::invert ( )

Inverts the this matrix.

Returns:
Integer error code, set to 0 if successful. Otherwise returns the LAPACK error code INFO.

Definition at line 787 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
int Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::computeEquilibrateScaling ( )

Computes the scaling vector S(i) = 1/sqrt(A(i,i)) of the this matrix.

Returns:
Integer error code, set to 0 if successful. Otherwise returns the LAPACK error code INFO.

Definition at line 666 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
int Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::equilibrateMatrix ( )

Equilibrates the this matrix.

Returns:
Integer error code, set to 0 if successful. Otherwise returns the LAPACK error code INFO.

Definition at line 687 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
int Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::equilibrateRHS ( )

Equilibrates the current RHS.

Returns:
Integer error code, set to 0 if successful. Otherwise returns the LAPACK error code INFO.

Definition at line 730 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
int Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::applyRefinement ( )

Apply Iterative Refinement.

Returns:
Integer error code, set to 0 if successful. Otherwise returns the LAPACK error code INFO.

Definition at line 637 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
int Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::unequilibrateLHS ( )

Unscales the solution vectors if equilibration was used to solve the system.

Returns:
Integer error code, set to 0 if successful. Otherwise returns the LAPACK error code INFO.

Definition at line 761 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
int Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::reciprocalConditionEstimate ( MagnitudeType &  Value)

Returns the reciprocal of the 1-norm condition number of the this matrix.

Parameters:
ValueOut On return contains the reciprocal of the 1-norm condition number of the this matrix.
Returns:
Integer error code, set to 0 if successful. Otherwise returns the LAPACK error code INFO.

Definition at line 817 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
bool Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::transpose ( ) [inline]

Returns true if transpose of this matrix has and will be used.

Definition at line 249 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
bool Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::factored ( ) [inline]

Returns true if matrix is factored (factor available via AF() and LDAF()).

Definition at line 252 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
bool Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::equilibratedA ( ) [inline]

Returns true if factor is equilibrated (factor available via AF() and LDAF()).

Definition at line 255 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
bool Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::equilibratedB ( ) [inline]

Returns true if RHS is equilibrated (RHS available via B() and LDB()).

Definition at line 258 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
bool Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::shouldEquilibrate ( ) [inline]

Returns true if the LAPACK general rules for equilibration suggest you should equilibrate the system.

Definition at line 261 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
bool Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::solutionErrorsEstimated ( ) [inline]

Returns true if forward and backward error estimated have been computed (available via FERR() and BERR()).

Definition at line 264 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
bool Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::inverted ( ) [inline]

Returns true if matrix inverse has been computed (inverse available via AF() and LDAF()).

Definition at line 267 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
bool Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::reciprocalConditionEstimated ( ) [inline]

Returns true if the condition number of the this matrix has been computed (value available via ReciprocalConditionEstimate()).

Definition at line 270 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
bool Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::solved ( ) [inline]

Returns true if the current set of vectors has been solved.

Definition at line 273 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
bool Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::solutionRefined ( ) [inline]

Returns true if the current set of vectors has been refined.

Definition at line 276 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
RCP<SerialDenseMatrix<OrdinalType, ScalarType> > Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::getMatrix ( ) const [inline]

Returns pointer to current matrix.

Definition at line 283 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
RCP<SerialDenseMatrix<OrdinalType, ScalarType> > Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::getFactoredMatrix ( ) const [inline]

Returns pointer to factored matrix (assuming factorization has been performed).

Definition at line 286 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
RCP<SerialDenseMatrix<OrdinalType, ScalarType> > Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::getLHS ( ) const [inline]

Returns pointer to current LHS.

Definition at line 289 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
RCP<SerialDenseMatrix<OrdinalType, ScalarType> > Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::getRHS ( ) const [inline]

Returns pointer to current RHS.

Definition at line 292 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
OrdinalType Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::numRows ( ) const [inline]

Returns row dimension of system.

Definition at line 295 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
OrdinalType Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::numCols ( ) const [inline]

Returns column dimension of system.

Definition at line 298 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
std::vector<OrdinalType> Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::IPIV ( ) const [inline]

Returns pointer to pivot vector (if factorization has been computed), zero otherwise.

Definition at line 301 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
MagnitudeType Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::ANORM ( ) const [inline]

Returns the 1-Norm of the this matrix (returns -1 if not yet computed).

Definition at line 304 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
MagnitudeType Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::RCOND ( ) const [inline]

Returns the reciprocal of the condition number of the this matrix (returns -1 if not yet computed).

Definition at line 307 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
MagnitudeType Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::ROWCND ( ) const [inline]

Ratio of smallest to largest row scale factors for the this matrix (returns -1 if not yet computed).

If ROWCND() is >= 0.1 and AMAX() is not close to overflow or underflow, then equilibration is not needed.

Definition at line 312 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
MagnitudeType Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::COLCND ( ) const [inline]

Ratio of smallest to largest column scale factors for the this matrix (returns -1 if not yet computed).

If COLCND() is >= 0.1 then equilibration is not needed.

Definition at line 317 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
MagnitudeType Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::AMAX ( ) const [inline]

Returns the absolute value of the largest entry of the this matrix (returns -1 if not yet computed).

Definition at line 320 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
std::vector<MagnitudeType> Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::FERR ( ) const [inline]

Returns a pointer to the forward error estimates computed by LAPACK.

Definition at line 323 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
std::vector<MagnitudeType> Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::BERR ( ) const [inline]

Returns a pointer to the backward error estimates computed by LAPACK.

Definition at line 326 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
std::vector<MagnitudeType> Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::R ( ) const [inline]

Returns a pointer to the row scaling vector used for equilibration.

Definition at line 329 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType, typename ScalarType>
std::vector<MagnitudeType> Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::C ( ) const [inline]

Returns a pointer to the column scale vector used for equilibration.

Definition at line 332 of file Teuchos_SerialDenseSolver.hpp.

template<typename OrdinalType , typename ScalarType >
void Teuchos::SerialDenseSolver< OrdinalType, ScalarType >::Print ( std::ostream &  os) const

Print service methods; defines behavior of ostream << operator.

Definition at line 844 of file Teuchos_SerialDenseSolver.hpp.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines