queso-0.52.0
TeuchosMatrix.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // QUESO - a library to support the Quantification of Uncertainty
5 // for Estimation, Simulation and Optimization
6 //
7 // Copyright (C) 2008-2015 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 #ifndef UQ_TEUCHOS_MATRIX_H
26 #define UQ_TEUCHOS_MATRIX_H
27 
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>
33 #endif
34 
35 #include <queso/Matrix.h>
36 
37 #ifdef QUESO_HAS_TRILINOS
38 
39 namespace QUESO {
40 
53 class TeuchosMatrix : public Matrix
54 {
55 public:
57 
58 
60 
61  TeuchosMatrix();
62 
64  TeuchosMatrix(const BaseEnvironment& env,
65  const Map& map,
66  unsigned int numCols);
67 
69  TeuchosMatrix(const BaseEnvironment& env,
70  const Map& map,
71  double diagValue);
72 
74  TeuchosMatrix(const TeuchosVector& v,
75  double diagValue);
76 
78 
79  TeuchosMatrix(const TeuchosVector& v);
80 
82  TeuchosMatrix(const TeuchosMatrix& B);
83 
85  ~TeuchosMatrix();
87 
89 
90  TeuchosMatrix& operator= (const TeuchosMatrix& rhs);
92 
94  TeuchosMatrix& operator*=(double a);
95 
97  TeuchosMatrix& operator/=(double a);
98 
100  TeuchosMatrix& operator+=(const TeuchosMatrix& rhs);
102  TeuchosMatrix& operator-=(const TeuchosMatrix& rhs);
104 
106 
107  double& operator()(unsigned int i, unsigned int j);
109 
111  const double& operator()(unsigned int i, unsigned int j) const;
113 
115 
116  unsigned int numRowsLocal () const;
118 
120  unsigned int numRowsGlobal () const;
121 
123  unsigned int numCols () const;
124 
126  double* values () ;//added by Kemelli on 12/04/12
127 
129  int stride () ;//added by Kemelli on 12/04/12
130 
132  double max () const;
133 
135 
136  unsigned int rank (double absoluteZeroThreshold, double relativeZeroThreshold) const;
137 
139  TeuchosMatrix transpose () const;
140 
142  TeuchosMatrix inverse () const;
143 
145  double determinant () const;
146 
148  double lnDeterminant () const;
150 
152 
153  double normFrob () const;
155 
157  double normMax () const;
159 
161 
162 
164  int chol () ;
165 
167  int svd (TeuchosMatrix& matU, TeuchosVector& vecS, TeuchosMatrix& matVt) const;
168 
170 
171  const TeuchosMatrix& svdMatU () const;
172 
174 
175  const TeuchosMatrix& svdMatV () const;
176 
178 
182  int svdSolve (const TeuchosVector& rhsVec, TeuchosVector& solVec) const;
183 
185 
188  int svdSolve (const TeuchosMatrix& rhsMat, TeuchosMatrix& solMat) const;
189 
190 
191 
193  TeuchosVector multiply (const TeuchosVector& x) const;
194 
196 
198  void invertMultiply (const TeuchosVector& b, TeuchosVector& x) const;
199 
201 
202  TeuchosVector invertMultiply (const TeuchosVector& b) const;
203 
205 
206  void invertMultiply (const TeuchosMatrix& B, TeuchosMatrix& X) const;
207 
209 
210  TeuchosMatrix invertMultiply (const TeuchosMatrix& B) const;
211 
213 
214  void invertMultiplyForceLU (const TeuchosVector& b, TeuchosVector& x) const;
215 
217 
219  TeuchosVector invertMultiplyForceLU (const TeuchosVector& b) const;
220 
222  void eigen (TeuchosVector& eigenValues, TeuchosMatrix* eigenVectors) const;
223 
225  void largestEigen (double& eigenValue, TeuchosVector& eigenVector) const;
226 
228  void smallestEigen (double& eigenValue, TeuchosVector& eigenVector) const;
229 
231 
233 
234 
236  void cwSet (double value);
237 
239  void cwSet (unsigned int rowId, unsigned int colId, const TeuchosMatrix& mat);
240 
241 
243  void getColumn (const unsigned int column_num, TeuchosVector& column) const;
244 
246  TeuchosVector getColumn (const unsigned int column_num) const;
247 
249  void setColumn (const unsigned int column_num, const TeuchosVector& column);
250 
252  void getRow (const unsigned int row_num, TeuchosVector& row) const;
253 
255  TeuchosVector getRow (const unsigned int row_num) const;
256 
258  void setRow (const unsigned int row_num, const TeuchosVector& row);
259 
261 
263  void zeroLower (bool includeDiagonal = false);
264 
266 
268  void zeroUpper (bool includeDiagonal = false);
269 
271 
272  void filterSmallValues (double thresholdValue);
273 
275 
276  void filterLargeValues (double thresholdValue);
277 
279  void fillWithTranspose (const TeuchosMatrix& mat);
280 
282  void fillWithBlocksDiagonally (const std::vector<const TeuchosMatrix* >& matrices);
283 
285  void fillWithBlocksDiagonally (const std::vector< TeuchosMatrix* >& matrices);
286 
288  void fillWithBlocksHorizontally(const std::vector<const TeuchosMatrix* >& matrices);
289 
291  void fillWithBlocksHorizontally(const std::vector< TeuchosMatrix* >& matrices);
292 
294  void fillWithBlocksVertically (const std::vector<const TeuchosMatrix* >& matrices);
295 
297  void fillWithBlocksVertically (const std::vector< TeuchosMatrix* >& matrices);
298 
300  void fillWithTensorProduct (const TeuchosMatrix& mat1, const TeuchosMatrix& mat2);
301 
303  void fillWithTensorProduct (const TeuchosMatrix& mat1, const TeuchosVector& vec2);
305 
306 
308 
309 
310  void mpiSum (const MpiComm& comm, TeuchosMatrix& M_global) const;
311 
312  void matlabLinearInterpExtrap (const TeuchosVector& x1Vec, const TeuchosMatrix& y1Mat, const TeuchosVector& x2Vec);
314 
316 
317  void print (std::ostream& os) const;
319 
321  void subReadContents (const std::string& fileName,
322  const std::string& fileType,
323  const std::set<unsigned int>& allowedSubEnvIds);
324 
326  void subWriteContents (const std::string& varNamePrefix,
327  const std::string& fileName,
328  const std::string& fileType,
329  const std::set<unsigned int>& allowedSubEnvIds) const;
331 
332 private:
333 
335  void copy (const TeuchosMatrix& src);
336 
338  void resetLU ();
339 
341  void multiply (const TeuchosVector& x, TeuchosVector& y) const;
342 
344 
350  int internalSvd () const;
351 
353  Teuchos::SerialDenseMatrix<int,double> m_mat;
354 
356  mutable Teuchos::SerialDenseMatrix<int,double> m_LU;
357 
359  mutable TeuchosMatrix* m_inverse;
360 
362  mutable Map* m_svdColMap;
363 
365  mutable TeuchosMatrix* m_svdUmat;
366 
368  mutable TeuchosVector* m_svdSvec;
369 
371  mutable TeuchosMatrix* m_svdVmat;
372 
374  mutable TeuchosMatrix* m_svdVTmat;
375 
377  mutable double m_determinant;
378 
380  mutable double m_lnDeterminant;
381 
382  mutable TeuchosMatrix* m_permutation;
383 
385  mutable int* v_pivoting;
386 
387 
388  mutable int m_signum;
389 
391  mutable bool m_isSingular;
392 };
393 
394 TeuchosMatrix operator* (double a, const TeuchosMatrix& mat);
395 TeuchosVector operator* (const TeuchosMatrix& mat, const TeuchosVector& vec);
396 TeuchosMatrix operator* (const TeuchosMatrix& m1, const TeuchosMatrix& m2 );
397 TeuchosMatrix operator+ (const TeuchosMatrix& m1, const TeuchosMatrix& m2 );
398 TeuchosMatrix operator- (const TeuchosMatrix& m1, const TeuchosMatrix& m2 );
399 TeuchosMatrix matrixProduct (const TeuchosVector& v1, const TeuchosVector& v2 );
400 TeuchosMatrix leftDiagScaling (const TeuchosVector& vec, const TeuchosMatrix& mat);
401 TeuchosMatrix rightDiagScaling(const TeuchosMatrix& mat, const TeuchosVector& vec);
402 std::ostream& operator<< (std::ostream& os, const TeuchosMatrix& obj);
403 
404 } // End namespace QUESO
405 
406 #endif // ifdef QUESO_HAS_TRILINOS
407 
408 #endif // UQ_TEUCHOS_MATRIX_H
GslMatrix operator*(double a, const GslMatrix &mat)
Definition: GslMatrix.C:2354
GslMatrix operator-(const GslMatrix &m1, const GslMatrix &m2)
Definition: GslMatrix.C:2404
GslMatrix operator+(const GslMatrix &m1, const GslMatrix &m2)
Definition: GslMatrix.C:2397
GslMatrix rightDiagScaling(const GslMatrix &mat, const GslVector &vec)
Definition: GslMatrix.C:2454
GslMatrix matrixProduct(const GslVector &v1, const GslVector &v2)
Definition: GslMatrix.C:2411
std::ostream & operator<<(std::ostream &os, const BaseEnvironment &obj)
GslMatrix leftDiagScaling(const GslVector &vec, const GslMatrix &mat)
Definition: GslMatrix.C:2427

Generated on Thu Apr 23 2015 19:30:54 for queso-0.52.0 by  doxygen 1.8.5