From 7fef1b00513e769486123efa4e96b14eda04feb6 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Mon, 24 Mar 2014 04:02:51 +0000 Subject: [PATCH] [Numerics] BandMatrix does not silently do LU when QR is specified Change GeneralMatrix to allow derived classes to not implement QR factorization. BandMatrix does not implement QR because this LAPACK does not contain a QR algorithm for this matrix type. --- include/cantera/numerics/BandMatrix.h | 33 ++---------------------- include/cantera/numerics/GeneralMatrix.h | 13 +++++++--- src/numerics/BandMatrix.cpp | 17 ------------ 3 files changed, 12 insertions(+), 51 deletions(-) diff --git a/include/cantera/numerics/BandMatrix.h b/include/cantera/numerics/BandMatrix.h index 96cf60260..379373ff3 100644 --- a/include/cantera/numerics/BandMatrix.h +++ b/include/cantera/numerics/BandMatrix.h @@ -218,22 +218,6 @@ public: virtual void zero(); - //! Factors the A matrix using the QR algorithm, overwriting A - /*! - * we set m_factored to 2 to indicate the matrix is now QR factored - * - * @return Returns the info variable from lapack - */ - virtual int factorQR(); - - //! Returns an estimate of the inverse of the condition number for the matrix - /*! - * The matrix must have been previously factored using the QR algorithm - * - * @return returns the inverse of the condition number - */ - virtual doublereal rcondQR(); - //! Returns an estimate of the inverse of the condition number for the matrix /*! * The matrix must have been previously factored using the LU algorithm @@ -244,21 +228,8 @@ public: */ virtual doublereal rcond(doublereal a1norm); - //! Change the way the matrix is factored - /*! - * @param fAlgorithm integer - * 0 LU factorization - * 1 QR factorization - */ - virtual void useFactorAlgorithm(int fAlgorithm); - - //! Returns the factor algorithm used - /*! - * 0 LU decomposition - * 1 QR decomposition - * - * This routine will always return 0 - */ + //! Returns the factor algorithm used. This method will always return 0 + //! (LU) for band matrices. virtual int factorAlgorithm() const; //! Returns the one norm of the matrix diff --git a/include/cantera/numerics/GeneralMatrix.h b/include/cantera/numerics/GeneralMatrix.h index c59fcde46..226e7bd30 100644 --- a/include/cantera/numerics/GeneralMatrix.h +++ b/include/cantera/numerics/GeneralMatrix.h @@ -15,6 +15,7 @@ #define CT_GENERALMATRIX_H #include "cantera/base/ct_defs.h" +#include "cantera/base/ctexceptions.h" namespace Cantera { @@ -77,7 +78,9 @@ public: * * @return Returns the info variable from lapack */ - virtual int factorQR() = 0; + virtual int factorQR() { + throw NotImplementedError("GeneralMatrix::factorQR"); + } //! Returns an estimate of the inverse of the condition number for the matrix /*! @@ -85,7 +88,9 @@ public: * * @return returns the inverse of the condition number */ - virtual doublereal rcondQR() = 0; + virtual doublereal rcondQR() { + throw NotImplementedError("GeneralMatrix::rcondQR"); + } //! Returns an estimate of the inverse of the condition number for the matrix /*! @@ -103,7 +108,9 @@ public: * 0 LU factorization * 1 QR factorization */ - virtual void useFactorAlgorithm(int fAlgorithm) = 0; + virtual void useFactorAlgorithm(int fAlgorithm) { + throw NotImplementedError("GeneralMatrix::useFactorAlgorithm"); + }; //! Return the factor algorithm used virtual int factorAlgorithm() const = 0; diff --git a/src/numerics/BandMatrix.cpp b/src/numerics/BandMatrix.cpp index c7dc96be3..6f3f855c6 100644 --- a/src/numerics/BandMatrix.cpp +++ b/src/numerics/BandMatrix.cpp @@ -333,18 +333,6 @@ void BandMatrix::err(const std::string& msg) const throw CanteraError("BandMatrix() unimplemented function", msg); } -int BandMatrix::factorQR() -{ - factor(); - return 0; -} - -doublereal BandMatrix::rcondQR() -{ - double a1norm = oneNorm(); - return rcond(a1norm); -} - doublereal BandMatrix::rcond(doublereal a1norm) { int printLevel = 0; @@ -376,11 +364,6 @@ doublereal BandMatrix::rcond(doublereal a1norm) return rcond; } -void BandMatrix::useFactorAlgorithm(int fAlgorithm) -{ - // QR algorithm isn't implemented for banded matrix. -} - int BandMatrix::factorAlgorithm() const { return 0;