Distinguish between factorization failures and other errors in DenseMatrix.solve
Input errors always throw exceptions, while factorization failures may be indicated by the return value, depending on the m_useReturnErrorCode variable of the DenseMatrix.
This commit is contained in:
parent
d8a4c6705a
commit
59b878bf41
3 changed files with 24 additions and 32 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue