New Binding Method extended to VCVS device

This commit is contained in:
Francesco Lannutti 2013-04-01 23:09:10 +02:00
parent 3872fe0171
commit bc6efce79c
2 changed files with 136 additions and 124 deletions

View File

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

View File

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