From bc6efce79cb0cc708990e39399cb267952235fde Mon Sep 17 00:00:00 2001 From: Francesco Lannutti Date: Mon, 1 Apr 2013 23:09:10 +0200 Subject: [PATCH] New Binding Method extended to VCVS device --- src/spicelib/devices/vcvs/vcvsbindCSC.c | 251 ++++++++++++------------ src/spicelib/devices/vcvs/vcvsdefs.h | 9 + 2 files changed, 136 insertions(+), 124 deletions(-) diff --git a/src/spicelib/devices/vcvs/vcvsbindCSC.c b/src/spicelib/devices/vcvs/vcvsbindCSC.c index 941da6f1d..1f844f911 100644 --- a/src/spicelib/devices/vcvs/vcvsbindCSC.c +++ b/src/spicelib/devices/vcvs/vcvsbindCSC.c @@ -1,5 +1,5 @@ /********** -Author: 2012 Francesco Lannutti +Author: 2013 Francesco Lannutti **********/ #include "ngspice/ngspice.h" @@ -7,102 +7,127 @@ Author: 2012 Francesco Lannutti #include "vcvsdefs.h" #include "ngspice/sperror.h" +#include + +static int -VCVSbindCSC(GENmodel *inModel, CKTcircuit *ckt) +BindCompare (const void *a, const void *b) { - VCVSmodel *model = (VCVSmodel *)inModel; - int i ; + BindElement *A, *B ; + A = (BindElement *)a ; + B = (BindElement *)b ; - /* loop through all the vcvs models */ - for( ; model != NULL; model = model->VCVSnextModel ) { - VCVSinstance *here; - - /* loop through all the instances of the model */ - for (here = model->VCVSinstances; here != NULL ; - here = here->VCVSnextInstance) { - - i = 0 ; - if ((here-> VCVSposNode != 0) && (here-> VCVSbranch != 0)) { - while (here->VCVSposIbrptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ; - here->VCVSposIbrptr = ckt->CKTmatrix->CKTbind_CSC [i] ; - } - i = 0 ; - if ((here-> VCVSnegNode != 0) && (here-> VCVSbranch != 0)) { - while (here->VCVSnegIbrptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ; - here->VCVSnegIbrptr = ckt->CKTmatrix->CKTbind_CSC [i] ; - } - i = 0 ; - if ((here-> VCVSbranch != 0) && (here-> VCVSnegNode != 0)) { - while (here->VCVSibrNegptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ; - here->VCVSibrNegptr = ckt->CKTmatrix->CKTbind_CSC [i] ; - } - i = 0 ; - if ((here-> VCVSbranch != 0) && (here-> VCVSposNode != 0)) { - while (here->VCVSibrPosptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ; - here->VCVSibrPosptr = ckt->CKTmatrix->CKTbind_CSC [i] ; - } - i = 0 ; - if ((here-> VCVSbranch != 0) && (here-> VCVScontPosNode != 0)) { - while (here->VCVSibrContPosptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ; - here->VCVSibrContPosptr = ckt->CKTmatrix->CKTbind_CSC [i] ; - } - i = 0 ; - if ((here-> VCVSbranch != 0) && (here-> VCVScontNegNode != 0)) { - while (here->VCVSibrContNegptr != ckt->CKTmatrix->CKTbind_Sparse [i]) i ++ ; - here->VCVSibrContNegptr = ckt->CKTmatrix->CKTbind_CSC [i] ; - } - } - } - return(OK); + return ((int)(A->Sparse - B->Sparse)) ; } int -VCVSbindCSCComplex(GENmodel *inModel, CKTcircuit *ckt) +VCVSbindCSC (GENmodel *inModel, CKTcircuit *ckt) { - VCVSmodel *model = (VCVSmodel *)inModel; - int i ; + VCVSmodel *model = (VCVSmodel *)inModel ; + VCVSinstance *here ; + double *i ; + BindElement *matched, *BindStruct ; + size_t nz ; - /* loop through all the vcvs models */ - for( ; model != NULL; model = model->VCVSnextModel ) { - VCVSinstance *here; + BindStruct = ckt->CKTmatrix->CKTbindStruct ; + nz = (size_t)ckt->CKTmatrix->CKTklunz ; + /* loop through all the VCVS models */ + for ( ; model != NULL ; model = model->VCVSnextModel) + { /* loop through all the instances of the model */ - for (here = model->VCVSinstances; here != NULL ; - here = here->VCVSnextInstance) { + for (here = model->VCVSinstances ; here != NULL ; here = here->VCVSnextInstance) + { + if ((here-> VCVSposNode != 0) && (here-> VCVSbranch != 0)) + { + i = here->VCVSposIbrptr ; + matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ; + here->VCVSposIbrptrStructPtr = matched ; + here->VCVSposIbrptr = matched->CSC ; + } - i = 0 ; - if ((here-> VCVSposNode != 0) && (here-> VCVSbranch != 0)) { - while (here->VCVSposIbrptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ; - here->VCVSposIbrptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ; - } - i = 0 ; - if ((here-> VCVSnegNode != 0) && (here-> VCVSbranch != 0)) { - while (here->VCVSnegIbrptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ; - here->VCVSnegIbrptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ; - } - i = 0 ; - if ((here-> VCVSbranch != 0) && (here-> VCVSnegNode != 0)) { - while (here->VCVSibrNegptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ; - here->VCVSibrNegptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ; - } - i = 0 ; - if ((here-> VCVSbranch != 0) && (here-> VCVSposNode != 0)) { - while (here->VCVSibrPosptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ; - here->VCVSibrPosptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ; - } - i = 0 ; - if ((here-> VCVSbranch != 0) && (here-> VCVScontPosNode != 0)) { - while (here->VCVSibrContPosptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ; - here->VCVSibrContPosptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ; - } - i = 0 ; - if ((here-> VCVSbranch != 0) && (here-> VCVScontNegNode != 0)) { - while (here->VCVSibrContNegptr != ckt->CKTmatrix->CKTbind_CSC [i]) i ++ ; - here->VCVSibrContNegptr = ckt->CKTmatrix->CKTbind_CSC_Complex [i] ; - } - } + if ((here-> VCVSnegNode != 0) && (here-> VCVSbranch != 0)) + { + i = here->VCVSnegIbrptr ; + matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ; + here->VCVSnegIbrptrStructPtr = matched ; + here->VCVSnegIbrptr = matched->CSC ; + } + + if ((here-> VCVSbranch != 0) && (here-> VCVSnegNode != 0)) + { + i = here->VCVSibrNegptr ; + matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ; + here->VCVSibrNegptrStructPtr = matched ; + here->VCVSibrNegptr = matched->CSC ; + } + + if ((here-> VCVSbranch != 0) && (here-> VCVSposNode != 0)) + { + i = here->VCVSibrPosptr ; + matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ; + here->VCVSibrPosptrStructPtr = matched ; + here->VCVSibrPosptr = matched->CSC ; + } + + if ((here-> VCVSbranch != 0) && (here-> VCVScontPosNode != 0)) + { + i = here->VCVSibrContPosptr ; + matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ; + here->VCVSibrContPosptrStructPtr = matched ; + here->VCVSibrContPosptr = matched->CSC ; + } + + if ((here-> VCVSbranch != 0) && (here-> VCVScontNegNode != 0)) + { + i = here->VCVSibrContNegptr ; + matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ; + here->VCVSibrContNegptrStructPtr = matched ; + here->VCVSibrContNegptr = matched->CSC ; + } + + } } - return(OK); + + return (OK) ; +} + +int +VCVSbindCSCComplex (GENmodel *inModel, CKTcircuit *ckt) +{ + VCVSmodel *model = (VCVSmodel *)inModel ; + VCVSinstance *here ; + + NG_IGNORE (ckt) ; + + /* loop through all the VCVS models */ + for ( ; model != NULL ; model = model->VCVSnextModel) + { + /* loop through all the instances of the model */ + for (here = model->VCVSinstances ; here != NULL ; here = here->VCVSnextInstance) + { + if ((here-> VCVSposNode != 0) && (here-> VCVSbranch != 0)) + here->VCVSposIbrptr = here->VCVSposIbrptrStructPtr->CSC_Complex ; + + if ((here-> VCVSnegNode != 0) && (here-> VCVSbranch != 0)) + here->VCVSnegIbrptr = here->VCVSnegIbrptrStructPtr->CSC_Complex ; + + if ((here-> VCVSbranch != 0) && (here-> VCVSnegNode != 0)) + here->VCVSibrNegptr = here->VCVSibrNegptrStructPtr->CSC_Complex ; + + if ((here-> VCVSbranch != 0) && (here-> VCVSposNode != 0)) + here->VCVSibrPosptr = here->VCVSibrPosptrStructPtr->CSC_Complex ; + + if ((here-> VCVSbranch != 0) && (here-> VCVScontPosNode != 0)) + here->VCVSibrContPosptr = here->VCVSibrContPosptrStructPtr->CSC_Complex ; + + if ((here-> VCVSbranch != 0) && (here-> VCVScontNegNode != 0)) + here->VCVSibrContNegptr = here->VCVSibrContNegptrStructPtr->CSC_Complex ; + + } + } + + return (OK) ; } int @@ -110,57 +135,35 @@ VCVSbindCSCComplexToReal (GENmodel *inModel, CKTcircuit *ckt) { VCVSmodel *model = (VCVSmodel *)inModel ; VCVSinstance *here ; - int i ; - /* loop through all the VoltageControlledVoltageSource models */ + NG_IGNORE (ckt) ; + + /* loop through all the VCVS models */ for ( ; model != NULL ; model = model->VCVSnextModel) { /* loop through all the instances of the model */ for (here = model->VCVSinstances ; here != NULL ; here = here->VCVSnextInstance) { - i = 0 ; - if ((here->VCVSposNode != 0) && (here->VCVSbranch != 0)) - { - while (here->VCVSposIbrptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ; - here->VCVSposIbrptr = ckt->CKTmatrix->CKTbind_CSC [i] ; - } + if ((here-> VCVSposNode != 0) && (here-> VCVSbranch != 0)) + here->VCVSposIbrptr = here->VCVSposIbrptrStructPtr->CSC ; - i = 0 ; - if ((here->VCVSnegNode != 0) && (here->VCVSbranch != 0)) - { - while (here->VCVSnegIbrptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ; - here->VCVSnegIbrptr = ckt->CKTmatrix->CKTbind_CSC [i] ; - } + if ((here-> VCVSnegNode != 0) && (here-> VCVSbranch != 0)) + here->VCVSnegIbrptr = here->VCVSnegIbrptrStructPtr->CSC ; - i = 0 ; - if ((here->VCVSbranch != 0) && (here->VCVSnegNode != 0)) - { - while (here->VCVSibrNegptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ; - here->VCVSibrNegptr = ckt->CKTmatrix->CKTbind_CSC [i] ; - } + if ((here-> VCVSbranch != 0) && (here-> VCVSnegNode != 0)) + here->VCVSibrNegptr = here->VCVSibrNegptrStructPtr->CSC ; - i = 0 ; - if ((here->VCVSbranch != 0) && (here->VCVSposNode != 0)) - { - while (here->VCVSibrPosptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ; - here->VCVSibrPosptr = ckt->CKTmatrix->CKTbind_CSC [i] ; - } + if ((here-> VCVSbranch != 0) && (here-> VCVSposNode != 0)) + here->VCVSibrPosptr = here->VCVSibrPosptrStructPtr->CSC ; - i = 0 ; - if ((here->VCVSbranch != 0) && (here->VCVScontPosNode != 0)) - { - while (here->VCVSibrContPosptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ; - here->VCVSibrContPosptr = ckt->CKTmatrix->CKTbind_CSC [i] ; - } + if ((here-> VCVSbranch != 0) && (here-> VCVScontPosNode != 0)) + here->VCVSibrContPosptr = here->VCVSibrContPosptrStructPtr->CSC ; + + if ((here-> VCVSbranch != 0) && (here-> VCVScontNegNode != 0)) + here->VCVSibrContNegptr = here->VCVSibrContNegptrStructPtr->CSC ; - i = 0 ; - if ((here->VCVSbranch != 0) && (here->VCVScontNegNode != 0)) - { - while (here->VCVSibrContNegptr != ckt->CKTmatrix->CKTbind_CSC_Complex [i]) i ++ ; - here->VCVSibrContNegptr = ckt->CKTmatrix->CKTbind_CSC [i] ; - } } } return (OK) ; -} \ No newline at end of file +} diff --git a/src/spicelib/devices/vcvs/vcvsdefs.h b/src/spicelib/devices/vcvs/vcvsdefs.h index 6073121c8..524ab1278 100644 --- a/src/spicelib/devices/vcvs/vcvsdefs.h +++ b/src/spicelib/devices/vcvs/vcvsdefs.h @@ -51,6 +51,15 @@ typedef struct sVCVSinstance { int VCVSsenParmNo; /* parameter # for sensitivity use; set equal to 0 if not a design parameter*/ +#ifdef KLU + BindElement *VCVSposIbrptrStructPtr ; + BindElement *VCVSnegIbrptrStructPtr ; + BindElement *VCVSibrNegptrStructPtr ; + BindElement *VCVSibrPosptrStructPtr ; + BindElement *VCVSibrContPosptrStructPtr ; + BindElement *VCVSibrContNegptrStructPtr ; +#endif + } VCVSinstance ; #define VCVSvOld VCVSstates