From 1ee798ec9db8b742347c66dfc2480be23a4e0888 Mon Sep 17 00:00:00 2001 From: Francesco Lannutti Date: Mon, 19 Oct 2020 01:05:24 +0200 Subject: [PATCH] Fixed CKTsetup for KLU when XSPICE is used --- src/spicelib/analysis/cktsetup.c | 95 +++++++++++++++++++++----------- 1 file changed, 62 insertions(+), 33 deletions(-) diff --git a/src/spicelib/analysis/cktsetup.c b/src/spicelib/analysis/cktsetup.c index 76470de0d..6e22c3b0a 100644 --- a/src/spicelib/analysis/cktsetup.c +++ b/src/spicelib/analysis/cktsetup.c @@ -36,12 +36,19 @@ CKTsetup(CKTcircuit *ckt) { int i; int error; + #ifdef XSPICE /* gtri - begin - Setup for adding rshunt option resistors */ CKTnode *node; int num_nodes; /* gtri - end - Setup for adding rshunt option resistors */ + +#ifdef KLU + BindElement BindNode, *matched, *BindStruct ; + size_t nz ; #endif +#endif + SMPmatrix *matrix; if (!ckt->CKThead) { @@ -108,39 +115,6 @@ CKTsetup(CKTcircuit *ckt) } } -#ifdef KLU - if (ckt->CKTmatrix->CKTkluMODE) - { - fprintf (stderr, "Using KLU as Direct Linear Solver\n") ; - - /* Convert the COO Storage to CSC for KLU and Fill the Binding Table */ - SMPconvertCOOtoCSC (matrix) ; - - /* Assign the KLU Pointers */ - for (i = 0 ; i < DEVmaxnum ; i++) - if (DEVices [i] && DEVices [i]->DEVbindCSC && ckt->CKThead [i]) - DEVices [i]->DEVbindCSC (ckt->CKThead [i], ckt) ; - } else { - fprintf (stderr, "Using SPARSE 1.3 as Direct Linear Solver\n") ; - } -#endif - - for(i=0;i<=MAX(2,ckt->CKTmaxOrder)+1;i++) { /* dctran needs 3 states as minimum */ - CKALLOC(ckt->CKTstates[i],ckt->CKTnumStates,double); - } -#ifdef WANT_SENSE2 - if(ckt->CKTsenInfo){ - /* to allocate memory to sensitivity structures if - * it is not done before */ - - error = NIsenReinit(ckt); - if(error) return(error); - } -#endif - if(ckt->CKTniState & NIUNINITIALIZED) { - error = NIreinit(ckt); - if(error) return(error); - } #ifdef XSPICE /* gtri - begin - Setup for adding rshunt option resistors */ @@ -173,6 +147,61 @@ CKTsetup(CKTcircuit *ckt) /* gtri - end - Setup for adding rshunt option resistors */ #endif +#ifdef KLU + if (ckt->CKTmatrix->CKTkluMODE) + { + fprintf (stderr, "Using KLU as Direct Linear Solver\n") ; + + /* Convert the COO Storage to CSC for KLU and Fill the Binding Table */ + SMPconvertCOOtoCSC (matrix) ; + + /* Assign the KLU Pointers */ + for (i = 0 ; i < DEVmaxnum ; i++) + if (DEVices [i] && DEVices [i]->DEVbindCSC && ckt->CKThead [i]) + DEVices [i]->DEVbindCSC (ckt->CKThead [i], ckt) ; + +#ifdef XSPICE + if (ckt->enh->rshunt_data.num_nodes > 0) { + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; + for(i = 0, node = ckt->CKTnodes; node; node = node->next) { + if((node->type == SP_VOLTAGE) && (node->number != 0)) { + BindNode.COO = ckt->enh->rshunt_data.diag [i] ; + BindNode.CSC = NULL ; + BindNode.CSC_Complex = NULL ; + matched = (BindElement *) bsearch (&BindNode, BindStruct, nz, sizeof (BindElement), BindCompare) ; + if (matched == NULL) { + printf ("Ptr %p not found in BindStruct Table\n", ckt->enh->rshunt_data.diag [i]) ; + } + ckt->enh->rshunt_data.diag [i] = matched->CSC ; + i++; + } + } + } +#endif + + } else { + fprintf (stderr, "Using SPARSE 1.3 as Direct Linear Solver\n") ; + } +#endif + + for(i=0;i<=MAX(2,ckt->CKTmaxOrder)+1;i++) { /* dctran needs 3 states as minimum */ + CKALLOC(ckt->CKTstates[i],ckt->CKTnumStates,double); + } +#ifdef WANT_SENSE2 + if(ckt->CKTsenInfo){ + /* to allocate memory to sensitivity structures if + * it is not done before */ + + error = NIsenReinit(ckt); + if(error) return(error); + } +#endif + if(ckt->CKTniState & NIUNINITIALIZED) { + error = NIreinit(ckt); + if(error) return(error); + } + return(OK); }