Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Public Attributes | Protected Attributes | List of all members
SquareMatrix Class Reference

A class for full (non-sparse) matrices with Fortran-compatible data storage. More...

#include <SquareMatrix.h>

Inheritance diagram for SquareMatrix:
[legend]
Collaboration diagram for SquareMatrix:
[legend]

Public Member Functions

 SquareMatrix ()
 Base Constructor. More...
 
 SquareMatrix (size_t n, doublereal v=0.0)
 Constructor. More...
 
 SquareMatrix (const SquareMatrix &right)
 Copy Constructor. More...
 
SquareMatrixoperator= (const SquareMatrix &right)
 Assignment operator. More...
 
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 void copyData (const GeneralMatrix &y)
 
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 GeneralMatrixduplMyselfAsGeneralMatrix () 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...
 
DenseMatrixoperator= (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_intipiv ()
 Return a changeable value of the pivot vector. More...
 
const vector_intipiv () 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...
 
Array2Doperator= (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_fpdata ()
 Return a reference to the data vector. More...
 
const vector_fpdata () 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...
 
GeneralMatrixoperator= (const GeneralMatrix &right)
 Assignment operator. More...
 
virtual ~GeneralMatrix ()
 Destructor. Does nothing. 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...
 
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

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...
 
- 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...
 

Detailed Description

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.

Constructor & Destructor Documentation

Base Constructor.

Definition at line 21 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.

Parameters
nsize of the square matrix
vinitial value of all matrix components.

Definition at line 28 of file SquareMatrix.cpp.

SquareMatrix ( const SquareMatrix right)

Copy Constructor.

Definition at line 37 of file SquareMatrix.cpp.

Member Function Documentation

SquareMatrix & operator= ( const SquareMatrix right)

Assignment operator.

Definition at line 45 of file SquareMatrix.cpp.

References SquareMatrix::a1norm_, GeneralMatrix::operator=(), DenseMatrix::operator=(), and SquareMatrix::useQR_.

int solve ( doublereal *  b,
size_t  nrhs = 1,
size_t  ldb = 0 
)
virtual

Solves the Ax = b system returning x in the b spot.

Parameters
bVector for the RHS of the equation system
nrhsNumber of right-hand sides to solve, default 1
ldbLeading dimension of the right-hand side array. Defaults to nRows()

Implements GeneralMatrix.

Definition at line 57 of file SquareMatrix.cpp.

References SquareMatrix::begin(), DATA_PTR, SquareMatrix::factor(), Cantera::int2str(), DenseMatrix::ipiv(), GeneralMatrix::m_factored, DenseMatrix::m_printLevel, DenseMatrix::m_useReturnErrorCode, Array2D::nColumns(), SquareMatrix::nRows(), SquareMatrix::solveQR(), SquareMatrix::useQR_, and Cantera::writelogf().

Referenced by MultiTransport::getMassFluxes(), MultiTransport::getSpeciesFluxes(), solveProb::solve(), and solveSP::solveSurfProb().

void zero ( )
virtual

Zero the matrix.

Implements GeneralMatrix.

Definition at line 92 of file SquareMatrix.cpp.

References Array2D::m_data, and SquareMatrix::nRows().

void mult ( const DenseMatrix b,
DenseMatrix prod 
) const
virtual

Multiply A*B and write result to prod.

Parameters
binput DenseMatrix B of size NxN
prodoutput output DenseMatrix prod size NxN

Reimplemented from DenseMatrix.

Definition at line 116 of file SquareMatrix.cpp.

void leftMult ( const doublereal *const  b,
doublereal *const  prod 
) const
virtual

Left-multiply the matrix by transpose(b), and write the result to prod.

Parameters
bleft multiply by this vector. The length must be equal to n the number of rows in the matrix.
prodResulting vector. This is of length m, the number of columns in the matrix

Reimplemented from DenseMatrix.

Definition at line 121 of file SquareMatrix.cpp.

References DenseMatrix::leftMult().

int factor ( )
virtual
int factorQR ( )
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

Returns
Returns the info variable from LAPACK

Reimplemented from GeneralMatrix.

Definition at line 152 of file SquareMatrix.cpp.

References SquareMatrix::a1norm_, SquareMatrix::begin(), DATA_PTR, Cantera::int2str(), GeneralMatrix::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().

doublereal rcondQR ( )
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

Returns
returns the inverse of the condition number

Reimplemented from GeneralMatrix.

Definition at line 266 of file SquareMatrix.cpp.

References SquareMatrix::begin(), Cantera::ct_dtrcon(), DATA_PTR, Cantera::int2str(), SquareMatrix::iwork_, GeneralMatrix::m_factored, Array2D::m_nrows, DenseMatrix::m_printLevel, DenseMatrix::m_useReturnErrorCode, SquareMatrix::rcond(), SquareMatrix::work, and Cantera::writelogf().

doublereal rcond ( doublereal  a1norm)
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

Parameters
a1normNorm of the matrix
Returns
returns the inverse of the condition number

Implements GeneralMatrix.

Definition at line 233 of file SquareMatrix.cpp.

References SquareMatrix::begin(), DATA_PTR, Cantera::int2str(), SquareMatrix::iwork_, GeneralMatrix::m_factored, Array2D::m_nrows, DenseMatrix::m_printLevel, DenseMatrix::m_useReturnErrorCode, SquareMatrix::work, and Cantera::writelogf().

Referenced by SquareMatrix::rcondQR().

doublereal oneNorm ( ) const
virtual

Calculate the one norm of the matrix.

Implements GeneralMatrix.

Definition at line 261 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.

Parameters
bRHS to be solved.

Definition at line 180 of file SquareMatrix.cpp.

References SquareMatrix::begin(), DATA_PTR, SquareMatrix::factorQR(), Cantera::int2str(), GeneralMatrix::m_factored, Array2D::m_nrows, DenseMatrix::m_printLevel, DenseMatrix::m_useReturnErrorCode, SquareMatrix::tau, SquareMatrix::work, and Cantera::writelogf().

Referenced by SquareMatrix::solve().

void setFactorFlag ( )

set the factored flag

Definition at line 147 of file SquareMatrix.cpp.

References GeneralMatrix::m_factored.

void useFactorAlgorithm ( int  fAlgorithm)
virtual

Change the way the matrix is factored.

Parameters
fAlgorithminteger 0 LU factorization 1 QR factorization

Reimplemented from GeneralMatrix.

Definition at line 294 of file SquareMatrix.cpp.

References SquareMatrix::useQR_.

int factorAlgorithm ( ) const
virtual

Returns the factor algorithm used.

0 LU decomposition 1 QR decomposition

This routine will always return 0

Implements GeneralMatrix.

Definition at line 299 of file SquareMatrix.cpp.

References SquareMatrix::useQR_.

doublereal * ptrColumn ( size_t  j)
virtual

Return a pointer to the top of column j, columns are assumed to be contiguous in memory.

Parameters
jValue of the column
Returns
Returns a pointer to the top of the column

Implements GeneralMatrix.

Definition at line 304 of file SquareMatrix.cpp.

References Array2D::ptrColumn().

Referenced by solveProb::solveProb().

virtual doublereal& operator() ( size_t  i,
size_t  j 
)
inlinevirtual

Index into the (i,j) element.

Parameters
irow
jcolumn

Returns a changeable reference to the matrix entry

Implements GeneralMatrix.

Definition at line 88 of file SquareMatrix.h.

References Array2D::operator()().

void copyData ( const GeneralMatrix y)
virtual
Deprecated:
To be removed after Cantera 2.2.

Implements GeneralMatrix.

Definition at line 309 of file SquareMatrix.cpp.

References Array2D::copyData().

virtual doublereal operator() ( size_t  i,
size_t  j 
) const
inlinevirtual

Constant Index into the (i,j) element.

Parameters
irow
jcolumn

Returns an unchangeable reference to the matrix entry

Implements GeneralMatrix.

Definition at line 95 of file SquareMatrix.h.

References Array2D::operator()().

size_t nRows ( ) const
virtual

Return the number of rows in the matrix.

Implements GeneralMatrix.

Definition at line 315 of file SquareMatrix.cpp.

References Array2D::m_nrows.

Referenced by SquareMatrix::factor(), SquareMatrix::solve(), and SquareMatrix::zero().

size_t nRowsAndStruct ( size_t *const  iStruct = 0) const
virtual

Return the size and structure of the matrix.

This is inherited from GeneralMatrix

Parameters
iStructOUTPUT Pointer to a vector of ints that describe the structure of the matrix. not used
Returns
returns the number of rows and columns in the matrix.

Implements GeneralMatrix.

Definition at line 320 of file SquareMatrix.cpp.

References Array2D::m_nrows.

GeneralMatrix * duplMyselfAsGeneralMatrix ( ) const
virtual

Duplicator member function.

This function will duplicate the matrix given a generic GeneralMatrix

Returns
Returns a pointer to the malloced object

Implements GeneralMatrix.

Definition at line 325 of file SquareMatrix.cpp.

References SquareMatrix::SquareMatrix().

vector_fp::iterator begin ( )
virtual

Return an iterator pointing to the first element.

We might drop this later

Implements GeneralMatrix.

Definition at line 330 of file SquareMatrix.cpp.

References Array2D::m_data.

Referenced by SquareMatrix::factor(), SquareMatrix::factorQR(), SquareMatrix::rcond(), SquareMatrix::rcondQR(), SquareMatrix::solve(), and SquareMatrix::solveQR().

vector_fp::const_iterator begin ( ) const
virtual

Return a const iterator pointing to the first element.

We might drop this later

Implements GeneralMatrix.

Definition at line 335 of file SquareMatrix.cpp.

References Array2D::m_data.

size_t checkRows ( doublereal &  valueSmall) const
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

Parameters
valueSmallOUTPUT value of the largest coefficient in the smallest row
Returns
index of the row that is most nearly zero

Implements GeneralMatrix.

Definition at line 345 of file SquareMatrix.cpp.

References Array2D::m_nrows, Cantera::npos, and Array2D::value().

size_t checkColumns ( doublereal &  valueSmall) const
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

Parameters
valueSmallOUTPUT value of the largest coefficient in the smallest column
Returns
index of the column that is most nearly zero

Implements GeneralMatrix.

Definition at line 362 of file SquareMatrix.cpp.

References Array2D::m_nrows, Cantera::npos, and Array2D::value().

Member Data Documentation

vector_fp tau

Work vector for QR algorithm.

Definition at line 123 of file SquareMatrix.h.

Referenced by SquareMatrix::factorQR(), and SquareMatrix::solveQR().

vector_fp work

Work vector for QR algorithm.

Definition at line 126 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 129 of file SquareMatrix.h.

Referenced by SquareMatrix::rcond(), and SquareMatrix::rcondQR().

doublereal a1norm_
protected

1-norm of the matrix. This is determined immediately before every factorization

Definition at line 132 of file SquareMatrix.h.

Referenced by SquareMatrix::factor(), SquareMatrix::factorQR(), SquareMatrix::oneNorm(), and SquareMatrix::operator=().

int useQR_
protected

Use the QR algorithm to factor and invert the matrix.

Definition at line 135 of file SquareMatrix.h.

Referenced by SquareMatrix::factor(), SquareMatrix::factorAlgorithm(), SquareMatrix::operator=(), SquareMatrix::solve(), and SquareMatrix::useFactorAlgorithm().


The documentation for this class was generated from the following files: