fix vsrc for pz analysis
This commit is contained in:
parent
634156844b
commit
d2562ba82f
|
|
@ -14,6 +14,20 @@ Copyright 1990 Regents of the University of California. All rights reserved.
|
||||||
#include "ngspice/devdefs.h"
|
#include "ngspice/devdefs.h"
|
||||||
#include "ngspice/sperror.h"
|
#include "ngspice/sperror.h"
|
||||||
|
|
||||||
|
#ifdef KLU
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
static
|
||||||
|
int
|
||||||
|
BindCompare (const void *a, const void *b)
|
||||||
|
{
|
||||||
|
BindElement *A, *B ;
|
||||||
|
A = (BindElement *)a ;
|
||||||
|
B = (BindElement *)b ;
|
||||||
|
|
||||||
|
return ((int)(A->Sparse - B->Sparse)) ;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int
|
int
|
||||||
CKTpzSetup(CKTcircuit *ckt, int type)
|
CKTpzSetup(CKTcircuit *ckt, int type)
|
||||||
|
|
@ -89,6 +103,77 @@ CKTpzSetup(CKTcircuit *ckt, int type)
|
||||||
|
|
||||||
job->PZnumswaps = 1;
|
job->PZnumswaps = 1;
|
||||||
|
|
||||||
|
#ifdef KLU
|
||||||
|
if (ckt->CKTmatrix->CKTkluMODE)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "Using KLU as Direct Linear Solver\n") ;
|
||||||
|
|
||||||
|
int i ;
|
||||||
|
int n = SMPmatSize (ckt->CKTmatrix) ;
|
||||||
|
ckt->CKTmatrix->CKTkluN = n ;
|
||||||
|
|
||||||
|
SMPnnz (ckt->CKTmatrix) ;
|
||||||
|
int nz = ckt->CKTmatrix->CKTklunz ;
|
||||||
|
|
||||||
|
ckt->CKTmatrix->CKTkluAp = TMALLOC (int, n + 1) ;
|
||||||
|
ckt->CKTmatrix->CKTkluAi = TMALLOC (int, nz) ;
|
||||||
|
ckt->CKTmatrix->CKTkluAx = TMALLOC (double, nz) ;
|
||||||
|
ckt->CKTmatrix->CKTkluIntermediate = TMALLOC (double, n) ;
|
||||||
|
|
||||||
|
ckt->CKTmatrix->CKTbindStruct = TMALLOC (BindElement, nz) ;
|
||||||
|
|
||||||
|
ckt->CKTmatrix->CKTdiag_CSC = TMALLOC (double *, n) ;
|
||||||
|
|
||||||
|
/* Complex Stuff needed for AC Analysis */
|
||||||
|
ckt->CKTmatrix->CKTkluAx_Complex = TMALLOC (double, 2 * nz) ;
|
||||||
|
ckt->CKTmatrix->CKTkluIntermediate_Complex = TMALLOC (double, 2 * n) ;
|
||||||
|
|
||||||
|
/* Binding Table from Sparse to CSC Format Creation */
|
||||||
|
SMPmatrix_CSC (ckt->CKTmatrix) ;
|
||||||
|
|
||||||
|
/* Binding Table Sorting */
|
||||||
|
qsort (ckt->CKTmatrix->CKTbindStruct, (size_t)nz, sizeof(BindElement), BindCompare) ;
|
||||||
|
|
||||||
|
/* KLU Pointers Assignment */
|
||||||
|
for (i = 0 ; i < DEVmaxnum ; i++)
|
||||||
|
if (DEVices [i] && DEVices [i]->DEVbindCSC && ckt->CKThead [i])
|
||||||
|
DEVices [i]->DEVbindCSC (ckt->CKThead [i], ckt) ;
|
||||||
|
|
||||||
|
/* ReOrder */
|
||||||
|
error = SMPpreOrder (ckt->CKTmatrix) ;
|
||||||
|
if (error) {
|
||||||
|
fprintf (stderr, "Error during ReOrdering\n") ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Conversion from Real Matrix to Complex Matrix */
|
||||||
|
for (i = 0 ; i < DEVmaxnum ; i++)
|
||||||
|
if (DEVices [i] && DEVices [i]->DEVbindCSCComplex && ckt->CKThead [i])
|
||||||
|
DEVices [i]->DEVbindCSCComplex (ckt->CKThead [i], ckt) ;
|
||||||
|
|
||||||
|
ckt->CKTmatrix->CKTkluMatrixIsComplex = CKTkluMatrixComplex ;
|
||||||
|
|
||||||
|
/* Input Pos */
|
||||||
|
if ((input_pos != 0) && (solution_col != 0))
|
||||||
|
{
|
||||||
|
double *j ;
|
||||||
|
|
||||||
|
j = job->PZdrive_pptr ;
|
||||||
|
job->PZdrive_pptr = ((BindElement *) bsearch (&j, ckt->CKTmatrix->CKTbindStruct, (size_t)nz, sizeof(BindElement), BindCompare))->CSC_Complex ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Input Neg */
|
||||||
|
if ((input_neg != 0) && (solution_col != 0))
|
||||||
|
{
|
||||||
|
double *j ;
|
||||||
|
|
||||||
|
j = job->PZdrive_nptr ;
|
||||||
|
job->PZdrive_nptr = ((BindElement *) bsearch (&j, ckt->CKTmatrix->CKTbindStruct, (size_t)nz, sizeof(BindElement), BindCompare))->CSC_Complex ;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fprintf (stderr, "Using SPARSE 1.3 as Direct Linear Solver\n") ;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
error = NIreinit(ckt);
|
error = NIreinit(ckt);
|
||||||
if (error)
|
if (error)
|
||||||
return(error);
|
return(error);
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,17 @@ VSRCbindCSC (GENmodel *inModel, CKTcircuit *ckt)
|
||||||
CREATE_KLU_BINDING_TABLE(VSRCnegIbrPtr, VSRCnegIbrBinding, VSRCnegNode, VSRCbranch);
|
CREATE_KLU_BINDING_TABLE(VSRCnegIbrPtr, VSRCnegIbrBinding, VSRCnegNode, VSRCbranch);
|
||||||
CREATE_KLU_BINDING_TABLE(VSRCibrNegPtr, VSRCibrNegBinding, VSRCbranch, VSRCnegNode);
|
CREATE_KLU_BINDING_TABLE(VSRCibrNegPtr, VSRCibrNegBinding, VSRCbranch, VSRCnegNode);
|
||||||
CREATE_KLU_BINDING_TABLE(VSRCibrPosPtr, VSRCibrPosBinding, VSRCbranch, VSRCposNode);
|
CREATE_KLU_BINDING_TABLE(VSRCibrPosPtr, VSRCibrPosBinding, VSRCbranch, VSRCposNode);
|
||||||
|
/* Pole-Zero Analysis */
|
||||||
|
if ((here-> VSRCbranch != 0) && (here-> VSRCbranch != 0))
|
||||||
|
{
|
||||||
|
i = here->VSRCibrIbrPtr ;
|
||||||
|
matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ;
|
||||||
|
here->VSRCibrIbrBinding = matched ;
|
||||||
|
if (matched != NULL)
|
||||||
|
{
|
||||||
|
here->VSRCibrIbrPtr = matched->CSC ;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,6 +78,14 @@ VSRCbindCSCComplex (GENmodel *inModel, CKTcircuit *ckt)
|
||||||
CONVERT_KLU_BINDING_TABLE_TO_COMPLEX(VSRCnegIbrPtr, VSRCnegIbrBinding, VSRCnegNode, VSRCbranch);
|
CONVERT_KLU_BINDING_TABLE_TO_COMPLEX(VSRCnegIbrPtr, VSRCnegIbrBinding, VSRCnegNode, VSRCbranch);
|
||||||
CONVERT_KLU_BINDING_TABLE_TO_COMPLEX(VSRCibrNegPtr, VSRCibrNegBinding, VSRCbranch, VSRCnegNode);
|
CONVERT_KLU_BINDING_TABLE_TO_COMPLEX(VSRCibrNegPtr, VSRCibrNegBinding, VSRCbranch, VSRCnegNode);
|
||||||
CONVERT_KLU_BINDING_TABLE_TO_COMPLEX(VSRCibrPosPtr, VSRCibrPosBinding, VSRCbranch, VSRCposNode);
|
CONVERT_KLU_BINDING_TABLE_TO_COMPLEX(VSRCibrPosPtr, VSRCibrPosBinding, VSRCbranch, VSRCposNode);
|
||||||
|
/* Pole-Zero Analysis */
|
||||||
|
if ((here-> VSRCbranch != 0) && (here-> VSRCbranch != 0))
|
||||||
|
{
|
||||||
|
if (here->VSRCibrIbrBinding != NULL)
|
||||||
|
{
|
||||||
|
here->VSRCibrIbrPtr = here->VSRCibrIbrBinding->CSC_Complex ;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -91,6 +110,14 @@ VSRCbindCSCComplexToReal (GENmodel *inModel, CKTcircuit *ckt)
|
||||||
CONVERT_KLU_BINDING_TABLE_TO_REAL(VSRCnegIbrPtr, VSRCnegIbrBinding, VSRCnegNode, VSRCbranch);
|
CONVERT_KLU_BINDING_TABLE_TO_REAL(VSRCnegIbrPtr, VSRCnegIbrBinding, VSRCnegNode, VSRCbranch);
|
||||||
CONVERT_KLU_BINDING_TABLE_TO_REAL(VSRCibrNegPtr, VSRCibrNegBinding, VSRCbranch, VSRCnegNode);
|
CONVERT_KLU_BINDING_TABLE_TO_REAL(VSRCibrNegPtr, VSRCibrNegBinding, VSRCbranch, VSRCnegNode);
|
||||||
CONVERT_KLU_BINDING_TABLE_TO_REAL(VSRCibrPosPtr, VSRCibrPosBinding, VSRCbranch, VSRCposNode);
|
CONVERT_KLU_BINDING_TABLE_TO_REAL(VSRCibrPosPtr, VSRCibrPosBinding, VSRCbranch, VSRCposNode);
|
||||||
|
/* Pole-Zero Analysis */
|
||||||
|
if ((here-> VSRCbranch != 0) && (here-> VSRCbranch != 0))
|
||||||
|
{
|
||||||
|
if (here->VSRCibrIbrBinding != NULL)
|
||||||
|
{
|
||||||
|
here->VSRCibrIbrPtr = here->VSRCibrIbrBinding->CSC ;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -116,6 +116,7 @@ typedef struct sVSRCinstance {
|
||||||
BindElement *VSRCnegIbrBinding ;
|
BindElement *VSRCnegIbrBinding ;
|
||||||
BindElement *VSRCibrNegBinding ;
|
BindElement *VSRCibrNegBinding ;
|
||||||
BindElement *VSRCibrPosBinding ;
|
BindElement *VSRCibrPosBinding ;
|
||||||
|
BindElement *VSRCibrIbrBinding ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} VSRCinstance ;
|
} VSRCinstance ;
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,9 @@ do { if((here->ptr = SMPmakeElt(matrix, here->first, here->second)) == NULL){\
|
||||||
TSTALLOC(VSRCnegIbrPtr, VSRCnegNode, VSRCbranch);
|
TSTALLOC(VSRCnegIbrPtr, VSRCnegNode, VSRCbranch);
|
||||||
TSTALLOC(VSRCibrNegPtr, VSRCbranch, VSRCnegNode);
|
TSTALLOC(VSRCibrNegPtr, VSRCbranch, VSRCnegNode);
|
||||||
TSTALLOC(VSRCibrPosPtr, VSRCbranch, VSRCposNode);
|
TSTALLOC(VSRCibrPosPtr, VSRCbranch, VSRCposNode);
|
||||||
|
|
||||||
|
#ifdef KLU
|
||||||
|
here->VSRCibrIbrPtr = NULL ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue