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

## ◆ SquareMatrix() [1/2]

 SquareMatrix ( )

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
 n size of the square matrix v initial value of all matrix components.

Definition at line 25 of file SquareMatrix.cpp.

References Cantera::warn_deprecated().

## ◆ 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
 b Vector for the RHS of the equation system nrhs Number of right-hand sides to solve, default 1 ldb Leading 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] b DenseMatrix B of size MxP [out] prod DenseMatrix 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
 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 from DenseMatrix.

Definition at line 112 of file SquareMatrix.cpp.

## ◆ factor()

 int factor ( )
virtual

Factors the A matrix, overwriting A.

We flip m_factored boolean to indicate that the matrix is now A-1.

Implements GeneralMatrix.

Definition at line 117 of file SquareMatrix.cpp.

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

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.

## ◆ 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
 a1norm Norm of the matrix
Returns
the inverse of the condition number

Implements GeneralMatrix.

Definition at line 232 of file SquareMatrix.cpp.

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
 b RHS 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
 fAlgorithm integer 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
 j Value 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
 i row j column
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
 i row j column
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
 iStruct OUTPUT 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
 valueSmall OUTPUT 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
 valueSmall OUTPUT 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().

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

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