Experimental changes:

Introduced new binding scheme for RES, CAP, IND, VSRC, (ISRC), BSIM4 models
 to improve speed
 The old method will not work anymore, so please use KLU only if you have
 these models in your circuit and nothing more!
This commit is contained in:
Francesco Lannutti 2012-11-04 13:50:36 +01:00 committed by Francesco Lannutti
parent de5e2accea
commit 38947fb651
17 changed files with 1544 additions and 1713 deletions

View File

@ -20,13 +20,15 @@ Modified: 2000 AlansFixes
#if defined(KLU)
#include "ngspice/klu.h"
#include "ngspice/spmatrix.h"
#elif defined(SuperLU)
#include "ngspice/slu_ddefs.h"
#elif defined(UMFPACK)
#include "ngspice/umfpack.h"
#endif
struct SMPmatrix {
/* SMPmatrix structure - Francesco Lannutti (2012-02) */
typedef struct sSMPmatrix {
MatrixFrame *SPmatrix ; /* pointer to sparse matrix */
#if defined(KLU)
@ -45,6 +47,7 @@ struct SMPmatrix {
double **CKTbind_Sparse ; /* KLU Sparse original element position */
double **CKTbind_CSC ; /* KLU new element position */
double **CKTbind_CSC_Complex ; /* KLU new element position in Complex analysis */
BindElement *CKTbindStruct ; /* KLU - Sparse Binding Structure */
double **CKTdiag_CSC ; /* KLU pointer to diagonal element to perform Gmin */
int CKTkluN ; /* KLU N, copied */
int CKTklunz ; /* KLU nz, copied for AC Analysis */
@ -97,10 +100,7 @@ struct SMPmatrix {
#define CKTumfpackOFF 0 /* UMFPACK MODE OFF definition */
#endif
};
/* SMPmatrix structure alias - Francesco Lannutti (2012-02) */
typedef struct SMPmatrix SMPmatrix ;
} SMPmatrix ;
#if defined(KLU) || defined(SuperLU) || defined(UMFPACK)

View File

@ -35,6 +35,8 @@
*/
/* Francesco Lannutti 2012-09 - NGSPICE Configuration File Inclusion */
#include "ngspice/config.h"
#ifndef spOKAY
@ -294,10 +296,21 @@ extern void spMultTransposed(MatrixPtr,spREAL*,spREAL*,spREAL*,spREAL*);
extern void spSolve( MatrixPtr, spREAL*, spREAL*, spREAL*, spREAL* );
extern void spSolveTransposed(MatrixPtr,spREAL*,spREAL*,spREAL*,spREAL*);
extern int WriteCol_original(MatrixPtr, int, spREAL *, int *, spREAL **, spREAL **, spREAL **);
extern int WriteCol_original_dump(MatrixPtr, int, spREAL *, int *);
extern void spMatrix_CSC(MatrixPtr, int *, int *, double *, int, double **, double **, double **);
extern void spMatrix_CSC_dump(MatrixPtr, char *);
extern void spRHS_CSC_dump(spREAL *, char *, MatrixPtr);
/* Francesco Lannutti - CSC Data Structure Conversion */
#ifdef KLU
typedef struct sBindElement {
double *Sparse ;
double *CSC ;
double *CSC_Complex ;
} BindElement ;
extern int WriteCol_original (MatrixPtr, int, spREAL *, spREAL *, int *, BindElement *, spREAL **) ;
extern int WriteCol_original_dump (MatrixPtr, int, spREAL *, int *) ;
extern void spMatrix_CSC (MatrixPtr, int *, int *, double *, double *, int, BindElement *, double **) ;
extern void spMatrix_CSC_dump (MatrixPtr, char *) ;
extern void spRHS_CSC_dump (spREAL *, char *, MatrixPtr) ;
#endif
/* ------------------------------------------------------ */
#endif /* spOKAY */

View File

@ -115,7 +115,7 @@ void
SMPmatrix_CSC (SMPmatrix *Matrix)
{
spMatrix_CSC (Matrix->SPmatrix, Matrix->CKTkluAp, Matrix->CKTkluAi, Matrix->CKTkluAx,
Matrix->CKTkluN, Matrix->CKTbind_Sparse, Matrix->CKTbind_CSC, Matrix->CKTdiag_CSC) ;
Matrix->CKTkluAx_Complex, Matrix->CKTkluN, Matrix->CKTbindStruct, Matrix->CKTdiag_CSC) ;
return ;
}

View File

@ -44,6 +44,7 @@ NIinit(CKTcircuit *ckt)
ckt->CKTmatrix->CKTbind_Sparse = NULL ;
ckt->CKTmatrix->CKTbind_CSC = NULL ;
ckt->CKTmatrix->CKTbind_CSC_Complex = NULL ;
ckt->CKTmatrix->CKTbindStruct = NULL ;
ckt->CKTmatrix->CKTdiag_CSC = NULL ;
ckt->CKTmatrix->CKTkluN = 0 ;
ckt->CKTmatrix->CKTklunz = 0 ;

View File

@ -21,7 +21,7 @@
/* Body */
int
WriteCol_original (MatrixPtr Matrix, int Col, spREAL *CSC_Element, int *CSC_Row, spREAL **bind_Sparse, spREAL **bind_KLU, spREAL **diag)
WriteCol_original (MatrixPtr Matrix, int Col, spREAL *CSC_Element, spREAL *CSC_Element_Complex, int *CSC_Row, BindElement *BindSparseCSC, spREAL **diag)
{
int i ;
ElementPtr current ;
@ -30,8 +30,9 @@ WriteCol_original (MatrixPtr Matrix, int Col, spREAL *CSC_Element, int *CSC_Row,
current = Matrix->FirstInCol [Col] ;
while (current != NULL) {
bind_Sparse [i] = (double *)current ;
bind_KLU [i] = &(CSC_Element [i]) ;
BindSparseCSC [i].Sparse = (double *)current ;
BindSparseCSC [i].CSC = &(CSC_Element [i]) ;
BindSparseCSC [i].CSC_Complex = &(CSC_Element_Complex [2 * i]) ;
CSC_Row [i] = (current->Row) - 1 ;
if (CSC_Row [i] == Col - 1)
diag [0] = &(CSC_Element [i]) ;
@ -61,15 +62,15 @@ WriteCol_original_dump (MatrixPtr Matrix, int Col, spREAL *CSC_Element, int *CSC
}
void
spMatrix_CSC (MatrixPtr Matrix, int *Ap, int *Ai, double *Ax, int n, double **bind_Sparse, double **bind_KLU, double **diag)
spMatrix_CSC (MatrixPtr Matrix, int *Ap, int *Ai, double *Ax, double *Ax_Complex, int n, BindElement *BindSparseCSC, double **diag)
{
int offset, i ;
offset = 0 ;
Ap[0] = offset ;
for (i = 1 ; i <= n ; i++) {
offset += WriteCol_original (Matrix, i, (spREAL *)(Ax + offset), (int *)(Ai + offset), (spREAL **)(bind_Sparse + offset),
(spREAL **)(bind_KLU + offset), (spREAL **)(diag + (i - 1))) ;
offset += WriteCol_original (Matrix, i, (spREAL *)(Ax + offset), (spREAL *)(Ax_Complex + 2 * offset),
(int *)(Ai + offset), BindSparseCSC + offset, (spREAL **)(diag + (i - 1))) ;
Ap[i] = offset ;
}

View File

@ -243,25 +243,15 @@ ACan(CKTcircuit *ckt, int restart)
ckt->CKTcurrentAnalysis = DOING_AC;
#ifdef KLU
int i, m ;
int i ;
if (ckt->CKTmatrix->CKTkluMODE)
{
/* Conversion from Real Matrix to Complex Matrix */
if (!ckt->CKTmatrix->CKTkluMatrixIsComplex)
{
ckt->CKTmatrix->CKTkluAx_Complex = TMALLOC (double, 2 * ckt->CKTmatrix->CKTklunz) ;
ckt->CKTmatrix->CKTbind_CSC_Complex = TMALLOC (double *, ckt->CKTmatrix->CKTklunz) ;
ckt->CKTmatrix->CKTkluIntermediate_Complex = TMALLOC (double, 2 * ckt->CKTmatrix->CKTkluN) ;
m = 0 ;
for (i = 0 ; i < ckt->CKTmatrix->CKTklunz ; i++)
{
ckt->CKTmatrix->CKTbind_CSC_Complex [i] = &(ckt->CKTmatrix->CKTkluAx_Complex [m]) ;
m += 2 ;
}
for (i = 0 ; i < DEVmaxnum ; i++)
if (DEVices [i] && DEVices [i]->DEVbindCSCComplex)
if (DEVices [i] && DEVices [i]->DEVbindCSCComplex && ckt->CKThead [i])
DEVices [i]->DEVbindCSCComplex (ckt->CKThead [i], ckt) ;
ckt->CKTmatrix->CKTkluMatrixIsComplex = CKTkluMatrixComplex ;
@ -286,7 +276,7 @@ ACan(CKTcircuit *ckt, int restart)
{
/* Conversion from Complex Matrix to Real Matrix */
for (i = 0 ; i < DEVmaxnum ; i++)
if (DEVices [i] && DEVices [i]->DEVbindCSCComplexToReal)
if (DEVices [i] && DEVices [i]->DEVbindCSCComplexToReal && ckt->CKThead [i])
DEVices [i]->DEVbindCSCComplexToReal (ckt->CKThead [i], ckt) ;
ckt->CKTmatrix->CKTkluMatrixIsComplex = CKTkluMatrixReal ;
@ -326,7 +316,7 @@ ACan(CKTcircuit *ckt, int restart)
{
/* Conversion from Real Matrix to Complex Matrix */
for (i = 0 ; i < DEVmaxnum ; i++)
if (DEVices [i] && DEVices [i]->DEVbindCSCComplex)
if (DEVices [i] && DEVices [i]->DEVbindCSCComplex && ckt->CKThead [i])
DEVices [i]->DEVbindCSCComplex (ckt->CKThead [i], ckt) ;
ckt->CKTmatrix->CKTkluMatrixIsComplex = CKTkluMatrixComplex ;
@ -438,7 +428,7 @@ endsweep:
{
/* Conversion from Complex Matrix to Real Matrix */
for (i = 0 ; i < DEVmaxnum ; i++)
if (DEVices [i] && DEVices [i]->DEVbindCSCComplexToReal)
if (DEVices [i] && DEVices [i]->DEVbindCSCComplexToReal && ckt->CKThead [i])
DEVices [i]->DEVbindCSCComplexToReal (ckt->CKThead [i], ckt) ;
ckt->CKTmatrix->CKTkluMatrixIsComplex = CKTkluMatrixReal ;

View File

@ -26,6 +26,24 @@ int nthreads;
return(E_NOMEM);\
}
#ifdef HAS_WINDOWS
extern void SetAnalyse( char * Analyse, int Percent);
#endif
#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
CKTsetup(CKTcircuit *ckt)
@ -103,14 +121,23 @@ CKTsetup(CKTcircuit *ckt)
ckt->CKTmatrix->CKTkluAx = TMALLOC (double, nz) ;
ckt->CKTmatrix->CKTkluIntermediate = TMALLOC (double, n) ;
ckt->CKTmatrix->CKTbind_Sparse = TMALLOC (double *, nz) ;
ckt->CKTmatrix->CKTbind_CSC = TMALLOC (double *, nz) ;
// ckt->CKTmatrix->CKTbind_Sparse = TMALLOC (double *, nz) ;
// ckt->CKTmatrix->CKTbind_CSC = TMALLOC (double *, nz) ;
ckt->CKTmatrix->CKTbindStruct = TMALLOC (BindElement, nz) ;
ckt->CKTmatrix->CKTdiag_CSC = TMALLOC (double *, n) ;
/* Binding Table Sparse-KLU creation */
/* 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) ;
@ -135,14 +162,19 @@ CKTsetup(CKTcircuit *ckt)
ckt->CKTmatrix->CKTsuperluIntermediate = TMALLOC (double, n) ;
ckt->CKTmatrix->CKTbind_Sparse = TMALLOC (double *, nz) ;
ckt->CKTmatrix->CKTbind_CSC = TMALLOC (double *, nz) ;
// ckt->CKTmatrix->CKTbind_Sparse = TMALLOC (double *, nz) ;
// ckt->CKTmatrix->CKTbind_CSC = TMALLOC (double *, nz) ;
ckt->CKTmatrix->CKTbindStruct = TMALLOC (BindElement, nz) ;
ckt->CKTmatrix->CKTdiag_CSC = TMALLOC (double *, n) ;
/* Binding Table Sparse-KLU creation */
/* 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) ;
dCreate_CompCol_Matrix (&(ckt->CKTmatrix->CKTsuperluA), n, n, nz, ckt->CKTmatrix->CKTsuperluAx,
ckt->CKTmatrix->CKTsuperluAi, ckt->CKTmatrix->CKTsuperluAp, SLU_NC, SLU_D, SLU_GE) ;
dCreate_Dense_Matrix (&(ckt->CKTmatrix->CKTsuperluI), n, 1, ckt->CKTmatrix->CKTsuperluIntermediate,
@ -172,13 +204,18 @@ CKTsetup(CKTcircuit *ckt)
ckt->CKTmatrix->CKTumfpackX = TMALLOC (double, n) ;
ckt->CKTmatrix->CKTbind_Sparse = TMALLOC (double *, nz) ;
ckt->CKTmatrix->CKTbind_CSC = TMALLOC (double *, nz) ;
// ckt->CKTmatrix->CKTbind_Sparse = TMALLOC (double *, nz) ;
// ckt->CKTmatrix->CKTbind_CSC = TMALLOC (double *, nz) ;
ckt->CKTmatrix->CKTbindStruct = TMALLOC (BindElement, nz) ;
ckt->CKTmatrix->CKTdiag_CSC = TMALLOC (double *, n) ;
/* Binding Table Sparse-KLU creation */
SMPmatrix_CSC (ckt->CKTmatrix) ;
/* 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) ;
for (i = 0 ; i < DEVmaxnum ; i++)
if (DEVices [i] && DEVices [i]->DEVbindCSC && ckt->CKThead [i])

File diff suppressed because it is too large Load Diff

View File

@ -569,6 +569,91 @@ typedef struct sBSIM4instance
double **BSIM4nVar;
#endif /* NONOISE */
#ifdef KLU
BindElement *BSIM4DPdStructPtr ;
BindElement *BSIM4DPdpStructPtr ;
BindElement *BSIM4DPgpStructPtr ;
BindElement *BSIM4DPgmStructPtr ;
BindElement *BSIM4DPspStructPtr ;
BindElement *BSIM4DPbpStructPtr ;
BindElement *BSIM4DPdbStructPtr ;
BindElement *BSIM4DdStructPtr ;
BindElement *BSIM4DdpStructPtr ;
BindElement *BSIM4GPdpStructPtr ;
BindElement *BSIM4GPgpStructPtr ;
BindElement *BSIM4GPgmStructPtr ;
BindElement *BSIM4GPgeStructPtr ;
BindElement *BSIM4GPspStructPtr ;
BindElement *BSIM4GPbpStructPtr ;
BindElement *BSIM4GMdpStructPtr ;
BindElement *BSIM4GMgpStructPtr ;
BindElement *BSIM4GMgmStructPtr ;
BindElement *BSIM4GMgeStructPtr ;
BindElement *BSIM4GMspStructPtr ;
BindElement *BSIM4GMbpStructPtr ;
BindElement *BSIM4GEdpStructPtr ;
BindElement *BSIM4GEgpStructPtr ;
BindElement *BSIM4GEgmStructPtr ;
BindElement *BSIM4GEgeStructPtr ;
BindElement *BSIM4GEspStructPtr ;
BindElement *BSIM4GEbpStructPtr ;
BindElement *BSIM4SPdpStructPtr ;
BindElement *BSIM4SPgpStructPtr ;
BindElement *BSIM4SPgmStructPtr ;
BindElement *BSIM4SPsStructPtr ;
BindElement *BSIM4SPspStructPtr ;
BindElement *BSIM4SPbpStructPtr ;
BindElement *BSIM4SPsbStructPtr ;
BindElement *BSIM4SspStructPtr ;
BindElement *BSIM4SsStructPtr ;
BindElement *BSIM4BPdpStructPtr ;
BindElement *BSIM4BPgpStructPtr ;
BindElement *BSIM4BPgmStructPtr ;
BindElement *BSIM4BPspStructPtr ;
BindElement *BSIM4BPdbStructPtr ;
BindElement *BSIM4BPbStructPtr ;
BindElement *BSIM4BPsbStructPtr ;
BindElement *BSIM4BPbpStructPtr ;
BindElement *BSIM4DBdpStructPtr ;
BindElement *BSIM4DBdbStructPtr ;
BindElement *BSIM4DBbpStructPtr ;
BindElement *BSIM4DBbStructPtr ;
BindElement *BSIM4SBspStructPtr ;
BindElement *BSIM4SBbpStructPtr ;
BindElement *BSIM4SBbStructPtr ;
BindElement *BSIM4SBsbStructPtr ;
BindElement *BSIM4BdbStructPtr ;
BindElement *BSIM4BbpStructPtr ;
BindElement *BSIM4BsbStructPtr ;
BindElement *BSIM4BbStructPtr ;
BindElement *BSIM4DgpStructPtr ;
BindElement *BSIM4DspStructPtr ;
BindElement *BSIM4DbpStructPtr ;
BindElement *BSIM4SdpStructPtr ;
BindElement *BSIM4SgpStructPtr ;
BindElement *BSIM4SbpStructPtr ;
BindElement *BSIM4QdpStructPtr ;
BindElement *BSIM4QgpStructPtr ;
BindElement *BSIM4QspStructPtr ;
BindElement *BSIM4QbpStructPtr ;
BindElement *BSIM4QqStructPtr ;
BindElement *BSIM4DPqStructPtr ;
BindElement *BSIM4GPqStructPtr ;
BindElement *BSIM4SPqStructPtr ;
#endif
} BSIM4instance ;
struct bsim4SizeDependParam

View File

@ -7,44 +7,70 @@ Author: 2012 Francesco Lannutti
#include "capdefs.h"
#include "ngspice/sperror.h"
#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)) ;
}
int
CAPbindCSC (GENmodel *inModel, CKTcircuit *ckt)
{
CAPmodel *model = (CAPmodel *)inModel ;
CAPinstance *here ;
int i ;
double *i ;
BindElement *matched, *BindStruct ;
size_t nz ;
/* loop through all the capacitor models */
for ( ; model != NULL ; model = model->CAPnextModel)
BindStruct = ckt->CKTmatrix->CKTbindStruct ;
nz = (size_t)ckt->CKTmatrix->CKTklunz ;
/* loop through all the capacitor models */
for ( ; model != NULL ; model = model->CAPnextModel)
{
/* loop through all the instances of the model */
for (here = model->CAPinstances ; here != NULL ; here = here->CAPnextInstance)
{
/* loop through all the instances of the model */
for (here = model->CAPinstances ; here != NULL ; here = here->CAPnextInstance)
if ((here->CAPposNode != 0) && (here->CAPposNode != 0))
{
i = 0 ;
if ((here->CAPposNode != 0) && (here->CAPposNode != 0)) {
while (here->CAPposPosptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ;
here->CAPposPosptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
i = here->CAPposPosptr ;
matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ;
here->CAPposPosStructPtr = matched ;
here->CAPposPosptr = matched->CSC ;
}
i = 0 ;
if ((here->CAPnegNode != 0) && (here->CAPnegNode != 0)) {
while (here->CAPnegNegptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ;
here->CAPnegNegptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
if ((here->CAPnegNode != 0) && (here->CAPnegNode != 0))
{
i = here->CAPnegNegptr ;
matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ;
here->CAPnegNegStructPtr = matched ;
here->CAPnegNegptr = matched->CSC ;
}
i = 0 ;
if ((here->CAPposNode != 0) && (here->CAPnegNode != 0)) {
while (here->CAPposNegptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ;
here->CAPposNegptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
if ((here->CAPposNode != 0) && (here->CAPnegNode != 0))
{
i = here->CAPposNegptr ;
matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ;
here->CAPposNegStructPtr = matched ;
here->CAPposNegptr = matched->CSC ;
}
i = 0 ;
if ((here->CAPnegNode != 0) && (here->CAPposNode != 0)) {
while (here->CAPnegPosptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ;
here->CAPnegPosptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
}
}
if ((here->CAPnegNode != 0) && (here->CAPposNode != 0))
{
i = here->CAPnegPosptr ;
matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ;
here->CAPnegPosStructPtr = matched ;
here->CAPnegPosptr = matched->CSC ;
}
}
}
return (OK) ;
}
@ -54,39 +80,28 @@ CAPbindCSCComplex (GENmodel *inModel, CKTcircuit *ckt)
{
CAPmodel *model = (CAPmodel *)inModel ;
CAPinstance *here ;
int i ;
/* loop through all the capacitor models */
for ( ; model != NULL ; model = model->CAPnextModel)
NG_IGNORE (ckt) ;
/* loop through all the capacitor models */
for ( ; model != NULL ; model = model->CAPnextModel)
{
/* loop through all the instances of the model */
for (here = model->CAPinstances ; here != NULL ; here = here->CAPnextInstance)
{
/* loop through all the instances of the model */
for (here = model->CAPinstances ; here != NULL ; here = here->CAPnextInstance)
{
i = 0 ;
if ((here->CAPposNode != 0) && (here->CAPposNode != 0)) {
while (here->CAPposPosptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ;
here->CAPposPosptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ;
}
if ((here->CAPposNode != 0) && (here->CAPposNode != 0))
here->CAPposPosptr = here->CAPposPosStructPtr->CSC_Complex ;
i = 0 ;
if ((here->CAPnegNode != 0) && (here->CAPnegNode != 0)) {
while (here->CAPnegNegptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ;
here->CAPnegNegptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ;
}
if ((here->CAPnegNode != 0) && (here->CAPnegNode != 0))
here->CAPnegNegptr = here->CAPnegNegStructPtr->CSC_Complex ;
i = 0 ;
if ((here->CAPposNode != 0) && (here->CAPnegNode != 0)) {
while (here->CAPposNegptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ;
here->CAPposNegptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ;
}
if ((here->CAPposNode != 0) && (here->CAPnegNode != 0))
here->CAPposNegptr = here->CAPposNegStructPtr->CSC_Complex ;
i = 0 ;
if ((here->CAPnegNode != 0) && (here->CAPposNode != 0)) {
while (here->CAPnegPosptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ;
here->CAPnegPosptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ;
}
}
}
if ((here->CAPnegNode != 0) && (here->CAPposNode != 0))
here->CAPnegPosptr = here->CAPnegPosStructPtr->CSC_Complex ;
}
}
return (OK) ;
}
@ -96,43 +111,28 @@ CAPbindCSCComplexToReal (GENmodel *inModel, CKTcircuit *ckt)
{
CAPmodel *model = (CAPmodel *)inModel ;
CAPinstance *here ;
int i ;
/* loop through all the capacitor models */
NG_IGNORE (ckt) ;
/* loop through all the capacitor models */
for ( ; model != NULL ; model = model->CAPnextModel)
{
/* loop through all the instances of the model */
for (here = model->CAPinstances ; here != NULL ; here = here->CAPnextInstance)
{
i = 0 ;
if ((here->CAPposNode != 0) && (here->CAPposNode != 0))
{
while (here->CAPposPosptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ;
here->CAPposPosptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
here->CAPposPosptr = here->CAPposPosStructPtr->CSC ;
i = 0 ;
if ((here->CAPnegNode != 0) && (here->CAPnegNode != 0))
{
while (here->CAPnegNegptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ;
here->CAPnegNegptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
here->CAPnegNegptr = here->CAPnegNegStructPtr->CSC ;
i = 0 ;
if ((here->CAPposNode != 0) && (here->CAPnegNode != 0))
{
while (here->CAPposNegptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ;
here->CAPposNegptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
here->CAPposNegptr = here->CAPposNegStructPtr->CSC ;
i = 0 ;
if ((here->CAPnegNode != 0) && (here->CAPposNode != 0))
{
while (here->CAPnegPosptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ;
here->CAPnegPosptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
here->CAPnegPosptr = here->CAPnegPosStructPtr->CSC ;
}
}
return (OK) ;
}
}

View File

@ -55,6 +55,13 @@ typedef struct sCAPinstance {
int CAPsenParmNo; /* parameter # for sensitivity use;
set equal to 0 if not a design parameter*/
#ifdef KLU
BindElement *CAPposPosStructPtr ;
BindElement *CAPposNegStructPtr ;
BindElement *CAPnegPosStructPtr ;
BindElement *CAPnegNegStructPtr ;
#endif
} CAPinstance ;
#define CAPqcap CAPstate /* charge on the capacitor */

View File

@ -7,100 +7,114 @@ Author: 2012 Francesco Lannutti
#include "inddefs.h"
#include "ngspice/sperror.h"
#include <stdlib.h>
static
int
INDbindCSC(GENmodel *inModel, CKTcircuit *ckt)
BindCompare (const void *a, const void *b)
{
INDmodel *model = (INDmodel *)inModel;
INDinstance *here;
int i ;
BindElement *A, *B ;
A = (BindElement *)a ;
B = (BindElement *)b ;
/* loop through all the INDacitor models */
for( ; model != NULL; model = model->INDnextModel ) {
/* loop through all the instances of the model */
for (here = model->INDinstances; here != NULL ;
here=here->INDnextInstance) {
i = 0 ;
if ((here->INDposNode != 0) && (here->INDbrEq != 0)) {
while (here->INDposIbrptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ;
here->INDposIbrptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
i = 0 ;
if ((here->INDnegNode != 0) && (here->INDbrEq != 0)) {
while (here->INDnegIbrptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ;
here->INDnegIbrptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
i = 0 ;
if ((here->INDbrEq != 0) && (here->INDnegNode != 0)) {
while (here->INDibrNegptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ;
here->INDibrNegptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
i = 0 ;
if ((here->INDbrEq != 0) && (here->INDposNode != 0)) {
while (here->INDibrPosptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ;
here->INDibrPosptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
i = 0 ;
if ((here->INDbrEq != 0) && (here->INDbrEq != 0)) {
while (here->INDibrIbrptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ;
here->INDibrIbrptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
}
}
return(OK);
return ((int)(A->Sparse - B->Sparse)) ;
}
int
INDbindCSCComplex(GENmodel *inModel, CKTcircuit *ckt)
INDbindCSC (GENmodel *inModel, CKTcircuit *ckt)
{
INDmodel *model = (INDmodel *)inModel;
INDinstance *here;
int i ;
INDmodel *model = (INDmodel *)inModel ;
INDinstance *here ;
double *i ;
BindElement *matched, *BindStruct ;
size_t nz ;
/* loop through all the INDacitor models */
for( ; model != NULL; model = model->INDnextModel ) {
BindStruct = ckt->CKTmatrix->CKTbindStruct ;
nz = (size_t)ckt->CKTmatrix->CKTklunz ;
/* loop through all the instances of the model */
for (here = model->INDinstances; here != NULL ;
here=here->INDnextInstance) {
/* loop through all the inductor models */
for ( ; model != NULL ; model = model->INDnextModel)
{
/* loop through all the instances of the model */
for (here = model->INDinstances ; here != NULL ; here = here->INDnextInstance)
{
if ((here->INDposNode != 0) && (here->INDbrEq != 0))
{
i = here->INDposIbrptr ;
matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ;
here->INDposIbrStructPtr = matched ;
here->INDposIbrptr = matched->CSC ;
}
i = 0 ;
if ((here->INDposNode != 0) && (here->INDbrEq != 0)) {
while (here->INDposIbrptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ;
here->INDposIbrptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ;
}
if ((here->INDnegNode != 0) && (here->INDbrEq != 0))
{
i = here->INDnegIbrptr ;
matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ;
here->INDnegIbrStructPtr = matched ;
here->INDnegIbrptr = matched->CSC ;
}
i = 0 ;
if ((here->INDnegNode != 0) && (here->INDbrEq != 0)) {
while (here->INDnegIbrptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ;
here->INDnegIbrptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ;
}
if ((here->INDbrEq != 0) && (here->INDnegNode != 0))
{
i = here->INDibrNegptr ;
matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ;
here->INDibrNegStructPtr = matched ;
here->INDibrNegptr = matched->CSC ;
}
i = 0 ;
if ((here->INDbrEq != 0) && (here->INDnegNode != 0)) {
while (here->INDibrNegptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ;
here->INDibrNegptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ;
}
if ((here->INDbrEq != 0) && (here->INDposNode != 0))
{
i = here->INDibrPosptr ;
matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ;
here->INDibrPosStructPtr = matched ;
here->INDibrPosptr = matched->CSC ;
}
i = 0 ;
if ((here->INDbrEq != 0) && (here->INDposNode != 0)) {
while (here->INDibrPosptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ;
here->INDibrPosptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ;
}
if ((here->INDbrEq != 0) && (here->INDbrEq != 0))
{
i = here->INDibrIbrptr ;
matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ;
here->INDibrIbrStructPtr = matched ;
here->INDibrIbrptr = matched->CSC ;
}
}
}
i = 0 ;
if ((here->INDbrEq != 0) && (here->INDbrEq != 0)) {
while (here->INDibrIbrptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ;
here->INDibrIbrptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ;
}
}
}
return(OK);
return (OK) ;
}
int
INDbindCSCComplex (GENmodel *inModel, CKTcircuit *ckt)
{
INDmodel *model = (INDmodel *)inModel ;
INDinstance *here ;
NG_IGNORE (ckt) ;
/* loop through all the inductor models */
for ( ; model != NULL ; model = model->INDnextModel)
{
/* loop through all the instances of the model */
for (here = model->INDinstances ; here != NULL ; here = here->INDnextInstance)
{
if ((here->INDposNode != 0) && (here->INDbrEq != 0))
here->INDposIbrptr = here->INDposIbrStructPtr->CSC_Complex ;
if ((here->INDnegNode != 0) && (here->INDbrEq != 0))
here->INDnegIbrptr = here->INDnegIbrStructPtr->CSC_Complex ;
if ((here->INDbrEq != 0) && (here->INDnegNode != 0))
here->INDibrNegptr = here->INDibrNegStructPtr->CSC_Complex ;
if ((here->INDbrEq != 0) && (here->INDposNode != 0))
here->INDibrPosptr = here->INDibrPosStructPtr->CSC_Complex ;
if ((here->INDbrEq != 0) && (here->INDbrEq != 0))
here->INDibrIbrptr = here->INDibrIbrStructPtr->CSC_Complex ;
}
}
return (OK) ;
}
int
@ -108,48 +122,29 @@ INDbindCSCComplexToReal (GENmodel *inModel, CKTcircuit *ckt)
{
INDmodel *model = (INDmodel *)inModel ;
INDinstance *here ;
int i ;
/* loop through all the Inductor models */
NG_IGNORE (ckt) ;
/* loop through all the inductor models */
for ( ; model != NULL ; model = model->INDnextModel)
{
/* loop through all the instances of the model */
for (here = model->INDinstances ; here != NULL ; here = here->INDnextInstance)
{
i = 0 ;
if ((here->INDposNode != 0) && (here->INDbrEq != 0))
{
while (here->INDposIbrptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ;
here->INDposIbrptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
here->INDposIbrptr = here->INDposIbrStructPtr->CSC ;
i = 0 ;
if ((here->INDnegNode != 0) && (here->INDbrEq != 0))
{
while (here->INDnegIbrptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ;
here->INDnegIbrptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
here->INDnegIbrptr = here->INDnegIbrStructPtr->CSC ;
i = 0 ;
if ((here->INDbrEq != 0) && (here->INDnegNode != 0))
{
while (here->INDibrNegptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ;
here->INDibrNegptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
here->INDibrNegptr = here->INDibrNegStructPtr->CSC ;
i = 0 ;
if ((here->INDbrEq != 0) && (here->INDposNode != 0))
{
while (here->INDibrPosptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ;
here->INDibrPosptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
here->INDibrPosptr = here->INDibrPosStructPtr->CSC ;
i = 0 ;
if ((here->INDbrEq != 0) && (here->INDbrEq != 0))
{
while (here->INDibrIbrptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ;
here->INDibrIbrptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
here->INDibrIbrptr = here->INDibrIbrStructPtr->CSC ;
}
}
@ -158,63 +153,67 @@ INDbindCSCComplexToReal (GENmodel *inModel, CKTcircuit *ckt)
#ifdef MUTUAL
int
MUTbindCSC(GENmodel *inModel, CKTcircuit *ckt)
MUTbindCSC (GENmodel *inModel, CKTcircuit *ckt)
{
MUTmodel *model = (MUTmodel *)inModel;
MUTinstance *here;
int i ;
MUTmodel *model = (MUTmodel *)inModel ;
MUTinstance *here ;
double *i ;
BindElement *matched, *BindStruct ;
size_t nz ;
/* loop through all the INDacitor models */
for( ; model != NULL; model = model->MUTnextModel ) {
BindStruct = ckt->CKTmatrix->CKTbindStruct ;
nz = (size_t)ckt->CKTmatrix->CKTklunz ;
/* loop through all the instances of the model */
for (here = model->MUTinstances; here != NULL ;
here=here->MUTnextInstance) {
/* loop through all the mutual inductor models */
for ( ; model != NULL ; model = model->MUTnextModel)
{
/* loop through all the instances of the model */
for (here = model->MUTinstances ; here != NULL ; here = here->MUTnextInstance)
{
if ((here->MUTind1->INDbrEq != 0) && (here->MUTind2->INDbrEq != 0))
{
i = here->MUTbr1br2 ;
matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ;
here->MUTbr1br2StructPtr = matched ;
here->MUTbr1br2 = matched->CSC ;
}
i = 0 ;
if ((here->MUTind1->INDbrEq != 0) && (here->MUTind2->INDbrEq != 0)) {
while (here->MUTbr1br2 != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ;
here->MUTbr1br2 = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
if ((here->MUTind2->INDbrEq != 0) && (here->MUTind1->INDbrEq != 0))
{
i = here->MUTbr2br1 ;
matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ;
here->MUTbr2br1StructPtr = matched ;
here->MUTbr2br1 = matched->CSC ;
}
}
}
i = 0 ;
if ((here->MUTind2->INDbrEq != 0) && (here->MUTind1->INDbrEq != 0)) {
while (here->MUTbr2br1 != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ;
here->MUTbr2br1 = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
}
}
return(OK);
return (OK) ;
}
int
MUTbindCSCComplex(GENmodel *inModel, CKTcircuit *ckt)
MUTbindCSCComplex (GENmodel *inModel, CKTcircuit *ckt)
{
MUTmodel *model = (MUTmodel *)inModel;
MUTinstance *here;
int i ;
MUTmodel *model = (MUTmodel *)inModel ;
MUTinstance *here ;
/* loop through all the INDacitor models */
for( ; model != NULL; model = model->MUTnextModel ) {
NG_IGNORE (ckt) ;
/* loop through all the instances of the model */
for (here = model->MUTinstances; here != NULL ;
here=here->MUTnextInstance) {
/* loop through all the mutual inductor models */
for ( ; model != NULL ; model = model->MUTnextModel)
{
/* loop through all the instances of the model */
for (here = model->MUTinstances ; here != NULL ; here = here->MUTnextInstance)
{
if ((here->MUTind1->INDbrEq != 0) && (here->MUTind2->INDbrEq != 0))
here->MUTbr1br2 = here->MUTbr1br2StructPtr->CSC_Complex ;
i = 0 ;
if ((here->MUTind1->INDbrEq != 0) && (here->MUTind2->INDbrEq != 0)) {
while (here->MUTbr1br2 != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ;
here->MUTbr1br2 = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ;
}
if ((here->MUTind2->INDbrEq != 0) && (here->MUTind1->INDbrEq != 0))
here->MUTbr2br1 = here->MUTbr2br1StructPtr->CSC_Complex ;
}
}
i = 0 ;
if ((here->MUTind2->INDbrEq != 0) && (here->MUTind1->INDbrEq != 0)) {
while (here->MUTbr2br1 != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ;
here->MUTbr2br1 = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ;
}
}
}
return(OK);
return (OK) ;
}
int
@ -222,27 +221,20 @@ MUTbindCSCComplexToReal (GENmodel *inModel, CKTcircuit *ckt)
{
MUTmodel *model = (MUTmodel *)inModel ;
MUTinstance *here ;
int i ;
/* loop through all the MutualInductor models */
NG_IGNORE (ckt) ;
/* loop through all the mutual inductor models */
for ( ; model != NULL ; model = model->MUTnextModel)
{
/* loop through all the instances of the model */
for (here = model->MUTinstances ; here != NULL ; here = here->MUTnextInstance)
{
i = 0 ;
if ((here->MUTind1->INDbrEq != 0) && (here->MUTind2->INDbrEq != 0))
{
while (here->MUTbr1br2 != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ;
here->MUTbr1br2 = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
here->MUTbr1br2 = here->MUTbr1br2StructPtr->CSC ;
i = 0 ;
if ((here->MUTind2->INDbrEq != 0) && (here->MUTind1->INDbrEq != 0))
{
while (here->MUTbr2br1 != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ;
here->MUTbr2br1 = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
here->MUTbr2br1 = here->MUTbr2br1StructPtr->CSC ;
}
}

View File

@ -59,6 +59,14 @@ typedef struct sINDinstance {
int INDsenParmNo; /* parameter # for sensitivity use;
set equal to 0 if not a design parameter*/
#ifdef KLU
BindElement *INDposIbrStructPtr ;
BindElement *INDnegIbrStructPtr ;
BindElement *INDibrPosStructPtr ;
BindElement *INDibrNegStructPtr ;
BindElement *INDibrIbrStructPtr ;
#endif
} INDinstance ;
#define INDflux INDstate /* flux in the inductor */
@ -125,6 +133,10 @@ typedef struct sMUTinstance {
int MUTsenParmNo; /* parameter # for sensitivity use;
set equal to 0 if not a design parameter*/
#ifdef KLU
BindElement *MUTbr1br2StructPtr ;
BindElement *MUTbr2br1StructPtr ;
#endif
} MUTinstance ;

View File

@ -7,88 +7,103 @@ Author: 2012 Francesco Lannutti
#include "resdefs.h"
#include "ngspice/sperror.h"
#include <stdlib.h>
static
int
RESbindCSC(GENmodel *inModel, CKTcircuit *ckt)
BindCompare (const void *a, const void *b)
{
RESmodel *model = (RESmodel *)inModel;
int i ;
BindElement *A, *B ;
A = (BindElement *)a ;
B = (BindElement *)b ;
/* loop through all the resistor models */
for( ; model != NULL; model = model->RESnextModel ) {
RESinstance *here;
/* loop through all the instances of the model */
for (here = model->RESinstances; here != NULL ;
here = here->RESnextInstance) {
i = 0 ;
if ((here->RESposNode != 0) && (here->RESposNode != 0)) {
while (here->RESposPosptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ;
here->RESposPosptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
i = 0 ;
if ((here->RESnegNode != 0) && (here->RESnegNode != 0)) {
while (here->RESnegNegptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ;
here->RESnegNegptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
i = 0 ;
if ((here->RESposNode != 0) && (here->RESnegNode != 0)) {
while (here->RESposNegptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ;
here->RESposNegptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
i = 0 ;
if ((here->RESnegNode != 0) && (here->RESposNode != 0)) {
while (here->RESnegPosptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ;
here->RESnegPosptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
}
}
return(OK);
return ((int)(A->Sparse - B->Sparse)) ;
}
int
RESbindCSCComplex(GENmodel *inModel, CKTcircuit *ckt)
RESbindCSC (GENmodel *inModel, CKTcircuit *ckt)
{
RESmodel *model = (RESmodel *)inModel;
int i ;
RESmodel *model = (RESmodel *)inModel ;
RESinstance *here ;
double *i ;
BindElement *matched, *BindStruct ;
size_t nz ;
/* loop through all the resistor models */
for( ; model != NULL; model = model->RESnextModel ) {
RESinstance *here;
BindStruct = ckt->CKTmatrix->CKTbindStruct ;
nz = (size_t)ckt->CKTmatrix->CKTklunz ;
/* loop through all the resistor models */
for ( ; model != NULL ; model = model->RESnextModel)
{
/* loop through all the instances of the model */
for (here = model->RESinstances; here != NULL ;
here = here->RESnextInstance) {
for (here = model->RESinstances ; here != NULL ; here = here->RESnextInstance)
{
if ((here->RESposNode != 0) && (here->RESposNode != 0))
{
i = here->RESposPosptr ;
matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ;
here->RESposPosStructPtr = matched ;
here->RESposPosptr = matched->CSC ;
}
i = 0 ;
if ((here->RESposNode != 0) && (here->RESposNode != 0)) {
while (here->RESposPosptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ;
here->RESposPosptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ;
}
if ((here->RESnegNode != 0) && (here->RESnegNode != 0))
{
i = here->RESnegNegptr ;
matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ;
here->RESnegNegStructPtr = matched ;
here->RESnegNegptr = matched->CSC ;
}
i = 0 ;
if ((here->RESnegNode != 0) && (here->RESnegNode != 0)) {
while (here->RESnegNegptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ;
here->RESnegNegptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ;
}
if ((here->RESposNode != 0) && (here->RESnegNode != 0))
{
i = here->RESposNegptr ;
matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ;
here->RESposNegStructPtr = matched ;
here->RESposNegptr = matched->CSC ;
}
i = 0 ;
if ((here->RESposNode != 0) && (here->RESnegNode != 0)) {
while (here->RESposNegptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ;
here->RESposNegptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ;
}
i = 0 ;
if ((here->RESnegNode != 0) && (here->RESposNode != 0)) {
while (here->RESnegPosptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ;
here->RESnegPosptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ;
}
}
if ((here->RESnegNode != 0) && (here->RESposNode != 0))
{
i = here->RESnegPosptr ;
matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ;
here->RESnegPosStructPtr = matched ;
here->RESnegPosptr = matched->CSC ;
}
}
}
return(OK);
return (OK) ;
}
int
RESbindCSCComplex (GENmodel *inModel, CKTcircuit *ckt)
{
RESmodel *model = (RESmodel *)inModel ;
RESinstance *here ;
NG_IGNORE (ckt) ;
/* loop through all the resistor models */
for ( ; model != NULL ; model = model->RESnextModel)
{
/* loop through all the instances of the model */
for (here = model->RESinstances ; here != NULL ; here = here->RESnextInstance)
{
if ((here->RESposNode != 0) && (here->RESposNode != 0))
here->RESposPosptr = here->RESposPosStructPtr->CSC_Complex ;
if ((here->RESnegNode != 0) && (here->RESnegNode != 0))
here->RESnegNegptr = here->RESnegNegStructPtr->CSC_Complex ;
if ((here->RESposNode != 0) && (here->RESnegNode != 0))
here->RESposNegptr = here->RESposNegStructPtr->CSC_Complex ;
if ((here->RESnegNode != 0) && (here->RESposNode != 0))
here->RESnegPosptr = here->RESnegPosStructPtr->CSC_Complex ;
}
}
return (OK) ;
}
int
@ -96,41 +111,26 @@ RESbindCSCComplexToReal (GENmodel *inModel, CKTcircuit *ckt)
{
RESmodel *model = (RESmodel *)inModel ;
RESinstance *here ;
int i ;
/* loop through all the resistor models */
NG_IGNORE (ckt) ;
/* loop through all the resistor models */
for ( ; model != NULL ; model = model->RESnextModel)
{
/* loop through all the instances of the model */
for (here = model->RESinstances ; here != NULL ; here = here->RESnextInstance)
{
i = 0 ;
if ((here->RESposNode != 0) && (here->RESposNode != 0))
{
while (here->RESposPosptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ;
here->RESposPosptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
here->RESposPosptr = here->RESposPosStructPtr->CSC ;
i = 0 ;
if ((here->RESnegNode != 0) && (here->RESnegNode != 0))
{
while (here->RESnegNegptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ;
here->RESnegNegptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
here->RESnegNegptr = here->RESnegNegStructPtr->CSC ;
i = 0 ;
if ((here->RESposNode != 0) && (here->RESnegNode != 0))
{
while (here->RESposNegptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ;
here->RESposNegptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
here->RESposNegptr = here->RESposNegStructPtr->CSC ;
i = 0 ;
if ((here->RESnegNode != 0) && (here->RESposNode != 0))
{
while (here->RESnegPosptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ;
here->RESnegPosptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
here->RESnegPosptr = here->RESnegPosStructPtr->CSC ;
}
}

View File

@ -81,6 +81,13 @@ typedef struct sRESinstance {
double **RESnVar;
#endif /* NONOISE */
#ifdef KLU
BindElement *RESposPosStructPtr ;
BindElement *RESposNegStructPtr ;
BindElement *RESnegPosStructPtr ;
BindElement *RESnegNegStructPtr ;
#endif
} RESinstance ;

View File

@ -7,88 +7,103 @@ Author: 2012 Francesco Lannutti
#include "vsrcdefs.h"
#include "ngspice/sperror.h"
#include <stdlib.h>
static
int
VSRCbindCSC(GENmodel *inModel, CKTcircuit *ckt)
BindCompare (const void *a, const void *b)
{
VSRCmodel *model = (VSRCmodel *)inModel;
int i ;
BindElement *A, *B ;
A = (BindElement *)a ;
B = (BindElement *)b ;
/* loop through all the resistor models */
for( ; model != NULL; model = model->VSRCnextModel ) {
VSRCinstance *here;
/* loop through all the instances of the model */
for (here = model->VSRCinstances; here != NULL ;
here = here->VSRCnextInstance) {
i = 0 ;
if ((here->VSRCposNode != 0) && (here->VSRCbranch != 0)) {
while (here->VSRCposIbrptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ;
here->VSRCposIbrptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
i = 0 ;
if ((here->VSRCnegNode != 0) && (here->VSRCbranch != 0)) {
while (here->VSRCnegIbrptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ;
here->VSRCnegIbrptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
i = 0 ;
if ((here->VSRCbranch != 0) && (here->VSRCnegNode != 0)) {
while (here->VSRCibrNegptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ;
here->VSRCibrNegptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
i = 0 ;
if ((here->VSRCbranch != 0) && (here->VSRCposNode != 0)) {
while (here->VSRCibrPosptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ;
here->VSRCibrPosptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
}
}
return(OK);
return ((int)(A->Sparse - B->Sparse)) ;
}
int
VSRCbindCSCComplex(GENmodel *inModel, CKTcircuit *ckt)
VSRCbindCSC (GENmodel *inModel, CKTcircuit *ckt)
{
VSRCmodel *model = (VSRCmodel *)inModel;
int i ;
VSRCmodel *model = (VSRCmodel *)inModel ;
VSRCinstance *here ;
double *i ;
BindElement *matched, *BindStruct ;
size_t nz ;
/* loop through all the resistor models */
for( ; model != NULL; model = model->VSRCnextModel ) {
VSRCinstance *here;
BindStruct = ckt->CKTmatrix->CKTbindStruct ;
nz = (size_t)ckt->CKTmatrix->CKTklunz ;
/* loop through all the voltage source models */
for ( ; model != NULL ; model = model->VSRCnextModel)
{
/* loop through all the instances of the model */
for (here = model->VSRCinstances; here != NULL ;
here = here->VSRCnextInstance) {
for (here = model->VSRCinstances ; here != NULL ; here = here->VSRCnextInstance)
{
if ((here->VSRCposNode != 0) && (here->VSRCbranch != 0))
{
i = here->VSRCposIbrptr ;
matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ;
here->VSRCposIbrStructPtr = matched ;
here->VSRCposIbrptr = matched->CSC ;
}
i = 0 ;
if ((here->VSRCposNode != 0) && (here->VSRCbranch != 0)) {
while (here->VSRCposIbrptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ;
here->VSRCposIbrptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ;
}
if ((here->VSRCnegNode != 0) && (here->VSRCbranch != 0))
{
i = here->VSRCnegIbrptr ;
matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ;
here->VSRCnegIbrStructPtr = matched ;
here->VSRCnegIbrptr = matched->CSC ;
}
i = 0 ;
if ((here->VSRCnegNode != 0) && (here->VSRCbranch != 0)) {
while (here->VSRCnegIbrptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ;
here->VSRCnegIbrptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ;
}
if ((here->VSRCbranch != 0) && (here->VSRCnegNode != 0))
{
i = here->VSRCibrNegptr ;
matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ;
here->VSRCibrNegStructPtr = matched ;
here->VSRCibrNegptr = matched->CSC ;
}
i = 0 ;
if ((here->VSRCbranch != 0) && (here->VSRCnegNode != 0)) {
while (here->VSRCibrNegptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ;
here->VSRCibrNegptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ;
}
i = 0 ;
if ((here->VSRCbranch != 0) && (here->VSRCposNode != 0)) {
while (here->VSRCibrPosptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ;
here->VSRCibrPosptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ;
}
}
if ((here->VSRCbranch != 0) && (here->VSRCposNode != 0))
{
i = here->VSRCibrPosptr ;
matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ;
here->VSRCibrPosStructPtr = matched ;
here->VSRCibrPosptr = matched->CSC ;
}
}
}
return(OK);
return (OK) ;
}
int
VSRCbindCSCComplex (GENmodel *inModel, CKTcircuit *ckt)
{
VSRCmodel *model = (VSRCmodel *)inModel ;
VSRCinstance *here ;
NG_IGNORE (ckt) ;
/* loop through all the voltage source models */
for ( ; model != NULL ; model = model->VSRCnextModel)
{
/* loop through all the instances of the model */
for (here = model->VSRCinstances ; here != NULL ; here = here->VSRCnextInstance)
{
if ((here->VSRCposNode != 0) && (here->VSRCbranch != 0))
here->VSRCposIbrptr = here->VSRCposIbrStructPtr->CSC_Complex ;
if ((here->VSRCnegNode != 0) && (here->VSRCbranch != 0))
here->VSRCnegIbrptr = here->VSRCnegIbrStructPtr->CSC_Complex ;
if ((here->VSRCbranch != 0) && (here->VSRCnegNode != 0))
here->VSRCibrNegptr = here->VSRCibrNegStructPtr->CSC_Complex ;
if ((here->VSRCbranch != 0) && (here->VSRCposNode != 0))
here->VSRCibrPosptr = here->VSRCibrPosStructPtr->CSC_Complex ;
}
}
return (OK) ;
}
int
@ -96,41 +111,26 @@ VSRCbindCSCComplexToReal (GENmodel *inModel, CKTcircuit *ckt)
{
VSRCmodel *model = (VSRCmodel *)inModel ;
VSRCinstance *here ;
int i ;
/* loop through all the source models */
NG_IGNORE (ckt) ;
/* loop through all the voltage source models */
for ( ; model != NULL ; model = model->VSRCnextModel)
{
/* loop through all the instances of the model */
for (here = model->VSRCinstances ; here != NULL ; here = here->VSRCnextInstance)
{
i = 0 ;
if ((here->VSRCposNode != 0) && (here->VSRCbranch != 0))
{
while (here->VSRCposIbrptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ;
here->VSRCposIbrptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
here->VSRCposIbrptr = here->VSRCposIbrStructPtr->CSC ;
i = 0 ;
if ((here->VSRCnegNode != 0) && (here->VSRCbranch != 0))
{
while (here->VSRCnegIbrptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ;
here->VSRCnegIbrptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
here->VSRCnegIbrptr = here->VSRCnegIbrStructPtr->CSC ;
i = 0 ;
if ((here->VSRCbranch != 0) && (here->VSRCnegNode != 0))
{
while (here->VSRCibrNegptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ;
here->VSRCibrNegptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
here->VSRCibrNegptr = here->VSRCibrNegStructPtr->CSC ;
i = 0 ;
if ((here->VSRCbranch != 0) && (here->VSRCposNode != 0))
{
while (here->VSRCibrPosptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ;
here->VSRCibrPosptr = ckt->CKTmatrix->CKTbind_CSC [i] ;
}
here->VSRCibrPosptr = here->VSRCibrPosStructPtr->CSC ;
}
}

View File

@ -75,6 +75,14 @@ typedef struct sVSRCinstance {
unsigned VSRCdF1given :1 ; /* flag to indicate source is an f1 distortion input */
unsigned VSRCdF2given :1 ; /* flag to indicate source is an f2 distortion input */
unsigned VSRCrGiven :1 ; /* flag to indicate repeating pwl */
#ifdef KLU
BindElement *VSRCposIbrStructPtr ;
BindElement *VSRCnegIbrStructPtr ;
BindElement *VSRCibrPosStructPtr ;
BindElement *VSRCibrNegStructPtr ;
#endif
} VSRCinstance ;