Fixed CKTsetup for KLU when XSPICE is used

This commit is contained in:
Francesco Lannutti 2020-10-19 01:05:24 +02:00 committed by Holger Vogt
parent 6ccaacaf1d
commit 1ee798ec9d
1 changed files with 62 additions and 33 deletions

View File

@ -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);
}