From 0f1d6eb8fde66b4521d35c5b76b0ac57672967c7 Mon Sep 17 00:00:00 2001 From: Francesco Lannutti Date: Mon, 1 Apr 2013 22:39:23 +0200 Subject: [PATCH] New Binding Method extended to IND and MUT devices --- src/spicelib/devices/ind/Makefile.am | 9 +- src/spicelib/devices/ind/indMUTbindCSC.c | 243 ----------------------- src/spicelib/devices/ind/indbindCSC.c | 155 +++++++++++++++ src/spicelib/devices/ind/inddefs.h | 10 +- src/spicelib/devices/ind/mutbindCSC.c | 113 +++++++++++ 5 files changed, 279 insertions(+), 251 deletions(-) delete mode 100644 src/spicelib/devices/ind/indMUTbindCSC.c create mode 100644 src/spicelib/devices/ind/indbindCSC.c create mode 100644 src/spicelib/devices/ind/mutbindCSC.c diff --git a/src/spicelib/devices/ind/Makefile.am b/src/spicelib/devices/ind/Makefile.am index 55b5bb562..ff223a2ce 100644 --- a/src/spicelib/devices/ind/Makefile.am +++ b/src/spicelib/devices/ind/Makefile.am @@ -41,15 +41,18 @@ libind_la_SOURCES = \ if KLU_WANTED -libind_la_SOURCES += indMUTbindCSC.c +libind_la_SOURCES += indbindCSC.c +libind_la_SOURCES += mutbindCSC.c endif if SuperLU_WANTED -libind_la_SOURCES += indMUTbindCSC.c +libind_la_SOURCES += indbindCSC.c +libind_la_SOURCES += mutbindCSC.c endif if UMFPACK_WANTED -libind_la_SOURCES += indMUTbindCSC.c +libind_la_SOURCES += indbindCSC.c +libind_la_SOURCES += mutbindCSC.c endif AM_CPPFLAGS = @AM_CPPFLAGS@ -I$(top_srcdir)/src/include diff --git a/src/spicelib/devices/ind/indMUTbindCSC.c b/src/spicelib/devices/ind/indMUTbindCSC.c deleted file mode 100644 index 6013cf322..000000000 --- a/src/spicelib/devices/ind/indMUTbindCSC.c +++ /dev/null @@ -1,243 +0,0 @@ -/********** -Author: 2012 Francesco Lannutti -**********/ - -#include "ngspice/ngspice.h" -#include "ngspice/cktdefs.h" -#include "inddefs.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 -INDbindCSC (GENmodel *inModel, CKTcircuit *ckt) -{ - INDmodel *model = (INDmodel *)inModel ; - INDinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; - size_t nz ; - - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; - - /* 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 ; - } - - 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 ; - } - - 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 ; - } - - 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 ; - } - - 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 ; - } - } - } - - 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 -INDbindCSCComplexToReal (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 ; - - if ((here->INDnegNode != 0) && (here->INDbrEq != 0)) - here->INDnegIbrptr = here->INDnegIbrStructPtr->CSC ; - - if ((here->INDbrEq != 0) && (here->INDnegNode != 0)) - here->INDibrNegptr = here->INDibrNegStructPtr->CSC ; - - if ((here->INDbrEq != 0) && (here->INDposNode != 0)) - here->INDibrPosptr = here->INDibrPosStructPtr->CSC ; - - if ((here->INDbrEq != 0) && (here->INDbrEq != 0)) - here->INDibrIbrptr = here->INDibrIbrStructPtr->CSC ; - } - } - - return (OK) ; -} - -#ifdef MUTUAL -int -MUTbindCSC (GENmodel *inModel, CKTcircuit *ckt) -{ - MUTmodel *model = (MUTmodel *)inModel ; - MUTinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; - size_t nz ; - - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; - - /* 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 ; - } - - 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 ; - } - } - } - - return (OK) ; -} - -int -MUTbindCSCComplex (GENmodel *inModel, CKTcircuit *ckt) -{ - MUTmodel *model = (MUTmodel *)inModel ; - MUTinstance *here ; - - 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) - { - if ((here->MUTind1->INDbrEq != 0) && (here->MUTind2->INDbrEq != 0)) - here->MUTbr1br2 = here->MUTbr1br2StructPtr->CSC_Complex ; - - if ((here->MUTind2->INDbrEq != 0) && (here->MUTind1->INDbrEq != 0)) - here->MUTbr2br1 = here->MUTbr2br1StructPtr->CSC_Complex ; - } - } - - return (OK) ; -} - -int -MUTbindCSCComplexToReal (GENmodel *inModel, CKTcircuit *ckt) -{ - MUTmodel *model = (MUTmodel *)inModel ; - MUTinstance *here ; - - 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) - { - if ((here->MUTind1->INDbrEq != 0) && (here->MUTind2->INDbrEq != 0)) - here->MUTbr1br2 = here->MUTbr1br2StructPtr->CSC ; - - if ((here->MUTind2->INDbrEq != 0) && (here->MUTind1->INDbrEq != 0)) - here->MUTbr2br1 = here->MUTbr2br1StructPtr->CSC ; - } - } - - return (OK) ; -} -#endif diff --git a/src/spicelib/devices/ind/indbindCSC.c b/src/spicelib/devices/ind/indbindCSC.c new file mode 100644 index 000000000..7558b1bc3 --- /dev/null +++ b/src/spicelib/devices/ind/indbindCSC.c @@ -0,0 +1,155 @@ +/********** +Author: 2013 Francesco Lannutti +**********/ + +#include "ngspice/ngspice.h" +#include "ngspice/cktdefs.h" +#include "inddefs.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 +INDbindCSC (GENmodel *inModel, CKTcircuit *ckt) +{ + INDmodel *model = (INDmodel *)inModel ; + INDinstance *here ; + double *i ; + BindElement *matched, *BindStruct ; + size_t nz ; + + BindStruct = ckt->CKTmatrix->CKTbindStruct ; + nz = (size_t)ckt->CKTmatrix->CKTklunz ; + + /* loop through all the IND 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->INDposIbrptrStructPtr = matched ; + here->INDposIbrptr = matched->CSC ; + } + + if ((here->INDnegNode != 0) && (here->INDbrEq != 0)) + { + i = here->INDnegIbrptr ; + matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ; + here->INDnegIbrptrStructPtr = matched ; + here->INDnegIbrptr = matched->CSC ; + } + + if ((here->INDbrEq != 0) && (here->INDnegNode != 0)) + { + i = here->INDibrNegptr ; + matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ; + here->INDibrNegptrStructPtr = matched ; + here->INDibrNegptr = matched->CSC ; + } + + if ((here->INDbrEq != 0) && (here->INDposNode != 0)) + { + i = here->INDibrPosptr ; + matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ; + here->INDibrPosptrStructPtr = matched ; + here->INDibrPosptr = matched->CSC ; + } + + if ((here->INDbrEq != 0) && (here->INDbrEq != 0)) + { + i = here->INDibrIbrptr ; + matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ; + here->INDibrIbrptrStructPtr = matched ; + here->INDibrIbrptr = matched->CSC ; + } + + } + } + + return (OK) ; +} + +int +INDbindCSCComplex (GENmodel *inModel, CKTcircuit *ckt) +{ + INDmodel *model = (INDmodel *)inModel ; + INDinstance *here ; + + NG_IGNORE (ckt) ; + + /* loop through all the IND 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->INDposIbrptrStructPtr->CSC_Complex ; + + if ((here->INDnegNode != 0) && (here->INDbrEq != 0)) + here->INDnegIbrptr = here->INDnegIbrptrStructPtr->CSC_Complex ; + + if ((here->INDbrEq != 0) && (here->INDnegNode != 0)) + here->INDibrNegptr = here->INDibrNegptrStructPtr->CSC_Complex ; + + if ((here->INDbrEq != 0) && (here->INDposNode != 0)) + here->INDibrPosptr = here->INDibrPosptrStructPtr->CSC_Complex ; + + if ((here->INDbrEq != 0) && (here->INDbrEq != 0)) + here->INDibrIbrptr = here->INDibrIbrptrStructPtr->CSC_Complex ; + + } + } + + return (OK) ; +} + +int +INDbindCSCComplexToReal (GENmodel *inModel, CKTcircuit *ckt) +{ + INDmodel *model = (INDmodel *)inModel ; + INDinstance *here ; + + NG_IGNORE (ckt) ; + + /* loop through all the IND 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->INDposIbrptrStructPtr->CSC ; + + if ((here->INDnegNode != 0) && (here->INDbrEq != 0)) + here->INDnegIbrptr = here->INDnegIbrptrStructPtr->CSC ; + + if ((here->INDbrEq != 0) && (here->INDnegNode != 0)) + here->INDibrNegptr = here->INDibrNegptrStructPtr->CSC ; + + if ((here->INDbrEq != 0) && (here->INDposNode != 0)) + here->INDibrPosptr = here->INDibrPosptrStructPtr->CSC ; + + if ((here->INDbrEq != 0) && (here->INDbrEq != 0)) + here->INDibrIbrptr = here->INDibrIbrptrStructPtr->CSC ; + + } + } + + return (OK) ; +} diff --git a/src/spicelib/devices/ind/inddefs.h b/src/spicelib/devices/ind/inddefs.h index 6f7228e14..16ae6bfda 100644 --- a/src/spicelib/devices/ind/inddefs.h +++ b/src/spicelib/devices/ind/inddefs.h @@ -60,11 +60,11 @@ typedef struct sINDinstance { set equal to 0 if not a design parameter*/ #ifdef KLU - BindElement *INDposIbrStructPtr ; - BindElement *INDnegIbrStructPtr ; - BindElement *INDibrPosStructPtr ; - BindElement *INDibrNegStructPtr ; - BindElement *INDibrIbrStructPtr ; + BindElement *INDposIbrptrStructPtr ; + BindElement *INDnegIbrptrStructPtr ; + BindElement *INDibrNegptrStructPtr ; + BindElement *INDibrPosptrStructPtr ; + BindElement *INDibrIbrptrStructPtr ; #endif } INDinstance ; diff --git a/src/spicelib/devices/ind/mutbindCSC.c b/src/spicelib/devices/ind/mutbindCSC.c new file mode 100644 index 000000000..d7124a931 --- /dev/null +++ b/src/spicelib/devices/ind/mutbindCSC.c @@ -0,0 +1,113 @@ +/********** +Author: 2013 Francesco Lannutti +**********/ + +#include "ngspice/ngspice.h" +#include "ngspice/cktdefs.h" +#include "inddefs.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 +MUTbindCSC (GENmodel *inModel, CKTcircuit *ckt) +{ + MUTmodel *model = (MUTmodel *)inModel ; + MUTinstance *here ; + double *i ; + BindElement *matched, *BindStruct ; + size_t nz ; + + BindStruct = ckt->CKTmatrix->CKTbindStruct ; + nz = (size_t)ckt->CKTmatrix->CKTklunz ; + + /* loop through all the MUT 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 ; + } + + 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 ; + } + + } + } + + return (OK) ; +} + +int +MUTbindCSCComplex (GENmodel *inModel, CKTcircuit *ckt) +{ + MUTmodel *model = (MUTmodel *)inModel ; + MUTinstance *here ; + + NG_IGNORE (ckt) ; + + /* loop through all the MUT 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 ; + + if ((here->MUTind2->INDbrEq != 0) && (here->MUTind1->INDbrEq != 0)) + here->MUTbr2br1 = here->MUTbr2br1StructPtr->CSC_Complex ; + + } + } + + return (OK) ; +} + +int +MUTbindCSCComplexToReal (GENmodel *inModel, CKTcircuit *ckt) +{ + MUTmodel *model = (MUTmodel *)inModel ; + MUTinstance *here ; + + NG_IGNORE (ckt) ; + + /* loop through all the MUT 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 ; + + if ((here->MUTind2->INDbrEq != 0) && (here->MUTind1->INDbrEq != 0)) + here->MUTbr2br1 = here->MUTbr2br1StructPtr->CSC ; + + } + } + + return (OK) ; +}