From fb39f64d7790be6efa5c1ffc2972a67fe838d4e3 Mon Sep 17 00:00:00 2001 From: Francesco Lannutti Date: Tue, 21 Jun 2016 14:53:53 +0200 Subject: [PATCH] Fixed Sensitivity Analysis integration for KLU --- src/maths/KLU/klusmp.c | 18 ++++++++++++++++++ src/spicelib/analysis/cktsens.c | 21 ++++++++++----------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/maths/KLU/klusmp.c b/src/maths/KLU/klusmp.c index a778542a2..321a69c97 100644 --- a/src/maths/KLU/klusmp.c +++ b/src/maths/KLU/klusmp.c @@ -1090,3 +1090,21 @@ SMPzeroRow (SMPmatrix *eMatrix, int Row) return spError (Matrix) ; } + +/* + * SMPconstMult() + */ +void +SMPconstMult (SMPmatrix *Matrix, double constant) +{ + spConstMult (Matrix->SPmatrix, constant) ; +} + +/* + * SMPmultiply() + */ +void +SMPmultiply (SMPmatrix *Matrix, double *RHS, double *Solution, double *iRHS, double *iSolution) +{ + spMultiply (Matrix->SPmatrix, RHS, Solution, iRHS, iSolution) ; +} diff --git a/src/spicelib/analysis/cktsens.c b/src/spicelib/analysis/cktsens.c index 0a9a85294..9601e9baf 100644 --- a/src/spicelib/analysis/cktsens.c +++ b/src/spicelib/analysis/cktsens.c @@ -71,8 +71,7 @@ int sens_sens(CKTcircuit *ckt, int restart) static double freq; static int nfreqs; static int i; - static SMPmatrix *delta_Y = NULL; - static MatrixFrame *Y; + static SMPmatrix *delta_Y = NULL, *Y; static double step_size; double *E, *iE; IFvalue value, nvalue; @@ -142,7 +141,7 @@ int sens_sens(CKTcircuit *ckt, int restart) if (error) return error; - size = SMPmatSize(ckt->CKTmatrix->SPmatrix); + size = SMPmatSize(ckt->CKTmatrix); /* Create the perturbation matrix */ // error = SMPnewMatrix(&(delta_Y->SPmatrix)); // No Size... @@ -246,7 +245,7 @@ int sens_sens(CKTcircuit *ckt, int restart) E = ckt->CKTrhs; iE = ckt->CKTirhs; - Y = ckt->CKTmatrix->SPmatrix; + Y = ckt->CKTmatrix; #ifdef ASDEBUG DEBUG(1) { @@ -321,7 +320,7 @@ int sens_sens(CKTcircuit *ckt, int restart) /* NIacIter solves into CKTrhsOld, CKTirhsOld and CKTmatrix->SPmatrix */ E = ckt->CKTrhsOld; iE = ckt->CKTirhsOld; - Y = ckt->CKTmatrix->SPmatrix; + Y = ckt->CKTmatrix; } /* Use a different vector & matrix */ @@ -361,7 +360,7 @@ int sens_sens(CKTcircuit *ckt, int restart) } #endif - SMPcClear(delta_Y->SPmatrix); + SMPcClear(delta_Y); for (j = 0; j < size; j++) { delta_I[j] = 0.0; @@ -428,7 +427,7 @@ int sens_sens(CKTcircuit *ckt, int restart) if (error && error != E_BADPARM) return error; - SMPconstMult(delta_Y->SPmatrix, -1.0); + SMPconstMult(delta_Y, -1.0); for (j = 0; j < size; j++) { delta_I[j] *= -1.0; delta_iI[j] *= -1.0; @@ -437,7 +436,7 @@ int sens_sens(CKTcircuit *ckt, int restart) #ifdef ASDEBUG DEBUG(2) { printf("Effect of negating matrix:\n"); - SMPprint(delta_Y->SPmatrix, NULL); + SMPprint(delta_Y, NULL); for (j = 0; j < size; j++) printf("%d: %g, %g\n", j, delta_I[j], delta_iI[j]); @@ -463,7 +462,7 @@ int sens_sens(CKTcircuit *ckt, int restart) #ifdef ASDEBUG DEBUG(2) { printf("Effect of changing the parameter:\n"); - SMPprint(delta_Y->SPmatrix, NULL); + SMPprint(delta_Y, NULL); for (j = 0; j < size; j++) printf("%d: %g, %g\n", j, delta_I[j], delta_iI[j]); @@ -487,7 +486,7 @@ int sens_sens(CKTcircuit *ckt, int restart) #endif /* delta_Y E */ - SMPmultiply(delta_Y->SPmatrix, delta_I_delta_Y, E, + SMPmultiply(delta_Y, delta_I_delta_Y, E, delta_iI_delta_Y, iE); #ifdef ASDEBUG @@ -606,7 +605,7 @@ int sens_sens(CKTcircuit *ckt, int restart) release_context(ckt->CKTirhs, saved_irhs); release_context(ckt->CKTmatrix->SPmatrix, saved_matrix); - SMPdestroy(delta_Y->SPmatrix); + SMPdestroy(delta_Y); FREE(delta_I); FREE(delta_iI);