Cantera  2.3.0
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)
 
SquareMatrixoperator= (const SquareMatrix &right)
 
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 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)
 
DenseMatrixoperator= (const DenseMatrix &y)
 
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)
 
Array2Doperator= (const Array2D &y)
 
void resize (size_t n, size_t m, doublereal v=0.0)
 Resize the array, and fill the new entries with 'v'. 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...
 
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=-1)
 Base Constructor. 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...
 
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...
 

Protected Attributes

doublereal a1norm_
 1-norm of the matrix. 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.

Deprecated:
Use class DenseMatrix instead. To be removed after Cantera 2.3.

Definition at line 20 of file SquareMatrix.h.

Constructor & Destructor Documentation

◆ SquareMatrix() [1/2]

Base Constructor.

Definition at line 17 of file SquareMatrix.cpp.

References Cantera::warn_deprecated().

Referenced by SquareMatrix::duplMyselfAsGeneralMatrix().

◆ SquareMatrix() [2/2]

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 25 of file SquareMatrix.cpp.

References Cantera::warn_deprecated().

Member Function Documentation

◆ solve()

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 54 of file SquareMatrix.cpp.

◆ zero()

void zero ( )
virtual

Zero the matrix.

Implements GeneralMatrix.

Definition at line 92 of file SquareMatrix.cpp.

References Array2D::m_data.

◆ mult()

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

Multiply A*B and write result to prod.

Take this matrix to be of size NxM.

Parameters
[in]bDenseMatrix B of size MxP
[out]prodDenseMatrix prod size NxP

Reimplemented from DenseMatrix.

Definition at line 107 of file SquareMatrix.cpp.

◆ leftMult()

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 112 of file SquareMatrix.cpp.

◆ factor()

int factor ( )
virtual

◆ factorQR()

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
the info variable from LAPACK

Reimplemented from GeneralMatrix.

Definition at line 148 of file SquareMatrix.cpp.

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

Referenced by SquareMatrix::factor().

◆ rcondQR()

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
the inverse of the condition number

Reimplemented from GeneralMatrix.

Definition at line 269 of file SquareMatrix.cpp.

References Cantera::ct_dtrcon(), SquareMatrix::iwork_, GeneralMatrix::m_factored, Array2D::m_nrows, SquareMatrix::rcond(), and SquareMatrix::work.

◆ rcond()

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
the inverse of the condition number

Implements GeneralMatrix.

Definition at line 232 of file SquareMatrix.cpp.

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

Referenced by SquareMatrix::rcondQR().

◆ oneNorm()

doublereal oneNorm ( ) const
virtual

Calculate the one norm of the matrix.

Implements GeneralMatrix.

Definition at line 264 of file SquareMatrix.cpp.

References SquareMatrix::a1norm_.

◆ solveQR()

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 179 of file SquareMatrix.cpp.

◆ setFactorFlag()

void setFactorFlag ( )

set the factored flag

Definition at line 143 of file SquareMatrix.cpp.

References GeneralMatrix::m_factored.

◆ useFactorAlgorithm()

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 301 of file SquareMatrix.cpp.

References SquareMatrix::useQR_.

◆ factorAlgorithm()

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 306 of file SquareMatrix.cpp.

References SquareMatrix::useQR_.

◆ ptrColumn()

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
a pointer to the top of the column

Implements GeneralMatrix.

Definition at line 311 of file SquareMatrix.cpp.

References Array2D::ptrColumn().

◆ operator()() [1/2]

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 80 of file SquareMatrix.h.

References Array2D::operator()().

◆ operator()() [2/2]

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 84 of file SquareMatrix.h.

References Array2D::operator()().

◆ nRows()

size_t nRows ( ) const
virtual

Return the number of rows in the matrix.

Implements GeneralMatrix.

Definition at line 316 of file SquareMatrix.cpp.

References Array2D::m_nrows.

Referenced by SquareMatrix::factor().

◆ nRowsAndStruct()

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
the number of rows and columns in the matrix.
Deprecated:
Unused. To be removed after Cantera 2.3.

Implements GeneralMatrix.

Definition at line 321 of file SquareMatrix.cpp.

References Array2D::m_nrows, and Cantera::warn_deprecated().

◆ duplMyselfAsGeneralMatrix()

GeneralMatrix * duplMyselfAsGeneralMatrix ( ) const
virtual

Duplicator member function.

This function will duplicate the matrix given a generic GeneralMatrix

Returns
a pointer to the newly created object

Implements GeneralMatrix.

Definition at line 328 of file SquareMatrix.cpp.

References SquareMatrix::SquareMatrix().

◆ begin() [1/2]

vector_fp::iterator begin ( )
virtual

Return an iterator pointing to the first element.

We might drop this later

Implements GeneralMatrix.

Definition at line 333 of file SquareMatrix.cpp.

References Array2D::m_data.

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

◆ begin() [2/2]

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 338 of file SquareMatrix.cpp.

References Array2D::m_data.

◆ checkRows()

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 348 of file SquareMatrix.cpp.

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

◆ checkColumns()

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 365 of file SquareMatrix.cpp.

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

Member Data Documentation

◆ tau

vector_fp tau

Work vector for QR algorithm.

Definition at line 113 of file SquareMatrix.h.

Referenced by SquareMatrix::factorQR().

◆ work

vector_fp work

Work vector for QR algorithm.

Definition at line 116 of file SquareMatrix.h.

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

◆ iwork_

vector_int iwork_

Integer work vector for QR algorithms.

Definition at line 119 of file SquareMatrix.h.

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

◆ a1norm_

doublereal a1norm_
protected

1-norm of the matrix.

This is determined immediately before every factorization

Definition at line 123 of file SquareMatrix.h.

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

◆ useQR_

int useQR_
protected

Use the QR algorithm to factor and invert the matrix.

Definition at line 126 of file SquareMatrix.h.

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


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