queso-0.53.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  TeuchosMatrix(const BaseEnvironment& env,
61  const Map& map,
62  unsigned int numCols);
63 
65  TeuchosMatrix(const BaseEnvironment& env,
66  const Map& map,
67  double diagValue);
68 
70  TeuchosMatrix(const TeuchosVector& v,
71  double diagValue);
72 
74 
75  TeuchosMatrix(const TeuchosVector& v);
76 
78  TeuchosMatrix(const TeuchosMatrix& B);
79 
81  ~TeuchosMatrix();
83 
85 
86  TeuchosMatrix& operator= (const TeuchosMatrix& rhs);
88 
90  TeuchosMatrix& operator*=(double a);
91 
93  TeuchosMatrix& operator/=(double a);
94 
96  TeuchosMatrix& operator+=(const TeuchosMatrix& rhs);
98  TeuchosMatrix& operator-=(const TeuchosMatrix& rhs);
100 
102 
103  double& operator()(unsigned int i, unsigned int j);
105 
107  const double& operator()(unsigned int i, unsigned int j) const;
109 
111 
112  unsigned int numRowsLocal () const;
114 
116  unsigned int numRowsGlobal () const;
117 
119  unsigned int numCols () const;
120 
122  double* values () ;//added by Kemelli on 12/04/12
123 
125  int stride () ;//added by Kemelli on 12/04/12
126 
128  double max () const;
129 
131 
132  unsigned int rank (double absoluteZeroThreshold, double relativeZeroThreshold) const;
133 
135  TeuchosMatrix transpose () const;
136 
138  TeuchosMatrix inverse () const;
139 
141  double determinant () const;
142 
144  double lnDeterminant () const;
146 
148 
149  double normFrob () const;
151 
153  double normMax () const;
155 
157 
158 
160  int chol () ;
161 
163  int svd (TeuchosMatrix& matU, TeuchosVector& vecS, TeuchosMatrix& matVt) const;
164 
166 
167  const TeuchosMatrix& svdMatU () const;
168 
170 
171  const TeuchosMatrix& svdMatV () const;
172 
174 
178  int svdSolve (const TeuchosVector& rhsVec, TeuchosVector& solVec) const;
179 
181 
184  int svdSolve (const TeuchosMatrix& rhsMat, TeuchosMatrix& solMat) const;
185 
186 
187 
189  TeuchosVector multiply (const TeuchosVector& x) const;
190 
192 
194  void invertMultiply (const TeuchosVector& b, TeuchosVector& x) const;
195 
197 
198  TeuchosVector invertMultiply (const TeuchosVector& b) const;
199 
201 
202  void invertMultiply (const TeuchosMatrix& B, TeuchosMatrix& X) const;
203 
205 
206  TeuchosMatrix invertMultiply (const TeuchosMatrix& B) const;
207 
209 
210  void invertMultiplyForceLU (const TeuchosVector& b, TeuchosVector& x) const;
211 
213 
215  TeuchosVector invertMultiplyForceLU (const TeuchosVector& b) const;
216 
218  void eigen (TeuchosVector& eigenValues, TeuchosMatrix* eigenVectors) const;
219 
221  void largestEigen (double& eigenValue, TeuchosVector& eigenVector) const;
222 
224  void smallestEigen (double& eigenValue, TeuchosVector& eigenVector) const;
225 
227 
229 
230 
232  void cwSet (double value);
233 
235  void cwSet (unsigned int rowId, unsigned int colId, const TeuchosMatrix& mat);
236 
237 
239  void getColumn (const unsigned int column_num, TeuchosVector& column) const;
240 
242  TeuchosVector getColumn (const unsigned int column_num) const;
243 
245  void setColumn (const unsigned int column_num, const TeuchosVector& column);
246 
248  void getRow (const unsigned int row_num, TeuchosVector& row) const;
249 
251  TeuchosVector getRow (const unsigned int row_num) const;
252 
254  void setRow (const unsigned int row_num, const TeuchosVector& row);
255 
257 
259  void zeroLower (bool includeDiagonal = false);
260 
262 
264  void zeroUpper (bool includeDiagonal = false);
265 
267 
268  void filterSmallValues (double thresholdValue);
269 
271 
272  void filterLargeValues (double thresholdValue);
273 
275  void fillWithTranspose (const TeuchosMatrix& mat);
276 
278  void fillWithBlocksDiagonally (const std::vector<const TeuchosMatrix* >& matrices);
279 
281  void fillWithBlocksDiagonally (const std::vector< TeuchosMatrix* >& matrices);
282 
284  void fillWithBlocksHorizontally(const std::vector<const TeuchosMatrix* >& matrices);
285 
287  void fillWithBlocksHorizontally(const std::vector< TeuchosMatrix* >& matrices);
288 
290  void fillWithBlocksVertically (const std::vector<const TeuchosMatrix* >& matrices);
291 
293  void fillWithBlocksVertically (const std::vector< TeuchosMatrix* >& matrices);
294 
296  void fillWithTensorProduct (const TeuchosMatrix& mat1, const TeuchosMatrix& mat2);
297 
299  void fillWithTensorProduct (const TeuchosMatrix& mat1, const TeuchosVector& vec2);
301 
302 
304 
305 
306  void mpiSum (const MpiComm& comm, TeuchosMatrix& M_global) const;
307 
308  void matlabLinearInterpExtrap (const TeuchosVector& x1Vec, const TeuchosMatrix& y1Mat, const TeuchosVector& x2Vec);
310 
312 
313  void print (std::ostream& os) const;
315 
317  void subReadContents (const std::string& fileName,
318  const std::string& fileType,
319  const std::set<unsigned int>& allowedSubEnvIds);
320 
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;
327 
328 private:
330 
331  TeuchosMatrix();
332 
334  void copy (const TeuchosMatrix& src);
335 
337  void resetLU ();
338 
340  void multiply (const TeuchosVector& x, TeuchosVector& y) const;
341 
343 
349  int internalSvd () const;
350 
352  Teuchos::SerialDenseMatrix<int,double> m_mat;
353 
355  mutable Teuchos::SerialDenseMatrix<int,double> m_LU;
356 
358  mutable TeuchosMatrix* m_inverse;
359 
361  mutable Map* m_svdColMap;
362 
364  mutable TeuchosMatrix* m_svdUmat;
365 
367  mutable TeuchosVector* m_svdSvec;
368 
370  mutable TeuchosMatrix* m_svdVmat;
371 
373  mutable TeuchosMatrix* m_svdVTmat;
374 
376  mutable double m_determinant;
377 
379  mutable double m_lnDeterminant;
380 
381  mutable TeuchosMatrix* m_permutation;
382 
384  mutable int* v_pivoting;
385 
386 
387  mutable int m_signum;
388 
390  mutable bool m_isSingular;
391 };
392 
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);
402 
403 } // End namespace QUESO
404 
405 #endif // ifdef QUESO_HAS_TRILINOS
406 
407 #endif // UQ_TEUCHOS_MATRIX_H
GslMatrix operator*(double a, const GslMatrix &mat)
Definition: GslMatrix.C:1972
GslMatrix leftDiagScaling(const GslVector &vec, const GslMatrix &mat)
Definition: GslMatrix.C:2042
std::ostream & operator<<(std::ostream &os, const BaseEnvironment &obj)
GslMatrix operator+(const GslMatrix &m1, const GslMatrix &m2)
Definition: GslMatrix.C:2012
GslMatrix rightDiagScaling(const GslMatrix &mat, const GslVector &vec)
Definition: GslMatrix.C:2063
GslMatrix matrixProduct(const GslVector &v1, const GslVector &v2)
Definition: GslMatrix.C:2026
GslMatrix operator-(const GslMatrix &m1, const GslMatrix &m2)
Definition: GslMatrix.C:2019
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
Definition: License.txt:60

Generated on Thu Jun 11 2015 13:52:31 for queso-0.53.0 by  doxygen 1.8.5