Cantera
3.0.0
|
A class for full (non-sparse) matrices with Fortran-compatible data storage, which adds matrix operations to class Array2D. More...
#include <DenseMatrix.h>
A class for full (non-sparse) matrices with Fortran-compatible data storage, which adds matrix operations to class Array2D.
The dense matrix class adds matrix operations onto the Array2D class. These matrix operations are carried out by the appropriate BLAS and LAPACK routines
Error handling from BLAS and LAPACK are handled via the following formulation. Depending on a variable, a singular matrix or other terminal error condition from LAPACK is handled by either throwing an exception or by returning the error code condition to the calling routine.
The int variable, m_useReturnErrorCode, determines which method is used. The default value of zero means that an exception is thrown. A value of 1 means that a return code is used.
Reporting of these LAPACK error conditions is handled by the class variable m_printLevel. The default is for no reporting. If m_printLevel is nonzero, the error condition is reported to Cantera's log file.
Definition at line 54 of file DenseMatrix.h.
Public Member Functions | |
DenseMatrix ()=default | |
Default Constructor. | |
DenseMatrix (size_t n, size_t m, double v=0.0) | |
Constructor. | |
DenseMatrix (const DenseMatrix &y) | |
DenseMatrix & | operator= (const DenseMatrix &y) |
void | resize (size_t n, size_t m, double v=0.0) override |
Resize the matrix. | |
virtual double *const * | colPts () |
const double *const * | const_colPts () const |
Return a const vector of const pointers to the columns. | |
virtual void | mult (const double *b, double *prod) const |
virtual void | mult (const DenseMatrix &b, DenseMatrix &prod) const |
Multiply A*B and write result to prod . | |
virtual void | leftMult (const double *const b, double *const prod) const |
Left-multiply the matrix by transpose(b), and write the result to prod. | |
vector< int > & | ipiv () |
Return a changeable value of the pivot vector. | |
const vector< int > & | ipiv () const |
Return a changeable value of the pivot vector. | |
Public Member Functions inherited from Array2D | |
Array2D ()=default | |
Default constructor. | |
Array2D (const size_t m, const size_t n, const double v=0.0) | |
Constructor. | |
Array2D (const size_t m, const size_t n, const double *values) | |
Constructor. | |
Array2D (const Array2D &y) | |
Array2D & | operator= (const Array2D &y) |
virtual void | resize (size_t n, size_t m, double v=0.0) |
Resize the array, and fill the new entries with 'v'. | |
void | appendColumn (const vector< double > &c) |
Append a column to the existing matrix using a std vector. | |
void | appendColumn (const double *const c) |
Append a column to the existing matrix. | |
void | setRow (size_t n, const double *const rw) |
Set the nth row to array rw. | |
void | getRow (size_t n, double *const rw) |
Get the nth row and return it in a vector. | |
void | setColumn (size_t m, double *const col) |
Set the values in column m to those in array col. | |
void | getColumn (size_t m, double *const col) |
Get the values in column m. | |
void | zero () |
Set all of the entries to zero. | |
double & | operator() (size_t i, size_t j) |
Allows setting elements using the syntax A(i,j) = x. | |
double | operator() (size_t i, size_t j) const |
Allows retrieving elements using the syntax x = A(i,j). | |
double & | value (size_t i, size_t j) |
Returns a changeable reference to position in the matrix. | |
double | value (size_t i, size_t j) const |
Returns the value of a single matrix entry. | |
size_t | nRows () const |
Number of rows. | |
size_t | nColumns () const |
Number of columns. | |
iterator | begin () |
Return an iterator pointing to the first element. | |
iterator | end () |
Return an iterator pointing past the last element. | |
const_iterator | begin () const |
Return a const iterator pointing to the first element. | |
const_iterator | end () const |
Return a const iterator pointing to past the last element. | |
vector< double > & | data () |
Return a reference to the data vector. | |
const vector< double > & | data () const |
Return a const reference to the data vector. | |
void | operator*= (double a) |
double * | ptrColumn (size_t j) |
Return a pointer to the top of column j, columns are contiguous in memory. | |
const double * | ptrColumn (size_t j) const |
Return a const pointer to the top of column j, columns are contiguous in memory. | |
Public Attributes | |
int | m_useReturnErrorCode = 0 |
Error Handling Flag. | |
int | m_printLevel = 0 |
Print Level. | |
Protected Attributes | |
vector< int > | m_ipiv |
Vector of pivots. Length is equal to the max of m and n. | |
vector< double * > | m_colPts |
Vector of column pointers. | |
Protected Attributes inherited from Array2D | |
vector< double > | m_data |
Data stored in a single array. | |
size_t | m_nrows = 0 |
Number of rows. | |
size_t | m_ncols = 0 |
Number of columns. | |
Additional Inherited Members | |
Public Types inherited from Array2D | |
typedef vector< double >::iterator | iterator |
Type definition for the iterator class that is can be used by Array2D types. | |
typedef vector< double >::const_iterator | const_iterator |
Type definition for the const_iterator class that is can be used by Array2D types. | |
|
default |
Default Constructor.
DenseMatrix | ( | size_t | n, |
size_t | m, | ||
double | v = 0.0 |
||
) |
Constructor.
Create an n
by m
matrix, and initialize all elements to v
.
n | New number of rows |
m | New number of columns |
v | Default fill value. defaults to zero. |
Definition at line 20 of file DenseMatrix.cpp.
DenseMatrix | ( | const DenseMatrix & | y | ) |
Definition at line 32 of file DenseMatrix.cpp.
DenseMatrix & operator= | ( | const DenseMatrix & | y | ) |
Definition at line 44 of file DenseMatrix.cpp.
|
overridevirtual |
Resize the matrix.
Resize the matrix to n rows by m cols.
n | New number of rows |
m | New number of columns |
v | Default fill value. defaults to zero. |
Reimplemented from Array2D.
Definition at line 60 of file DenseMatrix.cpp.
|
virtual |
Definition at line 72 of file DenseMatrix.cpp.
const double *const * const_colPts | ( | ) | const |
Return a const vector of const pointers to the columns.
Note, the Jacobian can not be altered by this routine, and therefore the member function is const.
Definition at line 77 of file DenseMatrix.cpp.
|
virtual |
Definition at line 82 of file DenseMatrix.cpp.
|
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 |
Definition at line 97 of file DenseMatrix.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 |
Definition at line 117 of file DenseMatrix.cpp.
vector< int > & ipiv | ( | ) |
Return a changeable value of the pivot vector.
Definition at line 128 of file DenseMatrix.cpp.
|
inline |
Return a changeable value of the pivot vector.
Definition at line 123 of file DenseMatrix.h.
|
protected |
Vector of pivots. Length is equal to the max of m and n.
Definition at line 129 of file DenseMatrix.h.
|
protected |
Vector of column pointers.
Definition at line 132 of file DenseMatrix.h.
int m_useReturnErrorCode = 0 |
Error Handling Flag.
The default is to set this to 0. In this case, if a factorization is requested and can't be achieved, a CESingularMatrix exception is triggered. No return code is used, because an exception is thrown. If this is set to 1, then an exception is not thrown. Routines return with an error code, that is up to the calling routine to handle correctly. Negative return codes always throw an exception.
Definition at line 144 of file DenseMatrix.h.
int m_printLevel = 0 |
Print Level.
Printing is done to the log file using the routine writelogf().
Level of printing that is carried out. Only error conditions are printed out, if this value is nonzero.
Definition at line 153 of file DenseMatrix.h.