From caf1ee7c471506a718e3339ae764aa41a199d7e4 Mon Sep 17 00:00:00 2001 From: Francesco Lannutti Date: Thu, 22 Oct 2020 00:58:11 +0200 Subject: [PATCH] Fixed a crash when SPARSE is used --- src/maths/ni/niiter.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/maths/ni/niiter.c b/src/maths/ni/niiter.c index 7671db3df..bf945f3f6 100644 --- a/src/maths/ni/niiter.c +++ b/src/maths/ni/niiter.c @@ -114,7 +114,9 @@ NIiter(CKTcircuit *ckt, int maxIter) startTime = SPfrontEnd->IFseconds(); #ifdef KLU - ckt->CKTmatrix->SMPkluMatrix->KLUloadDiagGmin = 1 ; + if (ckt->CKTkluMODE) { + ckt->CKTmatrix->SMPkluMatrix->KLUloadDiagGmin = 1 ; + } #endif error = SMPreorder(ckt->CKTmatrix, ckt->CKTpivotAbsTol, @@ -146,7 +148,9 @@ NIiter(CKTcircuit *ckt, int maxIter) startTime = SPfrontEnd->IFseconds(); #ifdef KLU - ckt->CKTmatrix->SMPkluMatrix->KLUloadDiagGmin = 1 ; + if (ckt->CKTkluMODE) { + ckt->CKTmatrix->SMPkluMatrix->KLUloadDiagGmin = 1 ; + } #endif error = SMPluFac(ckt->CKTmatrix, ckt->CKTpivotAbsTol, @@ -155,7 +159,7 @@ NIiter(CKTcircuit *ckt, int maxIter) SPfrontEnd->IFseconds() - startTime; #ifdef KLU - if (error == E_SINGULAR) { + if ((ckt->CKTkluMODE) && (error == E_SINGULAR)) { /* Francesco Lannutti - 25 Aug 2020 * If the matrix is numerically singular during ReFactorization, take the same matrix and factor it from scratch in the same iteration. @@ -183,9 +187,17 @@ NIiter(CKTcircuit *ckt, int maxIter) return(error); } } else if (error) { - SMPgetError(ckt->CKTmatrix, &i, &j); - SPfrontEnd->IFerrorf (ERR_WARNING, "singular matrix: check nodes %s and %s\n", NODENAME(ckt, i), NODENAME(ckt, j)); + if (!(ckt->CKTkluMODE) && (error == E_SINGULAR)) { + /* Francesco Lannutti - 25 Aug 2020 + * If the matrix is numerically singular during ReFactorization, factor it from scratch at the next iteration. + * This is the original SPICE3F5 code and uses SPARSE. + */ + + ckt->CKTniState |= NISHOULDREORDER; + DEBUGMSG(" forced reordering....\n"); + continue; + } /* CKTload(ckt); */ /* SMPprint(ckt->CKTmatrix, stdout); */ /* seems to be singular - pass the bad news up */