From 5513f6e5f617763aa0c4bfbb9ce7d2b559400f75 Mon Sep 17 00:00:00 2001 From: Francesco Lannutti Date: Mon, 22 Jun 2020 19:23:03 +0200 Subject: [PATCH] Handled the SINGULAR matrix case in a more clever way! --- src/maths/KLU/klusmp.c | 45 ++++++++++++++++++++++-------------------- src/maths/ni/niinit.c | 1 - src/maths/ni/niiter.c | 1 + 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/maths/KLU/klusmp.c b/src/maths/KLU/klusmp.c index 3bf97e21c..ab6bb77fc 100644 --- a/src/maths/KLU/klusmp.c +++ b/src/maths/KLU/klusmp.c @@ -409,6 +409,10 @@ SMPcLUfac (SMPmatrix *Matrix, double PivTol) if (ret == 0) { + if (Matrix->CKTkluCommon->status == KLU_SINGULAR) { + fprintf (stderr, "Warning (ReFactor): KLU Matrix is SINGULAR\n") ; + return E_SINGULAR ; + } if (Matrix->CKTkluCommon == NULL) { fprintf (stderr, "Error (ReFactor): KLUcommon object is NULL. A problem occurred\n") ; } @@ -421,10 +425,6 @@ SMPcLUfac (SMPmatrix *Matrix, double PivTol) } return 1 ; } else { - if (Matrix->CKTkluCommon->status == KLU_SINGULAR) { - fprintf (stderr, "Warning (ReFactor): KLU Matrix is SINGULAR\n") ; - return E_SINGULAR ; - } return 0 ; } } else { @@ -454,6 +454,10 @@ SMPluFac (SMPmatrix *Matrix, double PivTol, double Gmin) if (ret == 0) { + if (Matrix->CKTkluCommon->status == KLU_SINGULAR) { + fprintf (stderr, "Warning (ReFactor): KLU Matrix is SINGULAR\n") ; + return E_SINGULAR ; + } if (Matrix->CKTkluCommon == NULL) { fprintf (stderr, "Error (ReFactor): KLUcommon object is NULL. A problem occurred\n") ; } @@ -466,10 +470,6 @@ SMPluFac (SMPmatrix *Matrix, double PivTol, double Gmin) } return 1 ; } else { - if (Matrix->CKTkluCommon->status == KLU_SINGULAR) { - fprintf (stderr, "Warning (ReFactor): KLU Matrix is SINGULAR\n") ; - return E_SINGULAR ; - } return 0 ; } } else { @@ -511,6 +511,10 @@ SMPluFacKLUforCIDER (SMPmatrix *Matrix) if (ret == 0) { + if (Matrix->CKTkluCommon->status == KLU_SINGULAR) { + fprintf (stderr, "Warning (ReFactor) (CIDER): KLU Matrix is SINGULAR\n") ; + return E_SINGULAR ; + } if (Matrix->CKTkluCommon == NULL) { fprintf (stderr, "Error (ReFactor) (CIDER): KLUcommon object is NULL. A problem occurred\n") ; } @@ -523,10 +527,6 @@ SMPluFacKLUforCIDER (SMPmatrix *Matrix) } return 1 ; } else { - if (Matrix->CKTkluCommon->status == KLU_SINGULAR) { - fprintf (stderr, "Warning (ReFactor) (CIDER): KLU Matrix is SINGULAR\n") ; - return E_SINGULAR ; - } return 0 ; } } else { @@ -557,6 +557,10 @@ SMPcReorder (SMPmatrix *Matrix, double PivTol, double PivRel, int *NumSwaps) if (Matrix->CKTkluNumeric == NULL) { fprintf (stderr, "Error (Factor): KLUnumeric object is NULL. A problem occurred\n") ; + if (Matrix->CKTkluCommon->status == KLU_SINGULAR) { + fprintf (stderr, "Warning (Factor): KLU Matrix is SINGULAR\n") ; + return 0 ; + } if (Matrix->CKTkluCommon == NULL) { fprintf (stderr, "Error (Factor): KLUcommon object is NULL. A problem occurred\n") ; } @@ -568,9 +572,6 @@ SMPcReorder (SMPmatrix *Matrix, double PivTol, double PivRel, int *NumSwaps) } return 1 ; } else { - if (Matrix->CKTkluCommon->status == KLU_SINGULAR) { - fprintf (stderr, "Warning (Factor): KLU Matrix is SINGULAR\n") ; - } return 0 ; } } else { @@ -602,6 +603,10 @@ SMPreorder (SMPmatrix *Matrix, double PivTol, double PivRel, double Gmin) if (Matrix->CKTkluNumeric == NULL) { fprintf (stderr, "Error (Factor): KLUnumeric object is NULL. A problem occurred\n") ; + if (Matrix->CKTkluCommon->status == KLU_SINGULAR) { + fprintf (stderr, "Warning (Factor): KLU Matrix is SINGULAR\n") ; + return 0 ; + } if (Matrix->CKTkluCommon == NULL) { fprintf (stderr, "Error (Factor): KLUcommon object is NULL. A problem occurred\n") ; } @@ -613,9 +618,6 @@ SMPreorder (SMPmatrix *Matrix, double PivTol, double PivRel, double Gmin) } return 1 ; } else { - if (Matrix->CKTkluCommon->status == KLU_SINGULAR) { - fprintf (stderr, "Warning (Factor): KLU Matrix is SINGULAR\n") ; - } return 0 ; } } else { @@ -661,6 +663,10 @@ SMPreorderKLUforCIDER (SMPmatrix *Matrix) if (Matrix->SMPkluMatrix->KLUmatrixNumeric == NULL) { fprintf (stderr, "Error (Factor) (CIDER): KLUnumeric object is NULL. A problem occurred\n") ; + if (Matrix->CKTkluCommon->status == KLU_SINGULAR) { + fprintf (stderr, "Warning (Factor): KLU Matrix is SINGULAR\n") ; + return 0 ; + } if (Matrix->CKTkluCommon == NULL) { fprintf (stderr, "Error (Factor) (CIDER): KLUcommon object is NULL. A problem occurred\n") ; } @@ -672,9 +678,6 @@ SMPreorderKLUforCIDER (SMPmatrix *Matrix) } return 1 ; } else { - if (Matrix->CKTkluCommon->status == KLU_SINGULAR) { - fprintf (stderr, "Warning (Factor) (CIDER): KLU Matrix is SINGULAR\n") ; - } return 0 ; } } else { diff --git a/src/maths/ni/niinit.c b/src/maths/ni/niinit.c index aa064f7ef..301269de5 100644 --- a/src/maths/ni/niinit.c +++ b/src/maths/ni/niinit.c @@ -48,7 +48,6 @@ NIinit(CKTcircuit *ckt) ckt->CKTmatrix->CKTkluMODE = ckt->CKTkluMODE ; /* TO BE SUBSTITUTED WITH THE HEURISTICS */ klu_defaults (ckt->CKTmatrix->CKTkluCommon) ; - ckt->CKTmatrix->CKTkluCommon->halt_if_singular = 0 ; #endif ckt->CKTniState = NIUNINITIALIZED; diff --git a/src/maths/ni/niiter.c b/src/maths/ni/niiter.c index 575497674..4d2e854f8 100644 --- a/src/maths/ni/niiter.c +++ b/src/maths/ni/niiter.c @@ -146,6 +146,7 @@ NIiter(CKTcircuit *ckt, int maxIter) #ifdef KLU if (error == E_SINGULAR) { + fprintf (stderr, "Warning: KLU ReFactor failed. Factoring again...\n") ; ckt->CKTniState |= NISHOULDREORDER; error = SMPreorder(ckt->CKTmatrix, ckt->CKTpivotAbsTol, ckt->CKTpivotRelTol, ckt->CKTdiagGmin); ckt->CKTstat->STATreorderTime += SPfrontEnd->IFseconds() - startTime;