24 BandMatrix::BandMatrix() :
44 data.resize(n*(2*kl + ku + 1));
45 ludata.resize(n*(2*kl + ku + 1));
50 size_t ldab = (2*kl + ku + 1);
51 for (
size_t j = 0; j < n; j++) {
73 for (
size_t j = 0; j <
m_n; j++) {
93 for (
size_t j = 0; j <
m_n; j++) {
104 data.resize(n*(2*kl + ku + 1));
105 ludata.resize(n*(2*kl + ku + 1));
109 size_t ldab = (2 *
m_kl +
m_ku + 1);
110 for (
size_t j = 0; j < n; j++) {
118 std::fill(
data.begin(),
data.end(), v);
124 std::fill(
data.begin(),
data.end(), 0.0);
141 if (i + m_ku < j || i > j +
m_kl) {
149 if (i + m_ku < j || i > j +
m_kl) {
157 int jj =
static_cast<int>(j);
158 int ii =
static_cast<int>(i);
159 size_t rw = (int)
m_kl + (
int)
m_ku + (int) ii - jj;
215 int kl =
static_cast<int>(
m_kl);
216 int ku =
static_cast<int>(
m_ku);
217 int nr =
static_cast<int>(
nRows());
218 doublereal sum = 0.0;
219 for (
int m = 0; m < nr; m++) {
221 for (
int j = m - kl; j <= m + ku; j++) {
222 if (j >= 0 && j < (
int)
m_n) {
223 sum +=
_value(m,j) * b[j];
232 int kl =
static_cast<int>(
m_kl);
233 int ku =
static_cast<int>(
m_ku);
234 int nc =
static_cast<int>(
nColumns());
235 doublereal sum = 0.0;
236 for (
int n = 0; n < nc; n++) {
238 for (
int i = n - ku; i <= n + kl; i++) {
239 if (i >= 0 && i < (
int)
m_n) {
241 sum +=
_value(ii,n) * b[ii];
260 ofstream fout(
"bandmatrix.csv");
261 fout << *
this << endl;
286 ofstream fout(
"bandmatrix.csv");
287 fout << *
this << endl;
317 size_t nr = m.
nRows();
319 for (
size_t i = 0; i < nr; i++) {
320 for (
size_t j = 0; j < nc; j++) {
330 throw CanteraError(
"BandMatrix() unimplemented function", msg);
342 return rcond(a1norm);
348 int useReturnErrorCode = 0;
355 doublereal
rcond = 0.0;
357 throw CanteraError(
"BandMatrix::rcond()",
"matrix isn't factored correctly");
367 writelogf(
"BandMatrix::rcond(): DGBCON returned INFO = %d\n", rinfo);
369 if (! useReturnErrorCode) {
388 int ku =
static_cast<int>(
m_ku);
389 int kl =
static_cast<int>(
m_kl);
390 doublereal
value = 0.0;
391 for (
int j = 0; j < (int)
m_n; j++) {
392 doublereal sum = 0.0;
394 for (
int i = j - ku; i <= j + kl; i++) {
395 sum += fabs(colP[kl + ku + i - j]);
406 valueSmall = 1.0E300;
407 size_t iSmall =
npos;
409 for (
int i = 0; i < (int)
m_n; i++) {
411 for (
int j = i - (
int)
m_kl; j <= i + (int)
m_ku; j++) {
412 if (j >= 0 && j < (
int)
m_n) {
413 vv = fabs(
value(i,j));
419 if (valueS < valueSmall) {
422 if (valueSmall == 0.0) {
432 valueSmall = 1.0E300;
433 size_t jSmall =
npos;
435 for (
int j = 0; j < (int)
m_n; j++) {
437 for (
int i = j - (
int)
m_ku; i <= j + (int)
m_kl; i++) {
438 if (i >= 0 && i < (
int)
m_n) {
439 vv = fabs(
value(i,j));
445 if (valueS < valueSmall) {
448 if (valueSmall == 0.0) {
479 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.
virtual int factorQR()
Factors the A matrix using the QR algorithm, overwriting A.
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"
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.
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.
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).
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 void clearFactorFlag()
Clear the factored flag.
virtual size_t nRowsAndStruct(size_t *const iStruct=0) const
Return the size and structure of the matrix.
virtual doublereal rcondQR()
Returns an estimate of the inverse of the condition number for the matrix.
void writelogf(const char *fmt,...)
Write a formatted message to the screen.
void err(const std::string &msg) const
Error function that gets called for unhandled cases.
virtual doublereal rcond(doublereal a1norm)
Returns an estimate of the inverse of the condition number for the matrix.
vector_int m_ipiv
Pivot vector.
bool m_factored
Boolean indicating whether the matrix is factored.
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 bool factored() const
Report whether the current matrix has been factored.
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.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
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.