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
53 class TeuchosMatrix :
public Matrix
60 TeuchosMatrix(
const BaseEnvironment& env,
62 unsigned int numCols);
65 TeuchosMatrix(
const BaseEnvironment& env,
70 TeuchosMatrix(
const TeuchosVector& v,
75 TeuchosMatrix(
const TeuchosVector& v);
78 TeuchosMatrix(
const TeuchosMatrix& B);
86 TeuchosMatrix& operator= (
const TeuchosMatrix& rhs);
90 TeuchosMatrix& operator*=(
double a);
93 TeuchosMatrix& operator/=(
double a);
96 TeuchosMatrix& operator+=(
const TeuchosMatrix& rhs);
98 TeuchosMatrix& operator-=(
const TeuchosMatrix& rhs);
103 double& operator()(
unsigned int i,
unsigned int j);
107 const double& operator()(
unsigned int i,
unsigned int j)
const;
112 unsigned int numRowsLocal ()
const;
116 unsigned int numRowsGlobal ()
const;
119 unsigned int numCols ()
const;
132 unsigned int rank (
double absoluteZeroThreshold,
double relativeZeroThreshold)
const;
135 TeuchosMatrix transpose ()
const;
138 TeuchosMatrix inverse ()
const;
141 double determinant ()
const;
144 double lnDeterminant ()
const;
149 double normFrob ()
const;
153 double normMax ()
const;
163 int svd (TeuchosMatrix& matU, TeuchosVector& vecS, TeuchosMatrix& matVt)
const;
167 const TeuchosMatrix& svdMatU ()
const;
171 const TeuchosMatrix& svdMatV ()
const;
178 int svdSolve (
const TeuchosVector& rhsVec, TeuchosVector& solVec)
const;
184 int svdSolve (
const TeuchosMatrix& rhsMat, TeuchosMatrix& solMat)
const;
189 TeuchosVector multiply (
const TeuchosVector& x)
const;
194 void invertMultiply (
const TeuchosVector& b, TeuchosVector& x)
const;
198 TeuchosVector invertMultiply (
const TeuchosVector& b)
const;
202 void invertMultiply (
const TeuchosMatrix& B, TeuchosMatrix& X)
const;
206 TeuchosMatrix invertMultiply (
const TeuchosMatrix& B)
const;
210 void invertMultiplyForceLU (
const TeuchosVector& b, TeuchosVector& x)
const;
215 TeuchosVector invertMultiplyForceLU (
const TeuchosVector& b)
const;
218 void eigen (TeuchosVector& eigenValues, TeuchosMatrix* eigenVectors)
const;
221 void largestEigen (
double& eigenValue, TeuchosVector& eigenVector)
const;
224 void smallestEigen (
double& eigenValue, TeuchosVector& eigenVector)
const;
232 void cwSet (
double value);
235 void cwSet (
unsigned int rowId,
unsigned int colId,
const TeuchosMatrix& mat);
239 void getColumn (
const unsigned int column_num, TeuchosVector& column)
const;
242 TeuchosVector getColumn (
const unsigned int column_num)
const;
245 void setColumn (
const unsigned int column_num,
const TeuchosVector& column);
248 void getRow (
const unsigned int row_num, TeuchosVector& row)
const;
251 TeuchosVector getRow (
const unsigned int row_num)
const;
254 void setRow (
const unsigned int row_num,
const TeuchosVector& row);
259 void zeroLower (
bool includeDiagonal =
false);
264 void zeroUpper (
bool includeDiagonal =
false);
268 void filterSmallValues (
double thresholdValue);
272 void filterLargeValues (
double thresholdValue);
275 void fillWithTranspose (
const TeuchosMatrix& mat);
278 void fillWithBlocksDiagonally (
const std::vector<const TeuchosMatrix* >& matrices);
281 void fillWithBlocksDiagonally (
const std::vector< TeuchosMatrix* >& matrices);
284 void fillWithBlocksHorizontally(
const std::vector<const TeuchosMatrix* >& matrices);
287 void fillWithBlocksHorizontally(
const std::vector< TeuchosMatrix* >& matrices);
290 void fillWithBlocksVertically (
const std::vector<const TeuchosMatrix* >& matrices);
293 void fillWithBlocksVertically (
const std::vector< TeuchosMatrix* >& matrices);
296 void fillWithTensorProduct (
const TeuchosMatrix& mat1,
const TeuchosMatrix& mat2);
299 void fillWithTensorProduct (
const TeuchosMatrix& mat1,
const TeuchosVector& vec2);
306 void mpiSum (
const MpiComm& comm, TeuchosMatrix& M_global)
const;
308 void matlabLinearInterpExtrap (
const TeuchosVector& x1Vec,
const TeuchosMatrix& y1Mat,
const TeuchosVector& x2Vec);
313 void print (std::ostream& os)
const;
317 void subReadContents (
const std::string& fileName,
318 const std::string& fileType,
319 const std::set<unsigned int>& allowedSubEnvIds);
322 void subWriteContents (
const std::string& varNamePrefix,
323 const std::string& fileName,
324 const std::string& fileType,
325 const std::set<unsigned int>& allowedSubEnvIds)
const;
334 void copy (
const TeuchosMatrix& src);
340 void multiply (
const TeuchosVector& x, TeuchosVector& y)
const;
349 int internalSvd ()
const;
352 Teuchos::SerialDenseMatrix<int,double> m_mat;
355 mutable Teuchos::SerialDenseMatrix<int,double> m_LU;
358 mutable TeuchosMatrix* m_inverse;
361 mutable Map* m_svdColMap;
364 mutable TeuchosMatrix* m_svdUmat;
367 mutable TeuchosVector* m_svdSvec;
370 mutable TeuchosMatrix* m_svdVmat;
373 mutable TeuchosMatrix* m_svdVTmat;
376 mutable double m_determinant;
379 mutable double m_lnDeterminant;
381 mutable TeuchosMatrix* m_permutation;
384 mutable int* v_pivoting;
387 mutable int m_signum;
390 mutable bool m_isSingular;
393 TeuchosMatrix
operator* (
double a,
const TeuchosMatrix& mat);
394 TeuchosVector
operator* (
const TeuchosMatrix& mat,
const TeuchosVector& vec);
395 TeuchosMatrix
operator* (
const TeuchosMatrix& m1,
const TeuchosMatrix& m2 );
396 TeuchosMatrix
operator+ (
const TeuchosMatrix& m1,
const TeuchosMatrix& m2 );
397 TeuchosMatrix
operator- (
const TeuchosMatrix& m1,
const TeuchosMatrix& m2 );
398 TeuchosMatrix
matrixProduct (
const TeuchosVector& v1,
const TeuchosVector& v2 );
399 TeuchosMatrix
leftDiagScaling (
const TeuchosVector& vec,
const TeuchosMatrix& mat);
400 TeuchosMatrix
rightDiagScaling(
const TeuchosMatrix& mat,
const TeuchosVector& vec);
401 std::ostream&
operator<< (std::ostream& os,
const TeuchosMatrix& obj);
405 #endif // ifdef QUESO_HAS_TRILINOS
407 #endif // UQ_TEUCHOS_MATRIX_H
GslMatrix operator*(double a, const GslMatrix &mat)
GslMatrix leftDiagScaling(const GslVector &vec, const GslMatrix &mat)
std::ostream & operator<<(std::ostream &os, const BaseEnvironment &obj)
GslMatrix operator+(const GslMatrix &m1, const GslMatrix &m2)
GslMatrix rightDiagScaling(const GslMatrix &mat, const GslVector &vec)
GslMatrix matrixProduct(const GslVector &v1, const GslVector &v2)
GslMatrix operator-(const GslMatrix &m1, const GslMatrix &m2)
and that you are informed that you can do these things To protect your we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it For if you distribute copies of the whether gratis or for a you must give the recipients all the rights that we gave you You must make sure that receive or can get the source code If you link other code with the you must provide complete object files to the so that they can relink them with the library after making changes to the library and recompiling it And you must show them these terms so they know their rights We protect your rights with a two step which gives you legal permission to copy