14 #include "cantera/numerics/eigen_dense.h"
23 m_ipiv.resize(std::max(n, m));
32DenseMatrix& DenseMatrix::operator=(
const DenseMatrix& y)
37 Array2D::operator=(y);
45 m_ipiv.resize(std::max(n,m));
48void DenseMatrix::mult(span<const double> b, span<double> prod)
const
53 ct_dgemv(ctlapack::ColMajor, ctlapack::NoTranspose,
54 static_cast<int>(
nRows()),
56 static_cast<int>(
nRows()), b.data(), 1, 0.0, prod.data(), 1);
59 MappedVector bm(
const_cast<double*
>(b.data()),
nColumns());
60 MappedVector pm(prod.data(),
nRows());
69 "Inner matrix dimensions do not agree: {} != {}",
nColumns(), B.
nRows());
73 "Output matrix has wrong dimensions: {}x{} != {}x{}",
87 for (
size_t n = 0; n <
nColumns(); n++) {
89 for (
size_t i = 0; i <
nRows(); i++) {
90 sum +=
value(i,n)*b[i];
104 throw CanteraError(
"solve(DenseMatrix& A, span<double> b)",
105 "Can only solve a square matrix");
112 checkArraySize(
"solve(DenseMatrix& A, span<double> b)", b.size(), ldb * nrhs);
117 throw CanteraError(
"solve(DenseMatrix& A, span<double> b)",
118 "DGETRF returned INFO = {}. U(i,i) is exactly zero. The factorization has"
119 " been completed, but the factor U is exactly singular, and division by zero will occur if "
120 "it is used to solve a system of equations.", info);
121 }
else if (info < 0) {
122 throw CanteraError(
"solve(DenseMatrix& A, span<double> b)",
123 "DGETRF returned INFO = {}. The argument i has an illegal value", info);
126 ct_dgetrs(ctlapack::NoTranspose, A.
nRows(), nrhs, A.
data().data(),
127 A.
nRows(), &A.
ipiv()[0], b.data(), ldb, info);
129 throw CanteraError(
"solve(DenseMatrix& A, span<double> b)",
130 "DGETRS returned INFO = {}", info);
135 auto lu = Am.partialPivLu();
137 auto lu = Am.fullPivLu();
138 if (lu.nonzeroPivots() <
static_cast<long int>(A.
nColumns())) {
139 throw CanteraError(
"solve(DenseMatrix& A, span<double> b)",
140 "Matrix appears to be rank-deficient: non-zero pivots = {}; columns = {}",
144 for (
size_t i = 0; i < nrhs; i++) {
145 MappedVector bm(b.data() + ldb*i, A.
nColumns());
166 ct_dgemv(ctlapack::ColMajor, ctlapack::NoTranspose,
167 static_cast<int>(A.
nRows()),
static_cast<int>(A.
nColumns()), 1.0,
168 A.
data().data(),
static_cast<int>(A.
nRows()), b.data(), 1, 1.0, prod.data(), 1);
171 MappedVector bm(
const_cast<double*
>(b.data()), A.
nColumns());
172 MappedVector pm(prod.data(), A.
nRows());
181 integer n =
static_cast<int>(nn !=
npos ? nn : A.
nRows());
182 ct_dgetrf(n, n, A.
data().data(),
static_cast<int>(A.
nRows()),
185 throw CanteraError(
"invert(DenseMatrix& A, size_t nn)",
"DGETRF returned INFO = {}", info);
188 vector<double> work(n);
189 integer lwork =
static_cast<int>(work.size());
190 ct_dgetri(n, A.
data().data(),
static_cast<int>(A.
nRows()),
191 &A.
ipiv()[0], &work[0], lwork, info);
193 throw CanteraError(
"invert(DenseMatrix& A, size_t nn)",
"DGETRI returned INFO={}", info);
200 Am.topLeftCorner(nn, nn) = Am.topLeftCorner(nn, nn).inverse();
Headers for the DenseMatrix object, which deals with dense rectangular matrices and description of th...
A class for 2D arrays stored in column-major (Fortran-compatible) form.
vector< double > m_data
Data stored in a single array.
size_t nRows() const
Number of rows.
size_t nColumns() const
Number of columns.
span< double > col(size_t j)
Return a writable span over column j.
vector< double > & data()
Return a reference to the data vector.
double & value(size_t i, size_t j)
Returns a changeable reference to position in the matrix.
virtual void resize(size_t n, size_t m, double v=0.0)
Resize the array, and fill the new entries with 'v'.
Base class for exceptions thrown by Cantera classes.
A class for full (non-sparse) matrices with Fortran-compatible data storage, which adds matrix operat...
void resize(size_t n, size_t m, double v=0.0) override
Resize the matrix.
vector< int > & ipiv()
Return a changeable value of the pivot vector.
DenseMatrix()=default
Default Constructor.
virtual void leftMult(span< const double > b, span< double > prod) const
Left-multiply the matrix by transpose(b), and write the result to prod.
vector< int > m_ipiv
Vector of pivots. Length is equal to the max of m and n.
This file contains definitions for utility functions and text for modules, inputfiles and logging,...
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"
void increment(const DenseMatrix &A, span< const double > b, span< double > prod)
Multiply A*b and add it to the result in prod. Uses BLAS routine DGEMV.
void solve(DenseMatrix &A, span< double > b, size_t nrhs, size_t ldb)
Solve Ax = b. Array b is overwritten on exit with x.
void multiply(const DenseMatrix &A, span< const double > b, span< double > prod)
Multiply A*b and return the result in prod. Uses BLAS routine DGEMV.
void invert(DenseMatrix &A, size_t nn)
invert A. A is overwritten with A^-1.
void checkArraySize(const char *procedure, size_t available, size_t required)
Wrapper for throwing ArraySizeError.
Contains declarations for string manipulation functions within Cantera.