New Binding Method extended to SW device

This commit is contained in:
Francesco Lannutti 2013-04-01 23:06:15 +02:00
parent 476542e754
commit 07d64a68b5
2 changed files with 109 additions and 92 deletions

View File

@ -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 <stdlib.h>
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) ;
}
}

View File

@ -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 */