[Numerics] move 'm_factored' up to GeneralMatrix

This commit is contained in:
Ray Speth 2014-03-24 04:03:01 +00:00
parent 4467b898a5
commit 90c2d58973
7 changed files with 18 additions and 52 deletions

View file

@ -237,9 +237,6 @@ public:
virtual GeneralMatrix* duplMyselfAsGeneralMatrix() const; virtual GeneralMatrix* duplMyselfAsGeneralMatrix() const;
//! Report whether the current matrix has been factored.
virtual bool factored() const;
//! Return a pointer to the top of column j, column values are assumed to be contiguous in memory //! Return a pointer to the top of column j, column values are assumed to be contiguous in memory
/*! /*!
* The LAPACK bandstructure has column values which are contiguous in memory: * The LAPACK bandstructure has column values which are contiguous in memory:
@ -280,9 +277,6 @@ public:
*/ */
virtual void copyData(const GeneralMatrix& y); virtual void copyData(const GeneralMatrix& y);
//! Clear the factored flag
virtual void clearFactorFlag();
//! Check to see if we have any zero rows in the jacobian //! Check to see if we have any zero rows in the jacobian
/*! /*!
* This utility routine checks to see if any rows are zero. * This utility routine checks to see if any rows are zero.
@ -313,9 +307,6 @@ protected:
//! Factorized data //! Factorized data
vector_fp ludata; vector_fp ludata;
//! Boolean indicating whether the matrix is factored
bool m_factored;
//! Number of rows and columns of the matrix //! Number of rows and columns of the matrix
size_t m_n; size_t m_n;

View file

@ -130,7 +130,9 @@ public:
virtual size_t nRowsAndStruct(size_t* const iStruct = 0) const = 0; virtual size_t nRowsAndStruct(size_t* const iStruct = 0) const = 0;
//! clear the factored flag //! clear the factored flag
virtual void clearFactorFlag() = 0; virtual void clearFactorFlag() {
m_factored = 0;
};
//! Solves the Ax = b system returning x in the b spot. //! Solves the Ax = b system returning x in the b spot.
/*! /*!
@ -142,7 +144,9 @@ public:
virtual int solve(doublereal* b, size_t nrhs=1, size_t ldb=0) = 0; virtual int solve(doublereal* b, size_t nrhs=1, size_t ldb=0) = 0;
//! true if the current factorization is up to date with the matrix //! true if the current factorization is up to date with the matrix
virtual bool factored() const = 0; virtual bool factored() const {
return (m_factored != 0);
}
//! Return a pointer to the top of column j, columns are assumed to be contiguous in memory //! Return a pointer to the top of column j, columns are assumed to be contiguous in memory
/*! /*!
@ -228,6 +232,11 @@ public:
*/ */
int matrixType_; int matrixType_;
protected:
//! Indicates whether the matrix is factored. 0 for unfactored; Non-zero values
//! indicate a particular factorization (LU=1, QR=2).
int m_factored;
}; };
} }
#endif #endif

View file

@ -69,12 +69,9 @@ public:
*/ */
int solveQR(doublereal* b); int solveQR(doublereal* b);
virtual void clearFactorFlag();
//! set the factored flag //! set the factored flag
void setFactorFlag(); void setFactorFlag();
virtual bool factored() const;
virtual void useFactorAlgorithm(int fAlgorithm); virtual void useFactorAlgorithm(int fAlgorithm);
//! Returns the factor algorithm used //! Returns the factor algorithm used
@ -121,11 +118,6 @@ public:
virtual size_t checkRows(doublereal& valueSmall) const; virtual size_t checkRows(doublereal& valueSmall) const;
virtual size_t checkColumns(doublereal& valueSmall) const; virtual size_t checkColumns(doublereal& valueSmall) const;
protected:
//! the factor flag
int m_factored;
public:
//! Work vector for QR algorithm //! Work vector for QR algorithm
vector_fp tau; vector_fp tau;

View file

