20 m_useReturnErrorCode(0),
28 m_useReturnErrorCode(0),
31 m_ipiv.resize(std::max(n, m));
34 for (
size_t j = 0; j < m; j++) {
43 m_useReturnErrorCode(0),
49 for (
size_t j = 0; j <
m_ncols; j++) {
63 for (
size_t j = 0; j <
m_ncols; j++) {
74 m_ipiv.resize(std::max(n,m));
77 for (
size_t j = 0; j <
m_ncols; j++) {
83 doublereal*
const* DenseMatrix::colPts()
93 void DenseMatrix::mult(
const double* b,
double* prod)
const
95 ct_dgemv(ctlapack::ColMajor, ctlapack::NoTranspose,
96 static_cast<int>(
nRows()),
98 static_cast<int>(
nRows()), b, 1, 0.0, prod, 1);
104 throw CanteraError(
"mult(const DenseMatrix &B, DenseMatrix &prod)",
105 "Cannot multiply matrices that are not square and/or not the same size.");
108 doublereal*
const* prodcols = prod.colPts();
109 for (
size_t col=0; col <
m_ncols; ++col) {
111 mult(bcols[col], prodcols[col]);
120 for (
size_t n = 0; n < nc; n++) {
122 for (
size_t i = 0; i < nr; i++) {
123 sum +=
value(i,n)*b[i];
139 writelogf(
"solve(DenseMatrix& A, double* b): Can only solve a square matrix\n");
141 throw CELapackError(
"solve(DenseMatrix& A, double* b)",
"Can only solve a square matrix");
147 writelogf(
"solve(DenseMatrix& A, double* b): DGETRF returned INFO = %d U(i,i) is exactly zero. The factorization has"
148 " been completed, but the factor U is exactly singular, and division by zero will occur if "
149 "it is used to solve a system of equations.\n", info);
153 "DGETRF returned INFO = "+
int2str(info) +
". U(i,i) is exactly zero. The factorization has"
154 " been completed, but the factor U is exactly singular, and division by zero will occur if "
155 "it is used to solve a system of equations.");
158 }
else if (info < 0) {
160 writelogf(
"solve(DenseMatrix& A, double* b): DGETRF returned INFO = %d. The argument i has an illegal value\n", info);
164 "DGETRF returned INFO = "+
int2str(info) +
". The argument i has an illegal value");
171 writelogf(
"solve(DenseMatrix& A, double* b): DGETRS returned INFO = %d\n", info);
174 throw CELapackError(
"solve(DenseMatrix& A, double* b)",
"DGETRS returned INFO = "+
int2str(info));
185 writelogf(
"solve(DenseMatrix& A, DenseMatrix& b): Can only solve a square matrix\n");
188 throw CELapackError(
"solve(DenseMatrix& A, DenseMatrix& b)",
"Can only solve a square matrix");
197 writelogf(
"solve(DenseMatrix& A, DenseMatrix& b): DGETRF returned INFO = %d U(i,i) is exactly zero. The factorization has"
198 " been completed, but the factor U is exactly singular, and division by zero will occur if "
199 "it is used to solve a system of equations.\n", info);
203 "DGETRF returned INFO = "+
int2str(info) +
". U(i,i) is exactly zero. The factorization has"
204 " been completed, but the factor U is exactly singular, and division by zero will occur if "
205 "it is used to solve a system of equations.");
209 writelogf(
"solve(DenseMatrix& A, DenseMatrix& b): DGETRF returned INFO = %d. The argument i has an illegal value\n", info);
213 "DGETRF returned INFO = "+
int2str(info) +
". The argument i has an illegal value");
223 writelogf(
"solve(DenseMatrix& A, DenseMatrix& b): DGETRS returned INFO = %d\n", info);
226 throw CELapackError(
"solve(DenseMatrix& A, DenseMatrix& b)",
"DGETRS returned INFO = "+
int2str(info));
235 ct_dgemv(ctlapack::ColMajor, ctlapack::NoTranspose,
236 static_cast<int>(A.
nRows()), static_cast<int>(A.
nColumns()), 1.0,
242 ct_dgemv(ctlapack::ColMajor, ctlapack::NoTranspose,
243 static_cast<int>(A.
nRows()), static_cast<int>(A.
nRows()), 1.0,
249 integer n =
static_cast<int>(nn !=
npos ? nn : A.
nRows());
255 writelogf(
"invert(DenseMatrix& A, int nn): DGETRS returned INFO = %d\n", info);
264 integer lwork =
static_cast<int>(work.size());
266 &A.
ipiv()[0], &work[0], lwork, info);
269 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'.
Various templated functions that carry out common vector operations (see Templated Utility Functions)...
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.
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
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.
int solve(DenseMatrix &A, double *b)
Solve Ax = b. Array b is overwritten on exit with x.
doublereal * ptrColumn(size_t j)
Return a pointer to the top of column j, columns are contiguous in memory.
This file contains definitions for utility functions and text for modules, inputfiles, logs, textlogs, HTML_logs (see Input File Handling, Diagnostic Output, Writing messages to the screen and Writing HTML Logfiles).
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...