diff --git a/src/maths/ni/niiter.c b/src/maths/ni/niiter.c index 4d2e854f8..41b811bc6 100644 --- a/src/maths/ni/niiter.c +++ b/src/maths/ni/niiter.c @@ -146,6 +146,13 @@ NIiter(CKTcircuit *ckt, int maxIter) #ifdef KLU if (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. + * This is my mod with KLU. It saves run-time, but also the system at the next iteration may be different. + * How do we guarantee that the system is the same at the next iteration? So, the original SPARSE version below sounds like a bug. + */ + fprintf (stderr, "Warning: KLU ReFactor failed. Factoring again...\n") ; ckt->CKTniState |= NISHOULDREORDER; error = SMPreorder(ckt->CKTmatrix, ckt->CKTpivotAbsTol, ckt->CKTpivotRelTol, ckt->CKTdiagGmin); @@ -168,6 +175,12 @@ NIiter(CKTcircuit *ckt, int maxIter) #else if (error) { if (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;