Cantera
2.0
|
A class for full (non-sparse) matrices with Fortran-compatible data storage, which adds matrix operations to class Array2D. More...
#include <DenseMatrix.h>
Public Types | |
typedef vector_fp::iterator | iterator |
Type definition for the iterator class that is can be used by Array2D types. | |
typedef vector_fp::const_iterator | const_iterator |
Type definition for the const_iterator class that is can be used by Array2D types. | |
Public Member Functions | |
DenseMatrix () | |
Default Constructor. | |
DenseMatrix (size_t n, size_t m, doublereal v=0.0) | |
Constructor. | |
DenseMatrix (const DenseMatrix &y) | |
Copy constructor. | |
DenseMatrix & | operator= (const DenseMatrix &y) |
Assignment operator. | |
virtual | ~DenseMatrix () |
Destructor. Does nothing. | |
void | resize (size_t n, size_t m, doublereal v=0.0) |
Resize the matrix. | |
virtual doublereal *const * | colPts () |
Return a vector of const pointers to the columns. | |
const doublereal *const * | const_colPts () const |
Return a const vector of const pointers to the columns. | |
virtual void | mult (const double *b, double *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. | |
void | copyData (const Array2D &y) |
Copy the data from one array into another without doing any checking. | |
void | appendColumn (const vector_fp &c) |
Append a column to the existing matrix using a std vector. | |
void | appendColumn (const doublereal *const c) |
Append a column to the existing matrix. | |
void | setRow (size_t n, const doublereal *const rw) |
Set the nth row to array rw. | |
void | getRow (size_t n, doublereal *const rw) |
Get the nth row and return it in a vector. | |
void | setColumn (size_t m, doublereal *const col) |
Set the values in column m to those in array col. | |
void | getColumn (size_t m, doublereal *const col) |
Get the values in column m. | |
void | axpy (doublereal a, const Array2D &x, const Array2D &y) |
Evaluate z = a*x + y. | |
void | zero () |
Set all of the entries to zero. | |
doublereal & | operator() (size_t i, size_t j) |
Allows setting elements using the syntax A(i,j) = x. | |
doublereal | operator() (size_t i, size_t j) const |
Allows retrieving elements using the syntax x = A(i,j). | |
doublereal & | value (size_t i, size_t j) |
Returns a changeable reference to position in the matrix. | |
doublereal | 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. | |
const_iterator | begin () const |
Return a const iterator pointing to the first element. | |
iterator | end () |
Return an iterator pointing past the last element. | |
const_iterator | end () const |
Return a const iterator pointing to past the last element. | |
vector_fp & | data () |
Return a reference to the data vector. | |
const vector_fp & | data () const |
Return a const reference to the data vector. | |
doublereal * | ptrColumn (size_t j) |
Return a pointer to the top of column j, columns are contiguous in memory. | |
const doublereal * | 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 |
Error Handling Flag. | |
int | m_printLevel |
Print Level. | |
Protected Attributes | |
vector_int | m_ipiv |
Vector of pivots. Length is equal to the max of m and n. | |
std::vector< doublereal * > | m_colPts |
Vector of column pointers. | |
vector_fp | m_data |
Data stored in a single array. | |
size_t | m_nrows |
Number of rows. | |
size_t | m_ncols |
Number of columns. | |
Friends | |
int | solve (DenseMatrix &A, double *b) |
Solve Ax = b. Array b is overwritten on exit with x. | |
int | solve (DenseMatrix &A, DenseMatrix &b) |
Solve Ax = b for multiple right-hand-side vectors. | |
int | invert (DenseMatrix &A, int nn) |
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.
|
inherited |
|
inherited |
DenseMatrix | ( | ) |
Default Constructor.
Definition at line 18 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 30 of file DenseMatrix.cpp.
References DenseMatrix::m_colPts, Array2D::m_data, DenseMatrix::m_ipiv, Array2D::m_nrows, and ckr::max().
DenseMatrix | ( | const DenseMatrix & | y | ) |
Copy constructor.
y | Object to be copied |
Definition at line 49 of file DenseMatrix.cpp.
References DenseMatrix::ipiv(), DenseMatrix::m_colPts, Array2D::m_data, DenseMatrix::m_ipiv, Array2D::m_ncols, and Array2D::m_nrows.
|
virtual |
Destructor. Does nothing.
Definition at line 82 of file DenseMatrix.cpp.
DenseMatrix & operator= | ( | const DenseMatrix & | y | ) |
Assignment operator.
y | Object to be copied |
Definition at line 65 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 86 of file DenseMatrix.cpp.
References DenseMatrix::m_colPts, Array2D::m_data, DenseMatrix::m_ipiv, Array2D::m_ncols, Array2D::m_nrows, ckr::max(), and Array2D::resize().
Referenced by LTI_Pairwise_Interaction::getMatrixTransProp(), LTI_StefanMaxwell_PPN::getMatrixTransProp(), LiquidTranInteraction::init(), MultiPhase::init(), GasTransport::initGas(), MultiTransport::initGas(), DustyGasTransport::initialize(), LiquidTransport::initLiquid(), AqueousTransport::initLiquid(), MultiPhaseEquil::MultiPhaseEquil(), SquareMatrix::resize(), TransportFactory::setupLiquidTransport(), TransportFactory::setupMM(), MultiTransport::solveLMatrixEquation(), and LiquidTransport::stefan_maxwell_solve().
|
virtual |
Return a vector of const pointers to the columns.
Note the value of the pointers are protected by their being const. However, the value of the matrix is open to being changed.
Reimplemented in SquareMatrix.
Definition at line 98 of file DenseMatrix.cpp.
References DenseMatrix::m_colPts.
Referenced by SquareMatrix::colPts().
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 103 of file DenseMatrix.cpp.
References DenseMatrix::m_colPts.
|
virtual |
Multiply A*b and write result to prod
.
b | input vector b with length N |
prod | output output vector prod length = M |
Reimplemented in SquareMatrix, and L_Matrix.
Definition at line 108 of file DenseMatrix.cpp.
References Array2D::nRows(), and Array2D::ptrColumn().
Referenced by SquareMatrix::mult().
|
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 116 of file DenseMatrix.cpp.
References Array2D::nColumns(), Array2D::nRows(), and Array2D::value().
Referenced by ChemEquil::equilibrate(), and SquareMatrix::leftMult().
vector_int & ipiv | ( | ) |
Return a changeable value of the pivot vector.
Definition at line 130 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 161 of file DenseMatrix.h.
References DenseMatrix::m_ipiv.
|
inlineinherited |
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 |
Definition at line 139 of file Array.h.
References DATA_PTR, Array2D::m_data, Array2D::m_ncols, Array2D::m_nrows, and Array2D::ptrColumn().
Referenced by SquareMatrix::copyData().
|
inlineinherited |
Append a column to the existing matrix using a std vector.
This operation will add a column onto the existing matrix.
c | This vector<doublereal> is the entries in the column to be added. It must have a length equal to m_nrows or greater. |
Definition at line 152 of file Array.h.
References Array2D::m_data, Array2D::m_ncols, Array2D::m_nrows, and Array2D::value().
|
inlineinherited |
Append a column to the existing matrix.
This operation will add a column onto the existing matrix.
c | This vector of doubles is the entries in the column to be added. It must have a length equal to m_nrows or greater. |
Definition at line 169 of file Array.h.
References Array2D::m_data, Array2D::m_ncols, Array2D::m_nrows, and Array2D::value().
|
inlineinherited |
Set the nth row to array rw.
n | Index of the row to be changed |
rw | Vector for the row. Must have a length of m_ncols. |
Definition at line 183 of file Array.h.
References Array2D::m_data, Array2D::m_ncols, and Array2D::m_nrows.
|
inlineinherited |
Get the nth row and return it in a vector.
n | Index of the row to be returned. |
rw | Return Vector for the operation. Must have a length of m_ncols. |
Definition at line 195 of file Array.h.
References Array2D::m_data, Array2D::m_ncols, and Array2D::m_nrows.
Referenced by StFlow::save().
|
inlineinherited |
Set the values in column m to those in array col.
A(i,m) = col(i)
m | Column to set |
col | pointer to a col vector. Vector must have a length of m_nrows. |
Definition at line 209 of file Array.h.
References Array2D::m_data, and Array2D::m_nrows.
|
inlineinherited |
Get the values in column m.
col(i) = A(i,m)
m | Column to set |
col | pointer to a col vector that will be returned |
Definition at line 222 of file Array.h.
References Array2D::m_data, and Array2D::m_nrows.
Evaluate z = a*x + y.
This function evaluates the AXPY operation, and stores the result in the object's Array2D object. It's assumed that all 3 objects have the same dimensions, but no error checking is done.
a | scalar to multiply x with |
x | First Array2D object to be used |
y | Second Array2D object to be used |
Definition at line 246 of file Array.h.
References Array2D::begin(), and Array2D::end().
|
inlineinherited |
Set all of the entries to zero.
Definition at line 256 of file Array.h.
References Array2D::m_data, Array2D::m_ncols, and Array2D::m_nrows.
Referenced by IonsFromNeutralVPSSTP::s_update_dlnActCoeff_dlnN(), PhaseCombo_Interaction::s_update_dlnActCoeff_dlnN(), MargulesVPSSTP::s_update_dlnActCoeff_dlnN(), MixedSolventElectrolyte::s_update_dlnActCoeff_dlnN(), and RedlichKisterVPSSTP::s_update_dlnActCoeff_dX_().
|
inlineinherited |
Allows setting elements using the syntax A(i,j) = x.
i | row index |
j | column index. |
Definition at line 274 of file Array.h.
References Array2D::value().
Referenced by SquareMatrix::operator()().
|
inlineinherited |
Allows retrieving elements using the syntax x = A(i,j).
i | Index for the row to be retrieved |
j | Index for the column to be retrieved. |
Definition at line 286 of file Array.h.
References Array2D::value().
|
inlineinherited |
Returns a changeable reference to position in the matrix.
This is a key entry. Returns a reference to the matrixes (i,j) element. This may be used as an L value.
i | The row index |
j | The column index |
Definition at line 300 of file Array.h.
References Array2D::m_data, and Array2D::m_nrows.
Referenced by Array2D::appendColumn(), SquareMatrix::checkColumns(), SquareMatrix::checkRows(), DenseMatrix::leftMult(), Array2D::operator()(), and DebyeHuckel::s_update_lnMolalityActCoeff().
|
inlineinherited |
Returns the value of a single matrix entry.
This is a key entry. Returns the value of the matrix position (i,j) element.
i | The row index |
j | The column index |
Definition at line 312 of file Array.h.
References Array2D::m_data, and Array2D::m_nrows.
|
inlineinherited |
Number of rows.
Definition at line 317 of file Array.h.
References Array2D::m_nrows.
Referenced by MultiTransport::getMassFluxes(), ctml::getMatrixValues(), MultiTransport::getSpeciesFluxes(), Cantera::increment(), Cantera::invert(), DenseMatrix::leftMult(), DenseMatrix::mult(), Cantera::multiply(), Cantera::operator<<(), Cantera::outputExcel(), Cantera::outputTEC(), and Cantera::solve().
|
inlineinherited |
Number of columns.
Definition at line 322 of file Array.h.
References Array2D::m_ncols.
Referenced by MultiTransport::getMassFluxes(), ctml::getMatrixValues(), MultiTransport::getSpeciesFluxes(), DenseMatrix::leftMult(), Cantera::multiply(), Cantera::operator<<(), Cantera::outputExcel(), Cantera::outputTEC(), StFlow::save(), SquareMatrix::solve(), and Cantera::solve().
|
inlineinherited |
Return an iterator pointing to the first element.
Definition at line 327 of file Array.h.
References Array2D::m_data.
Referenced by Array2D::axpy(), Cantera::operator*=(), and Cantera::operator+=().
|
inlineinherited |
Return a const iterator pointing to the first element.
Definition at line 337 of file Array.h.
References Array2D::m_data.
|
inlineinherited |
Return an iterator pointing past the last element.
Definition at line 332 of file Array.h.
References Array2D::m_data.
Referenced by Array2D::axpy(), Cantera::operator*=(), and Cantera::operator+=().
|
inlineinherited |
Return a const iterator pointing to past the last element.
Definition at line 342 of file Array.h.
References Array2D::m_data.
|
inlineinherited |
Return a reference to the data vector.
Definition at line 347 of file Array.h.
References Array2D::m_data.
|
inlineinherited |
Return a const reference to the data vector.
Definition at line 352 of file Array.h.
References Array2D::m_data.
|
inlineinherited |
Return a pointer to the top of column j, columns are contiguous in memory.
j | Value of the column |
Definition at line 363 of file Array.h.
References Array2D::m_data, and Array2D::m_nrows.
Referenced by Array2D::copyData(), MultiTransport::getMassFluxes(), MultiTransport::getSpeciesFluxes(), Cantera::increment(), Cantera::invert(), DenseMatrix::mult(), Cantera::multiply(), SquareMatrix::ptrColumn(), HMWSoln::s_updatePitzer_CoeffWRTemp(), Cantera::solve(), solveProb::solveProb(), solveSP::solveSP(), AqueousTransport::stefan_maxwell_solve(), DustyGasTransport::updateBinaryDiffCoeffs(), and StFlow::updateTransport().
|
inlineinherited |
Return a const pointer to the top of column j, columns are contiguous in memory.
j | Value of the column |
Definition at line 374 of file Array.h.
References Array2D::m_data, and Array2D::m_nrows.
|
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 135 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 181 of file DenseMatrix.cpp.
|
protected |
Vector of pivots. Length is equal to the max of m and n.
Definition at line 168 of file DenseMatrix.h.
Referenced by DenseMatrix::DenseMatrix(), DenseMatrix::ipiv(), DenseMatrix::operator=(), and DenseMatrix::resize().
|
protected |
Vector of column pointers.
Definition at line 171 of file DenseMatrix.h.
Referenced by DenseMatrix::colPts(), 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 182 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 190 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().
|
protectedinherited |
Data stored in a single array.
Definition at line 381 of file Array.h.
Referenced by Array2D::appendColumn(), Array2D::Array2D(), SquareMatrix::begin(), Array2D::begin(), Array2D::copyData(), Array2D::data(), DenseMatrix::DenseMatrix(), Array2D::end(), Array2D::getColumn(), Array2D::getRow(), DenseMatrix::operator=(), Array2D::operator=(), Array2D::ptrColumn(), DenseMatrix::resize(), Array2D::resize(), Array2D::setColumn(), Array2D::setRow(), Array2D::value(), SquareMatrix::zero(), and Array2D::zero().
|
protectedinherited |
Number of rows.
Definition at line 384 of file Array.h.
Referenced by Array2D::appendColumn(), Array2D::Array2D(), SquareMatrix::checkColumns(), SquareMatrix::checkRows(), Array2D::copyData(), DenseMatrix::DenseMatrix(), SquareMatrix::factor(), SquareMatrix::factorQR(), Array2D::getColumn(), Array2D::getRow(), SquareMatrix::nRows(), Array2D::nRows(), SquareMatrix::nRowsAndStruct(), DenseMatrix::operator=(), Array2D::operator=(), Array2D::ptrColumn(), SquareMatrix::rcond(), SquareMatrix::rcondQR(), DenseMatrix::resize(), Array2D::resize(), Array2D::setColumn(), Array2D::setRow(), SquareMatrix::solveQR(), Array2D::value(), and Array2D::zero().
|
protectedinherited |
Number of columns.
Definition at line 387 of file Array.h.
Referenced by Array2D::appendColumn(), Array2D::Array2D(), Array2D::copyData(), DenseMatrix::DenseMatrix(), Array2D::getRow(), Array2D::nColumns(), DenseMatrix::operator=(), Array2D::operator=(), DenseMatrix::resize(), Array2D::resize(), Array2D::setRow(), and Array2D::zero().