13 #if SUNDIALS_USE_LAPACK 14 #include "cvodes/cvodes_lapack.h" 16 #include "cvodes/cvodes_dense.h" 17 #include "cvodes/cvodes_band.h" 29 BandMatrix::BandMatrix() :
45 data.resize(n*(2*kl + ku + 1));
46 ludata.resize(n*(2*kl + ku + 1));
51 m_lu_col_ptrs.resize(n);
52 size_t ldab = (2*kl + ku + 1);
53 for (
size_t j = 0; j < n; j++) {
55 m_lu_col_ptrs[j] = &
ludata[ldab * j];
74 m_lu_col_ptrs.resize(
m_n);
76 for (
size_t j = 0; j <
m_n; j++) {
78 m_lu_col_ptrs[j] = &
ludata[ldab * j];
82 BandMatrix& BandMatrix::operator=(
const BandMatrix& y)
87 GeneralMatrix::operator=(y);
95 m_lu_col_ptrs.resize(
m_n);
97 for (
size_t j = 0; j <
m_n; j++) {
99 m_lu_col_ptrs[j] = &
ludata[ldab * j];
110 data.resize(n*(2*kl + ku + 1));
111 ludata.resize(n*(2*kl + ku + 1));
115 m_lu_col_ptrs.resize(
m_n);
116 size_t ldab = (2 *
m_kl +
m_ku + 1);
117 for (
size_t j = 0; j < n; j++) {
119 m_lu_col_ptrs[j] = &
ludata[ldab * j];
126 std::fill(
data.begin(),
data.end(), v);
132 std::fill(
data.begin(),
data.end(), 0.0);
149 if (i + m_ku < j || i > j +
m_kl) {
157 if (i + m_ku < j || i > j +
m_kl) {
181 "To be removed after Cantera 2.3.");
216 for (
size_t m = 0; m <
m_n; m++) {
218 size_t start = (m >=
m_kl) ? m -
m_kl : 0;
219 size_t stop = std::min(m +
m_ku + 1,
m_n);
220 for (
size_t j = start; j < stop; j++) {
221 sum +=
_value(m,j) * b[j];
229 for (
size_t n = 0; n <
m_n; n++) {
231 size_t start = (n >=
m_ku) ? n -
m_ku : 0;
232 size_t stop = std::min(n +
m_kl + 1,
m_n);
233 for (
size_t i = start; i < stop; i++) {
234 sum +=
_value(i,n) * b[i];
249 long int smu = nu + nl;
250 m_info = bandGBTRF(m_lu_col_ptrs.data(),
static_cast<long int>(
nColumns()),
251 nu, nl, smu,
m_ipiv.data());
255 "Factorization failed with DGBTRF error code {}.", m_info);
278 ipiv().data(), b, ldb, m_info);
282 long int smu = nu + nl;
283 double** a = m_lu_col_ptrs.data();
284 bandGBTRS(a, static_cast<long int>(
nColumns()), smu, nl,
m_ipiv.data(), b);
290 "Linear solve failed with DGBTRS error code {}.", m_info);
319 for (
size_t i = 0; i < m.
nRows(); i++) {
321 for (
size_t j = 1; j < m.nColumns(); j++) {
335 throw CanteraError(
"BandMatrix::rcond()",
"matrix isn't factored correctly");
344 throw CanteraError(
"BandMatrix::rcond()",
"DGBCON returned INFO = {}", rinfo);
348 throw CanteraError(
"BandMatrix::rcond",
"not implemented when LAPACK is missing");
360 for (
size_t j = 0; j <
m_n; j++) {
362 size_t start = (j >=
m_ku) ? j -
m_ku : 0;
363 size_t stop = std::min(j +
m_kl + 1,
m_n);
364 for (
size_t i = start; i < stop; i++) {
365 sum += std::abs(
_value(i,j));
374 valueSmall = 1.0E300;
375 size_t iSmall =
npos;
376 for (
size_t i = 0; i <
m_n; i++) {
378 size_t start = (i >
m_kl) ? i -
m_kl : 0;
379 size_t stop = std::min(i +
m_ku + 1,
m_n);
380 for (
size_t j = start; j < stop; j++) {
381 valueS = std::max(fabs(
_value(i,j)), valueS);
383 if (valueS < valueSmall) {
386 if (valueSmall == 0.0) {
396 valueSmall = 1.0E300;
397 size_t jSmall =
npos;
398 for (
size_t j = 0; j <
m_n; j++) {
400 size_t start = (j >
m_ku) ? j -
m_ku : 0;
401 size_t stop = std::min(j +
m_kl + 1,
m_n);
402 for (
size_t i = start; i < stop; i++) {
403 valueS = std::max(fabs(
_value(i,j)), valueS);
405 if (valueS < valueSmall) {
408 if (valueSmall == 0.0) {
size_t m_kl
Number of subdiagonals of the matrix.
virtual vector_fp::iterator begin()
Returns an iterator for the start of the band storage data.
vector_int iwork_
Extra work array needed - size = n.
virtual doublereal * ptrColumn(size_t j)
Return a pointer to the top of column j.
vector_fp work_
Extra dp work array needed - size = 3n.
BandMatrix()
Base Constructor.
doublereal _value(size_t i, size_t j) const
Return the value of the (i,j) element for (i,j) within the bandwidth.
virtual size_t checkColumns(doublereal &valueSmall) const
Check to see if we have any zero columns in the Jacobian.
Various templated functions that carry out common vector operations (see Templated Utility Functions)...
const size_t npos
index returned by functions to indicate "no position"
int m_factored
Indicates whether the matrix is factored.
int solve(const doublereal *const b, doublereal *const x)
Solve the matrix problem Ax = b.
doublereal & operator()(size_t i, size_t j)
Index into the (i,j) element.
size_t index(size_t i, size_t j) const
Returns the location in the internal 1D array corresponding to the (i,j) element in the banded array...
virtual void leftMult(const doublereal *const b, doublereal *const prod) const
Multiply b*A and write result to prod.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
vector_fp data
Matrix data.
size_t m_n
Number of rows and columns of the matrix.
size_t nSubDiagonals() const
Number of subdiagonals.
void resize(size_t n, size_t kl, size_t ku, doublereal v=0.0)
Resize the matrix problem.
size_t nColumns() const
Number of columns.
virtual doublereal *const * colPts()
Return a vector of const pointers to the columns.
pivot_vector_t m_ipiv
Pivot vector.
virtual doublereal oneNorm() const
Returns the one norm of the matrix.
virtual int factorAlgorithm() const
Returns the factor algorithm used.
size_t nSuperDiagonals() const
Number of superdiagonals.
virtual doublereal rcond(doublereal a1norm)
Returns an estimate of the inverse of the condition number for the matrix.
virtual size_t checkRows(doublereal &valueSmall) const
Check to see if we have any zero rows in the Jacobian.
Base class for exceptions thrown by Cantera classes.
doublereal & value(size_t i, size_t j)
Return a changeable reference to element (i,j).
vector_fp ludata
Factorized data.
virtual size_t nRowsAndStruct(size_t *const iStruct=0) const
Return the size and structure of the matrix.
size_t m_ku
Number of super diagonals of the matrix.
virtual size_t nRows() const
Return the number of rows in the matrix.
size_t ldim() const
Return the number of rows of storage needed for the band storage.
void bfill(doublereal v=0.0)
Fill or zero the matrix.
doublereal m_zero
value of zero
Contains declarations for string manipulation functions within Cantera.
int factor()
Perform an LU decomposition, the LAPACK routine DGBTRF is used.
virtual void zero()
Zero the matrix elements.
std::vector< doublereal * > m_colPtrs
Vector of column pointers.
virtual GeneralMatrix * duplMyselfAsGeneralMatrix() const
Duplicator member function.
Namespace for the Cantera kernel.
virtual void mult(const doublereal *b, doublereal *prod) const
Multiply A*b and write result to prod.
pivot_vector_t & ipiv()
Return a reference to the pivot vector.
vector_fp::iterator end()
Returns an iterator for the end of the band storage data.
Declarations for the class BandMatrix which is a child class of GeneralMatrix for banded matrices han...
A class for banded matrices, involving matrix inversion processes.