Cantera  2.3.0
SquareMatrix.h
Go to the documentation of this file.
1 //! @file SquareMatrix.h Dense, Square (not sparse) matrices.
2
3 // This file is part of Cantera. See License.txt in the top-level directory or
5
6 #ifndef CT_SQUAREMATRIX_H
7 #define CT_SQUAREMATRIX_H
8
9 #include "DenseMatrix.h"
10 #include "GeneralMatrix.h"
11
12 namespace Cantera
13 {
14
15 /**
16  * A class for full (non-sparse) matrices with Fortran-compatible data storage.
17  * Adds matrix inversion operations to this class from DenseMatrix.
18  * @deprecated Use class DenseMatrix instead. To be removed after Cantera 2.3.
19  */
20 class SquareMatrix: public DenseMatrix, public GeneralMatrix
21 {
22 public:
23  //! Base Constructor.
24  SquareMatrix();
25
26  //! Constructor.
27  /*!
28  * Create an \c n by \c n matrix, and initialize all elements to \c v.
29  *
30  * @param n size of the square matrix
31  * @param v initial value of all matrix components.
32  */
33  SquareMatrix(size_t n, doublereal v = 0.0);
34
35  SquareMatrix(const SquareMatrix& right);
36  SquareMatrix& operator=(const SquareMatrix& right);
37
38  int solve(doublereal* b, size_t nrhs=1, size_t ldb=0);
39
40  void resize(size_t n, size_t m, doublereal v = 0.0);
41
42  //! Zero the matrix
43  void zero();
44
45  virtual void mult(const doublereal* b, doublereal* prod) const;
46  virtual void mult(const DenseMatrix& b, DenseMatrix& prod) const;
47  virtual void leftMult(const doublereal* const b, doublereal* const prod) const;
48
49  int factor();
50  virtual int factorQR();
51
52  virtual doublereal rcondQR();
53  virtual doublereal rcond(doublereal a1norm);
54
55  virtual doublereal oneNorm() const;
56
57  //! Solves the linear problem Ax=b using the QR algorithm returning x in the
58  //! b spot
59  /*!
60  * @param b RHS to be solved.
61  */
62  int solveQR(doublereal* b);
63
64  //! set the factored flag
65  void setFactorFlag();
66
67  virtual void useFactorAlgorithm(int fAlgorithm);
68
69  //! Returns the factor algorithm used
70  /*!
71  * 0 LU decomposition
72  * 1 QR decomposition
73  *
74  * This routine will always return 0
75  */
76  virtual int factorAlgorithm() const;
77
78  virtual doublereal* ptrColumn(size_t j);
79
80  virtual doublereal& operator()(size_t i, size_t j) {
81  return Array2D::operator()(i, j);
82  }
83
84  virtual doublereal operator()(size_t i, size_t j) const {
85  return Array2D::operator()(i, j);
86  }
87
88  virtual size_t nRows() const;
89
90  //! Return the size and structure of the matrix
91  /*!
92  * This is inherited from GeneralMatrix
93  *
94  * @param iStruct OUTPUT Pointer to a vector of ints that describe the
95  * structure of the matrix. not used
96  *
97  * @returns the number of rows and columns in the matrix.
98  * @deprecated Unused. To be removed after Cantera 2.3.
99  */
100  size_t nRowsAndStruct(size_t* const iStruct = 0) const;
101
102  virtual GeneralMatrix* duplMyselfAsGeneralMatrix() const;
103
104  virtual vector_fp::iterator begin();
105  virtual vector_fp::const_iterator begin() const;
106
107  virtual doublereal* const* colPts();
108
109  virtual size_t checkRows(doublereal& valueSmall) const;
110  virtual size_t checkColumns(doublereal& valueSmall) const;
111
112  //! Work vector for QR algorithm
114
115  //! Work vector for QR algorithm
117
118  //! Integer work vector for QR algorithms
120 protected:
121  //! 1-norm of the matrix. This is determined immediately before every
122  //! factorization
123  doublereal a1norm_;
124
125  //! Use the QR algorithm to factor and invert the matrix
126  int useQR_;
127 };
128 }
129
130 #endif
virtual size_t checkRows(doublereal &valueSmall) const
Check to see if we have any zero rows in the Jacobian.
virtual doublereal rcond(doublereal a1norm)
Returns an estimate of the inverse of the condition number for the matrix.
vector_fp work
Work vector for QR algorithm.
Definition: SquareMatrix.h:116
virtual size_t checkColumns(doublereal &valueSmall) const
Check to see if we have any zero columns in the Jacobian.
virtual doublereal operator()(size_t i, size_t j) const
Constant Index into the (i,j) element.
Definition: SquareMatrix.h:84
Generic matrix.
Definition: GeneralMatrix.h:21
std::vector< int > vector_int
Vector of ints.
Definition: ct_defs.h:159
size_t nRowsAndStruct(size_t *const iStruct=0) const
Return the size and structure of the matrix.
vector_fp tau
Work vector for QR algorithm.
Definition: SquareMatrix.h:113
virtual vector_fp::iterator begin()
Return an iterator pointing to the first element.
int solve(doublereal *b, size_t nrhs=1, size_t ldb=0)
Solves the Ax = b system returning x in the b spot.
virtual size_t nRows() const
Return the number of rows in the matrix.
virtual doublereal & operator()(size_t i, size_t j)
Index into the (i,j) element.
Definition: SquareMatrix.h:80
void zero()
Zero the matrix.
A class for full (non-sparse) matrices with Fortran-compatible data storage.
Definition: SquareMatrix.h:20
int factor()
Factors the A matrix, overwriting A.
virtual int factorAlgorithm() const
Returns the factor algorithm used.
virtual void useFactorAlgorithm(int fAlgorithm)
Change the way the matrix is factored.
int solveQR(doublereal *b)
Solves the linear problem Ax=b using the QR algorithm returning x in the b spot.
virtual GeneralMatrix * duplMyselfAsGeneralMatrix() const
Duplicator member function.
doublereal & operator()(size_t i, size_t j)
Allows setting elements using the syntax A(i,j) = x.
Definition: Array.h:230
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:157
Headers for the DenseMatrix object, which deals with dense rectangular matrices and description of th...
vector_int iwork_
Integer work vector for QR algorithms.
Definition: SquareMatrix.h:119
virtual doublereal oneNorm() const
Calculate the one norm of the matrix.
virtual doublereal * ptrColumn(size_t j)
Return a pointer to the top of column j, columns are assumed to be contiguous in memory.
Declarations for the class GeneralMatrix which is a virtual base class for matrices handled by solver...
virtual void leftMult(const doublereal *const b, doublereal *const prod) const
Left-multiply the matrix by transpose(b), and write the result to prod.
virtual doublereal rcondQR()
Returns an estimate of the inverse of the condition number for the matrix.
int useQR_
Use the QR algorithm to factor and invert the matrix.
Definition: SquareMatrix.h:126
void setFactorFlag()
set the factored flag
Namespace for the Cantera kernel.
Definition: application.cpp:29
doublereal a1norm_
1-norm of the matrix.
Definition: SquareMatrix.h:123
SquareMatrix()
Base Constructor.
A class for full (non-sparse) matrices with Fortran-compatible data storage, which adds matrix operat...
Definition: DenseMatrix.h:72
virtual int factorQR()
Factors the A matrix using the QR algorithm, overwriting A.