22 BandMatrix::BandMatrix() :
38 data.resize(n*(2*kl + ku + 1));
39 ludata.resize(n*(2*kl + ku + 1));
44 size_t ldab = (2*kl + ku + 1);
45 for (
size_t j = 0; j < n; j++) {
65 for (
size_t j = 0; j <
m_n; j++) {
84 for (
size_t j = 0; j <
m_n; j++) {
95 data.resize(n*(2*kl + ku + 1));
96 ludata.resize(n*(2*kl + ku + 1));
100 size_t ldab = (2 *
m_kl +
m_ku + 1);
101 for (
size_t j = 0; j < n; j++) {
109 std::fill(
data.begin(),
data.end(), v);
115 std::fill(
data.begin(),
data.end(), 0.0);
132 if (i + m_ku < j || i > j +
m_kl) {
140 if (i + m_ku < j || i > j +
m_kl) {
148 int jj =
static_cast<int>(j);
149 int ii =
static_cast<int>(i);
150 size_t rw = (int)
m_kl + (
int)
m_ku + (int) ii - jj;
200 int kl =
static_cast<int>(
m_kl);
201 int ku =
static_cast<int>(
m_ku);
202 int nr =
static_cast<int>(
nRows());
203 doublereal sum = 0.0;
204 for (
int m = 0; m < nr; m++) {
206 for (
int j = m - kl; j <= m + ku; j++) {
207 if (j >= 0 && j < (
int)
m_n) {
208 sum +=
_value(m,j) * b[j];
217 int kl =
static_cast<int>(
m_kl);
218 int ku =
static_cast<int>(
m_ku);
219 int nc =
static_cast<int>(
nColumns());
220 doublereal sum = 0.0;
221 for (
int n = 0; n < nc; n++) {
223 for (
int i = n - ku; i <= n + kl; i++) {
224 if (i >= 0 && i < (
int)
m_n) {
226 sum +=
_value(ii,n) * b[ii];
245 ofstream fout(
"bandmatrix.csv");
246 fout << *
this << endl;
274 ofstream fout(
"bandmatrix.csv");
275 fout << *
this << endl;
305 size_t nr = m.
nRows();
307 for (
size_t i = 0; i < nr; i++) {
308 for (
size_t j = 0; j < nc; j++) {
319 int useReturnErrorCode = 0;
326 doublereal
rcond = 0.0;
328 throw CanteraError(
"BandMatrix::rcond()",
"matrix isn't factored correctly");
337 writelogf(
"BandMatrix::rcond(): DGBCON returned INFO = %d\n", rinfo);
339 if (! useReturnErrorCode) {
353 int ku =
static_cast<int>(
m_ku);
354 int kl =
static_cast<int>(
m_kl);
355 doublereal
value = 0.0;
356 for (
int j = 0; j < (int)
m_n; j++) {
357 doublereal sum = 0.0;
359 for (
int i = j - ku; i <= j + kl; i++) {
360 sum += fabs(colP[kl + ku + i - j]);
362 value = std::max(sum, value);
369 valueSmall = 1.0E300;
370 size_t iSmall =
npos;
371 for (
int i = 0; i < (int)
m_n; i++) {
373 for (
int j = i - (
int)
m_kl; j <= i + (int)
m_ku; j++) {
374 if (j >= 0 && j < (
int)
m_n) {
375 valueS = std::max(fabs(
value(i,j)), valueS);
378 if (valueS < valueSmall) {
381 if (valueSmall == 0.0) {
391 valueSmall = 1.0E300;
392 size_t jSmall =
npos;
393 for (
int j = 0; j < (int)
m_n; j++) {
395 for (
int i = j - (
int)
m_ku; i <= j + (int)
m_kl; i++) {
396 if (i >= 0 && i < (
int)
m_n) {
397 valueS = std::max(fabs(
value(i,j)), valueS);
400 if (valueS < valueSmall) {
403 if (valueSmall == 0.0) {
428 warn_deprecated(
"BandMatrix::copyData",
"To be removed after Cantera 2.2.");
430 size_t n =
sizeof(doublereal) *
m_n * (2 *
m_kl +
m_ku + 1);
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)=0
Return a pointer to the top of column j, columns are assumed to be contiguous in memory.
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
virtual doublereal * ptrColumn(size_t j)
Return a pointer to the top of column j, column values are assumed to be contiguous in memory...
vector_fp work_
Extra dp work array needed - size = 3n.
BandMatrix()
Base Constructor.
vector_int & ipiv()
Return a reference to the pivot vector.
BandMatrix & operator=(const BandMatrix &y)
assignment operator
doublereal _value(size_t i, size_t j) const
Return the value of the (i,j) element for (i,j) within the bandwidth.
Various templated functions that carry out common vector operations (see Templated Utility Functions)...
size_t nSuperDiagonals() const
Number of superdiagonals.
const size_t npos
index returned by functions to indicate "no position"
int m_factored
Indicates whether the matrix is factored.
virtual size_t checkRows(doublereal &valueSmall) const
Check to see if we have any zero rows in the Jacobian.
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.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
size_t nColumns() const
Number of columns.
vector_fp data
Matrix data.
size_t m_n
Number of rows and columns of the matrix.
void resize(size_t n, size_t kl, size_t ku, doublereal v=0.0)
Resize the matrix problem.
virtual void leftMult(const doublereal *const b, doublereal *const prod) const
Multiply b*A and write result to prod.
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.
std::vector< int > vector_int
Vector of ints.
virtual size_t nRowsAndStruct(size_t *const iStruct=0) const
Return the size and structure of the matrix.
void writelogf(const char *fmt,...)
Write a formatted message to the screen.
virtual doublereal rcond(doublereal a1norm)
Returns an estimate of the inverse of the condition number for the matrix.
vector_int m_ipiv
Pivot vector.
Base class for exceptions thrown by Cantera classes.
doublereal & value(size_t i, size_t j)
Return a changeable reference to element (i,j).
size_t ldim() const
Return the number of rows of storage needed for the band storage.
virtual doublereal *const * colPts()
Return a vector of const pointers to the columns.
virtual void copyData(const GeneralMatrix &y)
Copy the data from one array into another without doing any checking.
virtual size_t nRows() const
Return the number of rows in the matrix.
vector_fp ludata
Factorized data.
virtual int factorAlgorithm() const
Returns the factor algorithm used.
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...
size_t m_ku
Number of super diagonals of the matrix.
virtual void useFactorAlgorithm(int fAlgorithm)
Change the way the matrix is factored.
void bfill(doublereal v=0.0)
Fill or zero the matrix.
doublereal m_zero
value of zero
virtual doublereal oneNorm() const
Returns the one norm of the matrix.
Contains declarations for string manipulation functions within Cantera.
int factor()
Perform an LU decomposition, the LAPACK routine DGBTRF is used.
#define DATA_PTR(vec)
Creates a pointer to the start of the raw data for a vector.
virtual void mult(const doublereal *b, doublereal *prod) const
Multiply A*b and write result to prod.
virtual void zero()
Zero the matrix elements.
std::vector< doublereal * > m_colPtrs
Vector of column pointers.
GeneralMatrix & operator=(const GeneralMatrix &right)
Assignment operator.
size_t nSubDiagonals() const
Number of subdiagonals.
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.