15 m_useReturnErrorCode(0),
22 m_useReturnErrorCode(0),
25 m_ipiv.resize(std::max(n, m));
28 for (
size_t j = 0; j < m; j++) {
36 m_useReturnErrorCode(0),
42 for (
size_t j = 0; j <
m_ncols; j++) {
56 for (
size_t j = 0; j <
m_ncols; j++) {
67 m_ipiv.resize(std::max(n,m));
70 for (
size_t j = 0; j <
m_ncols; j++) {
76 doublereal*
const* DenseMatrix::colPts()
86 void DenseMatrix::mult(
const double* b,
double* prod)
const
88 ct_dgemv(ctlapack::ColMajor, ctlapack::NoTranspose,
89 static_cast<int>(
nRows()),
91 static_cast<int>(
nRows()), b, 1, 0.0, prod, 1);
97 throw CanteraError(
"mult(const DenseMatrix &B, DenseMatrix &prod)",
98 "Cannot multiply matrices that are not square and/or not the same size.");
101 doublereal*
const* prodcols = prod.colPts();
102 for (
size_t col=0; col <
m_ncols; ++col) {
104 mult(bcols[col], prodcols[col]);
113 for (
size_t n = 0; n < nc; n++) {
115 for (
size_t i = 0; i < nr; i++) {
116 sum +=
value(i,n)*b[i];
132 writelogf(
"solve(DenseMatrix& A, double* b): Can only solve a square matrix\n");
134 throw CELapackError(
"solve(DenseMatrix& A, double* b)",
"Can only solve a square matrix");
140 writelogf(
"solve(DenseMatrix& A, double* b): DGETRF returned INFO = %d U(i,i) is exactly zero. The factorization has"
141 " been completed, but the factor U is exactly singular, and division by zero will occur if "
142 "it is used to solve a system of equations.\n", info);
146 "DGETRF returned INFO = "+
int2str(info) +
". U(i,i) is exactly zero. The factorization has"
147 " been completed, but the factor U is exactly singular, and division by zero will occur if "
148 "it is used to solve a system of equations.");
151 }
else if (info < 0) {
153 writelogf(
"solve(DenseMatrix& A, double* b): DGETRF returned INFO = %d. The argument i has an illegal value\n", info);
157 "DGETRF returned INFO = "+
int2str(info) +
". The argument i has an illegal value");
167 writelogf(
"solve(DenseMatrix& A, double* b): DGETRS returned INFO = %d\n", info);
170 throw CELapackError(
"solve(DenseMatrix& A, double* b)",
"DGETRS returned INFO = "+
int2str(info));
183 ct_dgemv(ctlapack::ColMajor, ctlapack::NoTranspose,
184 static_cast<int>(A.
nRows()), static_cast<int>(A.
nColumns()), 1.0,
190 ct_dgemv(ctlapack::ColMajor, ctlapack::NoTranspose,
191 static_cast<int>(A.
nRows()), static_cast<int>(A.
nRows()), 1.0,
197 integer n =
static_cast<int>(nn !=
npos ? nn : A.
nRows());
203 writelogf(
"invert(DenseMatrix& A, int nn): DGETRS returned INFO = %d\n", info);
212 integer lwork =
static_cast<int>(work.size());
214 &A.
ipiv()[0], &work[0], lwork, info);
217 writelogf(
"invert(DenseMatrix& A, int nn): DGETRS returned INFO = %d\n", info);
const doublereal *const * const_colPts() const
Return a const vector of const pointers to the columns.
DenseMatrix & operator=(const DenseMatrix &y)
Assignment operator.
size_t nRows() const
Number of rows.
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
int invert(DenseMatrix &A, size_t nn)
invert A. A is overwritten with A^-1.
vector_fp m_data
Data stored in a single array.
void resize(size_t n, size_t m, doublereal v=0.0)
Resize the array, and fill the new entries with 'v'.
Array2D & operator=(const Array2D &y)
assignment operator
const size_t npos
index returned by functions to indicate "no position"
vector_int m_ipiv
Vector of pivots. Length is equal to the max of m and n.
int solve(DenseMatrix &A, double *b, size_t nrhs, size_t ldb)
Solve Ax = b. Array b is overwritten on exit with x.
void increment(const DenseMatrix &A, const double *b, double *prod)
Multiply A*b and add it to the result in prod. Uses BLAS routine DGEMV.
int m_printLevel
Print Level.
doublereal * ptrColumn(size_t j)
Return a pointer to the top of column j, columns are contiguous in memory.
A class for 2D arrays stored in column-major (Fortran-compatible) form.
std::vector< int > vector_int
Vector of ints.
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.
std::vector< doublereal * > m_colPts
Vector of column pointers.
size_t nColumns() const
Number of columns.
void multiply(const DenseMatrix &A, const double *const b, double *const prod)
Multiply A*b and return the result in prod. Uses BLAS routine DGEMV.
size_t m_ncols
Number of columns.
size_t m_nrows
Number of rows.
Base class for exceptions thrown by Cantera classes.
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.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Headers for the DenseMatrix object, which deals with dense rectangular matrices and description of th...
Contains declarations for string manipulation functions within Cantera.
Exception thrown when an LAPACK error is encountered associated with inverting or solving a matrix...
DenseMatrix()
Default Constructor.
int m_useReturnErrorCode
Error Handling Flag.
vector_int & ipiv()
Return a changeable value of the pivot vector.
A class for full (non-sparse) matrices with Fortran-compatible data storage, which adds matrix operat...