queso-0.57.1
|
Class for matrix operations using Teuchos (Trilinos). More...
#include <TeuchosMatrix.h>
Public Member Functions | |
Constructor/Destructor methods | |
TeuchosMatrix (const BaseEnvironment &env, const Map &map, unsigned int numCols) | |
Shaped Constructor: creates a shaped matrix with numCols columns. More... | |
TeuchosMatrix (const BaseEnvironment &env, const Map &map, double diagValue) | |
Shaped Constructor: creates a square matrix with size map.NumGlobalElements() and diagonal values all equal to diagValue . More... | |
TeuchosMatrix (const TeuchosVector &v, double diagValue) | |
Shaped Constructor: creates a square matrix with size v.sizeLocal() and diagonal values all equal to diagValue . More... | |
TeuchosMatrix (const TeuchosVector &v) | |
Shaped Constructor: creates a square matrix with size v.sizeLocal() . More... | |
TeuchosMatrix (const TeuchosMatrix &B) | |
Shaped Constructor: this matrix is a copy of matrix B . More... | |
~TeuchosMatrix () | |
Destructor. More... | |
Set methods | |
TeuchosMatrix & | operator= (const TeuchosMatrix &rhs) |
Copies values from matrix rhs to this . More... | |
TeuchosMatrix & | operator*= (double a) |
Stores in this the coordinate-wise multiplication of this and a . More... | |
TeuchosMatrix & | operator/= (double a) |
Stores in this the coordinate-wise division of this by a . More... | |
TeuchosMatrix & | operator+= (const TeuchosMatrix &rhs) |
Stores in this the coordinate-wise addition of this and rhs . More... | |
TeuchosMatrix & | operator-= (const TeuchosMatrix &rhs) |
Stores in this the coordinate-wise subtraction of this by rhs . More... | |
Accessor methods | |
double & | operator() (unsigned int i, unsigned int j) |
Element access method (non-const). More... | |
const double & | operator() (unsigned int i, unsigned int j) const |
Element access method (const). More... | |
Attribute methods | |
unsigned int | numRowsLocal () const |
Returns the local row dimension of this matrix. More... | |
unsigned int | numRowsGlobal () const |
Returns the global row dimension of this matrix. More... | |
unsigned int | numCols () const |
Returns the column dimension of this matrix. More... | |
double * | values () |
Returns a pointer to the first element of this matrix. More... | |
int | stride () |
Returns the stride between the columns of this matrix in memory. More... | |
double | max () const |
Returns the maximum element value of the matrix. More... | |
unsigned int | rank (double absoluteZeroThreshold, double relativeZeroThreshold) const |
This function returns the number of singular values of this matrix (rank). More... | |
TeuchosMatrix | transpose () const |
This function calculates the transpose of this matrix (square). More... | |
TeuchosMatrix | inverse () const |
This function calculates the inverse of this matrix (square). More... | |
double | determinant () const |
Calculates the determinant of this matrix. More... | |
double | lnDeterminant () const |
Calculates the ln(determinant) of this matrix. More... | |
Norm methods | |
double | normFrob () const |
Returns the Frobenius norm of this matrix. More... | |
double | normMax () const |
Returns the Frobenius norm of this matrix. More... | |
Mathematical methods | |
int | chol () |
Computes Cholesky factorization of this , a real symmetric positive definite matrix. More... | |
int | svd (TeuchosMatrix &matU, TeuchosVector &vecS, TeuchosMatrix &matVt) const |
Checks for the dimension of this matrix, matU , VecS and matVt , and calls the protected routine internalSvd to compute the singular values of this . More... | |
const TeuchosMatrix & | svdMatU () const |
This function calls private member TeuchosMatrix::internalSvd() to set a M-by-N orthogonal matrix U of the singular value decomposition (svd) of a general rectangular M-by-N matrix A. More... | |
const TeuchosMatrix & | svdMatV () const |
This function calls private member TeuchosMatrix::internalSvd() to set a N-by-N orthogonal square matrix V of the singular value decomposition (svd) of a general rectangular M-by-N matrix A. More... | |
int | svdSolve (const TeuchosVector &rhsVec, TeuchosVector &solVec) const |
This function solves the system A x = b using the singular value decomposition (U, S, V) of A which must have been computed previously with TeuchosMatrix::svd (x=solVec, b=rhsVec). More... | |
int | svdSolve (const TeuchosMatrix &rhsMat, TeuchosMatrix &solMat) const |
This function solves the system A x = b using the singular value decomposition (U, S, V) of A which must have been computed previously with TeuchosMatrix::svd (x=solMat, b=rhsMat). More... | |
TeuchosVector | multiply (const TeuchosVector &x) const |
This function multiplies this matrix by vector x and returns a vector. More... | |
void | invertMultiply (const TeuchosVector &b, TeuchosVector &x) const |
This function calculates the inverse of this matrix, multiplies it with vector b and stores the result in vector x . More... | |
TeuchosVector | invertMultiply (const TeuchosVector &b) const |
This function calculates the inverse of this matrix and multiplies it with vector b . More... | |
void | invertMultiply (const TeuchosMatrix &B, TeuchosMatrix &X) const |
This function calculates the inverse of this matrix, multiplies it with matrix B and stores the result in matrix X . More... | |
TeuchosMatrix | invertMultiply (const TeuchosMatrix &B) const |
This function calculates the inverse of this matrix and multiplies it with matrix B . More... | |
void | invertMultiplyForceLU (const TeuchosVector &b, TeuchosVector &x) const |
This function calculates the inverse of this matrix, multiplies it with vector b and stores the result in vector x . More... | |
TeuchosVector | invertMultiplyForceLU (const TeuchosVector &b) const |
This function calculates the inverse of this matrix and multiplies it with vector b . More... | |
void | eigen (TeuchosVector &eigenValues, TeuchosMatrix *eigenVectors) const |
This function computes the eigenvalues of a real symmetric matrix. More... | |
void | largestEigen (double &eigenValue, TeuchosVector &eigenVector) const |
This function finds largest eigenvalue, namely eigenValue , of this matrix and its corresponding eigenvector, namely eigenVector . More... | |
void | smallestEigen (double &eigenValue, TeuchosVector &eigenVector) const |
This function finds smallest eigenvalue, namely eigenValue , of this matrix and its corresponding eigenvector, namely eigenVector . More... | |
Get/Set methods | |
void | cwSet (double value) |
Component-wise set all values to this with value. More... | |
void | cwSet (unsigned int rowId, unsigned int colId, const TeuchosMatrix &mat) |
Set the components of which positions are greater than (rowId,colId) with the value of mat(rowId,colId). More... | |
void | getColumn (const unsigned int column_num, TeuchosVector &column) const |
This function gets the column_num-th column of this matrix and stores it into vector column . More... | |
TeuchosVector | getColumn (const unsigned int column_num) const |
This function gets the column_num-th column of this matrix. More... | |
void | setColumn (const unsigned int column_num, const TeuchosVector &column) |
This function copies vector column into the column_num-th column of this matrix. More... | |
void | getRow (const unsigned int row_num, TeuchosVector &row) const |
This function gets the row_num-th column of this matrix and stores it into vector row . More... | |
TeuchosVector | getRow (const unsigned int row_num) const |
This function gets the row_num-th column of this matrix. More... | |
void | setRow (const unsigned int row_num, const TeuchosVector &row) |
This function copies vector row into the row_num-th column of this matrix. More... | |
void | zeroLower (bool includeDiagonal=false) |
This function sets all the entries above the main diagonal (inclusive or not) of this matrix to zero. More... | |
void | zeroUpper (bool includeDiagonal=false) |
This function sets all the entries bellow the main diagonal (inclusive or not) of this matrix to zero. More... | |
void | filterSmallValues (double thresholdValue) |
This function sets to zero (filters) all entries of this matrix which are smaller than thresholdValue . More... | |
void | filterLargeValues (double thresholdValue) |
This function sets to zero (filters) all entries of this matrix which are greater than thresholdValue . More... | |
void | fillWithTranspose (const TeuchosMatrix &mat) |
This function stores the transpose of this matrix into this matrix. More... | |
void | fillWithBlocksDiagonally (const std::vector< const TeuchosMatrix * > &matrices) |
This function fills this matrix diagonally with const block matrices. More... | |
void | fillWithBlocksDiagonally (const std::vector< TeuchosMatrix * > &matrices) |
This function fills this matrix diagonally with block matrices. More... | |
void | fillWithBlocksHorizontally (const std::vector< const TeuchosMatrix * > &matrices) |
This function fills this matrix horizontally with const block matrices. More... | |
void | fillWithBlocksHorizontally (const std::vector< TeuchosMatrix * > &matrices) |
This function fills this matrix horizontally with block matrices. More... | |
void | fillWithBlocksVertically (const std::vector< const TeuchosMatrix * > &matrices) |
This function fills this matrix vertically with const block matrices. More... | |
void | fillWithBlocksVertically (const std::vector< TeuchosMatrix * > &matrices) |
This function fills this matrix vertically with block matrices. More... | |
void | fillWithTensorProduct (const TeuchosMatrix &mat1, const TeuchosMatrix &mat2) |
This function calculates the tensor product of matrices mat1 and mat2 and stores it in this matrix. More... | |
void | fillWithTensorProduct (const TeuchosMatrix &mat1, const TeuchosVector &vec2) |
This function calculates the tensor product of matrix mat1 and vector vec2 and stores it in this matrix. More... | |
Miscellaneous methods | |
void | mpiSum (const MpiComm &comm, TeuchosMatrix &M_global) const |
void | matlabLinearInterpExtrap (const TeuchosVector &x1Vec, const TeuchosMatrix &y1Mat, const TeuchosVector &x2Vec) |
I/O methods | |
void | print (std::ostream &os) const |
Print method. Defines the behavior of the ostream << operator inherited from the Object class. More... | |
void | subReadContents (const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds) |
Read contents of subenvironment from file fileName . More... | |
void | subWriteContents (const std::string &varNamePrefix, const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds) const |
Write contents of subenvironment in file fileName . More... | |
Public Member Functions inherited from QUESO::Matrix | |
Matrix (const BaseEnvironment &env, const Map &map) | |
Shaped constructor. More... | |
virtual | ~Matrix () |
Virtual Destructor. More... | |
const BaseEnvironment & | env () const |
const Map & | map () const |
unsigned int | numOfProcsForStorage () const |
void | setPrintHorizontally (bool value) const |
Determines whether the matrix should be printed horizontally. More... | |
bool | getPrintHorizontally () const |
Checks if matrix will be is printed horizontally. More... | |
void | setInDebugMode (bool value) const |
Determines whether QUESO will run through this class in debug mode. More... | |
bool | getInDebugMode () const |
Checks if QUESO will run through this class in debug mode. More... | |
Private Member Functions | |
TeuchosMatrix () | |
Default Constructor. More... | |
void | copy (const TeuchosMatrix &src) |
In this function this matrix receives a copy of matrix src . More... | |
void | resetLU () |
In this function resets the LU decomposition of this matrix, as well as deletes the private member pointers, if existing. More... | |
void | multiply (const TeuchosVector &x, TeuchosVector &y) const |
This function multiplies this matrix by vector x and stores the resulting vector in y . More... | |
int | internalSvd () const |
This function factorizes the M-by-N matrix A into the singular value decomposition A = U S V^T for M >= N. On output the matrix A is replaced by U. More... | |
Private Attributes | |
Teuchos::SerialDenseMatrix < int, double > | m_mat |
Teuchos matrix, also referred to as this matrix. More... | |
Teuchos::SerialDenseMatrix < int, double > | m_LU |
Teuchos matrix for the LU decomposition of m_mat. More... | |
TeuchosMatrix * | m_inverse |
Stores the inverse of this matrix. More... | |
Map * | m_svdColMap |
Mapping for matrices involved in the singular value decomposition (svd) routine. More... | |
TeuchosMatrix * | m_svdUmat |
m_svdUmat stores the M-by-N orthogonal matrix U after the singular value decomposition of a matrix. More... | |
TeuchosVector * | m_svdSvec |
m_svdSvec stores the diagonal of the N-by-N diagonal matrix of singular values S after the singular value decomposition of a matrix. More... | |
TeuchosMatrix * | m_svdVmat |
m_svdVmat stores the N-by-N orthogonal square matrix V after the singular value decomposition of a matrix. More... | |
TeuchosMatrix * | m_svdVTmat |
m_svdVmatT stores the transpose of N-by-N orthogonal square matrix V, namely V^T, after the singular value decomposition of a matrix. More... | |
double | m_determinant |
The determinant of this matrix. More... | |
double | m_lnDeterminant |
The natural logarithm of the determinant of this matrix. More... | |
TeuchosMatrix * | m_permutation |
int * | v_pivoting |
The pivoting vector of a LU decomposition. More... | |
int | m_signum |
bool | m_isSingular |
Indicates whether or not this matrix is singular. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from QUESO::Matrix | |
virtual void | base_copy (const Matrix &src) |
Copies base data from matrix src to this matrix. More... | |
Protected Attributes inherited from QUESO::Matrix | |
const BaseEnvironment & | m_env |
QUESO environment variable. More... | |
const Map | m_map |
Mapping variable. More... | |
const Map & | m_map |
Mapping variable. More... | |
bool | m_printHorizontally |
Flag for either or not print this matrix. More... | |
bool | m_inDebugMode |
Flag for either or not QUESO is in debug mode. More... | |
Class for matrix operations using Teuchos (Trilinos).
This class creates and provides basic support for matrices of templated type as a specialization of Matrix using Teuchos matrices (from Trilinos), which are defined by an encapsulated Teuchos::SerialDenseMatrix structure.
Definition at line 53 of file TeuchosMatrix.h.
QUESO::TeuchosMatrix::TeuchosMatrix | ( | const BaseEnvironment & | env, |
const Map & | map, | ||
unsigned int | numCols | ||
) |
Shaped Constructor: creates a shaped matrix with numCols
columns.
Definition at line 43 of file TeuchosMatrix.C.
References m_LU, m_mat, and QUESO::Map::NumGlobalElements().
QUESO::TeuchosMatrix::TeuchosMatrix | ( | const BaseEnvironment & | env, |
const Map & | map, | ||
double | diagValue | ||
) |
Shaped Constructor: creates a square matrix with size map.NumGlobalElements()
and diagonal values all equal to diagValue
.
Definition at line 67 of file TeuchosMatrix.C.
References m_LU, m_mat, and QUESO::Map::NumGlobalElements().
QUESO::TeuchosMatrix::TeuchosMatrix | ( | const TeuchosVector & | v, |
double | diagValue | ||
) |
Shaped Constructor: creates a square matrix with size v.sizeLocal()
and diagonal values all equal to diagValue
.
Definition at line 95 of file TeuchosMatrix.C.
References m_LU, m_mat, and QUESO::TeuchosVector::sizeLocal().
QUESO::TeuchosMatrix::TeuchosMatrix | ( | const TeuchosVector & | v | ) |
Shaped Constructor: creates a square matrix with size v.sizeLocal()
.
The diagonal values of this matrix are the elements in vector v
.
Definition at line 123 of file TeuchosMatrix.C.
References dim, m_LU, m_mat, and QUESO::TeuchosVector::sizeLocal().
QUESO::TeuchosMatrix::TeuchosMatrix | ( | const TeuchosMatrix & | B | ) |
Shaped Constructor: this
matrix is a copy of matrix B
.
Definition at line 150 of file TeuchosMatrix.C.
References QUESO::Matrix::base_copy(), copy(), m_LU, m_mat, numCols(), and numRowsLocal().
QUESO::TeuchosMatrix::~TeuchosMatrix | ( | ) |
Destructor.
Definition at line 174 of file TeuchosMatrix.C.
References resetLU().
|
private |
Default Constructor.
Creates an empty matrix vector of no dimension. It should not be used by user.
Referenced by internalSvd(), inverse(), and svdSolve().
|
virtual |
Computes Cholesky factorization of this
, a real symmetric positive definite matrix.
In case fails to be symmetric and positive definite, an error will be returned.
Implements QUESO::Matrix.
Definition at line 568 of file TeuchosMatrix.C.
References QUESO::Matrix::m_env, m_mat, QUESO::UQ_MATRIX_IS_NOT_POS_DEFINITE_RC, and QUESO::BaseEnvironment::worldRank().
|
private |
In this function this
matrix receives a copy of matrix src
.
Definition at line 1931 of file TeuchosMatrix.C.
References m_mat, numCols(), numRowsLocal(), and resetLU().
Referenced by operator=(), and TeuchosMatrix().
void QUESO::TeuchosMatrix::cwSet | ( | double | value | ) |
Component-wise set all values to this
with value.
Definition at line 1189 of file TeuchosMatrix.C.
References m_mat.
void QUESO::TeuchosMatrix::cwSet | ( | unsigned int | rowId, |
unsigned int | colId, | ||
const TeuchosMatrix & | mat | ||
) |
Set the components of which
positions are greater than (rowId,colId) with the value of mat(rowId,colId).
Definition at line 1198 of file TeuchosMatrix.C.
References numCols(), and numRowsLocal().
double QUESO::TeuchosMatrix::determinant | ( | ) | const |
Calculates the determinant of this
matrix.
Definition at line 442 of file TeuchosMatrix.C.
References QUESO::BaseEnvironment::displayVerbosity(), invertMultiply(), m_determinant, QUESO::Matrix::m_env, m_lnDeterminant, m_LU, QUESO::Matrix::m_map, and QUESO::BaseEnvironment::subDisplayFile().
void QUESO::TeuchosMatrix::eigen | ( | TeuchosVector & | eigenValues, |
TeuchosMatrix * | eigenVectors | ||
) | const |
This function computes the eigenvalues of a real symmetric matrix.
Definition at line 1039 of file TeuchosMatrix.C.
References m_mat, numRowsLocal(), QUESO::queso_require_equal_to_msg, QUESO::queso_require_not_equal_to_msg, and QUESO::TeuchosVector::sizeLocal().
void QUESO::TeuchosMatrix::fillWithBlocksDiagonally | ( | const std::vector< const TeuchosMatrix * > & | matrices | ) |
This function fills this
matrix diagonally with const block matrices.
Definition at line 1439 of file TeuchosMatrix.C.
References numCols(), numRowsLocal(), and QUESO::queso_require_equal_to_msg.
void QUESO::TeuchosMatrix::fillWithBlocksDiagonally | ( | const std::vector< TeuchosMatrix * > & | matrices | ) |
This function fills this
matrix diagonally with block matrices.
Definition at line 1469 of file TeuchosMatrix.C.
References numCols(), numRowsLocal(), and QUESO::queso_require_equal_to_msg.
void QUESO::TeuchosMatrix::fillWithBlocksHorizontally | ( | const std::vector< const TeuchosMatrix * > & | matrices | ) |
This function fills this
matrix horizontally with const block matrices.
Definition at line 1499 of file TeuchosMatrix.C.
References numCols(), numRowsLocal(), and QUESO::queso_require_equal_to_msg.
void QUESO::TeuchosMatrix::fillWithBlocksHorizontally | ( | const std::vector< TeuchosMatrix * > & | matrices | ) |
This function fills this
matrix horizontally with block matrices.
Definition at line 1526 of file TeuchosMatrix.C.
References numCols(), numRowsLocal(), and QUESO::queso_require_equal_to_msg.
void QUESO::TeuchosMatrix::fillWithBlocksVertically | ( | const std::vector< const TeuchosMatrix * > & | matrices | ) |
This function fills this
matrix vertically with const block matrices.
Definition at line 1553 of file TeuchosMatrix.C.
References numCols(), numRowsLocal(), and QUESO::queso_require_equal_to_msg.
void QUESO::TeuchosMatrix::fillWithBlocksVertically | ( | const std::vector< TeuchosMatrix * > & | matrices | ) |
This function fills this
matrix vertically with block matrices.
Definition at line 1579 of file TeuchosMatrix.C.
References numCols(), numRowsLocal(), and QUESO::queso_require_equal_to_msg.
void QUESO::TeuchosMatrix::fillWithTensorProduct | ( | const TeuchosMatrix & | mat1, |
const TeuchosMatrix & | mat2 | ||
) |
This function calculates the tensor product of matrices mat1
and mat2
and stores it in this
matrix.
Definition at line 1605 of file TeuchosMatrix.C.
References numCols(), numRowsLocal(), and QUESO::queso_require_equal_to_msg.
void QUESO::TeuchosMatrix::fillWithTensorProduct | ( | const TeuchosMatrix & | mat1, |
const TeuchosVector & | vec2 | ||
) |
This function calculates the tensor product of matrix mat1
and vector vec2
and stores it in this
matrix.
Definition at line 1628 of file TeuchosMatrix.C.
References numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, and QUESO::TeuchosVector::sizeLocal().
void QUESO::TeuchosMatrix::fillWithTranspose | ( | const TeuchosMatrix & | mat | ) |
This function stores the transpose of this
matrix into this
matrix.
Definition at line 1420 of file TeuchosMatrix.C.
References numCols(), numRowsLocal(), and QUESO::queso_require_equal_to_msg.
void QUESO::TeuchosMatrix::filterLargeValues | ( | double | thresholdValue | ) |
This function sets to zero (filters) all entries of this
matrix which are greater than thresholdValue
.
If thresholdValue
< 0 then no values will be filtered.
Definition at line 1397 of file TeuchosMatrix.C.
References numCols(), and numRowsLocal().
void QUESO::TeuchosMatrix::filterSmallValues | ( | double | thresholdValue | ) |
This function sets to zero (filters) all entries of this
matrix which are smaller than thresholdValue
.
If thresholdValue
< 0 then no values will be filtered.
Definition at line 1375 of file TeuchosMatrix.C.
References numCols(), and numRowsLocal().
void QUESO::TeuchosMatrix::getColumn | ( | const unsigned int | column_num, |
TeuchosVector & | column | ||
) | const |
This function gets the column_num-th column of this
matrix and stores it into vector column
.
Definition at line 1220 of file TeuchosMatrix.C.
References m_mat, numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, and QUESO::TeuchosVector::sizeLocal().
Referenced by getColumn(), invertMultiply(), matlabLinearInterpExtrap(), and svdSolve().
TeuchosVector QUESO::TeuchosMatrix::getColumn | ( | const unsigned int | column_num | ) | const |
This function gets the column_num-th column of this
matrix.
Definition at line 1242 of file TeuchosMatrix.C.
References getColumn(), QUESO::Matrix::m_env, and QUESO::Matrix::m_map.
void QUESO::TeuchosMatrix::getRow | ( | const unsigned int | row_num, |
TeuchosVector & | row | ||
) | const |
This function gets the row_num-th column of this
matrix and stores it into vector row
.
Definition at line 1272 of file TeuchosMatrix.C.
References m_mat, numRowsLocal(), QUESO::queso_require_equal_to_msg, and QUESO::TeuchosVector::sizeLocal().
Referenced by getRow().
TeuchosVector QUESO::TeuchosMatrix::getRow | ( | const unsigned int | row_num | ) | const |
This function gets the row_num-th column of this
matrix.
Definition at line 1289 of file TeuchosMatrix.C.
References getRow(), QUESO::Matrix::m_env, and QUESO::Matrix::m_map.
|
private |
This function factorizes the M-by-N matrix A into the singular value decomposition A = U S V^T for M >= N. On output the matrix A is replaced by U.
This function uses Teuchos GESVD computes the singular value decomposition (SVD) of a real M-by-N matrix A, optionally computing the left and/or right singular vectors. The SVD is written A = U * SIGMA * transpose(V), where SIGMA is an M-by-N matrix which is zero except for its min(m,n) diagonal elements, U is an M-by-M orthogonal matrix, and V is an N-by-N orthogonal matrix. The diagonal elements of SIGMA are the singular values of A; they are real and non-negative, and are returned in descending order. The first min(m,n) columns of U and V are the left and right singular vectors of A. Note that the routine returns V**T, not V.
Definition at line 2015 of file TeuchosMatrix.C.
References QUESO::Matrix::m_env, m_mat, m_svdColMap, m_svdSvec, m_svdUmat, m_svdVmat, m_svdVTmat, QUESO::Matrix::map(), numCols(), numRowsLocal(), stride(), TeuchosMatrix(), values(), and QUESO::TeuchosVector::values().
Referenced by rank(), svd(), svdMatU(), svdMatV(), and svdSolve().
TeuchosMatrix QUESO::TeuchosMatrix::inverse | ( | ) | const |
This function calculates the inverse of this
matrix (square).
Definition at line 392 of file TeuchosMatrix.C.
References QUESO::BaseEnvironment::checkingLevel(), QUESO::TeuchosVector::cwSet(), QUESO::BaseEnvironment::displayVerbosity(), invertMultiply(), lnDeterminant(), QUESO::Matrix::m_env, m_inverse, QUESO::Matrix::m_map, numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, QUESO::BaseEnvironment::subDisplayFile(), and TeuchosMatrix().
void QUESO::TeuchosMatrix::invertMultiply | ( | const TeuchosVector & | b, |
TeuchosVector & | x | ||
) | const |
This function calculates the inverse of this
matrix, multiplies it with vector b
and stores the result in vector x
.
It checks for a previous LU decomposition of this
matrix and does not recompute it if private attribute m_LU != NULL .
Definition at line 791 of file TeuchosMatrix.C.
References QUESO::BaseEnvironment::displayVerbosity(), QUESO::Matrix::m_env, QUESO::Matrix::m_inDebugMode, m_isSingular, m_LU, m_mat, QUESO::TeuchosVector::norm2(), numCols(), QUESO::queso_require_equal_to_msg, QUESO::queso_require_not_equal_to_msg, QUESO::TeuchosVector::sizeLocal(), QUESO::BaseEnvironment::subDisplayFile(), and v_pivoting.
Referenced by determinant(), inverse(), invertMultiply(), and lnDeterminant().
TeuchosVector QUESO::TeuchosMatrix::invertMultiply | ( | const TeuchosVector & | b | ) | const |
This function calculates the inverse of this
matrix and multiplies it with vector b
.
It calls void TeuchosMatrix::invertMultiply(const TeuchosVector& b, TeuchosVector& x) internally.
Definition at line 778 of file TeuchosMatrix.C.
References invertMultiply(), QUESO::Matrix::m_env, QUESO::Matrix::m_map, numCols(), QUESO::queso_require_equal_to_msg, and QUESO::TeuchosVector::sizeLocal().
void QUESO::TeuchosMatrix::invertMultiply | ( | const TeuchosMatrix & | B, |
TeuchosMatrix & | X | ||
) | const |
This function calculates the inverse of this
matrix, multiplies it with matrix B
and stores the result in matrix X
.
It checks for a previous LU decomposition of this
matrix and does not recompute it if private attribute m_LU
!= NULL .
Definition at line 906 of file TeuchosMatrix.C.
References getColumn(), invertMultiply(), QUESO::Matrix::m_env, QUESO::Matrix::m_map, numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, and setColumn().
TeuchosMatrix QUESO::TeuchosMatrix::invertMultiply | ( | const TeuchosMatrix & | B | ) | const |
This function calculates the inverse of this
matrix and multiplies it with matrix B
.
It calls void TeuchosMatrix::invertMultiply(const TeuchosMatrix& B, TeuchosMatrix& X) const internally.
Definition at line 896 of file TeuchosMatrix.C.
References invertMultiply(), QUESO::Matrix::m_env, QUESO::Matrix::m_map, and numCols().
void QUESO::TeuchosMatrix::invertMultiplyForceLU | ( | const TeuchosVector & | b, |
TeuchosVector & | x | ||
) | const |
This function calculates the inverse of this
matrix, multiplies it with vector b
and stores the result in vector x
.
It recalculates the LU decomposition of this
matrix.
Definition at line 941 of file TeuchosMatrix.C.
References m_isSingular, m_LU, m_mat, numCols(), QUESO::queso_require_equal_to_msg, QUESO::queso_require_not_equal_to_msg, QUESO::TeuchosVector::sizeLocal(), and v_pivoting.
Referenced by invertMultiplyForceLU().
TeuchosVector QUESO::TeuchosMatrix::invertMultiplyForceLU | ( | const TeuchosVector & | b | ) | const |
This function calculates the inverse of this
matrix and multiplies it with vector b
.
It calls void TeuchosMatrix::InvertMultiplyForceLU(const TeuchosVector& b, TeuchosVector& x) const;(const TeuchosVector& b,
TeuchosVector& x) internally.
Definition at line 928 of file TeuchosMatrix.C.
References invertMultiplyForceLU(), QUESO::Matrix::m_env, QUESO::Matrix::m_map, numCols(), QUESO::queso_require_equal_to_msg, and QUESO::TeuchosVector::sizeLocal().
void QUESO::TeuchosMatrix::largestEigen | ( | double & | eigenValue, |
TeuchosVector & | eigenVector | ||
) | const |
This function finds largest eigenvalue, namely eigenValue
, of this
matrix and its corresponding eigenvector, namely eigenVector
.
Definition at line 1097 of file TeuchosMatrix.C.
References m_mat, QUESO::queso_require_not_equal_to_msg, and QUESO::TeuchosVector::sizeLocal().
double QUESO::TeuchosMatrix::lnDeterminant | ( | ) | const |
Calculates the ln(determinant) of this
matrix.
Definition at line 491 of file TeuchosMatrix.C.
References QUESO::BaseEnvironment::displayVerbosity(), invertMultiply(), m_determinant, QUESO::Matrix::m_env, m_lnDeterminant, m_LU, QUESO::Matrix::m_map, and QUESO::BaseEnvironment::subDisplayFile().
Referenced by inverse().
void QUESO::TeuchosMatrix::matlabLinearInterpExtrap | ( | const TeuchosVector & | x1Vec, |
const TeuchosMatrix & | y1Mat, | ||
const TeuchosVector & | x2Vec | ||
) |
Definition at line 1693 of file TeuchosMatrix.C.
References getColumn(), QUESO::TeuchosVector::matlabLinearInterpExtrap(), numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, setColumn(), and QUESO::TeuchosVector::sizeLocal().
double QUESO::TeuchosMatrix::max | ( | ) | const |
Returns the maximum element value of the matrix.
Definition at line 315 of file TeuchosMatrix.C.
References numCols(), and numRowsLocal().
void QUESO::TeuchosMatrix::mpiSum | ( | const MpiComm & | comm, |
TeuchosMatrix & | M_global | ||
) | const |
Definition at line 1653 of file TeuchosMatrix.C.
References QUESO::MpiComm::Allreduce(), numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, and QUESO::size.
TeuchosVector QUESO::TeuchosMatrix::multiply | ( | const TeuchosVector & | x | ) | const |
This function multiplies this
matrix by vector x
and returns a vector.
Definition at line 765 of file TeuchosMatrix.C.
References QUESO::Matrix::m_env, QUESO::Matrix::m_map, numCols(), QUESO::queso_require_equal_to_msg, and QUESO::TeuchosVector::sizeLocal().
Referenced by QUESO::operator*().
|
private |
This function multiplies this
matrix by vector x
and stores the resulting vector in y
.
Definition at line 1993 of file TeuchosMatrix.C.
References numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, and QUESO::TeuchosVector::sizeLocal().
double QUESO::TeuchosMatrix::normFrob | ( | ) | const |
Returns the Frobenius norm of this
matrix.
Definition at line 541 of file TeuchosMatrix.C.
References m_mat.
double QUESO::TeuchosMatrix::normMax | ( | ) | const |
Returns the Frobenius norm of this
matrix.
Definition at line 548 of file TeuchosMatrix.C.
References numCols(), and numRowsLocal().
|
virtual |
Returns the column dimension of this
matrix.
Implements QUESO::Matrix.
Definition at line 290 of file TeuchosMatrix.C.
References m_mat.
Referenced by copy(), cwSet(), fillWithBlocksDiagonally(), fillWithBlocksHorizontally(), fillWithBlocksVertically(), fillWithTensorProduct(), fillWithTranspose(), filterLargeValues(), filterSmallValues(), getColumn(), internalSvd(), inverse(), invertMultiply(), invertMultiplyForceLU(), QUESO::leftDiagScaling(), matlabLinearInterpExtrap(), max(), mpiSum(), multiply(), normMax(), QUESO::operator*(), operator+=(), operator-=(), print(), rank(), QUESO::rightDiagScaling(), setColumn(), subReadContents(), subWriteContents(), svd(), svdSolve(), TeuchosMatrix(), transpose(), zeroLower(), and zeroUpper().
|
virtual |
Returns the global row dimension of this
matrix.
Implements QUESO::Matrix.
Definition at line 282 of file TeuchosMatrix.C.
References m_mat.
|
virtual |
Returns the local row dimension of this
matrix.
Implements QUESO::Matrix.
Definition at line 274 of file TeuchosMatrix.C.
References m_mat.
Referenced by copy(), cwSet(), eigen(), fillWithBlocksDiagonally(), fillWithBlocksHorizontally(), fillWithBlocksVertically(), fillWithTensorProduct(), fillWithTranspose(), filterLargeValues(), filterSmallValues(), getColumn(), getRow(), internalSvd(), inverse(), invertMultiply(), QUESO::leftDiagScaling(), matlabLinearInterpExtrap(), max(), mpiSum(), multiply(), normMax(), QUESO::operator*(), operator+=(), operator-=(), print(), rank(), QUESO::rightDiagScaling(), setColumn(), setRow(), subReadContents(), subWriteContents(), svd(), svdSolve(), TeuchosMatrix(), transpose(), zeroLower(), and zeroUpper().
double & QUESO::TeuchosMatrix::operator() | ( | unsigned int | i, |
unsigned int | j | ||
) |
Element access method (non-const).
Definition at line 244 of file TeuchosMatrix.C.
References m_mat, and resetLU().
const double & QUESO::TeuchosMatrix::operator() | ( | unsigned int | i, |
unsigned int | j | ||
) | const |
Element access method (const).
Definition at line 262 of file TeuchosMatrix.C.
References m_mat.
TeuchosMatrix & QUESO::TeuchosMatrix::operator*= | ( | double | a | ) |
Stores in this
the coordinate-wise multiplication of this
and a
.
Definition at line 192 of file TeuchosMatrix.C.
References m_mat, and resetLU().
TeuchosMatrix & QUESO::TeuchosMatrix::operator+= | ( | const TeuchosMatrix & | rhs | ) |
Stores in this
the coordinate-wise addition of this
and rhs
.
Definition at line 212 of file TeuchosMatrix.C.
References numCols(), numRowsLocal(), and resetLU().
TeuchosMatrix & QUESO::TeuchosMatrix::operator-= | ( | const TeuchosMatrix & | rhs | ) |
Stores in this
the coordinate-wise subtraction of this
by rhs
.
Definition at line 227 of file TeuchosMatrix.C.
References numCols(), numRowsLocal(), and resetLU().
TeuchosMatrix & QUESO::TeuchosMatrix::operator/= | ( | double | a | ) |
Stores in this
the coordinate-wise division of this
by a
.
Definition at line 203 of file TeuchosMatrix.C.
References m_mat, and resetLU().
TeuchosMatrix & QUESO::TeuchosMatrix::operator= | ( | const TeuchosMatrix & | rhs | ) |
Copies values from matrix rhs
to this
.
Definition at line 183 of file TeuchosMatrix.C.
References copy(), and resetLU().
|
virtual |
Print method. Defines the behavior of the ostream << operator inherited from the Object class.
Implements QUESO::Matrix.
Definition at line 1721 of file TeuchosMatrix.C.
References QUESO::Matrix::m_printHorizontally, numCols(), and numRowsLocal().
Referenced by QUESO::operator<<().
unsigned int QUESO::TeuchosMatrix::rank | ( | double | absoluteZeroThreshold, |
double | relativeZeroThreshold | ||
) | const |
This function returns the number of singular values of this
matrix (rank).
The rank function provides an estimate of the number of linearly independent rows or columns of a full matrix.
Definition at line 335 of file TeuchosMatrix.C.
References QUESO::BaseEnvironment::displayVerbosity(), internalSvd(), QUESO::Matrix::m_env, m_svdSvec, numCols(), numRowsLocal(), QUESO::TeuchosVector::sizeLocal(), and QUESO::BaseEnvironment::subDisplayFile().
|
private |
In this function resets the LU decomposition of this
matrix, as well as deletes the private member pointers, if existing.
Definition at line 1946 of file TeuchosMatrix.C.
References m_determinant, m_inverse, m_isSingular, m_lnDeterminant, m_LU, m_signum, m_svdColMap, m_svdSvec, m_svdUmat, m_svdVmat, m_svdVTmat, and v_pivoting.
Referenced by copy(), operator()(), operator*=(), operator+=(), operator-=(), operator/=(), operator=(), setColumn(), zeroLower(), zeroUpper(), and ~TeuchosMatrix().
void QUESO::TeuchosMatrix::setColumn | ( | const unsigned int | column_num, |
const TeuchosVector & | column | ||
) |
This function copies vector column
into the column_num-th column of this
matrix.
Definition at line 1255 of file TeuchosMatrix.C.
References m_mat, numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, resetLU(), and QUESO::TeuchosVector::sizeLocal().
Referenced by invertMultiply(), matlabLinearInterpExtrap(), and svdSolve().
void QUESO::TeuchosMatrix::setRow | ( | const unsigned int | row_num, |
const TeuchosVector & | row | ||
) |
This function copies vector row
into the row_num-th column of this
matrix.
Definition at line 1301 of file TeuchosMatrix.C.
References m_mat, numRowsLocal(), QUESO::queso_require_equal_to_msg, and QUESO::TeuchosVector::sizeLocal().
void QUESO::TeuchosMatrix::smallestEigen | ( | double & | eigenValue, |
TeuchosVector & | eigenVector | ||
) | const |
This function finds smallest eigenvalue, namely eigenValue
, of this
matrix and its corresponding eigenvector, namely eigenVector
.
Definition at line 1141 of file TeuchosMatrix.C.
References m_mat, QUESO::queso_require_not_equal_to_msg, and QUESO::TeuchosVector::sizeLocal().
int QUESO::TeuchosMatrix::stride | ( | ) |
Returns the stride between the columns of this matrix in memory.
Definition at line 306 of file TeuchosMatrix.C.
References m_mat.
Referenced by internalSvd(), and svdSolve().
void QUESO::TeuchosMatrix::subReadContents | ( | const std::string & | fileName, |
const std::string & | fileType, | ||
const std::set< unsigned int > & | allowedSubEnvIds | ||
) |
Read contents of subenvironment from file fileName
.
Definition at line 1751 of file TeuchosMatrix.C.
References QUESO::BaseEnvironment::closeFile(), QUESO::BaseEnvironment::fullRank(), QUESO::FilePtrSetStruct::ifsVar, QUESO::Matrix::m_env, numCols(), QUESO::Matrix::numOfProcsForStorage(), numRowsLocal(), QUESO::BaseEnvironment::openInputFile(), QUESO::queso_require_equal_to_msg, QUESO::BaseEnvironment::subDisplayFile(), and QUESO::BaseEnvironment::subRank().
void QUESO::TeuchosMatrix::subWriteContents | ( | const std::string & | varNamePrefix, |
const std::string & | fileName, | ||
const std::string & | fileType, | ||
const std::set< unsigned int > & | allowedSubEnvIds | ||
) | const |
Write contents of subenvironment in file fileName
.
Definition at line 1885 of file TeuchosMatrix.C.
References QUESO::BaseEnvironment::closeFile(), QUESO::Matrix::m_env, numCols(), QUESO::Matrix::numOfProcsForStorage(), numRowsLocal(), QUESO::FilePtrSetStruct::ofsVar, QUESO::BaseEnvironment::openOutputFile(), QUESO::BaseEnvironment::subIdString(), and QUESO::BaseEnvironment::subRank().
int QUESO::TeuchosMatrix::svd | ( | TeuchosMatrix & | matU, |
TeuchosVector & | vecS, | ||
TeuchosMatrix & | matVt | ||
) | const |
Checks for the dimension of this
matrix, matU
, VecS
and matVt
, and calls the protected routine internalSvd
to compute the singular values of this
.
Definition at line 617 of file TeuchosMatrix.C.
References internalSvd(), m_svdSvec, m_svdUmat, m_svdVTmat, numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, and QUESO::TeuchosVector::sizeLocal().
const TeuchosMatrix & QUESO::TeuchosMatrix::svdMatU | ( | ) | const |
This function calls private member TeuchosMatrix::internalSvd() to set a M-by-N orthogonal matrix U of the singular value decomposition (svd) of a general rectangular M-by-N matrix A.
A general rectangular M-by-N matrix A has a singular value decomposition (svd) into the product of an M-by-N orthogonal matrix U, an N-by-N diagonal matrix of singular values S and the transpose of an N-by-N orthogonal square matrix V, A = U S V^T.
Definition at line 639 of file TeuchosMatrix.C.
References internalSvd(), and m_svdUmat.
Referenced by svdSolve().
const TeuchosMatrix & QUESO::TeuchosMatrix::svdMatV | ( | ) | const |
This function calls private member TeuchosMatrix::internalSvd() to set a N-by-N orthogonal square matrix V of the singular value decomposition (svd) of a general rectangular M-by-N matrix A.
A general rectangular M-by-N matrix A has a singular value decomposition (svd) into the product of an M-by-N orthogonal matrix U, an N-by-N diagonal matrix of singular values S and the transpose of an N-by-N orthogonal square matrix V, A = U S V^T.
Definition at line 649 of file TeuchosMatrix.C.
References internalSvd(), and m_svdVmat.
int QUESO::TeuchosMatrix::svdSolve | ( | const TeuchosVector & | rhsVec, |
TeuchosVector & | solVec | ||
) | const |
This function solves the system A x = b using the singular value decomposition (U, S, V) of A which must have been computed previously with TeuchosMatrix::svd (x=solVec, b=rhsVec).
An orthogonal matrix A has a norm-preserving property, i.e. for any vector v,
\[ ||Av|| = ||v|| \]
Then:
\[ min( ||Ax - b||^2) = min(||Ax - b||) = min(||U D V^T x - b||) = min(||D V x - U b||)\]
Substituting
\[ y = V^T x \]
and
\[ b' = U^T b \]
gives us
\[ Dy = b'\]
with D being a diagonal matrix. Or,
\[ y = inv(D) U^T b \]
and we only have to solve the linear system:
\[ V^T x = y\]
Definition at line 667 of file TeuchosMatrix.C.
References QUESO::BaseEnvironment::displayVerbosity(), internalSvd(), QUESO::Matrix::m_env, m_svdSvec, m_svdUmat, m_svdVmat, m_svdVTmat, numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, QUESO::TeuchosVector::sizeLocal(), stride(), QUESO::BaseEnvironment::subDisplayFile(), svdMatU(), TeuchosMatrix(), transpose(), values(), and QUESO::TeuchosVector::values().
Referenced by svdSolve().
int QUESO::TeuchosMatrix::svdSolve | ( | const TeuchosMatrix & | rhsMat, |
TeuchosMatrix & | solMat | ||
) | const |
This function solves the system A x = b using the singular value decomposition (U, S, V) of A which must have been computed previously with TeuchosMatrix::svd (x=solMat, b=rhsMat).
Note that solMat is a matrix. Thus, to solve the system of equations ' * solMath = rhsMat', this method calls svdSolve(const TeuchosVector& rhsVec, TeuchosVector& solVec) passing one column of solMat with its respective column of rhsMat, .
Definition at line 735 of file TeuchosMatrix.C.
References getColumn(), QUESO::Matrix::m_env, QUESO::Matrix::map(), numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, setColumn(), and svdSolve().
TeuchosMatrix QUESO::TeuchosMatrix::transpose | ( | ) | const |
This function calculates the transpose of this
matrix (square).
Definition at line 372 of file TeuchosMatrix.C.
References QUESO::Matrix::m_env, QUESO::Matrix::m_map, numCols(), numRowsLocal(), and QUESO::queso_require_equal_to_msg.
Referenced by svdSolve().
double * QUESO::TeuchosMatrix::values | ( | ) |
Returns a pointer to the first element of this
matrix.
Definition at line 298 of file TeuchosMatrix.C.
References m_mat.
Referenced by internalSvd(), and svdSolve().
|
virtual |
This function sets all the entries above the main diagonal (inclusive or not) of this
matrix to zero.
If \c includeDiagonal = false, then only the entries above the main diagonal are set to zero;
if includeDiagonal
= true, then the elements of the matrix diagonal are also set to zero.
Implements QUESO::Matrix.
Definition at line 1318 of file TeuchosMatrix.C.
References numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, and resetLU().
|
virtual |
This function sets all the entries bellow the main diagonal (inclusive or not) of this
matrix to zero.
If \c includeDiagonal = false, then only the entries bellow the main diagonal are set to zero;
if includeDiagonal
= true, then the elements of the matrix diagonal are also set to zero.
Implements QUESO::Matrix.
Definition at line 1347 of file TeuchosMatrix.C.
References numCols(), numRowsLocal(), QUESO::queso_require_equal_to_msg, and resetLU().
|
mutableprivate |
The determinant of this
matrix.
Definition at line 376 of file TeuchosMatrix.h.
Referenced by determinant(), lnDeterminant(), and resetLU().
|
mutableprivate |
Stores the inverse of this
matrix.
Definition at line 358 of file TeuchosMatrix.h.
|
mutableprivate |
Indicates whether or not this
matrix is singular.
Definition at line 390 of file TeuchosMatrix.h.
Referenced by invertMultiply(), invertMultiplyForceLU(), and resetLU().
|
mutableprivate |
The natural logarithm of the determinant of this
matrix.
Definition at line 379 of file TeuchosMatrix.h.
Referenced by determinant(), lnDeterminant(), and resetLU().
|
mutableprivate |
Teuchos matrix for the LU decomposition of m_mat.
Definition at line 355 of file TeuchosMatrix.h.
Referenced by determinant(), invertMultiply(), invertMultiplyForceLU(), lnDeterminant(), resetLU(), and TeuchosMatrix().
|
private |
Teuchos matrix, also referred to as this
matrix.
Definition at line 352 of file TeuchosMatrix.h.
Referenced by chol(), copy(), cwSet(), eigen(), getColumn(), getRow(), internalSvd(), invertMultiply(), invertMultiplyForceLU(), largestEigen(), normFrob(), numCols(), numRowsGlobal(), numRowsLocal(), operator()(), operator*=(), operator/=(), setColumn(), setRow(), smallestEigen(), stride(), TeuchosMatrix(), and values().
|
mutableprivate |
Definition at line 381 of file TeuchosMatrix.h.
|
mutableprivate |
Definition at line 387 of file TeuchosMatrix.h.
Referenced by resetLU().
|
mutableprivate |
Mapping for matrices involved in the singular value decomposition (svd) routine.
Definition at line 361 of file TeuchosMatrix.h.
Referenced by internalSvd(), and resetLU().
|
mutableprivate |
m_svdSvec stores the diagonal of the N-by-N diagonal matrix of singular values S after the singular value decomposition of a matrix.
Definition at line 367 of file TeuchosMatrix.h.
Referenced by internalSvd(), rank(), resetLU(), svd(), and svdSolve().
|
mutableprivate |
m_svdUmat stores the M-by-N orthogonal matrix U after the singular value decomposition of a matrix.
Definition at line 364 of file TeuchosMatrix.h.
Referenced by internalSvd(), resetLU(), svd(), svdMatU(), and svdSolve().
|
mutableprivate |
m_svdVmat stores the N-by-N orthogonal square matrix V after the singular value decomposition of a matrix.
Definition at line 370 of file TeuchosMatrix.h.
Referenced by internalSvd(), resetLU(), svdMatV(), and svdSolve().
|
mutableprivate |
m_svdVmatT stores the transpose of N-by-N orthogonal square matrix V, namely V^T, after the singular value decomposition of a matrix.
Definition at line 373 of file TeuchosMatrix.h.
Referenced by internalSvd(), resetLU(), svd(), and svdSolve().
|
mutableprivate |
The pivoting vector of a LU decomposition.
Definition at line 384 of file TeuchosMatrix.h.
Referenced by invertMultiply(), invertMultiplyForceLU(), and resetLU().