From debb5b8ece0e89ab271deff4d147555d7de4c7d1 Mon Sep 17 00:00:00 2001 From: Francesco Lannutti Date: Sat, 28 Sep 2013 11:54:48 +0200 Subject: [PATCH] Fixed DiagGmin Stepping Algorithm --- src/include/ngspice/cktdefs.h | 5 +++++ src/maths/ni/nireinit.c | 8 ++++++++ src/maths/sparse/spsmp.c | 12 ++++++++++-- src/maths/sparse/sputils.c | 2 ++ src/spicelib/analysis/cktload.c | 9 +++++++++ src/spicelib/analysis/cktsetup.c | 16 ++++++++++++++++ 6 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/include/ngspice/cktdefs.h b/src/include/ngspice/cktdefs.h index 18eeed2f5..d885e5ae6 100644 --- a/src/include/ngspice/cktdefs.h +++ b/src/include/ngspice/cktdefs.h @@ -107,6 +107,11 @@ struct CKTcircuit { #define GEAR 2 SMPmatrix *CKTmatrix; /* pointer to sparse matrix */ + +/*!!*/ + /* GMIN Stepping */ + double **CKTdiag ; /* Vector of pointers to the real diagonal elements */ + int CKTniState; /* internal state */ double *CKTrhs; /* current rhs value - being loaded */ double *CKTrhsOld; /* previous rhs value for convergence diff --git a/src/maths/ni/nireinit.c b/src/maths/ni/nireinit.c index cc14aee53..64f598cda 100644 --- a/src/maths/ni/nireinit.c +++ b/src/maths/ni/nireinit.c @@ -33,6 +33,14 @@ NIreinit( CKTcircuit *ckt) CKALLOC(CKTirhs,size+1,double); CKALLOC(CKTirhsOld,size+1,double); CKALLOC(CKTirhsSpare,size+1,double); + +/*!!*/ + /* GMIN Stepping */ + int i ; + CKALLOC(CKTdiag,size+1,double*); + for (i = 0 ; i <= size ; i++) + ckt->CKTdiag [i] = NULL ; + #ifdef PREDICTOR CKALLOC(CKTpred,size+1,double); for( i=0;i<8;i++) { diff --git a/src/maths/sparse/spsmp.c b/src/maths/sparse/spsmp.c index daa736d9c..f6a676005 100644 --- a/src/maths/sparse/spsmp.c +++ b/src/maths/sparse/spsmp.c @@ -106,6 +106,7 @@ extern double scalbn(double, int); extern double logb(double); #endif +/*!!*/ static void LoadGmin(SMPmatrix *Matrix, double Gmin); @@ -170,7 +171,10 @@ SMPluFac(SMPmatrix *Matrix, double PivTol, double Gmin) { NG_IGNORE(PivTol); spSetReal( Matrix ); - LoadGmin( Matrix, Gmin ); + +/*!!*/ +// LoadGmin( Matrix, Gmin ); + return spFactor( Matrix ); } @@ -194,7 +198,10 @@ int SMPreorder(SMPmatrix *Matrix, double PivTol, double PivRel, double Gmin) { spSetReal( Matrix ); - LoadGmin( Matrix, Gmin ); + +/*!!*/ +// LoadGmin( Matrix, Gmin ); + return spOrderAndFactor( Matrix, NULL, PivRel, PivTol, YES ); } @@ -419,6 +426,7 @@ SMPcDProd(SMPmatrix *Matrix, SPcomplex *pMantissa, int *pExponent) * for compatibility with Spice3. */ +/*!!*/ static void LoadGmin(SMPmatrix *Matrix, double Gmin) { diff --git a/src/maths/sparse/sputils.c b/src/maths/sparse/sputils.c index 32e7e9f5b..4d86f2854 100644 --- a/src/maths/sparse/sputils.c +++ b/src/maths/sparse/sputils.c @@ -294,8 +294,10 @@ SwapCols( MatrixPtr Matrix, ElementPtr pTwin1, ElementPtr pTwin2 ) Matrix->ExtToIntColMap[Matrix->IntToExtColMap[Col1]]=Col1; #endif +/*!!*/ Matrix->Diag[Col1] = pTwin2; Matrix->Diag[Col2] = pTwin1; + Matrix->NumberOfInterchangesIsOdd = !Matrix->NumberOfInterchangesIsOdd; return; } diff --git a/src/spicelib/analysis/cktload.c b/src/spicelib/analysis/cktload.c index 62b6f2a47..87169770b 100644 --- a/src/spicelib/analysis/cktload.c +++ b/src/spicelib/analysis/cktload.c @@ -74,6 +74,15 @@ CKTload(CKTcircuit *ckt) } } +/*!!*/ + /* GMIN Stepping */ + for (i = 1 ; i <= size ; i++) + { + if (ckt->CKTdiag [i] != NULL) + { + *(ckt->CKTdiag [i]) += ckt->CKTdiagGmin ; + } + } #ifdef XSPICE /* gtri - add - wbk - 11/26/90 - reset the MIF init flags */ diff --git a/src/spicelib/analysis/cktsetup.c b/src/spicelib/analysis/cktsetup.c index 446749094..b8fa0b0a0 100644 --- a/src/spicelib/analysis/cktsetup.c +++ b/src/spicelib/analysis/cktsetup.c @@ -127,6 +127,22 @@ CKTsetup(CKTcircuit *ckt) /* gtri - end - Setup for adding rshunt option resistors */ #endif + +/*!!*/ + /* GMIN Stepping */ + CKTnode *node ; + + node = ckt->CKTnodes ; + for (i = 1 ; i <= SMPmatSize (ckt->CKTmatrix) ; i++) + { + node = node->next ; + + if (node->type == SP_VOLTAGE) + { + ckt->CKTdiag [i] = SMPmakeElt (ckt->CKTmatrix, i, i) ; + } + } + return(OK); }