diff --git a/include/cantera/numerics/DenseMatrix.h b/include/cantera/numerics/DenseMatrix.h index f7946b573..0ddf974dd 100644 --- a/include/cantera/numerics/DenseMatrix.h +++ b/include/cantera/numerics/DenseMatrix.h @@ -177,7 +177,7 @@ public: * The default is to set this to 0. In this case, if a factorization is requested and can't be achieved, * a CESingularMatrix exception is triggered. No return code is used, because an exception is thrown. * If this is set to 1, then an exception is not thrown. Routines return with an error code, that is up - * to the calling routine to handle correctly + * to the calling routine to handle correctly. Negative return codes always throw an exception. */ int m_useReturnErrorCode; diff --git a/src/equil/ChemEquil.cpp b/src/equil/ChemEquil.cpp index 0fdd6f1fe..263425959 100644 --- a/src/equil/ChemEquil.cpp +++ b/src/equil/ChemEquil.cpp @@ -396,11 +396,8 @@ int ChemEquil::estimateElementPotentials(thermo_t& s, vector_fp& lambda_RT, b[m] = mu_RT[m_component[m]]; } - int info; - try { - info = solve(aa, DATA_PTR(b)); - } catch (CanteraError& err) { - err.save(); + int info = solve(aa, DATA_PTR(b)); + if (info) { if (loglevel > 0) { addLogEntry("failed to estimate initial element potentials."); } diff --git a/src/numerics/DenseMatrix.cpp b/src/numerics/DenseMatrix.cpp index a129e0bcb..9e09da9ea 100644 --- a/src/numerics/DenseMatrix.cpp +++ b/src/numerics/DenseMatrix.cpp @@ -139,44 +139,39 @@ int solve(DenseMatrix& A, double* b) if (A.m_printLevel) { writelogf("solve(DenseMatrix& A, double* b): Can only solve a square matrix\n"); } - if (! A.m_useReturnErrorCode) { - throw CELapackError("solve(DenseMatrix& A, double* b)", "Can only solve a square matrix"); - } - return -1; + throw CELapackError("solve(DenseMatrix& A, double* b)", "Can only solve a square matrix"); } ct_dgetrf(A.nRows(), A.nColumns(), A.ptrColumn(0), A.nRows(), &A.ipiv()[0], info); - if (info != 0) { - if (info > 0) { - if (A.m_printLevel) { - writelogf("solve(DenseMatrix& A, double* b): DGETRF returned INFO = %d U(i,i) is exactly zero. The factorization has" - " been completed, but the factor U is exactly singular, and division by zero will occur if " - "it is used to solve a system of equations.\n", info); - } - if (! A.m_useReturnErrorCode) { - throw CELapackError("solve(DenseMatrix& A, double* b)", - "DGETRF returned INFO = "+int2str(info) + ". U(i,i) is exactly zero. The factorization has" - " been completed, but the factor U is exactly singular, and division by zero will occur if " - "it is used to solve a system of equations."); - } - } else { - if (A.m_printLevel) { - writelogf("solve(DenseMatrix& A, double* b): DGETRF returned INFO = %d. The argument i has an illegal value\n", info); - } - if (! A.m_useReturnErrorCode) { - throw CELapackError("solve(DenseMatrix& A, double* b)", - "DGETRF returned INFO = "+int2str(info) + ". The argument i has an illegal value"); - } + if (info > 0) { + if (A.m_printLevel) { + writelogf("solve(DenseMatrix& A, double* b): DGETRF returned INFO = %d U(i,i) is exactly zero. The factorization has" + " been completed, but the factor U is exactly singular, and division by zero will occur if " + "it is used to solve a system of equations.\n", info); + } + if (!A.m_useReturnErrorCode) { + throw CELapackError("solve(DenseMatrix& A, double* b)", + "DGETRF returned INFO = "+int2str(info) + ". U(i,i) is exactly zero. The factorization has" + " been completed, but the factor U is exactly singular, and division by zero will occur if " + "it is used to solve a system of equations."); } return info; + } else if (info < 0) { + if (A.m_printLevel) { + writelogf("solve(DenseMatrix& A, double* b): DGETRF returned INFO = %d. The argument i has an illegal value\n", info); + } + + throw CELapackError("solve(DenseMatrix& A, double* b)", + "DGETRF returned INFO = "+int2str(info) + ". The argument i has an illegal value"); } + ct_dgetrs(ctlapack::NoTranspose, A.nRows(), 1, A.ptrColumn(0), A.nRows(), &A.ipiv()[0], b, A.nColumns(), info); if (info != 0) { if (A.m_printLevel) { writelogf("solve(DenseMatrix& A, double* b): DGETRS returned INFO = %d\n", info); } - if (! A.m_useReturnErrorCode) { + if (info < 0 || !A.m_useReturnErrorCode) { throw CELapackError("solve(DenseMatrix& A, double* b)", "DGETRS returned INFO = "+int2str(info)); } }