From 07d64a68b59e2c541dc2020aa3c1320105f3adf4 Mon Sep 17 00:00:00 2001 From: Francesco Lannutti Date: Mon, 1 Apr 2013 23:06:15 +0200 Subject: [PATCH] New Binding Method extended to SW device --- src/spicelib/devices/sw/swbindCSC.c | 193 +++++++++++++++------------- src/spicelib/devices/sw/swdefs.h | 8 ++ 2 files changed, 109 insertions(+), 92 deletions(-) diff --git a/src/spicelib/devices/sw/swbindCSC.c b/src/spicelib/devices/sw/swbindCSC.c index 67e22df90..590cb535b 100644 --- a/src/spicelib/devices/sw/swbindCSC.c +++ b/src/spicelib/devices/sw/swbindCSC.c @@ -1,5 +1,5 @@ /********** -Author: 2012 Francesco Lannutti +Author: 2013 Francesco Lannutti **********/ #include "ngspice/ngspice.h" @@ -7,82 +7,105 @@ Author: 2012 Francesco Lannutti #include "swdefs.h" #include "ngspice/sperror.h" +#include + +static int -SWbindCSC(GENmodel *inModel, CKTcircuit *ckt) +BindCompare (const void *a, const void *b) { - SWmodel *model = (SWmodel *)inModel; - int i ; + BindElement *A, *B ; + A = (BindElement *)a ; + B = (BindElement *)b ; - /* loop through all the sw models */ - for( ; model != NULL; model = model->SWnextModel ) { - SWinstance *here; - - /* loop through all the instances of the model */ - for (here = model->SWinstances; here != NULL ; - here = here->SWnextInstance) { - - i = 0 ; - if ((here-> SWposNode != 0) && (here-> SWposNode != 0)) { - while (here->SWposPosptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ; - here->SWposPosptr = ckt->CKTmatrix->CKTbind_CSC [i] ; - } - i = 0 ; - if ((here-> SWposNode != 0) && (here-> SWnegNode != 0)) { - while (here->SWposNegptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ; - here->SWposNegptr = ckt->CKTmatrix->CKTbind_CSC [i] ; - } - i = 0 ; - if ((here-> SWnegNode != 0) && (here-> SWposNode != 0)) { - while (here->SWnegPosptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ; - here->SWnegPosptr = ckt->CKTmatrix->CKTbind_CSC [i] ; - } - i = 0 ; - if ((here-> SWnegNode != 0) && (here-> SWnegNode != 0)) { - while (here->SWnegNegptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ; - here->SWnegNegptr = ckt->CKTmatrix->CKTbind_CSC [i] ; - } - } - } - return(OK); + return ((int)(A->Sparse - B->Sparse)) ; } int -SWbindCSCComplex(GENmodel *inModel, CKTcircuit *ckt) +SWbindCSC (GENmodel *inModel, CKTcircuit *ckt) { - SWmodel *model = (SWmodel *)inModel; - int i ; + SWmodel *model = (SWmodel *)inModel ; + SWinstance *here ; + double *i ; + BindElement *matched, *BindStruct ; + size_t nz ; - /* loop through all the sw models */ - for( ; model != NULL; model = model->SWnextModel ) { - SWinstance *here; + BindStruct = ckt->CKTmatrix->CKTbindStruct ; + nz = (size_t)ckt->CKTmatrix->CKTklunz ; + /* loop through all the SW models */ + for ( ; model != NULL ; model = model->SWnextModel) + { /* loop through all the instances of the model */ - for (here = model->SWinstances; here != NULL ; - here = here->SWnextInstance) { + for (here = model->SWinstances ; here != NULL ; here = here->SWnextInstance) + { + if ((here-> SWposNode != 0) && (here-> SWposNode != 0)) + { + i = here->SWposPosptr ; + matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ; + here->SWposPosptrStructPtr = matched ; + here->SWposPosptr = matched->CSC ; + } - i = 0 ; - if ((here-> SWposNode != 0) && (here-> SWposNode != 0)) { - while (here->SWposPosptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ; - here->SWposPosptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ; - } - i = 0 ; - if ((here-> SWposNode != 0) && (here-> SWnegNode != 0)) { - while (here->SWposNegptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ; - here->SWposNegptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ; - } - i = 0 ; - if ((here-> SWnegNode != 0) && (here-> SWposNode != 0)) { - while (here->SWnegPosptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ; - here->SWnegPosptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ; - } - i = 0 ; - if ((here-> SWnegNode != 0) && (here-> SWnegNode != 0)) { - while (here->SWnegNegptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ; - here->SWnegNegptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ; - } - } + if ((here-> SWposNode != 0) && (here-> SWnegNode != 0)) + { + i = here->SWposNegptr ; + matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ; + here->SWposNegptrStructPtr = matched ; + here->SWposNegptr = matched->CSC ; + } + + if ((here-> SWnegNode != 0) && (here-> SWposNode != 0)) + { + i = here->SWnegPosptr ; + matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ; + here->SWnegPosptrStructPtr = matched ; + here->SWnegPosptr = matched->CSC ; + } + + if ((here-> SWnegNode != 0) && (here-> SWnegNode != 0)) + { + i = here->SWnegNegptr ; + matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ; + here->SWnegNegptrStructPtr = matched ; + here->SWnegNegptr = matched->CSC ; + } + + } } - return(OK); + + return (OK) ; +} + +int +SWbindCSCComplex (GENmodel *inModel, CKTcircuit *ckt) +{ + SWmodel *model = (SWmodel *)inModel ; + SWinstance *here ; + + NG_IGNORE (ckt) ; + + /* loop through all the SW models */ + for ( ; model != NULL ; model = model->SWnextModel) + { + /* loop through all the instances of the model */ + for (here = model->SWinstances ; here != NULL ; here = here->SWnextInstance) + { + if ((here-> SWposNode != 0) && (here-> SWposNode != 0)) + here->SWposPosptr = here->SWposPosptrStructPtr->CSC_Complex ; + + if ((here-> SWposNode != 0) && (here-> SWnegNode != 0)) + here->SWposNegptr = here->SWposNegptrStructPtr->CSC_Complex ; + + if ((here-> SWnegNode != 0) && (here-> SWposNode != 0)) + here->SWnegPosptr = here->SWnegPosptrStructPtr->CSC_Complex ; + + if ((here-> SWnegNode != 0) && (here-> SWnegNode != 0)) + here->SWnegNegptr = here->SWnegNegptrStructPtr->CSC_Complex ; + + } + } + + return (OK) ; } int @@ -90,43 +113,29 @@ SWbindCSCComplexToReal (GENmodel *inModel, CKTcircuit *ckt) { SWmodel *model = (SWmodel *)inModel ; SWinstance *here ; - int i ; - /* loop through all the sw models */ + NG_IGNORE (ckt) ; + + /* loop through all the SW models */ for ( ; model != NULL ; model = model->SWnextModel) { /* loop through all the instances of the model */ for (here = model->SWinstances ; here != NULL ; here = here->SWnextInstance) { - i = 0 ; - if ((here->SWposNode != 0) && (here->SWposNode != 0)) - { - while (here->SWposPosptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ; - here->SWposPosptr = ckt->CKTmatrix->CKTbind_CSC [i] ; - } + if ((here-> SWposNode != 0) && (here-> SWposNode != 0)) + here->SWposPosptr = here->SWposPosptrStructPtr->CSC ; - i = 0 ; - if ((here->SWposNode != 0) && (here->SWnegNode != 0)) - { - while (here->SWposNegptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ; - here->SWposNegptr = ckt->CKTmatrix->CKTbind_CSC [i] ; - } + if ((here-> SWposNode != 0) && (here-> SWnegNode != 0)) + here->SWposNegptr = here->SWposNegptrStructPtr->CSC ; - i = 0 ; - if ((here->SWnegNode != 0) && (here->SWposNode != 0)) - { - while (here->SWnegPosptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ; - here->SWnegPosptr = ckt->CKTmatrix->CKTbind_CSC [i] ; - } + if ((here-> SWnegNode != 0) && (here-> SWposNode != 0)) + here->SWnegPosptr = here->SWnegPosptrStructPtr->CSC ; + + if ((here-> SWnegNode != 0) && (here-> SWnegNode != 0)) + here->SWnegNegptr = here->SWnegNegptrStructPtr->CSC ; - i = 0 ; - if ((here->SWnegNode != 0) && (here->SWnegNode != 0)) - { - while (here->SWnegNegptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ; - here->SWnegNegptr = ckt->CKTmatrix->CKTbind_CSC [i] ; - } } } return (OK) ; -} \ No newline at end of file +} diff --git a/src/spicelib/devices/sw/swdefs.h b/src/spicelib/devices/sw/swdefs.h index ce3c89d44..2eae2c168 100644 --- a/src/spicelib/devices/sw/swdefs.h +++ b/src/spicelib/devices/sw/swdefs.h @@ -47,6 +47,14 @@ typedef struct sSWinstance { #else /* NONOISE */ double *SWnVar; #endif /* NONOISE */ + +#ifdef KLU + BindElement *SWposPosptrStructPtr ; + BindElement *SWposNegptrStructPtr ; + BindElement *SWnegPosptrStructPtr ; + BindElement *SWnegNegptrStructPtr ; +#endif + } SWinstance ; /* data per model */