21 SquareMatrix::SquareMatrix() :
78 ct_dgetrs(ctlapack::NoTranspose, static_cast<int>(
nRows()),
79 nrhs, &(*(
begin())), static_cast<int>(
nRows()),
83 writelogf(
"SquareMatrix::solve(): DGETRS returned INFO = %d\n", info);
102 (void) memset((
void*) sm, 0, nn *
sizeof(double));
106 void SquareMatrix::resize(
size_t n,
size_t m, doublereal v)
111 void SquareMatrix::mult(
const doublereal* b, doublereal* prod)
const
113 DenseMatrix::mult(b, prod);
118 DenseMatrix::mult(b, prod);
132 integer n =
static_cast<int>(
nRows());
138 writelogf(
"SquareMatrix::factor(): DGETRS returned INFO = %d\n", info);
161 size_t lwork =
work.size();
165 writelogf(
"SquareMatrix::factorQR(): DGEQRF returned INFO = %d\n", info);
171 size_t lworkOpt =
static_cast<size_t>(
work[0]);
172 if (lworkOpt > lwork) {
173 work.resize(lworkOpt);
193 size_t lwork =
work.size();
202 ct_dormqr(ctlapack::Left, ctlapack::Transpose,
m_nrows, 1,
m_nrows, &(*(
begin())),
m_nrows,
DATA_PTR(
tau), b,
m_nrows,
206 writelogf(
"SquareMatrix::solveQR(): DORMQR returned INFO = %d\n", info);
212 size_t lworkOpt =
static_cast<size_t>(
work[0]);
213 if (lworkOpt > lwork) {
214 work.resize(lworkOpt);
219 ct_dtrtrs(ctlapack::UpperTriangular, ctlapack::NoTranspose, &dd,
m_nrows, 1, &(*(
begin())),
m_nrows, b,
223 writelogf(
"SquareMatrix::solveQR(): DTRTRS returned INFO = %d\n", info);
242 doublereal
rcond = 0.0;
244 throw CELapackError(
"SquareMatrix::rcond()",
"matrix isn't factored correctly");
252 writelogf(
"SquareMatrix::rcond(): DGECON returned INFO = %d\n", rinfo);
275 doublereal
rcond = 0.0;
277 throw CELapackError(
"SquareMatrix::rcondQR()",
"matrix isn't factored correctly");
285 writelogf(
"SquareMatrix::rcondQR(): DTRCON returned INFO = %d\n", rinfo);
340 doublereal*
const* SquareMatrix::colPts()
342 return DenseMatrix::colPts();
347 valueSmall = 1.0E300;
348 size_t iSmall =
npos;
349 for (
size_t i = 0; i <
m_nrows; i++) {
351 for (
size_t j = 0; j <
m_nrows; j++) {
352 valueS = std::max(fabs(
value(i,j)), valueS);
354 if (valueS < valueSmall) {
364 valueSmall = 1.0E300;
365 size_t jSmall =
npos;
366 for (
size_t j = 0; j <
m_nrows; j++) {
368 for (
size_t i = 0; i <
m_nrows; i++) {
369 valueS = std::max(fabs(
value(i,j)), valueS);
371 if (valueS < valueSmall) {
DenseMatrix & operator=(const DenseMatrix &y)
Assignment operator.
Dense, Square (not sparse) matrices.
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
virtual doublereal rcond(doublereal a1norm)
Returns an estimate of the inverse of the condition number for the matrix.
vector_fp m_data
Data stored in a single array.
vector_fp work
Work vector for QR algorithm.
const size_t npos
index returned by functions to indicate "no position"
int m_factored
Indicates whether the matrix is factored.
void copyData(const Array2D &y)
Copy the data from one array into another without doing any checking.
int m_printLevel
Print Level.
doublereal * ptrColumn(size_t j)
Return a pointer to the top of column j, columns are contiguous in memory.
SquareMatrix & operator=(const SquareMatrix &right)
Assignment operator.
void resize(size_t n, size_t m, doublereal v=0.0)
Resize the matrix.
void writelogf(const char *fmt,...)
Write a formatted message to the screen.
virtual GeneralMatrix * duplMyselfAsGeneralMatrix() const
Duplicator member function.
virtual size_t checkColumns(doublereal &valueSmall) const
Check to see if we have any zero columns in the Jacobian.
vector_fp tau
Work vector for QR algorithm.
virtual vector_fp::iterator begin()
Return an iterator pointing to the first element.
int solve(doublereal *b, size_t nrhs=1, size_t ldb=0)
Solves the Ax = b system returning x in the b spot.
virtual void leftMult(const doublereal *const b, doublereal *const prod) const
Left-multiply the matrix by transpose(b), and write the result to prod.
void zero()
Zero the matrix.
size_t nColumns() const
Number of columns.
virtual doublereal oneNorm() const
Calculate the one norm of the matrix.
A class for full (non-sparse) matrices with Fortran-compatible data storage.
int factor()
Factors the A matrix, overwriting A.
size_t m_nrows
Number of rows.
doublereal ct_dtrcon(const char *norm, ctlapack::upperlower_t uplot, const char *diag, size_t n, doublereal *a, size_t lda, doublereal *work, int *iwork, int &info)
virtual void useFactorAlgorithm(int fAlgorithm)
Change the way the matrix is factored.
int solveQR(doublereal *b)
Solves the linear problem Ax=b using the QR algorithm returning x in the b spot.
doublereal & value(size_t i, size_t j)
Returns a changeable reference to position in the matrix.
virtual void leftMult(const double *const b, double *const prod) const
Left-multiply the matrix by transpose(b), and write the result to prod.
virtual size_t checkRows(doublereal &valueSmall) const
Check to see if we have any zero rows in the Jacobian.
virtual void copyData(const GeneralMatrix &y)
virtual size_t nRows() const
Return the number of rows in the matrix.
Contains declarations for string manipulation functions within Cantera.
#define DATA_PTR(vec)
Creates a pointer to the start of the raw data for a vector.
virtual int factorAlgorithm() const
Returns the factor algorithm used.
virtual doublereal * ptrColumn(size_t j)
Return a pointer to the top of column j, columns are assumed to be contiguous in memory.
virtual doublereal rcondQR()
Returns an estimate of the inverse of the condition number for the matrix.
std::vector< int > iwork_
Integer work vector for QR algorithms.
Exception thrown when an LAPACK error is encountered associated with inverting or solving a matrix...
GeneralMatrix & operator=(const GeneralMatrix &right)
Assignment operator.
int useQR_
Use the QR algorithm to factor and invert the matrix.
size_t nRowsAndStruct(size_t *const iStruct=0) const
Return the size and structure of the matrix.
int m_useReturnErrorCode
Error Handling Flag.
void setFactorFlag()
set the factored flag
doublereal a1norm_
1-norm of the matrix. This is determined immediately before every factorization
vector_int & ipiv()
Return a changeable value of the pivot vector.
SquareMatrix()
Base Constructor.
A class for full (non-sparse) matrices with Fortran-compatible data storage, which adds matrix operat...
virtual int factorQR()
Factors the A matrix using the QR algorithm, overwriting A.