Cantera
2.3.0
|
A class for full (non-sparse) matrices with Fortran-compatible data storage. More...
#include <SquareMatrix.h>
Public Member Functions | |
SquareMatrix () | |
Base Constructor. More... | |
SquareMatrix (size_t n, doublereal v=0.0) | |
Constructor. More... | |
SquareMatrix (const SquareMatrix &right) | |
SquareMatrix & | operator= (const SquareMatrix &right) |
int | solve (doublereal *b, size_t nrhs=1, size_t ldb=0) |
Solves the Ax = b system returning x in the b spot. More... | |
void | resize (size_t n, size_t m, doublereal v=0.0) |
void | zero () |
Zero the matrix. More... | |
virtual void | mult (const doublereal *b, doublereal *prod) const |
virtual void | mult (const DenseMatrix &b, DenseMatrix &prod) const |
Multiply A*B and write result to prod . More... | |
virtual void | leftMult (const doublereal *const b, doublereal *const prod) const |
Left-multiply the matrix by transpose(b), and write the result to prod. More... | |
int | factor () |
Factors the A matrix, overwriting A. More... | |
virtual int | factorQR () |
Factors the A matrix using the QR algorithm, overwriting A. More... | |
virtual doublereal | rcondQR () |
Returns an estimate of the inverse of the condition number for the matrix. More... | |
virtual doublereal | rcond (doublereal a1norm) |
Returns an estimate of the inverse of the condition number for the matrix. More... | |
virtual doublereal | oneNorm () const |
Calculate the one norm of the matrix. More... | |
int | solveQR (doublereal *b) |
Solves the linear problem Ax=b using the QR algorithm returning x in the b spot. More... | |
void | setFactorFlag () |
set the factored flag More... | |
virtual void | useFactorAlgorithm (int fAlgorithm) |
Change the way the matrix is factored. More... | |
virtual int | factorAlgorithm () const |
Returns the factor algorithm used. More... | |
virtual doublereal * | ptrColumn (size_t j) |
Return a pointer to the top of column j, columns are assumed to be contiguous in memory. More... | |
virtual doublereal & | operator() (size_t i, size_t j) |
Index into the (i,j) element. More... | |
virtual doublereal | operator() (size_t i, size_t j) const |
Constant Index into the (i,j) element. More... | |
virtual size_t | nRows () const |
Return the number of rows in the matrix. More... | |
size_t | nRowsAndStruct (size_t *const iStruct=0) const |
Return the size and structure of the matrix. More... | |
virtual GeneralMatrix * | duplMyselfAsGeneralMatrix () const |
Duplicator member function. More... | |
virtual vector_fp::iterator | begin () |
Return an iterator pointing to the first element. More... | |
virtual vector_fp::const_iterator | begin () const |
Return a const iterator pointing to the first element. More... | |
virtual doublereal *const * | colPts () |
virtual size_t | checkRows (doublereal &valueSmall) const |
Check to see if we have any zero rows in the Jacobian. More... | |
virtual size_t | checkColumns (doublereal &valueSmall) const |
Check to see if we have any zero columns in the Jacobian. More... | |
Public Member Functions inherited from DenseMatrix | |
DenseMatrix () | |
Default Constructor. More... | |
DenseMatrix (size_t n, size_t m, doublereal v=0.0) | |
Constructor. More... | |
DenseMatrix (const DenseMatrix &y) | |
DenseMatrix & | operator= (const DenseMatrix &y) |
void | resize (size_t n, size_t m, doublereal v=0.0) |
Resize the matrix. More... | |
const doublereal *const * | const_colPts () const |
Return a const vector of const pointers to the columns. More... | |
vector_int & | ipiv () |
Return a changeable value of the pivot vector. More... | |
const vector_int & | ipiv () const |
Return a changeable value of the pivot vector. More... | |
Public Member Functions inherited from Array2D | |
Array2D () | |
Default constructor. More... | |
Array2D (const size_t m, const size_t n, const doublereal v=0.0) | |
Constructor. More... | |
Array2D (const size_t m, const size_t n, const doublereal *values) | |
Constructor. More... | |
Array2D (const Array2D &y) | |
Array2D & | operator= (const Array2D &y) |
void | resize (size_t n, size_t m, doublereal v=0.0) |
Resize the array, and fill the new entries with 'v'. More... | |
void | appendColumn (const vector_fp &c) |
Append a column to the existing matrix using a std vector. More... | |
void | appendColumn (const doublereal *const c) |
Append a column to the existing matrix. More... | |
void | setRow (size_t n, const doublereal *const rw) |
Set the nth row to array rw. More... | |
void | getRow (size_t n, doublereal *const rw) |
Get the nth row and return it in a vector. More... | |
void | setColumn (size_t m, doublereal *const col) |
Set the values in column m to those in array col. More... | |
void | getColumn (size_t m, doublereal *const col) |
Get the values in column m. More... | |
void | axpy (doublereal a, const Array2D &x, const Array2D &y) |
Evaluate z = a*x + y. More... | |
void | zero () |
Set all of the entries to zero. More... | |
doublereal & | operator() (size_t i, size_t j) |
Allows setting elements using the syntax A(i,j) = x. More... | |
doublereal | operator() (size_t i, size_t j) const |
Allows retrieving elements using the syntax x = A(i,j). More... | |
doublereal & | value (size_t i, size_t j) |
Returns a changeable reference to position in the matrix. More... | |
doublereal | value (size_t i, size_t j) const |
Returns the value of a single matrix entry. More... | |
size_t | nRows () const |
Number of rows. More... | |
size_t | nColumns () const |
Number of columns. More... | |
iterator | begin () |
Return an iterator pointing to the first element. More... | |
iterator | end () |
Return an iterator pointing past the last element. More... | |
const_iterator | begin () const |
Return a const iterator pointing to the first element. More... | |
const_iterator | end () const |
Return a const iterator pointing to past the last element. More... | |
vector_fp & | data () |
Return a reference to the data vector. More... | |
const vector_fp & | data () const |
Return a const reference to the data vector. More... | |
doublereal * | ptrColumn (size_t j) |
Return a pointer to the top of column j, columns are contiguous in memory. More... | |
const doublereal * | ptrColumn (size_t j) const |
Return a const pointer to the top of column j, columns are contiguous in memory. More... | |
Public Member Functions inherited from GeneralMatrix | |
GeneralMatrix (int matType=-1) | |
Base Constructor. More... | |
virtual void | clearFactorFlag () |
clear the factored flag More... | |
virtual bool | factored () const |
true if the current factorization is up to date with the matrix More... | |
Public Attributes | |
vector_fp | tau |
Work vector for QR algorithm. More... | |
vector_fp | work |
Work vector for QR algorithm. More... | |
vector_int | iwork_ |
Integer work vector for QR algorithms. More... | |
Public Attributes inherited from DenseMatrix | |
int | m_useReturnErrorCode |
Error Handling Flag. More... | |
int | m_printLevel |
Print Level. More... | |
Protected Attributes | |
doublereal | a1norm_ |
1-norm of the matrix. More... | |
int | useQR_ |
Use the QR algorithm to factor and invert the matrix. More... | |
Protected Attributes inherited from DenseMatrix | |
vector_int | m_ipiv |
Vector of pivots. Length is equal to the max of m and n. More... | |
std::vector< doublereal * > | m_colPts |
Vector of column pointers. More... | |
Protected Attributes inherited from Array2D | |
vector_fp | m_data |
Data stored in a single array. More... | |
size_t | m_nrows |
Number of rows. More... | |
size_t | m_ncols |
Number of columns. More... | |
Protected Attributes inherited from GeneralMatrix | |
int | m_factored |
Indicates whether the matrix is factored. More... | |
Additional Inherited Members | |
Public Types inherited from Array2D | |
typedef vector_fp::iterator | iterator |
Type definition for the iterator class that is can be used by Array2D types. More... | |
typedef vector_fp::const_iterator | const_iterator |
Type definition for the const_iterator class that is can be used by Array2D types. More... | |
A class for full (non-sparse) matrices with Fortran-compatible data storage.
Adds matrix inversion operations to this class from DenseMatrix.
Definition at line 20 of file SquareMatrix.h.
SquareMatrix | ( | ) |
Base Constructor.
Definition at line 17 of file SquareMatrix.cpp.
References Cantera::warn_deprecated().
Referenced by SquareMatrix::duplMyselfAsGeneralMatrix().
SquareMatrix | ( | size_t | n, |
doublereal | v = 0.0 |
||
) |
Constructor.
Create an n
by n
matrix, and initialize all elements to v
.
n | size of the square matrix |
v | initial value of all matrix components. |
Definition at line 25 of file SquareMatrix.cpp.
References Cantera::warn_deprecated().
|
virtual |
Solves the Ax = b system returning x in the b spot.
b | Vector for the RHS of the equation system |
nrhs | Number of right-hand sides to solve, default 1 |
ldb | Leading dimension of the right-hand side array. Defaults to nRows() |
Implements GeneralMatrix.
Definition at line 54 of file SquareMatrix.cpp.
|
virtual |
Zero the matrix.
Implements GeneralMatrix.
Definition at line 92 of file SquareMatrix.cpp.
References Array2D::m_data.
|
virtual |
Multiply A*B and write result to prod
.
Take this matrix to be of size NxM.
[in] | b | DenseMatrix B of size MxP |
[out] | prod | DenseMatrix prod size NxP |
Reimplemented from DenseMatrix.
Definition at line 107 of file SquareMatrix.cpp.
|
virtual |
Left-multiply the matrix by transpose(b), and write the result to prod.
b | left multiply by this vector. The length must be equal to n the number of rows in the matrix. |
prod | Resulting vector. This is of length m, the number of columns in the matrix |
Reimplemented from DenseMatrix.
Definition at line 112 of file SquareMatrix.cpp.
|
virtual |
Factors the A matrix, overwriting A.
We flip m_factored boolean to indicate that the matrix is now A-1.
Implements GeneralMatrix.
Definition at line 117 of file SquareMatrix.cpp.
References SquareMatrix::a1norm_, SquareMatrix::begin(), Array2D::data(), SquareMatrix::factorQR(), DenseMatrix::ipiv(), GeneralMatrix::m_factored, Array2D::m_nrows, DenseMatrix::m_printLevel, DenseMatrix::m_useReturnErrorCode, SquareMatrix::nRows(), SquareMatrix::useQR_, and Cantera::writelogf().
|
virtual |
Factors the A matrix using the QR algorithm, overwriting A.
we set m_factored to 2 to indicate the matrix is now QR factored
Reimplemented from GeneralMatrix.
Definition at line 148 of file SquareMatrix.cpp.
References SquareMatrix::a1norm_, SquareMatrix::begin(), GeneralMatrix::m_factored, Array2D::m_nrows, DenseMatrix::m_printLevel, DenseMatrix::m_useReturnErrorCode, SquareMatrix::tau, SquareMatrix::work, and Cantera::writelogf().
Referenced by SquareMatrix::factor().
|
virtual |
Returns an estimate of the inverse of the condition number for the matrix.
The matrix must have been previously factored using the QR algorithm
Reimplemented from GeneralMatrix.
Definition at line 269 of file SquareMatrix.cpp.
References Cantera::ct_dtrcon(), SquareMatrix::iwork_, GeneralMatrix::m_factored, Array2D::m_nrows, SquareMatrix::rcond(), and SquareMatrix::work.
|
virtual |
Returns an estimate of the inverse of the condition number for the matrix.
The matrix must have been previously factored using the LU algorithm
a1norm | Norm of the matrix |
Implements GeneralMatrix.
Definition at line 232 of file SquareMatrix.cpp.
References SquareMatrix::begin(), SquareMatrix::iwork_, GeneralMatrix::m_factored, Array2D::m_nrows, DenseMatrix::m_printLevel, DenseMatrix::m_useReturnErrorCode, SquareMatrix::work, and Cantera::writelogf().
Referenced by SquareMatrix::rcondQR().
|
virtual |
Calculate the one norm of the matrix.
Implements GeneralMatrix.
Definition at line 264 of file SquareMatrix.cpp.
References SquareMatrix::a1norm_.
int solveQR | ( | doublereal * | b | ) |
Solves the linear problem Ax=b using the QR algorithm returning x in the b spot.
b | RHS to be solved. |
Definition at line 179 of file SquareMatrix.cpp.
void setFactorFlag | ( | ) |
set the factored flag
Definition at line 143 of file SquareMatrix.cpp.
References GeneralMatrix::m_factored.
|
virtual |
Change the way the matrix is factored.
fAlgorithm | integer 0 LU factorization 1 QR factorization |
Reimplemented from GeneralMatrix.
Definition at line 301 of file SquareMatrix.cpp.
References SquareMatrix::useQR_.
|
virtual |
Returns the factor algorithm used.
0 LU decomposition 1 QR decomposition
This routine will always return 0
Implements GeneralMatrix.
Definition at line 306 of file SquareMatrix.cpp.
References SquareMatrix::useQR_.
|
virtual |
Return a pointer to the top of column j, columns are assumed to be contiguous in memory.
j | Value of the column |
Implements GeneralMatrix.
Definition at line 311 of file SquareMatrix.cpp.
References Array2D::ptrColumn().
|
inlinevirtual |
Index into the (i,j) element.
i | row |
j | column |
Implements GeneralMatrix.
Definition at line 80 of file SquareMatrix.h.
References Array2D::operator()().
|
inlinevirtual |
Constant Index into the (i,j) element.
i | row |
j | column |
Implements GeneralMatrix.
Definition at line 84 of file SquareMatrix.h.
References Array2D::operator()().
|
virtual |
Return the number of rows in the matrix.
Implements GeneralMatrix.
Definition at line 316 of file SquareMatrix.cpp.
References Array2D::m_nrows.
Referenced by SquareMatrix::factor().
|
virtual |
Return the size and structure of the matrix.
This is inherited from GeneralMatrix
iStruct | OUTPUT Pointer to a vector of ints that describe the structure of the matrix. not used |
Implements GeneralMatrix.
Definition at line 321 of file SquareMatrix.cpp.
References Array2D::m_nrows, and Cantera::warn_deprecated().
|
virtual |
Duplicator member function.
This function will duplicate the matrix given a generic GeneralMatrix
Implements GeneralMatrix.
Definition at line 328 of file SquareMatrix.cpp.
References SquareMatrix::SquareMatrix().
|
virtual |
Return an iterator pointing to the first element.
We might drop this later
Implements GeneralMatrix.
Definition at line 333 of file SquareMatrix.cpp.
References Array2D::m_data.
Referenced by SquareMatrix::factor(), SquareMatrix::factorQR(), and SquareMatrix::rcond().
|
virtual |
Return a const iterator pointing to the first element.
We might drop this later
Implements GeneralMatrix.
Definition at line 338 of file SquareMatrix.cpp.
References Array2D::m_data.
|
virtual |
Check to see if we have any zero rows in the Jacobian.
This utility routine checks to see if any rows are zero. The smallest row is returned along with the largest coefficient in that row
valueSmall | OUTPUT value of the largest coefficient in the smallest row |
Implements GeneralMatrix.
Definition at line 348 of file SquareMatrix.cpp.
References Array2D::m_nrows, Cantera::npos, and Array2D::value().
|
virtual |
Check to see if we have any zero columns in the Jacobian.
This utility routine checks to see if any columns are zero. The smallest column is returned along with the largest coefficient in that column
valueSmall | OUTPUT value of the largest coefficient in the smallest column |
Implements GeneralMatrix.
Definition at line 365 of file SquareMatrix.cpp.
References Array2D::m_nrows, Cantera::npos, and Array2D::value().
vector_fp tau |
Work vector for QR algorithm.
Definition at line 113 of file SquareMatrix.h.
Referenced by SquareMatrix::factorQR().
vector_fp work |
Work vector for QR algorithm.
Definition at line 116 of file SquareMatrix.h.
Referenced by SquareMatrix::factorQR(), SquareMatrix::rcond(), and SquareMatrix::rcondQR().
vector_int iwork_ |
Integer work vector for QR algorithms.
Definition at line 119 of file SquareMatrix.h.
Referenced by SquareMatrix::rcond(), and SquareMatrix::rcondQR().
|
protected |
1-norm of the matrix.
This is determined immediately before every factorization
Definition at line 123 of file SquareMatrix.h.
Referenced by SquareMatrix::factor(), SquareMatrix::factorQR(), and SquareMatrix::oneNorm().
|
protected |
Use the QR algorithm to factor and invert the matrix.
Definition at line 126 of file SquareMatrix.h.
Referenced by SquareMatrix::factor(), SquareMatrix::factorAlgorithm(), and SquareMatrix::useFactorAlgorithm().