diff --git a/src/spicelib/devices/numd/Makefile.am b/src/spicelib/devices/numd/Makefile.am index a9c263e89..1e6c33ec6 100644 --- a/src/spicelib/devices/numd/Makefile.am +++ b/src/spicelib/devices/numd/Makefile.am @@ -24,6 +24,18 @@ libnumd_la_SOURCES = \ numdtrun.c +if KLU_WANTED +libnumd_la_SOURCES += numdbindCSC.c +endif + +if SuperLU_WANTED +libnumd_la_SOURCES += numdbindCSC.c +endif + +if UMFPACK_WANTED +libnumd_la_SOURCES += numdbindCSC.c +endif + AM_CPPFLAGS = @AM_CPPFLAGS@ -I$(top_srcdir)/src/include AM_CFLAGS = $(STATIC) diff --git a/src/spicelib/devices/numd/numdbindCSC.c b/src/spicelib/devices/numd/numdbindCSC.c new file mode 100644 index 000000000..dfb0ef8d4 --- /dev/null +++ b/src/spicelib/devices/numd/numdbindCSC.c @@ -0,0 +1,141 @@ +/********** +Author: 2013 Francesco Lannutti +**********/ + +#include "ngspice/ngspice.h" +#include "ngspice/cktdefs.h" +#include "numddefs.h" +#include "ngspice/sperror.h" + +#include + +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 +NUMDbindCSC (GENmodel *inModel, CKTcircuit *ckt) +{ + NUMDmodel *model = (NUMDmodel *)inModel ; + NUMDinstance *here ; + double *i ; + BindElement *matched, *BindStruct ; + size_t nz ; + + BindStruct = ckt->CKTmatrix->CKTbindStruct ; + nz = (size_t)ckt->CKTmatrix->CKTklunz ; + + /* loop through all the NUMD models */ + for ( ; model != NULL ; model = model->NUMDnextModel) + { + /* loop through all the instances of the model */ + for (here = model->NUMDinstances ; here != NULL ; here = here->NUMDnextInstance) + { + if ((here-> NUMDposNode != 0) && (here-> NUMDposNode != 0)) + { + i = here->NUMDposPosPtr ; + matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ; + here->NUMDposPosStructPtr = matched ; + here->NUMDposPosPtr = matched->CSC ; + } + + if ((here-> NUMDnegNode != 0) && (here-> NUMDnegNode != 0)) + { + i = here->NUMDnegNegPtr ; + matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ; + here->NUMDnegNegStructPtr = matched ; + here->NUMDnegNegPtr = matched->CSC ; + } + + if ((here-> NUMDnegNode != 0) && (here-> NUMDposNode != 0)) + { + i = here->NUMDnegPosPtr ; + matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ; + here->NUMDnegPosStructPtr = matched ; + here->NUMDnegPosPtr = matched->CSC ; + } + + if ((here-> NUMDposNode != 0) && (here-> NUMDnegNode != 0)) + { + i = here->NUMDposNegPtr ; + matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ; + here->NUMDposNegStructPtr = matched ; + here->NUMDposNegPtr = matched->CSC ; + } + + } + } + + return (OK) ; +} + +int +NUMDbindCSCComplex (GENmodel *inModel, CKTcircuit *ckt) +{ + NUMDmodel *model = (NUMDmodel *)inModel ; + NUMDinstance *here ; + + NG_IGNORE (ckt) ; + + /* loop through all the NUMD models */ + for ( ; model != NULL ; model = model->NUMDnextModel) + { + /* loop through all the instances of the model */ + for (here = model->NUMDinstances ; here != NULL ; here = here->NUMDnextInstance) + { + if ((here-> NUMDposNode != 0) && (here-> NUMDposNode != 0)) + here->NUMDposPosPtr = here->NUMDposPosStructPtr->CSC_Complex ; + + if ((here-> NUMDnegNode != 0) && (here-> NUMDnegNode != 0)) + here->NUMDnegNegPtr = here->NUMDnegNegStructPtr->CSC_Complex ; + + if ((here-> NUMDnegNode != 0) && (here-> NUMDposNode != 0)) + here->NUMDnegPosPtr = here->NUMDnegPosStructPtr->CSC_Complex ; + + if ((here-> NUMDposNode != 0) && (here-> NUMDnegNode != 0)) + here->NUMDposNegPtr = here->NUMDposNegStructPtr->CSC_Complex ; + + } + } + + return (OK) ; +} + +int +NUMDbindCSCComplexToReal (GENmodel *inModel, CKTcircuit *ckt) +{ + NUMDmodel *model = (NUMDmodel *)inModel ; + NUMDinstance *here ; + + NG_IGNORE (ckt) ; + + /* loop through all the NUMD models */ + for ( ; model != NULL ; model = model->NUMDnextModel) + { + /* loop through all the instances of the model */ + for (here = model->NUMDinstances ; here != NULL ; here = here->NUMDnextInstance) + { + if ((here-> NUMDposNode != 0) && (here-> NUMDposNode != 0)) + here->NUMDposPosPtr = here->NUMDposPosStructPtr->CSC ; + + if ((here-> NUMDnegNode != 0) && (here-> NUMDnegNode != 0)) + here->NUMDnegNegPtr = here->NUMDnegNegStructPtr->CSC ; + + if ((here-> NUMDnegNode != 0) && (here-> NUMDposNode != 0)) + here->NUMDnegPosPtr = here->NUMDnegPosStructPtr->CSC ; + + if ((here-> NUMDposNode != 0) && (here-> NUMDnegNode != 0)) + here->NUMDposNegPtr = here->NUMDposNegStructPtr->CSC ; + + } + } + + return (OK) ; +} diff --git a/src/spicelib/devices/numd/numddefs.h b/src/spicelib/devices/numd/numddefs.h index 4b833bdce..196e50bb7 100644 --- a/src/spicelib/devices/numd/numddefs.h +++ b/src/spicelib/devices/numd/numddefs.h @@ -62,6 +62,14 @@ typedef struct sNUMDinstance { unsigned NUMDicFileGiven:1; /* flag to indicate init. cond. file given */ unsigned NUMDtempGiven:1; /* flag to indicate temp was specified */ unsigned NUMDprintGiven:1; /* flag to indicate if print was specified */ + +#ifdef KLU + BindElement *NUMDposPosStructPtr ; + BindElement *NUMDnegNegStructPtr ; + BindElement *NUMDnegPosStructPtr ; + BindElement *NUMDposNegStructPtr ; +#endif + } NUMDinstance;