From 55e77741284abb7cfb3ff80ed98e72839f540d31 Mon Sep 17 00:00:00 2001 From: rlar Date: Sat, 25 Apr 2015 11:18:20 +0200 Subject: [PATCH] cccs, vccs, isrc, untested ... --- src/spicelib/devices/cccs/Makefile.am | 1 + src/spicelib/devices/cccs/cccsdefs.h | 5 ++ src/spicelib/devices/cccs/cccsext.h | 2 + src/spicelib/devices/cccs/cccsfindbr.c | 36 +++++++++++++ src/spicelib/devices/cccs/cccsinit.c | 4 +- src/spicelib/devices/cccs/cccsload.c | 6 +++ src/spicelib/devices/cccs/cccspzld.c | 5 ++ src/spicelib/devices/cccs/cccsset.c | 30 ++++++++++- src/spicelib/devices/dev.c | 2 +- src/spicelib/devices/isrc/Makefile.am | 2 + src/spicelib/devices/isrc/isrcdefs.h | 6 +++ src/spicelib/devices/isrc/isrcext.h | 3 ++ src/spicelib/devices/isrc/isrcfindbr.c | 36 +++++++++++++ src/spicelib/devices/isrc/isrcinit.c | 6 +-- src/spicelib/devices/isrc/isrcload.c | 7 ++- src/spicelib/devices/isrc/isrcsetup.c | 71 ++++++++++++++++++++++++++ src/spicelib/devices/vccs/Makefile.am | 1 + src/spicelib/devices/vccs/vccsdefs.h | 9 +++- src/spicelib/devices/vccs/vccsext.h | 2 + src/spicelib/devices/vccs/vccsfindbr.c | 36 +++++++++++++ src/spicelib/devices/vccs/vccsinit.c | 4 +- src/spicelib/devices/vccs/vccsload.c | 9 +++- src/spicelib/devices/vccs/vccspzld.c | 9 +++- src/spicelib/devices/vccs/vccsset.c | 30 ++++++++++- 24 files changed, 303 insertions(+), 19 deletions(-) create mode 100644 src/spicelib/devices/cccs/cccsfindbr.c create mode 100644 src/spicelib/devices/isrc/isrcfindbr.c create mode 100644 src/spicelib/devices/isrc/isrcsetup.c create mode 100644 src/spicelib/devices/vccs/vccsfindbr.c diff --git a/src/spicelib/devices/cccs/Makefile.am b/src/spicelib/devices/cccs/Makefile.am index 566cb2774..99589b698 100644 --- a/src/spicelib/devices/cccs/Makefile.am +++ b/src/spicelib/devices/cccs/Makefile.am @@ -13,6 +13,7 @@ libcccs_la_SOURCES = \ cccsinit.h \ cccsitf.h \ cccsload.c \ + cccsfindbr.c \ cccsmdel.c \ cccspar.c \ cccspzld.c \ diff --git a/src/spicelib/devices/cccs/cccsdefs.h b/src/spicelib/devices/cccs/cccsdefs.h index 036a0f15d..403cead3a 100644 --- a/src/spicelib/devices/cccs/cccsdefs.h +++ b/src/spicelib/devices/cccs/cccsdefs.h @@ -25,6 +25,8 @@ typedef struct sCCCSinstance { int CCCSposNode; /* number of positive node of source */ int CCCSnegNode; /* number of negative node of source */ int CCCScontBranch; /* number of branch eq of controlling source */ + int CCCSposPrimeNode; /* number of node between resistor and vprobe */ + int CCCSbranch; /* number of vprobe branch current node */ char *CCCScontName; /* pointer to name of controlling instance */ @@ -36,6 +38,9 @@ typedef struct sCCCSinstance { *(positive node, control branch eq)*/ double *CCCSnegContBrptr; /* pointer to sparse matrix element at *(negative node, control branch eq)*/ + double *CCCS_pos_ibr; + double *CCCS_posPrime_ibr; + unsigned CCCScoeffGiven :1 ; /* flag to indicate coeff given */ unsigned CCCSmGiven :1 ; /* flag to indicate multiplier given */ diff --git a/src/spicelib/devices/cccs/cccsext.h b/src/spicelib/devices/cccs/cccsext.h index 5a8934518..2225e7f6b 100644 --- a/src/spicelib/devices/cccs/cccsext.h +++ b/src/spicelib/devices/cccs/cccsext.h @@ -16,4 +16,6 @@ extern int CCCSsLoad(GENmodel*,CKTcircuit*); extern void CCCSsPrint(GENmodel*,CKTcircuit*); extern int CCCSsSetup(SENstruct*,GENmodel*); extern int CCCSsetup(SMPmatrix*,GENmodel*,CKTcircuit*,int*); +extern int CCCSunsetup(GENmodel*,CKTcircuit*); +extern int CCCSfindBr(CKTcircuit*, GENmodel*, IFuid); diff --git a/src/spicelib/devices/cccs/cccsfindbr.c b/src/spicelib/devices/cccs/cccsfindbr.c new file mode 100644 index 000000000..8bf9699c9 --- /dev/null +++ b/src/spicelib/devices/cccs/cccsfindbr.c @@ -0,0 +1,36 @@ +/*********************************** +* Author: Marcel Hendrix, Feb 2015 * +***********************************/ + +#include "ngspice/ngspice.h" +#include "ngspice/cktdefs.h" +#include "cccsdefs.h" +#include "ngspice/sperror.h" +#include "ngspice/suffix.h" + + +int +CCCSfindBr (CKTcircuit *ckt, GENmodel *inModel, IFuid name) +{ + CCCSmodel *model = (CCCSmodel *) inModel; + CCCSinstance *here; + + for (; model; model = model->CCCSnextModel) + for (here = model->CCCSinstances; here; here = here->CCCSnextInstance) + if (here->CCCSname == name) { + + if (!here->CCCSbranch) { + CKTnode *tmp; + int error; + + error = CKTmkCur(ckt, &tmp, here->CCCSname, "branch"); + if (error) + return error; + here->CCCSbranch = tmp->number; + } + + return here->CCCSbranch; + } + + return 0; +} diff --git a/src/spicelib/devices/cccs/cccsinit.c b/src/spicelib/devices/cccs/cccsinit.c index 92b593ae4..512799f97 100644 --- a/src/spicelib/devices/cccs/cccsinit.c +++ b/src/spicelib/devices/cccs/cccsinit.c @@ -43,11 +43,11 @@ SPICEdev CCCSinfo = { /* DEVmodParam */ NULL, /* DEVload */ CCCSload, /* DEVsetup */ CCCSsetup, - /* DEVunsetup */ NULL, + /* DEVunsetup */ CCCSunsetup, /* DEVpzSetup */ CCCSsetup, /* DEVtemperature*/ NULL, /* DEVtrunc */ NULL, - /* DEVfindBranch */ NULL, + /* DEVfindBranch */ CCCSfindBr, /* DEVacLoad */ CCCSload, /* DEVaccept */ NULL, /* DEVdestroy */ CCCSdestroy, diff --git a/src/spicelib/devices/cccs/cccsload.c b/src/spicelib/devices/cccs/cccsload.c index fcf823c85..62696689c 100644 --- a/src/spicelib/devices/cccs/cccsload.c +++ b/src/spicelib/devices/cccs/cccsload.c @@ -34,6 +34,12 @@ CCCSload(GENmodel *inModel, CKTcircuit *ckt) *(here->CCCSposContBrptr) += here->CCCScoeff ; *(here->CCCSnegContBrptr) -= here->CCCScoeff ; + + if (here->CCCSbranch) { + *(here->CCCS_pos_ibr) += 1.0; + *(here->CCCS_posPrime_ibr) -= 1.0; + } + } } return(OK); diff --git a/src/spicelib/devices/cccs/cccspzld.c b/src/spicelib/devices/cccs/cccspzld.c index e4b1ff37e..4a7efff6b 100644 --- a/src/spicelib/devices/cccs/cccspzld.c +++ b/src/spicelib/devices/cccs/cccspzld.c @@ -36,6 +36,11 @@ CCCSpzLoad(GENmodel *inModel, CKTcircuit *ckt, SPcomplex *s) *(here->CCCSposContBrptr) += here->CCCScoeff ; *(here->CCCSnegContBrptr) -= here->CCCScoeff ; + + if (here->CCCSbranch) { + *(here->CCCS_pos_ibr) += 1.0; + *(here->CCCS_posPrime_ibr) -= 1.0; + } } } return(OK); diff --git a/src/spicelib/devices/cccs/cccsset.c b/src/spicelib/devices/cccs/cccsset.c index 343f4c943..5cc06d4cb 100644 --- a/src/spicelib/devices/cccs/cccsset.c +++ b/src/spicelib/devices/cccs/cccsset.c @@ -46,9 +46,35 @@ do { if((here->ptr = SMPmakeElt(matrix, here->first, here->second)) == NULL){\ return(E_NOMEM);\ } } while(0) - TSTALLOC(CCCSposContBrptr,CCCSposNode,CCCScontBranch); - TSTALLOC(CCCSnegContBrptr,CCCSnegNode,CCCScontBranch); + if (here->CCCSbranch == 0) { + here->CCCSposPrimeNode = here->CCCSposNode; + } else { + here->CCCSposPrimeNode = here->CCCSbranch; + TSTALLOC(CCCS_pos_ibr, CCCSposNode, CCCSbranch); + TSTALLOC(CCCS_posPrime_ibr, CCCSposPrimeNode, CCCSbranch); + } + + TSTALLOC(CCCSposContBrptr, CCCSposPrimeNode, CCCScontBranch); + TSTALLOC(CCCSnegContBrptr, CCCSnegNode, CCCScontBranch); } } return(OK); } + + +int +CCCSunsetup(GENmodel *inModel, CKTcircuit *ckt) +{ + CCCSmodel *model = (CCCSmodel *) inModel; + CCCSinstance *here; + + for (; model; model = model->CCCSnextModel) + for (here = model->CCCSinstances; here; here = here->CCCSnextInstance) + if (here->CCCSbranch) { + CKTdltNNum(ckt, here->CCCSbranch); + here->CCCSbranch = 0; + here->CCCSposPrimeNode = 0; + } + + return OK; +} diff --git a/src/spicelib/devices/dev.c b/src/spicelib/devices/dev.c index 52140d62a..092624c4a 100644 --- a/src/spicelib/devices/dev.c +++ b/src/spicelib/devices/dev.c @@ -141,7 +141,7 @@ int add_udn(int,Evt_Udn_Info_t **); static SPICEdev *(*static_devices[])(void) = { /* URC device MUST precede both resistors and capacitors */ get_urc_info, - get_asrc_info, /* asrc must precede res, cap, ind and dio */ + get_asrc_info, /* asrc must precede res, cap, ind, dio, cccs, vccs, isrc */ get_bjt_info, get_bsim1_info, get_bsim2_info, diff --git a/src/spicelib/devices/isrc/Makefile.am b/src/spicelib/devices/isrc/Makefile.am index 90443bfc7..73525c50c 100644 --- a/src/spicelib/devices/isrc/Makefile.am +++ b/src/spicelib/devices/isrc/Makefile.am @@ -11,12 +11,14 @@ libisrc_la_SOURCES = \ isrcdel.c \ isrcdest.c \ isrcext.h \ + isrcfindbr.c \ isrcinit.c \ isrcinit.h \ isrcitf.h \ isrcload.c \ isrcmdel.c \ isrcpar.c \ + isrcsetup.c \ isrctemp.c diff --git a/src/spicelib/devices/isrc/isrcdefs.h b/src/spicelib/devices/isrc/isrcdefs.h index f06741eb7..5c8a5fe35 100644 --- a/src/spicelib/devices/isrc/isrcdefs.h +++ b/src/spicelib/devices/isrc/isrcdefs.h @@ -28,6 +28,12 @@ typedef struct sISRCinstance { int ISRCnegNode; /* number of negative node of source */ int ISRCposNode; /* number of positive node of source */ + int ISRCposPrimeNode; /* number of node between resistor and vprobe */ + int ISRCbranch; /* number of vprobe branch current node */ + + double *ISRC_pos_ibr; + double *ISRC_posPrime_ibr; + int ISRCfunctionType; /* code number of function type for source */ int ISRCfunctionOrder; /* order of the function for the source */ double *ISRCcoeffs; /* pointer to array of coefficients */ diff --git a/src/spicelib/devices/isrc/isrcext.h b/src/spicelib/devices/isrc/isrcext.h index fee30625b..1e9b77490 100644 --- a/src/spicelib/devices/isrc/isrcext.h +++ b/src/spicelib/devices/isrc/isrcext.h @@ -8,8 +8,11 @@ extern int ISRCacLoad(GENmodel*,CKTcircuit*); extern int ISRCask(CKTcircuit*,GENinstance*,int,IFvalue*,IFvalue*); extern int ISRCdelete(GENmodel*,IFuid,GENinstance**); extern void ISRCdestroy(GENmodel**); +extern int ISRCfindBr(CKTcircuit*, GENmodel*, IFuid); extern int ISRCload(GENmodel*,CKTcircuit*); extern int ISRCmDelete(GENmodel**,IFuid,GENmodel*); extern int ISRCparam(int,IFvalue*,GENinstance*,IFvalue*); extern int ISRCpzLoad(GENmodel*,CKTcircuit*,SPcomplex*); +extern int ISRCsetup(SMPmatrix*,GENmodel*,CKTcircuit*,int*); extern int ISRCtemp(GENmodel*,CKTcircuit*); +extern int ISRCunsetup(GENmodel*,CKTcircuit*); diff --git a/src/spicelib/devices/isrc/isrcfindbr.c b/src/spicelib/devices/isrc/isrcfindbr.c new file mode 100644 index 000000000..44b01cd9d --- /dev/null +++ b/src/spicelib/devices/isrc/isrcfindbr.c @@ -0,0 +1,36 @@ +/*********************************** +* Author: Marcel Hendrix, Feb 2015 * +***********************************/ + +#include "ngspice/ngspice.h" +#include "ngspice/cktdefs.h" +#include "isrcdefs.h" +#include "ngspice/sperror.h" +#include "ngspice/suffix.h" + + +int +ISRCfindBr (CKTcircuit *ckt, GENmodel *inModel, IFuid name) +{ + ISRCmodel *model = (ISRCmodel *) inModel; + ISRCinstance *here; + + for (; model; model = model->ISRCnextModel) + for (here = model->ISRCinstances; here; here = here->ISRCnextInstance) + if (here->ISRCname == name) { + + if (here->ISRCbranch == 0) { + CKTnode *tmp; + int error; + + error = CKTmkCur(ckt, &tmp, here->ISRCname, "branch"); + if (error) + return error; + here->ISRCbranch = tmp->number; + } + + return here->ISRCbranch; + } + + return 0; +} diff --git a/src/spicelib/devices/isrc/isrcinit.c b/src/spicelib/devices/isrc/isrcinit.c index 2d02d4ec5..358541ae2 100644 --- a/src/spicelib/devices/isrc/isrcinit.c +++ b/src/spicelib/devices/isrc/isrcinit.c @@ -43,12 +43,12 @@ SPICEdev ISRCinfo = { /* DEVparam */ ISRCparam, /* DEVmodParam */ NULL, /* DEVload */ ISRCload, - /* DEVsetup */ NULL, - /* DEVunsetup */ NULL, + /* DEVsetup */ ISRCsetup, + /* DEVunsetup */ ISRCunsetup, /* DEVpzSetup */ NULL, /* DEVtemperature*/ ISRCtemp, /* DEVtrunc */ NULL, - /* DEVfindBranch */ NULL, + /* DEVfindBranch */ ISRCfindBr, /* DEVacLoad */ ISRCacLoad, /* DEVaccept */ ISRCaccept, /* DEVdestroy */ ISRCdestroy, diff --git a/src/spicelib/devices/isrc/isrcload.c b/src/spicelib/devices/isrc/isrcload.c index f82f628d0..3fabab5d8 100644 --- a/src/spicelib/devices/isrc/isrcload.c +++ b/src/spicelib/devices/isrc/isrcload.c @@ -396,9 +396,14 @@ loadDone: #endif /* gtri - end - wbk - modify for supply ramping option */ - *(ckt->CKTrhs + (here->ISRCposNode)) += m * value; + *(ckt->CKTrhs + (here->ISRCposPrimeNode)) += m * value; *(ckt->CKTrhs + (here->ISRCnegNode)) -= m * value; + if (here->ISRCbranch) { + *(here->ISRC_pos_ibr) += 1.0; + *(here->ISRC_posPrime_ibr) -= 1.0; + } + /* gtri - end - wbk - modify to process srcFact, etc. for all sources */ #ifdef XSPICE diff --git a/src/spicelib/devices/isrc/isrcsetup.c b/src/spicelib/devices/isrc/isrcsetup.c new file mode 100644 index 000000000..3ac875b6b --- /dev/null +++ b/src/spicelib/devices/isrc/isrcsetup.c @@ -0,0 +1,71 @@ +/********** +Copyright 1990 Regents of the University of California. All rights reserved. +Author: 1985 Thomas L. Quarles +**********/ +/* + */ + + /* load the current source structure with those pointers needed later + * for fast matrix loading + */ + +#include "ngspice/ngspice.h" +#include "ngspice/smpdefs.h" +#include "ngspice/cktdefs.h" +#include "isrcdefs.h" +#include "ngspice/sperror.h" +#include "ngspice/suffix.h" + + +/*ARGSUSED*/ +int +ISRCsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states) +{ + ISRCmodel *model = (ISRCmodel *)inModel; + ISRCinstance *here; + + NG_IGNORE(states); + NG_IGNORE(ckt); + + /* loop through all the current source models */ + for( ; model != NULL; model = model->ISRCnextModel ) { + + /* loop through all the instances of the model */ + for (here = model->ISRCinstances; here != NULL ; + here=here->ISRCnextInstance) { + +/* macro to make elements with built in test for out of memory */ +#define TSTALLOC(ptr,first,second) \ +do { if((here->ptr = SMPmakeElt(matrix, here->first, here->second)) == NULL){\ + return(E_NOMEM);\ +} } while(0) + + if (here->ISRCbranch == 0) { + here->ISRCposPrimeNode = here->ISRCposNode; + } else { + here->ISRCposPrimeNode = here->ISRCbranch; + TSTALLOC(ISRC_pos_ibr, ISRCposNode, ISRCbranch); + TSTALLOC(ISRC_posPrime_ibr, ISRCposPrimeNode, ISRCbranch); + } + } + } + return(OK); +} + + +int +ISRCunsetup(GENmodel *inModel, CKTcircuit *ckt) +{ + ISRCmodel *model = (ISRCmodel *) inModel; + ISRCinstance *here; + + for (; model; model = model->ISRCnextModel) + for (here = model->ISRCinstances; here; here = here->ISRCnextInstance) + if (here->ISRCbranch) { + CKTdltNNum(ckt, here->ISRCbranch); + here->ISRCbranch = 0; + here->ISRCposPrimeNode = 0; + } + + return OK; +} diff --git a/src/spicelib/devices/vccs/Makefile.am b/src/spicelib/devices/vccs/Makefile.am index 145693195..050813ed9 100644 --- a/src/spicelib/devices/vccs/Makefile.am +++ b/src/spicelib/devices/vccs/Makefile.am @@ -13,6 +13,7 @@ libvccs_la_SOURCES = \ vccsinit.h \ vccsitf.h \ vccsload.c \ + vccsfindbr.c \ vccsmdel.c \ vccspar.c \ vccspzld.c \ diff --git a/src/spicelib/devices/vccs/vccsdefs.h b/src/spicelib/devices/vccs/vccsdefs.h index 13eb94aa1..b71a32f05 100644 --- a/src/spicelib/devices/vccs/vccsdefs.h +++ b/src/spicelib/devices/vccs/vccsdefs.h @@ -28,19 +28,24 @@ typedef struct sVCCSinstance { int VCCSnegNode; /* number of negative node of source */ int VCCScontPosNode; /* number of positive node of controlling source */ int VCCScontNegNode; /* number of negative node of controlling source */ + int VCCSposPrimeNode; /* number of node between resistor and vprobe */ + int VCCSbranch; /* number of vprobe branch current node */ double VCCSinitCond; /* initial condition (of controlling source) */ double VCCScoeff; /* coefficient */ double VCCSmValue; /* Parallel multiplier */ - double *VCCSposContPosptr; /* pointer to sparse matrix element at + double *VCCSposPrimeContPosptr; /* pointer to sparse matrix element at * (positive node, control positive node) */ - double *VCCSposContNegptr; /* pointer to sparse matrix element at + double *VCCSposPrimeContNegptr; /* pointer to sparse matrix element at * (negative node, control negative node) */ double *VCCSnegContPosptr; /* pointer to sparse matrix element at * (positive node, control positive node) */ double *VCCSnegContNegptr; /* pointer to sparse matrix element at * (negative node, control negative node) */ + double *VCCS_pos_ibr; + double *VCCS_posPrime_ibr; + unsigned VCCScoeffGiven :1 ;/* flag to indicate function coeffs given */ unsigned VCCSmGiven :1 ;/* flag to indicate multiplier given */ diff --git a/src/spicelib/devices/vccs/vccsext.h b/src/spicelib/devices/vccs/vccsext.h index 464020523..d7652015a 100644 --- a/src/spicelib/devices/vccs/vccsext.h +++ b/src/spicelib/devices/vccs/vccsext.h @@ -15,3 +15,5 @@ extern int VCCSsLoad(GENmodel*,CKTcircuit*); extern int VCCSsSetup(SENstruct*,GENmodel*); extern void VCCSsPrint(GENmodel*,CKTcircuit*); extern int VCCSsetup(SMPmatrix*,GENmodel*,CKTcircuit*,int*); +extern int VCCSunsetup(GENmodel*,CKTcircuit*); +extern int VCCSfindBr(CKTcircuit*, GENmodel*, IFuid); diff --git a/src/spicelib/devices/vccs/vccsfindbr.c b/src/spicelib/devices/vccs/vccsfindbr.c new file mode 100644 index 000000000..4a4ce62ef --- /dev/null +++ b/src/spicelib/devices/vccs/vccsfindbr.c @@ -0,0 +1,36 @@ +/*********************************** +* Author: Marcel Hendrix, Feb 2015 * +***********************************/ + +#include "ngspice/ngspice.h" +#include "ngspice/cktdefs.h" +#include "vccsdefs.h" +#include "ngspice/sperror.h" +#include "ngspice/suffix.h" + + +int +VCCSfindBr (CKTcircuit *ckt, GENmodel *inModel, IFuid name) +{ + VCCSmodel *model = (VCCSmodel *) inModel; + VCCSinstance *here; + + for (; model; model = model->VCCSnextModel) + for (here = model->VCCSinstances; here; here = here->VCCSnextInstance) + if (here->VCCSname == name) { + + if (!here->VCCSbranch) { + CKTnode *tmp; + int error; + + error = CKTmkCur(ckt, &tmp, here->VCCSname, "branch"); + if (error) + return error; + here->VCCSbranch = tmp->number; + } + + return here->VCCSbranch; + } + + return 0; +} diff --git a/src/spicelib/devices/vccs/vccsinit.c b/src/spicelib/devices/vccs/vccsinit.c index cdfa3c8dd..471541263 100644 --- a/src/spicelib/devices/vccs/vccsinit.c +++ b/src/spicelib/devices/vccs/vccsinit.c @@ -44,11 +44,11 @@ SPICEdev VCCSinfo = { /* DEVmodParam */ NULL, /* DEVload */ VCCSload, /* DEVsetup */ VCCSsetup, - /* DEVunsetup */ NULL, + /* DEVunsetup */ VCCSunsetup, /* DEVpzSetup */ VCCSsetup, /* DEVtemperature*/ NULL, /* DEVtrunc */ NULL, - /* DEVfindBranch */ NULL, + /* DEVfindBranch */ VCCSfindBr, /* DEVacLoad */ VCCSload, /* ac and normal loads are identical */ /* DEVaccept */ NULL, /* DEVdestroy */ VCCSdestroy, diff --git a/src/spicelib/devices/vccs/vccsload.c b/src/spicelib/devices/vccs/vccsload.c index a647d4f1a..4d1cf0f01 100644 --- a/src/spicelib/devices/vccs/vccsload.c +++ b/src/spicelib/devices/vccs/vccsload.c @@ -31,10 +31,15 @@ VCCSload(GENmodel *inModel, CKTcircuit *ckt) for (here = model->VCCSinstances; here != NULL ; here=here->VCCSnextInstance) { - *(here->VCCSposContPosptr) += here->VCCScoeff ; - *(here->VCCSposContNegptr) -= here->VCCScoeff ; + *(here->VCCSposPrimeContPosptr) += here->VCCScoeff ; + *(here->VCCSposPrimeContNegptr) -= here->VCCScoeff ; *(here->VCCSnegContPosptr) -= here->VCCScoeff ; *(here->VCCSnegContNegptr) += here->VCCScoeff ; + + if (here->VCCSbranch) { + *(here->VCCS_pos_ibr) += 1.0; + *(here->VCCS_posPrime_ibr) -= 1.0; + } } } return(OK); diff --git a/src/spicelib/devices/vccs/vccspzld.c b/src/spicelib/devices/vccs/vccspzld.c index 02a9c63ff..1c103b172 100644 --- a/src/spicelib/devices/vccs/vccspzld.c +++ b/src/spicelib/devices/vccs/vccspzld.c @@ -33,10 +33,15 @@ VCCSpzLoad(GENmodel *inModel, CKTcircuit *ckt, SPcomplex *s) for (here = model->VCCSinstances; here != NULL ; here=here->VCCSnextInstance) { - *(here->VCCSposContPosptr) += here->VCCScoeff ; - *(here->VCCSposContNegptr) -= here->VCCScoeff ; + *(here->VCCSposPrimeContPosptr) += here->VCCScoeff ; + *(here->VCCSposPrimeContNegptr) -= here->VCCScoeff ; *(here->VCCSnegContPosptr) -= here->VCCScoeff ; *(here->VCCSnegContNegptr) += here->VCCScoeff ; + + if (here->VCCSbranch) { + *(here->VCCS_pos_ibr) += 1.0; + *(here->VCCS_posPrime_ibr) -= 1.0; + } } } return(OK); diff --git a/src/spicelib/devices/vccs/vccsset.c b/src/spicelib/devices/vccs/vccsset.c index 0399385e2..ad91e276a 100644 --- a/src/spicelib/devices/vccs/vccsset.c +++ b/src/spicelib/devices/vccs/vccsset.c @@ -40,11 +40,37 @@ do { if((here->ptr = SMPmakeElt(matrix, here->first, here->second)) == NULL){\ return(E_NOMEM);\ } } while(0) - TSTALLOC(VCCSposContPosptr, VCCSposNode, VCCScontPosNode); - TSTALLOC(VCCSposContNegptr, VCCSposNode, VCCScontNegNode); + if (here->VCCSbranch == 0) { + here->VCCSposPrimeNode = here->VCCSposNode; + } else { + here->VCCSposPrimeNode = here->VCCSbranch; + TSTALLOC(VCCS_pos_ibr, VCCSposNode, VCCSbranch); + TSTALLOC(VCCS_posPrime_ibr, VCCSposPrimeNode, VCCSbranch); + } + + TSTALLOC(VCCSposPrimeContPosptr, VCCSposPrimeNode, VCCScontPosNode); + TSTALLOC(VCCSposPrimeContNegptr, VCCSposPrimeNode, VCCScontNegNode); TSTALLOC(VCCSnegContPosptr, VCCSnegNode, VCCScontPosNode); TSTALLOC(VCCSnegContNegptr, VCCSnegNode, VCCScontNegNode); } } return(OK); } + + +int +VCCSunsetup(GENmodel *inModel, CKTcircuit *ckt) +{ + VCCSmodel *model = (VCCSmodel *) inModel; + VCCSinstance *here; + + for (; model; model = model->VCCSnextModel) + for (here = model->VCCSinstances; here; here = here->VCCSnextInstance) + if (here->VCCSbranch) { + CKTdltNNum(ckt, here->VCCSbranch); + here->VCCSbranch = 0; + here->VCCSposPrimeNode = 0; + } + + return OK; +}