@ -1481,7 +1481,7 @@ void BEulerInt::doNewtonSolve(double time_curr, double* y_curr,
RRow[0] = delta_y[focusRow]; RRow[0] = delta_y[focusRow];
RRow[1] = delta_y[focusRow+1]; RRow[1] = delta_y[focusRow+1];
double Pcutoff = 1.0E-70; double Pcutoff = 1.0E-70;
if (!jac.m_factored) { if (!jac.factored()) {
jacBack = jac; jacBack = jac;
} else { } else {
freshJac = false; freshJac = false;

View file

@ -23,7 +23,6 @@ namespace Cantera
BandMatrix::BandMatrix() : BandMatrix::BandMatrix() :
GeneralMatrix(1), GeneralMatrix(1),
m_factored(false),
m_n(0), m_n(0),
m_kl(0), m_kl(0),
m_ku(0), m_ku(0),
@ -35,7 +34,6 @@ BandMatrix::BandMatrix() :
BandMatrix::BandMatrix(size_t n, size_t kl, size_t ku, doublereal v) : BandMatrix::BandMatrix(size_t n, size_t kl, size_t ku, doublereal v) :
GeneralMatrix(1), GeneralMatrix(1),
m_factored(false),
m_n(n), m_n(n),
m_kl(kl), m_kl(kl),
m_ku(ku), m_ku(ku),
@ -54,8 +52,7 @@ BandMatrix::BandMatrix(size_t n, size_t kl, size_t ku, doublereal v) :
} }
BandMatrix::BandMatrix(const BandMatrix& y) : BandMatrix::BandMatrix(const BandMatrix& y) :
GeneralMatrix(1), GeneralMatrix(y),
m_factored(false),
m_n(0), m_n(0),
m_kl(0), m_kl(0),
m_ku(0), m_ku(0),
@ -66,7 +63,6 @@ BandMatrix::BandMatrix(const BandMatrix& y) :
m_ku = y.m_ku; m_ku = y.m_ku;
data = y.data; data = y.data;
ludata = y.ludata; ludata = y.ludata;
m_factored = y.m_factored;
m_ipiv = y.m_ipiv; m_ipiv = y.m_ipiv;
m_colPtrs.resize(m_n); m_colPtrs.resize(m_n);
size_t ldab = (2 *m_kl + m_ku + 1); size_t ldab = (2 *m_kl + m_ku + 1);
@ -87,7 +83,6 @@ BandMatrix& BandMatrix::operator=(const BandMatrix& y)
m_ipiv = y.m_ipiv; m_ipiv = y.m_ipiv;
data = y.data; data = y.data;
ludata = y.ludata; ludata = y.ludata;
m_factored = y.m_factored;
m_colPtrs.resize(m_n); m_colPtrs.resize(m_n);
size_t ldab = (2 * m_kl + m_ku + 1); size_t ldab = (2 * m_kl + m_ku + 1);
for (size_t j = 0; j < m_n; j++) { for (size_t j = 0; j < m_n; j++) {
@ -439,11 +434,6 @@ GeneralMatrix* BandMatrix::duplMyselfAsGeneralMatrix() const
return new BandMatrix(*this); return new BandMatrix(*this);
} }
bool BandMatrix::factored() const
{
return m_factored;
}
doublereal* BandMatrix::ptrColumn(size_t j) doublereal* BandMatrix::ptrColumn(size_t j)
{ {
return m_colPtrs[j]; return m_colPtrs[j];
@ -462,9 +452,4 @@ void BandMatrix::copyData(const GeneralMatrix& y)
(void) memcpy(DATA_PTR(data), yyPtr->ptrColumn(0), n); (void) memcpy(DATA_PTR(data), yyPtr->ptrColumn(0), n);
} }
void BandMatrix::clearFactorFlag()
{
m_factored = 0;
}
} }

View file

@ -16,12 +16,14 @@ namespace Cantera
{ {
GeneralMatrix::GeneralMatrix(int matType) : GeneralMatrix::GeneralMatrix(int matType) :
matrixType_(matType) matrixType_(matType),
m_factored(0)
{ {
} }
GeneralMatrix::GeneralMatrix(const GeneralMatrix& y) : GeneralMatrix::GeneralMatrix(const GeneralMatrix& y) :
matrixType_(y.matrixType_) matrixType_(y.matrixType_),
m_factored(y.m_factored)
{ {
} }
@ -31,6 +33,7 @@ GeneralMatrix& GeneralMatrix::operator=(const GeneralMatrix& y)
return *this; return *this;
} }
matrixType_ = y.matrixType_; matrixType_ = y.matrixType_;
m_factored = y.m_factored;
return *this; return *this;
} }

View file

@ -22,7 +22,6 @@ namespace Cantera
SquareMatrix::SquareMatrix() : SquareMatrix::SquareMatrix() :
DenseMatrix(), DenseMatrix(),
GeneralMatrix(0), GeneralMatrix(0),
m_factored(0),
a1norm_(0.0), a1norm_(0.0),
useQR_(0) useQR_(0)
{ {
@ -31,7 +30,6 @@ SquareMatrix::SquareMatrix() :
SquareMatrix::SquareMatrix(size_t n, doublereal v) : SquareMatrix::SquareMatrix(size_t n, doublereal v) :
DenseMatrix(n, n, v), DenseMatrix(n, n, v),
GeneralMatrix(0), GeneralMatrix(0),
m_factored(0),
a1norm_(0.0), a1norm_(0.0),
useQR_(0) useQR_(0)
@ -41,7 +39,6 @@ SquareMatrix::SquareMatrix(size_t n, doublereal v) :
SquareMatrix::SquareMatrix(const SquareMatrix& y) : SquareMatrix::SquareMatrix(const SquareMatrix& y) :
DenseMatrix(y), DenseMatrix(y),
GeneralMatrix(0), GeneralMatrix(0),
m_factored(y.m_factored),
a1norm_(y.a1norm_), a1norm_(y.a1norm_),
useQR_(y.useQR_) useQR_(y.useQR_)
{ {
@ -54,7 +51,6 @@ SquareMatrix& SquareMatrix::operator=(const SquareMatrix& y)
} }
DenseMatrix::operator=(y); DenseMatrix::operator=(y);
GeneralMatrix::operator=(y); GeneralMatrix::operator=(y);
m_factored = y.m_factored;
a1norm_ = y.a1norm_; a1norm_ = y.a1norm_;
useQR_ = y.useQR_; useQR_ = y.useQR_;
return *this; return *this;
@ -150,11 +146,6 @@ int SquareMatrix::factor()
return info; return info;
} }
void SquareMatrix::clearFactorFlag()
{
m_factored = 0;
}
void SquareMatrix::setFactorFlag() void SquareMatrix::setFactorFlag()
{ {
m_factored = 1; m_factored = 1;
@ -315,11 +306,6 @@ int SquareMatrix::factorAlgorithm() const
return (int) useQR_; return (int) useQR_;
} }
bool SquareMatrix::factored() const
{
return (m_factored != 0);
}
doublereal* SquareMatrix::ptrColumn(size_t j) doublereal* SquareMatrix::ptrColumn(size_t j)
{ {
return Array2D::ptrColumn(j); return Array2D::ptrColumn(j);