Cantera
2.1.2
|
A class for full (non-sparse) matrices with Fortran-compatible data storage, which adds matrix operations to class Array2D. More...
#include <DenseMatrix.h>
Public Member Functions | |
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... | |
virtual doublereal *const * | colPts () |
const doublereal *const * | const_colPts () const |
Return a const vector of const pointers to the columns. More... | |
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 . More... | |
virtual void | leftMult (const double *const b, double *const prod) const |
Left-multiply the matrix by transpose(b), and write the result to prod. 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 Attributes | |
int | m_useReturnErrorCode |
Error Handling Flag. More... | |
int | m_printLevel |
Print Level. More... | |
Protected Attributes | |
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... | |
Friends | |
int | solve (DenseMatrix &A, double *b) |
Solve Ax = b. Array b is overwritten on exit with x. More... | |
int | solve (DenseMatrix &A, DenseMatrix &b) |
Solve Ax = b for multiple right-hand-side vectors. More... | |
int | invert (DenseMatrix &A, int nn) |
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, 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 of type, CELapackError, 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 70 of file DenseMatrix.h.
DenseMatrix | ( | ) |
Default Constructor.
Definition at line 17 of file DenseMatrix.cpp.
DenseMatrix | ( | size_t | n, |
size_t | m, | ||
doublereal | 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 25 of file DenseMatrix.cpp.
References DenseMatrix::m_colPts, Array2D::m_data, DenseMatrix::m_ipiv, and Array2D::m_nrows.
DenseMatrix | ( | const DenseMatrix & | y | ) |
Copy constructor.
y | Object to be copied |
Definition at line 40 of file DenseMatrix.cpp.
References DenseMatrix::ipiv(), DenseMatrix::m_colPts, Array2D::m_data, DenseMatrix::m_ipiv, Array2D::m_ncols, and Array2D::m_nrows.
DenseMatrix & operator= | ( | const DenseMatrix & | y | ) |
Assignment operator.
y | Object to be copied |
Definition at line 55 of file DenseMatrix.cpp.
References DenseMatrix::ipiv(), DenseMatrix::m_colPts, Array2D::m_data, DenseMatrix::m_ipiv, Array2D::m_ncols, Array2D::m_nrows, DenseMatrix::m_printLevel, DenseMatrix::m_useReturnErrorCode, and Array2D::operator=().
Referenced by SquareMatrix::operator=().
void resize | ( | size_t | n, |
size_t | m, | ||
doublereal | v = 0.0 |
||
) |
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. |
Definition at line 71 of file DenseMatrix.cpp.
References DenseMatrix::m_colPts, Array2D::m_data, DenseMatrix::m_ipiv, Array2D::m_ncols, Array2D::m_nrows, and Array2D::resize().
Referenced by LTI_Pairwise_Interaction::getMatrixTransProp(), LTI_StefanMaxwell_PPN::getMatrixTransProp(), LiquidTranInteraction::init(), MultiPhase::init(), GasTransport::initGas(), MultiTransport::initGas(), PecosTransport::initGas(), DustyGasTransport::initialize(), LiquidTransport::initLiquid(), AqueousTransport::initLiquid(), MultiPhaseEquil::MultiPhaseEquil(), LTI_StefanMaxwell_PPN::setParameters(), TransportFactory::setupLiquidTransport(), TransportFactory::setupMM(), and LiquidTransport::stefan_maxwell_solve().
const doublereal *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 88 of file DenseMatrix.cpp.
References DenseMatrix::m_colPts.
Referenced by DenseMatrix::mult().
|
virtual |
Multiply A*B and write result to prod
.
b | input DenseMatrix B of size NxN |
prod | output output DenseMatrix prod size NxN |
Reimplemented in SquareMatrix.
Definition at line 101 of file DenseMatrix.cpp.
References DenseMatrix::const_colPts(), Array2D::m_ncols, Array2D::m_nrows, Array2D::nColumns(), and Array2D::nRows().
|
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 in SquareMatrix.
Definition at line 115 of file DenseMatrix.cpp.
References Array2D::nColumns(), Array2D::nRows(), and Array2D::value().
Referenced by SquareMatrix::leftMult().
vector_int & ipiv | ( | ) |
Return a changeable value of the pivot vector.
Definition at line 129 of file DenseMatrix.cpp.
References DenseMatrix::m_ipiv.
Referenced by DenseMatrix::DenseMatrix(), SquareMatrix::factor(), MultiTransport::getMassFluxes(), MultiTransport::getSpeciesFluxes(), Cantera::invert(), DenseMatrix::operator=(), SquareMatrix::solve(), and Cantera::solve().
|
inline |
Return a changeable value of the pivot vector.
Definition at line 148 of file DenseMatrix.h.
References DenseMatrix::m_ipiv.
|
friend |
Solve Ax = b. Array b is overwritten on exit with x.
The solve class uses the LAPACK routine dgetrf to invert the m xy n matrix.
The factorization has the form A = P * L * U where P is a permutation matrix, L is lower triangular with unit diagonal elements (lower trapezoidal if m > n), and U is upper triangular (upper trapezoidal if m < n).
The system is then solved using the LAPACK routine dgetrs
A | Dense matrix to be factored |
b | rhs to be solved. |
Definition at line 134 of file DenseMatrix.cpp.
|
friend |
Solve Ax = b for multiple right-hand-side vectors.
A | Dense matrix to be factored |
b | Dense matrix of rhs's. Each column is a rhs |
Definition at line 180 of file DenseMatrix.cpp.
|
protected |
Vector of pivots. Length is equal to the max of m and n.
Definition at line 154 of file DenseMatrix.h.
Referenced by DenseMatrix::DenseMatrix(), DenseMatrix::ipiv(), DenseMatrix::operator=(), and DenseMatrix::resize().
|
protected |
Vector of column pointers.
Definition at line 157 of file DenseMatrix.h.
Referenced by DenseMatrix::const_colPts(), DenseMatrix::DenseMatrix(), DenseMatrix::operator=(), and DenseMatrix::resize().
int m_useReturnErrorCode |
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 167 of file DenseMatrix.h.
Referenced by SquareMatrix::factor(), SquareMatrix::factorQR(), Cantera::invert(), DenseMatrix::operator=(), SquareMatrix::rcond(), SquareMatrix::rcondQR(), SquareMatrix::solve(), Cantera::solve(), and SquareMatrix::solveQR().
int m_printLevel |
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 175 of file DenseMatrix.h.
Referenced by SquareMatrix::factor(), SquareMatrix::factorQR(), Cantera::invert(), DenseMatrix::operator=(), SquareMatrix::rcond(), SquareMatrix::rcondQR(), SquareMatrix::solve(), Cantera::solve(), and SquareMatrix::solveQR().