Added CPL Model to KLU
This commit is contained in:
parent
69f4b33cbc
commit
ae17e49bc4
|
|
@ -19,6 +19,10 @@ libcpl_la_SOURCES = \
|
||||||
cplsetup.c \
|
cplsetup.c \
|
||||||
cplinit.c
|
cplinit.c
|
||||||
|
|
||||||
|
if KLU_WANTED
|
||||||
|
libcpl_la_SOURCES += cplbindCSC.c
|
||||||
|
endif
|
||||||
|
|
||||||
AM_CPPFLAGS = @AM_CPPFLAGS@ -I$(top_srcdir)/src/include
|
AM_CPPFLAGS = @AM_CPPFLAGS@ -I$(top_srcdir)/src/include
|
||||||
AM_CFLAGS = $(STATIC)
|
AM_CFLAGS = $(STATIC)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,147 @@
|
||||||
|
/**********
|
||||||
|
Author: 2013 Francesco Lannutti
|
||||||
|
**********/
|
||||||
|
|
||||||
|
#include "ngspice/ngspice.h"
|
||||||
|
#include "ngspice/cktdefs.h"
|
||||||
|
#include "cpldefs.h"
|
||||||
|
#include "ngspice/sperror.h"
|
||||||
|
#include "ngspice/klu-binding.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
|
||||||
|
CPLbindCSC (GENmodel *inModel, CKTcircuit *ckt)
|
||||||
|
{
|
||||||
|
CPLmodel *model = (CPLmodel *)inModel ;
|
||||||
|
CPLinstance *here ;
|
||||||
|
double *i ;
|
||||||
|
BindElement *matched, *BindStruct ;
|
||||||
|
size_t nz ;
|
||||||
|
int m, p ;
|
||||||
|
|
||||||
|
BindStruct = ckt->CKTmatrix->CKTbindStruct ;
|
||||||
|
nz = (size_t)ckt->CKTmatrix->CKTklunz ;
|
||||||
|
|
||||||
|
/* loop through all the CPL models */
|
||||||
|
for ( ; model != NULL ; model = model->CPLnextModel)
|
||||||
|
{
|
||||||
|
/* loop through all the instances of the model */
|
||||||
|
for (here = model->CPLinstances ; here != NULL ; here = here->CPLnextInstance)
|
||||||
|
{
|
||||||
|
for (m = 0; m < here->dimension; m++) {
|
||||||
|
CREATE_KLU_BINDING_TABLE(CPLibr1Ibr1Ptr[m], CPLibr1Ibr1Binding[m], CPLibr1[m], CPLibr1[m]);
|
||||||
|
CREATE_KLU_BINDING_TABLE(CPLibr2Ibr2Ptr[m], CPLibr2Ibr2Binding[m], CPLibr2[m], CPLibr2[m]);
|
||||||
|
CREATE_KLU_BINDING_TABLE(CPLposIbr1Ptr[m], CPLposIbr1Binding[m], CPLposNodes[m], CPLibr1[m]);
|
||||||
|
CREATE_KLU_BINDING_TABLE(CPLnegIbr2Ptr[m], CPLnegIbr2Binding[m], CPLnegNodes[m], CPLibr2[m]);
|
||||||
|
CREATE_KLU_BINDING_TABLE(CPLposPosPtr[m], CPLposPosBinding[m], CPLposNodes[m], CPLposNodes[m]);
|
||||||
|
CREATE_KLU_BINDING_TABLE(CPLnegNegPtr[m], CPLnegNegBinding[m], CPLnegNodes[m], CPLnegNodes[m]);
|
||||||
|
CREATE_KLU_BINDING_TABLE(CPLnegPosPtr[m], CPLnegPosBinding[m], CPLnegNodes[m], CPLposNodes[m]);
|
||||||
|
CREATE_KLU_BINDING_TABLE(CPLposNegPtr[m], CPLposNegBinding[m], CPLposNodes[m], CPLnegNodes[m]);
|
||||||
|
|
||||||
|
for (p = 0; p < here->dimension; p++) {
|
||||||
|
CREATE_KLU_BINDING_TABLE(CPLibr1PosPtr[m][p], CPLibr1PosBinding[m][p], CPLibr1[m], CPLposNodes[p]);
|
||||||
|
CREATE_KLU_BINDING_TABLE(CPLibr2NegPtr[m][p], CPLibr2NegBinding[m][p], CPLibr2[m], CPLnegNodes[p]);
|
||||||
|
CREATE_KLU_BINDING_TABLE(CPLibr1NegPtr[m][p], CPLibr1NegBinding[m][p], CPLibr1[m], CPLnegNodes[p]);
|
||||||
|
CREATE_KLU_BINDING_TABLE(CPLibr2PosPtr[m][p], CPLibr2PosBinding[m][p], CPLibr2[m], CPLposNodes[p]);
|
||||||
|
CREATE_KLU_BINDING_TABLE(CPLibr1Ibr2Ptr[m][p], CPLibr1Ibr2Binding[m][p], CPLibr1[m], CPLibr2[p]);
|
||||||
|
CREATE_KLU_BINDING_TABLE(CPLibr2Ibr1Ptr[m][p], CPLibr2Ibr1Binding[m][p], CPLibr2[m], CPLibr1[p]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (OK) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
CPLbindCSCComplex (GENmodel *inModel, CKTcircuit *ckt)
|
||||||
|
{
|
||||||
|
CPLmodel *model = (CPLmodel *)inModel ;
|
||||||
|
CPLinstance *here ;
|
||||||
|
int m, p;
|
||||||
|
|
||||||
|
NG_IGNORE (ckt) ;
|
||||||
|
|
||||||
|
/* loop through all the CPL models */
|
||||||
|
for ( ; model != NULL ; model = model->CPLnextModel)
|
||||||
|
{
|
||||||
|
/* loop through all the instances of the model */
|
||||||
|
for (here = model->CPLinstances ; here != NULL ; here = here->CPLnextInstance)
|
||||||
|
{
|
||||||
|
for (m = 0; m < here->dimension; m++) {
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_COMPLEX(CPLibr1Ibr1Ptr[m], CPLibr1Ibr1Binding[m], CPLibr1[m], CPLibr1[m]);
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_COMPLEX(CPLibr2Ibr2Ptr[m], CPLibr2Ibr2Binding[m], CPLibr2[m], CPLibr2[m]);
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_COMPLEX(CPLposIbr1Ptr[m], CPLposIbr1Binding[m], CPLposNodes[m], CPLibr1[m]);
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_COMPLEX(CPLnegIbr2Ptr[m], CPLnegIbr2Binding[m], CPLnegNodes[m], CPLibr2[m]);
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_COMPLEX(CPLposPosPtr[m], CPLposPosBinding[m], CPLposNodes[m], CPLposNodes[m]);
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_COMPLEX(CPLnegNegPtr[m], CPLnegNegBinding[m], CPLnegNodes[m], CPLnegNodes[m]);
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_COMPLEX(CPLnegPosPtr[m], CPLnegPosBinding[m], CPLnegNodes[m], CPLposNodes[m]);
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_COMPLEX(CPLposNegPtr[m], CPLposNegBinding[m], CPLposNodes[m], CPLnegNodes[m]);
|
||||||
|
|
||||||
|
for (p = 0; p < here->dimension; p++) {
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_COMPLEX(CPLibr1PosPtr[m][p], CPLibr1PosBinding[m][p], CPLibr1[m], CPLposNodes[p]);
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_COMPLEX(CPLibr2NegPtr[m][p], CPLibr2NegBinding[m][p], CPLibr2[m], CPLnegNodes[p]);
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_COMPLEX(CPLibr1NegPtr[m][p], CPLibr1NegBinding[m][p], CPLibr1[m], CPLnegNodes[p]);
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_COMPLEX(CPLibr2PosPtr[m][p], CPLibr2PosBinding[m][p], CPLibr2[m], CPLposNodes[p]);
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_COMPLEX(CPLibr1Ibr2Ptr[m][p], CPLibr1Ibr2Binding[m][p], CPLibr1[m], CPLibr2[p]);
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_COMPLEX(CPLibr2Ibr1Ptr[m][p], CPLibr2Ibr1Binding[m][p], CPLibr2[m], CPLibr1[p]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (OK) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
CPLbindCSCComplexToReal (GENmodel *inModel, CKTcircuit *ckt)
|
||||||
|
{
|
||||||
|
CPLmodel *model = (CPLmodel *)inModel ;
|
||||||
|
CPLinstance *here ;
|
||||||
|
int m, p;
|
||||||
|
|
||||||
|
NG_IGNORE (ckt) ;
|
||||||
|
|
||||||
|
/* loop through all the CPL models */
|
||||||
|
for ( ; model != NULL ; model = model->CPLnextModel)
|
||||||
|
{
|
||||||
|
/* loop through all the instances of the model */
|
||||||
|
for (here = model->CPLinstances ; here != NULL ; here = here->CPLnextInstance)
|
||||||
|
{
|
||||||
|
for (m = 0; m < here->dimension; m++) {
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_REAL(CPLibr1Ibr1Ptr[m], CPLibr1Ibr1Binding[m], CPLibr1[m], CPLibr1[m]);
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_REAL(CPLibr2Ibr2Ptr[m], CPLibr2Ibr2Binding[m], CPLibr2[m], CPLibr2[m]);
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_REAL(CPLposIbr1Ptr[m], CPLposIbr1Binding[m], CPLposNodes[m], CPLibr1[m]);
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_REAL(CPLnegIbr2Ptr[m], CPLnegIbr2Binding[m], CPLnegNodes[m], CPLibr2[m]);
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_REAL(CPLposPosPtr[m], CPLposPosBinding[m], CPLposNodes[m], CPLposNodes[m]);
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_REAL(CPLnegNegPtr[m], CPLnegNegBinding[m], CPLnegNodes[m], CPLnegNodes[m]);
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_REAL(CPLnegPosPtr[m], CPLnegPosBinding[m], CPLnegNodes[m], CPLposNodes[m]);
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_REAL(CPLposNegPtr[m], CPLposNegBinding[m], CPLposNodes[m], CPLnegNodes[m]);
|
||||||
|
|
||||||
|
for (p = 0; p < here->dimension; p++) {
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_REAL(CPLibr1PosPtr[m][p], CPLibr1PosBinding[m][p], CPLibr1[m], CPLposNodes[p]);
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_REAL(CPLibr2NegPtr[m][p], CPLibr2NegBinding[m][p], CPLibr2[m], CPLnegNodes[p]);
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_REAL(CPLibr1NegPtr[m][p], CPLibr1NegBinding[m][p], CPLibr1[m], CPLnegNodes[p]);
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_REAL(CPLibr2PosPtr[m][p], CPLibr2PosBinding[m][p], CPLibr2[m], CPLposNodes[p]);
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_REAL(CPLibr1Ibr2Ptr[m][p], CPLibr1Ibr2Binding[m][p], CPLibr1[m], CPLibr2[p]);
|
||||||
|
CONVERT_KLU_BINDING_TABLE_TO_REAL(CPLibr2Ibr1Ptr[m][p], CPLibr2Ibr1Binding[m][p], CPLibr2[m], CPLibr1[p]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (OK) ;
|
||||||
|
}
|
||||||
|
|
@ -57,6 +57,25 @@ typedef struct sCPLinstance {
|
||||||
unsigned CPLdcGiven : 1;
|
unsigned CPLdcGiven : 1;
|
||||||
unsigned CPLlengthGiven : 1;
|
unsigned CPLlengthGiven : 1;
|
||||||
|
|
||||||
|
#ifdef KLU
|
||||||
|
BindElement **CPLibr1Ibr1Binding;
|
||||||
|
BindElement **CPLibr2Ibr2Binding;
|
||||||
|
BindElement **CPLposIbr1Binding;
|
||||||
|
BindElement **CPLnegIbr2Binding;
|
||||||
|
/* trial */
|
||||||
|
BindElement **CPLposPosBinding;
|
||||||
|
BindElement **CPLnegNegBinding;
|
||||||
|
BindElement **CPLposNegBinding;
|
||||||
|
BindElement **CPLnegPosBinding;
|
||||||
|
|
||||||
|
BindElement ***CPLibr1PosBinding;
|
||||||
|
BindElement ***CPLibr2NegBinding;
|
||||||
|
BindElement ***CPLibr1NegBinding;
|
||||||
|
BindElement ***CPLibr2PosBinding;
|
||||||
|
BindElement ***CPLibr1Ibr2Binding;
|
||||||
|
BindElement ***CPLibr2Ibr1Binding;
|
||||||
|
#endif
|
||||||
|
|
||||||
} CPLinstance ;
|
} CPLinstance ;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,3 +14,9 @@ extern int CPLmParam(int,IFvalue*, GENmodel*);
|
||||||
extern int CPLparam(int,IFvalue*, GENinstance*, IFvalue*);
|
extern int CPLparam(int,IFvalue*, GENinstance*, IFvalue*);
|
||||||
extern int CPLsetup(SMPmatrix*, GENmodel*, CKTcircuit*, int*);
|
extern int CPLsetup(SMPmatrix*, GENmodel*, CKTcircuit*, int*);
|
||||||
extern int CPLunsetup(GENmodel*, CKTcircuit*);
|
extern int CPLunsetup(GENmodel*, CKTcircuit*);
|
||||||
|
|
||||||
|
#ifdef KLU
|
||||||
|
extern int CPLbindCSC (GENmodel *, CKTcircuit *) ;
|
||||||
|
extern int CPLbindCSCComplex (GENmodel *, CKTcircuit *) ;
|
||||||
|
extern int CPLbindCSCComplexToReal (GENmodel *, CKTcircuit *) ;
|
||||||
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -76,9 +76,9 @@ SPICEdev CPLinfo = {
|
||||||
/* DEVmodSize */ &CPLmSize,
|
/* DEVmodSize */ &CPLmSize,
|
||||||
|
|
||||||
#ifdef KLU
|
#ifdef KLU
|
||||||
/* DEVbindCSC */ NULL,
|
/* DEVbindCSC */ CPLbindCSC,
|
||||||
/* DEVbindCSCComplex */ NULL,
|
/* DEVbindCSCComplex */ CPLbindCSCComplex,
|
||||||
/* DEVbindCSCComplexToReal */ NULL,
|
/* DEVbindCSCComplexToReal */ CPLbindCSCComplexToReal,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -211,6 +211,24 @@ do { if((here->ptr = SMPmakeElt(matrix, here->first, here->second)) == NULL){\
|
||||||
MATRIX_ALLOC(double, here->CPLibr1Ibr2Ptr, noL, noL);
|
MATRIX_ALLOC(double, here->CPLibr1Ibr2Ptr, noL, noL);
|
||||||
MATRIX_ALLOC(double, here->CPLibr2Ibr1Ptr, noL, noL);
|
MATRIX_ALLOC(double, here->CPLibr2Ibr1Ptr, noL, noL);
|
||||||
|
|
||||||
|
#ifdef KLU
|
||||||
|
VECTOR_ALLOC(BindElement, here->CPLibr1Ibr1Binding, noL);
|
||||||
|
VECTOR_ALLOC(BindElement, here->CPLibr2Ibr2Binding, noL);
|
||||||
|
VECTOR_ALLOC(BindElement, here->CPLposIbr1Binding, noL);
|
||||||
|
VECTOR_ALLOC(BindElement, here->CPLnegIbr2Binding, noL);
|
||||||
|
VECTOR_ALLOC(BindElement, here->CPLposPosBinding, noL);
|
||||||
|
VECTOR_ALLOC(BindElement, here->CPLnegNegBinding, noL);
|
||||||
|
VECTOR_ALLOC(BindElement, here->CPLnegPosBinding, noL);
|
||||||
|
VECTOR_ALLOC(BindElement, here->CPLposNegBinding, noL);
|
||||||
|
|
||||||
|
MATRIX_ALLOC(BindElement, here->CPLibr1PosBinding, noL, noL);
|
||||||
|
MATRIX_ALLOC(BindElement, here->CPLibr2NegBinding, noL, noL);
|
||||||
|
MATRIX_ALLOC(BindElement, here->CPLibr1NegBinding, noL, noL);
|
||||||
|
MATRIX_ALLOC(BindElement, here->CPLibr2PosBinding, noL, noL);
|
||||||
|
MATRIX_ALLOC(BindElement, here->CPLibr1Ibr2Binding, noL, noL);
|
||||||
|
MATRIX_ALLOC(BindElement, here->CPLibr2Ibr1Binding, noL, noL);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
branchname = TMALLOC(char *, here->dimension);
|
branchname = TMALLOC(char *, here->dimension);
|
||||||
if (! here->CPLibr1Given) {
|
if (! here->CPLibr1Given) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue