Cantera
2.1.2
|
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) | |
Copy Constructor. More... | |
SquareMatrix & | operator= (const SquareMatrix &right) |
Assignment operator. More... | |
int | solve (doublereal *b) |
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... | |
virtual void | clearFactorFlag () |
clear the factored flag More... | |
void | setFactorFlag () |
set the factored flag More... | |
virtual bool | factored () const |
true if the current factorization is up to date with the matrix 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 void | copyData (const GeneralMatrix &y) |
Copy the data from one array into another without doing any checking. 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) | |
Copy constructor. More... | |
DenseMatrix & | operator= (const DenseMatrix &y) |
Assignment operator. More... | |
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) | |
Copy constructor. More... | |
Array2D & | operator= (const Array2D &y) |
assignment operator More... | |
void | resize (size_t n, size_t m, doublereal v=0.0) |
Resize the array, and fill the new entries with 'v'. More... | |
void | copyData (const Array2D &y) |
Copy the data from one array into another without doing any checking. 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... | |
virtual | ~Array2D () |
Destructor. 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) | |
Base Constructor. More... | |
GeneralMatrix (const GeneralMatrix &right) | |
Copy Constructor. More... | |
GeneralMatrix & | operator= (const GeneralMatrix &right) |
Assignment operator. More... | |
virtual | ~GeneralMatrix () |
Destructor. Does nothing. More... | |
Public Attributes | |
vector_fp | tau |
Work vector for QR algorithm. More... | |
vector_fp | work |
Work vector for QR algorithm. More... | |
std::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... | |
Public Attributes inherited from GeneralMatrix | |
int | matrixType_ |
Matrix type. More... | |
Protected Attributes | |
int | m_factored |
the factor flag More... | |
doublereal | a1norm_ |
1-norm of the matrix. This is determined immediately before every factorization 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... | |
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 26 of file SquareMatrix.h.
SquareMatrix | ( | ) |
Base Constructor.
Definition at line 22 of file SquareMatrix.cpp.
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 31 of file SquareMatrix.cpp.
SquareMatrix | ( | const SquareMatrix & | right | ) |
Copy Constructor.
Definition at line 41 of file SquareMatrix.cpp.
SquareMatrix & operator= | ( | const SquareMatrix & | right | ) |
Assignment operator.
Definition at line 50 of file SquareMatrix.cpp.
References SquareMatrix::a1norm_, SquareMatrix::m_factored, GeneralMatrix::operator=(), DenseMatrix::operator=(), and SquareMatrix::useQR_.
|
virtual |
Solves the Ax = b system returning x in the b spot.
b | Vector for the rhs of the equation system |
Implements GeneralMatrix.
Definition at line 63 of file SquareMatrix.cpp.
References SquareMatrix::begin(), DATA_PTR, SquareMatrix::factor(), Cantera::int2str(), DenseMatrix::ipiv(), SquareMatrix::m_factored, DenseMatrix::m_printLevel, DenseMatrix::m_useReturnErrorCode, Array2D::nColumns(), SquareMatrix::nRows(), SquareMatrix::solveQR(), SquareMatrix::useQR_, and Cantera::writelogf().
|
virtual |
Zero the matrix.
Implements GeneralMatrix.
Definition at line 95 of file SquareMatrix.cpp.
References Array2D::m_data, and SquareMatrix::nRows().
|
virtual |
Multiply A*B and write result to prod
.
b | input DenseMatrix B of size NxN |
prod | output output DenseMatrix prod size NxN |
Reimplemented from DenseMatrix.
Definition at line 119 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 124 of file SquareMatrix.cpp.
References DenseMatrix::leftMult().
|
virtual |
Factors the A matrix, overwriting A.
Implements GeneralMatrix.
Definition at line 129 of file SquareMatrix.cpp.
References SquareMatrix::a1norm_, SquareMatrix::begin(), DATA_PTR, SquareMatrix::factorQR(), Cantera::int2str(), DenseMatrix::ipiv(), SquareMatrix::m_factored, Array2D::m_nrows, DenseMatrix::m_printLevel, DenseMatrix::m_useReturnErrorCode, SquareMatrix::nRows(), SquareMatrix::useQR_, and Cantera::writelogf().
Referenced by SquareMatrix::solve().
|
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
Implements GeneralMatrix.
Definition at line 160 of file SquareMatrix.cpp.
References SquareMatrix::a1norm_, SquareMatrix::begin(), DATA_PTR, Cantera::int2str(), SquareMatrix::m_factored, Array2D::m_nrows, DenseMatrix::m_printLevel, DenseMatrix::m_useReturnErrorCode, SquareMatrix::tau, SquareMatrix::work, and Cantera::writelogf().
Referenced by SquareMatrix::factor(), and SquareMatrix::solveQR().
|
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
Implements GeneralMatrix.
Definition at line 277 of file SquareMatrix.cpp.
References SquareMatrix::begin(), Cantera::ct_dtrcon(), DATA_PTR, Cantera::int2str(), SquareMatrix::iwork_, SquareMatrix::m_factored, Array2D::m_nrows, DenseMatrix::m_printLevel, DenseMatrix::m_useReturnErrorCode, SquareMatrix::rcond(), SquareMatrix::work, and Cantera::writelogf().
|
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 241 of file SquareMatrix.cpp.
References SquareMatrix::begin(), DATA_PTR, Cantera::int2str(), SquareMatrix::iwork_, SquareMatrix::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 272 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 188 of file SquareMatrix.cpp.
References SquareMatrix::begin(), DATA_PTR, SquareMatrix::factorQR(), Cantera::int2str(), SquareMatrix::m_factored, Array2D::m_nrows, DenseMatrix::m_printLevel, DenseMatrix::m_useReturnErrorCode, SquareMatrix::tau, SquareMatrix::work, and Cantera::writelogf().
Referenced by SquareMatrix::solve().
|
virtual |
clear the factored flag
Implements GeneralMatrix.
Definition at line 150 of file SquareMatrix.cpp.
References SquareMatrix::m_factored.
void setFactorFlag | ( | ) |
set the factored flag
Definition at line 155 of file SquareMatrix.cpp.
References SquareMatrix::m_factored.
|
virtual |
true if the current factorization is up to date with the matrix
Implements GeneralMatrix.
Definition at line 315 of file SquareMatrix.cpp.
References SquareMatrix::m_factored.
|
virtual |
Change the way the matrix is factored.
fAlgorithm | integer 0 LU factorization 1 QR factorization |
Implements GeneralMatrix.
Definition at line 305 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 310 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 320 of file SquareMatrix.cpp.
References Array2D::ptrColumn().
|
inlinevirtual |
Index into the (i,j) element.
i | row |
j | column |
Returns a changeable reference to the matrix entry
Implements GeneralMatrix.
Definition at line 91 of file SquareMatrix.h.
References Array2D::operator()().
|
virtual |
Copy the data from one array into another without doing any checking.
This differs from the assignment operator as no resizing is done and memcpy() is used.
y | Array to be copied |
Implements GeneralMatrix.
Definition at line 325 of file SquareMatrix.cpp.
References Array2D::copyData().
|
inlinevirtual |
Constant Index into the (i,j) element.
i | row |
j | column |
Returns an unchangeable reference to the matrix entry
Implements GeneralMatrix.
Definition at line 97 of file SquareMatrix.h.
References Array2D::operator()().
|
virtual |
Return the number of rows in the matrix.
Implements GeneralMatrix.
Definition at line 331 of file SquareMatrix.cpp.
References Array2D::m_nrows.
Referenced by SquareMatrix::factor(), SquareMatrix::solve(), and SquareMatrix::zero().
|
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 336 of file SquareMatrix.cpp.
References Array2D::m_nrows.
|
virtual |
Duplicator member function.
This function will duplicate the matrix given a generic GeneralMatrix
Implements GeneralMatrix.
Definition at line 341 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 346 of file SquareMatrix.cpp.
References Array2D::m_data.
Referenced by SquareMatrix::factor(), SquareMatrix::factorQR(), SquareMatrix::rcond(), SquareMatrix::rcondQR(), SquareMatrix::solve(), and SquareMatrix::solveQR().
|
virtual |
Return a const iterator pointing to the first element.
We might drop this later
Implements GeneralMatrix.
Definition at line 351 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 361 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 380 of file SquareMatrix.cpp.
References Array2D::m_nrows, Cantera::npos, and Array2D::value().
|
protected |
the factor flag
Definition at line 126 of file SquareMatrix.h.
Referenced by SquareMatrix::clearFactorFlag(), SquareMatrix::factor(), SquareMatrix::factored(), SquareMatrix::factorQR(), SquareMatrix::operator=(), SquareMatrix::rcond(), SquareMatrix::rcondQR(), SquareMatrix::setFactorFlag(), SquareMatrix::solve(), and SquareMatrix::solveQR().
vector_fp tau |
Work vector for QR algorithm.
Definition at line 130 of file SquareMatrix.h.
Referenced by SquareMatrix::factorQR(), and SquareMatrix::solveQR().
vector_fp work |
Work vector for QR algorithm.
Definition at line 133 of file SquareMatrix.h.
Referenced by SquareMatrix::factorQR(), SquareMatrix::rcond(), SquareMatrix::rcondQR(), and SquareMatrix::solveQR().
std::vector<int> iwork_ |
Integer work vector for QR algorithms.
Definition at line 136 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 139 of file SquareMatrix.h.
Referenced by SquareMatrix::factor(), SquareMatrix::factorQR(), SquareMatrix::oneNorm(), and SquareMatrix::operator=().
|
protected |
Use the QR algorithm to factor and invert the matrix.
Definition at line 142 of file SquareMatrix.h.
Referenced by SquareMatrix::factor(), SquareMatrix::factorAlgorithm(), SquareMatrix::operator=(), SquareMatrix::solve(), and SquareMatrix::useFactorAlgorithm().