25 #ifndef UQ_TEUCHOS_MATRIX_H
26 #define UQ_TEUCHOS_MATRIX_H
28 #ifdef QUESO_HAS_TRILINOS
29 #include <queso/TeuchosVector.h>
30 #include <Teuchos_SerialDenseVector.hpp>
31 #include <Teuchos_SerialDenseMatrix.hpp>
32 #include <Teuchos_LAPACK.hpp>
35 #include <queso/Matrix.h>
37 #ifdef QUESO_HAS_TRILINOS
103 double&
operator()(
unsigned int i,
unsigned int j);
107 const double&
operator()(
unsigned int i,
unsigned int j)
const;
132 unsigned int rank (
double absoluteZeroThreshold,
double relativeZeroThreshold)
const;
232 void cwSet (
double value);
259 void zeroLower (
bool includeDiagonal =
false);
264 void zeroUpper (
bool includeDiagonal =
false);
313 void print (std::ostream& os)
const;
318 const std::string& fileType,
319 const std::set<unsigned int>& allowedSubEnvIds);
323 const std::string& fileName,
324 const std::string& fileType,
325 const std::set<unsigned int>& allowedSubEnvIds)
const;
352 Teuchos::SerialDenseMatrix<int,double>
m_mat;
355 mutable Teuchos::SerialDenseMatrix<int,double>
m_LU;
405 #endif // ifdef QUESO_HAS_TRILINOS
407 #endif // UQ_TEUCHOS_MATRIX_H
void cwSet(double value)
Component-wise set all values to this with value.
TeuchosMatrix & operator-=(const TeuchosMatrix &rhs)
Stores in this the coordinate-wise subtraction of this by rhs.
unsigned int numRowsLocal() const
Returns the local row dimension of this matrix.
void fillWithBlocksHorizontally(const std::vector< const TeuchosMatrix * > &matrices)
This function fills this matrix horizontally with const block matrices.
TeuchosMatrix()
Default Constructor.
double normFrob() const
Returns the Frobenius norm of this matrix.
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 intern...
int stride()
Returns the stride between the columns of this matrix in memory.
A class for partitioning vectors and matrices.
const BaseEnvironment & env() const
const TeuchosMatrix & svdMatV() const
This function calls private member TeuchosMatrix::internalSvd() to set a N-by-N orthogonal square mat...
Map * m_svdColMap
Mapping for matrices involved in the singular value decomposition (svd) routine.
void invertMultiplyForceLU(const TeuchosVector &b, TeuchosVector &x) const
This function calculates the inverse of this matrix, multiplies it with vector b and stores the resul...
void eigen(TeuchosVector &eigenValues, TeuchosMatrix *eigenVectors) const
This function computes the eigenvalues of a real symmetric matrix.
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Teuchos::SerialDenseMatrix< int, double > m_LU
Teuchos matrix for the LU decomposition of m_mat.
TeuchosMatrix * m_svdVmat
m_svdVmat stores the N-by-N orthogonal square matrix V after the singular value decomposition of a ma...
TeuchosMatrix * m_svdUmat
m_svdUmat stores the M-by-N orthogonal matrix U after the singular value decomposition of a matrix...
double m_lnDeterminant
The natural logarithm of the determinant of this matrix.
~TeuchosMatrix()
Destructor.
const TeuchosMatrix & svdMatU() const
This function calls private member TeuchosMatrix::internalSvd() to set a M-by-N orthogonal matrix U o...
int chol()
Computes Cholesky factorization of this, a real symmetric positive definite matrix.
void setColumn(const unsigned int column_num, const TeuchosVector &column)
This function copies vector column into the column_num-th column of this matrix.
TeuchosMatrix & operator*=(double a)
Stores in this the coordinate-wise multiplication of this and a.
std::ostream & operator<<(std::ostream &os, const SequenceStatisticalOptions &obj)
TeuchosMatrix inverse() const
This function calculates the inverse of this matrix (square).
unsigned int numRowsGlobal() const
Returns the global row dimension of this matrix.
GslMatrix operator-(const GslMatrix &m1, const GslMatrix &m2)
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.
void fillWithTranspose(const TeuchosMatrix &mat)
This function stores the transpose of this matrix into this matrix.
TeuchosMatrix * m_inverse
Stores the inverse of this matrix.
TeuchosMatrix * m_permutation
void setRow(const unsigned int row_num, const TeuchosVector &row)
This function copies vector row into the row_num-th column of this matrix.
void zeroUpper(bool includeDiagonal=false)
This function sets all the entries bellow the main diagonal (inclusive or not) of this matrix to zero...
void largestEigen(double &eigenValue, TeuchosVector &eigenVector) const
This function finds largest eigenvalue, namely eigenValue, of this matrix and its corresponding eigen...
TeuchosVector multiply(const TeuchosVector &x) const
This function multiplies this matrix by vector x and returns a vector.
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...
double determinant() const
Calculates the determinant of this matrix.
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...
double normMax() const
Returns the Frobenius norm of this matrix.
int internalSvd() const
This function factorizes the M-by-N matrix A into the singular value decomposition A = U S V^T for M ...
void zeroLower(bool includeDiagonal=false)
This function sets all the entries above the main diagonal (inclusive or not) of this matrix to zero...
double * values()
Returns a pointer to the first element of this matrix.
TeuchosMatrix & operator+=(const TeuchosMatrix &rhs)
Stores in this the coordinate-wise addition of this and rhs.
int * v_pivoting
The pivoting vector of a LU decomposition.
Class for matrix operations (virtual).
TeuchosVector * m_svdSvec
m_svdSvec stores the diagonal of the N-by-N diagonal matrix of singular values S after the singular v...
GslMatrix operator*(double a, const GslMatrix &mat)
void matlabLinearInterpExtrap(const TeuchosVector &x1Vec, const TeuchosMatrix &y1Mat, const TeuchosVector &x2Vec)
void filterSmallValues(double thresholdValue)
This function sets to zero (filters) all entries of this matrix which are smaller than thresholdValue...
Teuchos::SerialDenseMatrix< int, double > m_mat
Teuchos matrix, also referred to as this matrix.
TeuchosMatrix & operator=(const TeuchosMatrix &rhs)
Copies values from matrix rhs to this.
TeuchosMatrix transpose() const
This function calculates the transpose of this matrix (square).
Class for vector operations using Teuchos (Trilinos).
void resetLU()
In this function resets the LU decomposition of this matrix, as well as deletes the private member po...
TeuchosMatrix * m_svdVTmat
m_svdVmatT stores the transpose of N-by-N orthogonal square matrix V, namely V^T, after the singular ...
bool m_isSingular
Indicates whether or not this matrix is singular.
void fillWithBlocksVertically(const std::vector< const TeuchosMatrix * > &matrices)
This function fills this matrix vertically with const block matrices.
double m_determinant
The determinant of this matrix.
GslMatrix matrixProduct(const GslVector &v1, const GslVector &v2)
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...
double max() const
Returns the maximum element value of the matrix.
void mpiSum(const MpiComm &comm, TeuchosMatrix &M_global) const
double lnDeterminant() const
Calculates the ln(determinant) of this matrix.
unsigned int numCols() const
Returns the column dimension of this matrix.
The QUESO MPI Communicator Class.
void print(std::ostream &os) const
Print method. Defines the behavior of the ostream << operator inherited from the Object class...
void subReadContents(const std::string &fileName, const std::string &fileType, const std::set< unsigned int > &allowedSubEnvIds)
Read contents of subenvironment from file fileName.
TeuchosMatrix & operator/=(double a)
Stores in this the coordinate-wise division of this by a.
void copy(const TeuchosMatrix &src)
In this function this matrix receives a copy of matrix src.
double & operator()(unsigned int i, unsigned int j)
Element access method (non-const).
GslMatrix leftDiagScaling(const GslVector &vec, const GslMatrix &mat)
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).
unsigned int rank(double absoluteZeroThreshold, double relativeZeroThreshold) const
This function returns the number of singular values of this matrix (rank).
GslMatrix rightDiagScaling(const GslMatrix &mat, const GslVector &vec)
void smallestEigen(double &eigenValue, TeuchosVector &eigenVector) const
This function finds smallest eigenvalue, namely eigenValue, of this matrix and its corresponding eige...
void invertMultiply(const TeuchosVector &b, TeuchosVector &x) const
This function calculates the inverse of this matrix, multiplies it with vector b and stores the resul...
Class for matrix operations using Teuchos (Trilinos).
GslMatrix operator+(const GslMatrix &m1, const GslMatrix &m2)
void filterLargeValues(double thresholdValue)
This function sets to zero (filters) all entries of this matrix which are greater than thresholdValue...
void fillWithBlocksDiagonally(const std::vector< const TeuchosMatrix * > &matrices)
This function fills this matrix diagonally with const block matrices.