diff --git a/src/spicelib/devices/adms/admst/ngspice.xml b/src/spicelib/devices/adms/admst/ngspice.xml index 32732a94c..f2a1efb0b 100644 --- a/src/spicelib/devices/adms/admst/ngspice.xml +++ b/src/spicelib/devices/adms/admst/ngspice.xml @@ -6,12 +6,6 @@ --> - - - - - - @@ -33,52 +27,22 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -86,116 +50,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -218,72 +72,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int @@ -374,191 +162,72 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -610,7 +279,6 @@ - @@ -632,17 +300,14 @@ - - - @@ -668,7 +333,7 @@ - + @@ -720,7 +385,7 @@ - + @@ -1036,91 +701,173 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -1128,23 +875,7 @@ - - - - - - - - - - - - - - - - - + /* math functions and appropriate derivatives */ @@ -2060,82 +1791,12 @@ inline double _d0_vt(double) { return 1.3806503e-23/1.602176462e-1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + $e @@ -2522,14 +2183,7 @@ inline double _d0_vt(double) { return 1.3806503e-23/1.602176462e-1 - - - - - - - - + @@ -2538,7 +2192,7 @@ inline double _d0_vt(double) { return 1.3806503e-23/1.602176462e-1 - + @@ -3107,75 +2761,6 @@ inline double _d0_vt(double) { return 1.3806503e-23/1.602176462e-1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -3279,7 +2864,7 @@ inline double _d0_vt(double) { return 1.3806503e-23/1.602176462e-1 - + @@ -3361,11 +2946,6 @@ inline double _d0_vt(double) { return 1.3806503e-23/1.602176462e-1 - - - - - @@ -3490,6 +3070,23 @@ inline double _d0_vt(double) { return 1.3806503e-23/1.602176462e-1 + + + + + + + + + + + + + + + + + @@ -3559,7 +3156,7 @@ inline double _d0_vt(double) { return 1.3806503e-23/1.602176462e-1 - + @@ -3576,14 +3173,7 @@ inline double _d0_vt(double) { return 1.3806503e-23/1.602176462e-1 -#include <ngspice/ngspice.h> -#include <ngspice/cktdefs.h> -#include <ngspice/smpdefs.h> -#include "$(module)defs.h" -#include <ngspice/const.h> -#include <ngspice/sperror.h> -#include <ngspice/ifsim.h> -#include <ngspice/suffix.h> +#include "$(module)itf.h" //fixme!!! redundant #define max(x,y) (((x)>(y))?(x):(y)) @@ -3626,14 +3216,10 @@ BUILT_SOURCES = \\ $(module).hxx \\ $(module)acld.c \\ $(module)ask.c \\ - $(module)defs.h \\ + $(module)itf.h \\ $(module)del.c \\ $(module)dest.c \\ - $(module)ext.h \\ - $(module)guesstopology.c \\ $(module)init.c \\ - $(module)init.h \\ - $(module)itf.h \\ $(module)load.c \\ $(module)mask.c \\ $(module)mdel.c \\ @@ -3650,25 +3236,21 @@ lib$(module)_la_SOURCES = \\ CLEANFILES = \\ \$(BUILT_SOURCES) \\ .$(module).va.adms \\ - .adms.implicit.xml \\ .interface.xml \\ *.h \\ *.xml -#TODO (not implemented) \\ - $(module)conv.c \\ - $(module)getic.c - AM_CPPFLAGS = -I\$(top_srcdir)/src/include MAINTAINERCLEANFILES = Makefile.in %.c %.hxx \\ - %acld.c %ask.c %defs.h %del.c %dest.c %ext.h %guesstopology.c \\ - %init.c %init.h %itf.h %load.c %mask.c %mdel.c %mpar.c %par.c \\ + %acld.c %ask.c %itf.h %del.c %dest.c \\ + %init.c %load.c %mask.c %mdel.c %mpar.c %par.c \\ %pzld.c %setup.c %temp.c %trunc.c \\ -: \$(srcdir)/admsva/%.va \$(ADMSXMLINTERFACE)/ngspice.xml - admsXml -I\$(srcdir) -I\$(srcdir)/admsva -f \$< -e \$(ADMSXMLINTERFACE)/ngspice.xml +: \$(srcdir)/admsva/%.va \$(ADMSXMLINTERFACE)/premint.xml \$(ADMSXMLINTERFACE)/ngspice.xml + admsXml -I\$(srcdir) -I\$(srcdir)/admsva -f \$< -e \$(ADMSXMLINTERFACE)/premint.xml + admsXml -I\$(srcdir) -f mna.va -e \$(ADMSXMLINTERFACE)/ngspice.xml @@ -3683,45 +3265,19 @@ MAINTAINERCLEANFILES = Makefile.in - + - - + - - - + + + + -#ifndef DEV_$(module) -#define DEV_$(module) - -extern SPICEdev *get_$(module)_info(void); - -#endif - - - - - - - - - - - - -#include "config.h" - -#include <ngspice/devdefs.h> - - - -#include "$(module)itf.h" -#include "$(module)ext.h" -#include "$(module)init.h" +#include "$(module)itf.h" SPICEdev $(module)info = { { "$module", @@ -3793,57 +3349,40 @@ get_$(module)_info(void) } - + - - + - - - + + + -#ifndef _$(module)INIT_H -#define _$(module)INIT_H +#ifndef $(module) +#define $(module) -extern IFparm $(module)pTable[ ]; -extern IFparm $(module)mPTable[ ]; -extern char *$(module)names[ ]; -extern int $(module)pTSize; -extern int $(module)mPTSize; -extern int $(module)nSize; -extern int $(module)iSize; -extern int $(module)mSize; +#include <src/include/ngspice/ngspice.h> +#include <src/include/ngspice/devdefs.h> +#include <src/include/ngspice/sperror.h> + +#ifndef DEV_$(module) +#define DEV_$(module) + +extern SPICEdev *get_$(module)_info(void); #endif - - - - - - - - - - - - - #ifndef __$(module)EXT_H #define __$(module)EXT_H -#include "$(module)defs.h" - extern int $(module)par(int,IFvalue*,GENinstance*,IFvalue*); extern int $(module)mParam(int,IFvalue*,GENmodel*); extern int $(module)load(GENmodel*,CKTcircuit*); extern int $(module)setup(SMPmatrix*,GENmodel*,CKTcircuit*,int*); -extern int $(module)guesstopology(SMPmatrix *, CKTcircuit *, $(module)model *, $(module)instance *); extern int $(module)temp(GENmodel*,CKTcircuit*); extern int $(module)ask(CKTcircuit *,GENinstance*,int,IFvalue*,IFvalue*); extern int $(module)mAsk(CKTcircuit*,GENmodel *,int, IFvalue*); @@ -3860,27 +3399,19 @@ extern void $(module)destroy(GENmodel**); #endif - - - - - - - - - - - - +#ifndef _$(module)INIT_H +#define _$(module)INIT_H -#ifndef $(module) -#define $(module) +extern IFparm $(module)pTable[ ]; +extern IFparm $(module)mPTable[ ]; +extern char *$(module)names[ ]; +extern int $(module)pTSize; +extern int $(module)mPTSize; +extern int $(module)nSize; +extern int $(module)iSize; +extern int $(module)mSize; -#include <ngspice/cktdefs.h> -#include <ngspice/ifsim.h> -#include <ngspice/gendefs.h> -#include <ngspice/complex.h> -#include <ngspice/noisedef.h> +#endif @@ -3918,6 +3449,8 @@ extern void $(module)destroy(GENmodel**); #define NGSPICE_DEBUG #endif +#define myFREE(x) {if(x) { free(x); (x) = 0; }} + #define EXIT_IF_ISNAN(var) \\ if(isnan((double) var)) \\ { \\ @@ -4100,33 +3633,21 @@ typedef struct s$(module)model { /* model structure */ -#include "$(module)ext.h" - -#include "analogfunction.h" - - #endif /*$(module)*/ - - - + + - + - - + + -#include <ngspice/ngspice.h> -#include <ngspice/const.h> -#include <ngspice/cktdefs.h> -#include "$(module)defs.h" -#include <ngspice/ifsim.h> -#include <ngspice/sperror.h> -#include <ngspice/suffix.h> +#include "$(module)itf.h" int $(module)ask(CKTcircuit *ckt, GENinstance *inst, int which, IFvalue *value, IFvalue *select) { @@ -4160,24 +3681,16 @@ int $(module)ask(CKTcircuit *ckt, GENinstance *inst, int which, IFvalue *value, - - + - + -#include <ngspice/ngspice.h> -#include <ngspice/const.h> -#include <ngspice/ifsim.h> -#include <ngspice/cktdefs.h> -#include <ngspice/devdefs.h> -#include "$(module)defs.h" -#include <ngspice/sperror.h> -#include <ngspice/suffix.h> +#include "$(module)itf.h" int $(module)mAsk(CKTcircuit *ckt, GENmodel *inst, int which, IFvalue *value) { @@ -4208,22 +3721,16 @@ int $(module)mAsk(CKTcircuit *ckt, GENmodel *inst, int which, IFvalue *value) - - + - + -#include <ngspice/ngspice.h> -#include <ngspice/const.h> -#include <ngspice/ifsim.h> -#include "$(module)defs.h" -#include <ngspice/sperror.h> -#include <ngspice/suffix.h> +#include "$(module)itf.h" int $(module)par(int param, IFvalue *value, GENinstance *inst, IFvalue *select) { @@ -4257,22 +3764,16 @@ int $(module)par(int param, IFvalue *value, GENinstance *inst, IFvalue *select) - - + - + -#include <ngspice/ngspice.h> -#include <ngspice/const.h> -#include <ngspice/ifsim.h> -#include "$(module)defs.h" -#include <ngspice/sperror.h> -#include <ngspice/suffix.h> +#include "$(module)itf.h" int $(module)mParam(int param, IFvalue *value, GENmodel *inMod) { @@ -4304,26 +3805,85 @@ int $(module)mParam(int param, IFvalue *value, GENmodel *inMod) - - + - + #define NGSPICE_DEBUG_OK -#include <ngspice/ngspice.h> -#include <ngspice/cktdefs.h> -#include "$(module)defs.h" -#include <ngspice/const.h> -#include <ngspice/trandefs.h> -#include <ngspice/sperror.h> -#include <ngspice/devdefs.h> -#include <ngspice/suffix.h> +#include "$(module)itf.h" + +#define ccap qcap+1 +int my$(module)NIintegrate(CKTcircuit *ckt, double *geq, double *ceq, double cap, int qcap) +{ + static char *ordmsg = "Illegal integration order"; + static char *methodmsg = "Unknown integration method"; + char *errMsg; //fixme cest une globale dans ngspice!!!! + #define myTMALLOC(t,n) (t*) malloc(sizeof(t) * (size_t)(n)) + + switch(ckt->CKTintegrateMethod) { + + case TRAPEZOIDAL: + switch(ckt->CKTorder) { + case 1: + *(ckt->CKTstate0+ccap) = ckt->CKTag[0] * (*(ckt->CKTstate0+qcap)) + + ckt->CKTag[1] * (*(ckt->CKTstate1+qcap)); + break; + case 2: + *(ckt->CKTstate0+ccap) = - *(ckt->CKTstate1+ccap) * ckt->CKTag[1] + + ckt->CKTag[0] * + ( *(ckt->CKTstate0+qcap) - *(ckt->CKTstate1+qcap) ); + break; + default: + errMsg = myTMALLOC(char, strlen(ordmsg) + 1); + strcpy(errMsg,ordmsg); + return(E_ORDER); + } + break; + case GEAR: + *(ckt->CKTstate0+ccap)=0; + switch(ckt->CKTorder) { + + case 6: + *(ckt->CKTstate0+ccap) += ckt->CKTag[6]* *(ckt->CKTstate6+qcap); + /* fall through */ + case 5: + *(ckt->CKTstate0+ccap) += ckt->CKTag[5]* *(ckt->CKTstate5+qcap); + /* fall through */ + case 4: + *(ckt->CKTstate0+ccap) += ckt->CKTag[4]* *(ckt->CKTstate4+qcap); + /* fall through */ + case 3: + *(ckt->CKTstate0+ccap) += ckt->CKTag[3]* *(ckt->CKTstate3+qcap); + /* fall through */ + case 2: + *(ckt->CKTstate0+ccap) += ckt->CKTag[2]* *(ckt->CKTstate2+qcap); + /* fall through */ + case 1: + *(ckt->CKTstate0+ccap) += ckt->CKTag[1]* *(ckt->CKTstate1+qcap); + *(ckt->CKTstate0+ccap) += ckt->CKTag[0]* *(ckt->CKTstate0+qcap); + break; + + default: + return(E_ORDER); + + } + break; + + default: + errMsg = myTMALLOC(char, strlen(methodmsg) + 1); + strcpy(errMsg,methodmsg); + return(E_METHOD); + } + *ceq = *(ckt->CKTstate0+ccap) - ckt->CKTag[0] * *(ckt->CKTstate0+qcap); + *geq = ckt->CKTag[0] * cap; + return(OK); +} /*fixme: noise not implemented in ngspice*/ #define ngspice_flickernoise(p,n,mag,freq,info)\\ @@ -4333,9 +3893,9 @@ int $(module)mParam(int param, IFvalue *value, GENmodel *inMod) {\\ } -#define NP(p) *(ckt->CKTrhsOld+here->p ## Node) -#define BP(p,n) (NP(p)-NP(n)) -#define DBGNODE(p) printf(#p "=%i - v=%e\\n",here->p ## Node,NP(p)); +#define voltages(p) *(ckt->CKTrhsOld+here->p ## Node) +#define BP(p,n) (voltages(p)-voltages(n)) +#define DBGNODE(p) printf(#p "=%i - v=%e\\n",here->p ## Node,voltages(p)); @@ -4360,7 +3920,7 @@ int $(module)mParam(int param, IFvalue *value, GENmodel *inMod) (here->JSVAL_ ## Sp ## _ ## Pn)-=v;\\ (here->JSVAL_ ## Sn ## _ ## Pp)-=v; #define _load_static_jacobian2s(Sp,Sn,Pp,v)\\ - _load_static_residual2(Sp,Sn,-v*NP(Pp))\\ + _load_static_residual2(Sp,Sn,-v*voltages(Pp))\\ *(here->PTR_J_ ## Sp ## _ ## Pp)+=v;\\ *(here->PTR_J_ ## Sn ## _ ## Pp)-=v;\\ (here->JSVAL_ ## Sp ## _ ## Pp)+=v;\\ @@ -4372,7 +3932,7 @@ int $(module)mParam(int param, IFvalue *value, GENmodel *inMod) (here->JSVAL_ ## Sp ## _ ## Pp)+=v;\\ (here->JSVAL_ ## Sp ## _ ## Pn)-=v; #define _load_static_jacobian1(Sp,Pp,v)\\ - _load_static_residual1(Sp,-v*NP(Pp))\\ + _load_static_residual1(Sp,-v*voltages(Pp))\\ *(here->PTR_J_ ## Sp ## _ ## Pp)+=v;\\ (here->JSVAL_ ## Sp ## _ ## Pp)+=v; @@ -4384,7 +3944,7 @@ if(ChargeComputationNeeded)\\ *(ckt->CKTstate0+here->state_##p##_##n)=v;\\ if(ckt->CKTmode & MODEINITTRAN)\\ *(ckt->CKTstate1+here->state_##p##_##n)=*(ckt->CKTstate0+here->state_##p##_##n);\\ - error = NIintegrate(ckt,&unused,&unused,0.0,here->state_##p##_##n);\\ + error = my$(module)NIintegrate(ckt,&unused,&unused,0.0,here->state_##p##_##n);\\ if(error) return(error);\\ if(ckt->CKTmode & MODEINITTRAN)\\ *(ckt->CKTstate1+here->state_##p##_##n+1) = *(ckt->CKTstate0+here->state_##p##_##n+1);\\ @@ -4399,7 +3959,7 @@ if(ChargeComputationNeeded)\\ *(ckt->CKTstate0+here->state_##p##_GND)=v;\\ if(ckt->CKTmode & MODEINITTRAN)\\ *(ckt->CKTstate1+here->state_##p##_GND)=*(ckt->CKTstate0+here->state_##p##_GND);\\ - error = NIintegrate(ckt,&unused,&unused,0.0,here->state_##p##_GND);\\ + error = my$(module)NIintegrate(ckt,&unused,&unused,0.0,here->state_##p##_GND);\\ if(error) return(error);\\ if(ckt->CKTmode & MODEINITTRAN)\\ *(ckt->CKTstate1+here->state_##p##_GND+1) = *(ckt->CKTstate0+here->state_##p##_GND+1);\\ @@ -4426,7 +3986,7 @@ if(ChargeComputationNeeded)\\ if(ChargeComputationNeeded)\\ {\\ double geq=(v)*ckt->CKTag[0];\\ - double ceq=geq*NP(Pp);\\ + double ceq=geq*voltages(Pp);\\ *(ckt->CKTrhs+here->Sp##Node)+=ceq;\\ *(ckt->CKTrhs+here->Sn##Node)-=ceq;\\ *(here->PTR_J_ ## Sp ## _ ## Pp)+=geq;\\ @@ -4449,7 +4009,7 @@ if(ChargeComputationNeeded)\\ if(ChargeComputationNeeded)\\ {\\ double geq=(v)*ckt->CKTag[0];\\ - double ceq=geq*NP(Pp);\\ + double ceq=geq*voltages(Pp);\\ *(ckt->CKTrhs+here->Sp##Node)+=ceq;\\ *(here->PTR_J_ ## Sp ## _ ## Pp)+=geq;\\ }\\ @@ -4477,7 +4037,7 @@ int $(module)load(GENmodel *inModel, CKTcircuit *ckt) } { -#include "$module.hxx" +#include "$module.hxx" } } /* End of Instance */ } /* End of Model */ @@ -4490,7 +4050,7 @@ int $(module)load(GENmodel *inModel, CKTcircuit *ckt) - + @@ -4557,21 +4117,16 @@ int $(module)load(GENmodel *inModel, CKTcircuit *ckt) - - + - + -#include <ngspice/ngspice.h> -#include <ngspice/cktdefs.h> -#include "$(module)defs.h" -#include <ngspice/sperror.h> -#include <ngspice/suffix.h> +#include "$(module)itf.h" int $(module)acLoad(GENmodel *inModel, CKTcircuit *ckt) { @@ -4592,22 +4147,16 @@ int $(module)acLoad(GENmodel *inModel, CKTcircuit *ckt) - - + - + -#include <ngspice/ngspice.h> -#include <ngspice/cktdefs.h> -#include <ngspice/complex.h> -#include "$(module)defs.h" -#include <ngspice/sperror.h> -#include <ngspice/suffix.h> +#include "$(module)itf.h" int $(module)pzLoad(GENmodel *inModel, CKTcircuit *ckt, SPcomplex *s) { @@ -4630,21 +4179,84 @@ int $(module)pzLoad(GENmodel *inModel, CKTcircuit *ckt, SPcomplex *s) - - + - + -#include <ngspice/ngspice.h> -#include <ngspice/cktdefs.h> -#include "$(module)defs.h" -#include <ngspice/sperror.h> -#include <ngspice/suffix.h> +#include "$(module)itf.h" + +#define ccap (qcap+1) +static void my$(module)CKTterr(int qcap, CKTcircuit *ckt, double *timeStep) +{ + double volttol; + double chargetol; + double tol; + double del; + double diff[8]; + double deltmp[8]; + double factor=0; + int i; + int j; + static double gearCoeff[] = { + .5, + .2222222222, + .1363636364, + .096, + .07299270073, + .05830903790 + }; + static double trapCoeff[] = { + .5, + .08333333333 + }; + + volttol = ckt->CKTabstol + ckt->CKTreltol * + MAX( fabs(*(ckt->CKTstate0+ccap)), fabs(*(ckt->CKTstate1+ccap))); + + chargetol = MAX(fabs(*(ckt->CKTstate0 +qcap)),fabs(*(ckt->CKTstate1+qcap))); + chargetol = ckt->CKTreltol * MAX(chargetol,ckt->CKTchgtol)/ckt->CKTdelta; + tol = MAX(volttol,chargetol); + /* now divided differences */ + for(i=ckt->CKTorder+1;i>=0;i--) { + diff[i] = *(ckt->CKTstates[i] + qcap); + } + for(i=0 ; i <= ckt->CKTorder ; i++) { + deltmp[i] = ckt->CKTdeltaOld[i]; + } + j = ckt->CKTorder; + for (;;) { + for(i=0;i <= j;i++) { + diff[i] = (diff[i] - diff[i+1])/deltmp[i]; + } + if (--j < 0) break; + for(i=0;i <= j;i++) { + deltmp[i] = deltmp[i+1] + ckt->CKTdeltaOld[i]; + } + } + switch(ckt->CKTintegrateMethod) { + case GEAR: + factor = gearCoeff[ckt->CKTorder-1]; + break; + + case TRAPEZOIDAL: + factor = trapCoeff[ckt->CKTorder - 1] ; + break; + } + del = ckt->CKTtrtol * tol/MAX(ckt->CKTabstol,factor * fabs(diff[0])); + if(ckt->CKTorder == 2) { + del = sqrt(del); + } else if (ckt->CKTorder > 2) { + del = exp(log(del)/ckt->CKTorder); + } + *timeStep = MIN(*timeStep,del); + return; +} + int $(module)trunc(GENmodel *inModel, CKTcircuit *ckt, double *timeStep) { @@ -4665,7 +4277,7 @@ int $(module)trunc(GENmodel *inModel, CKTcircuit *ckt, double *timeStep) #endif /* STEPDEBUG */ - CKTterr(here->state_%(pnode/name)_%(nnode/name), ckt, timeStep); + my$(module)CKTterr(here->state_%(pnode/name)_%(nnode/name), ckt, timeStep); @@ -4684,24 +4296,17 @@ int $(module)trunc(GENmodel *inModel, CKTcircuit *ckt, double *timeStep) - - + - - - + + + + -#include <ngspice/ngspice.h> -#include <ngspice/cktdefs.h> -#include <ngspice/smpdefs.h> -#include "$(module)defs.h" -#include <ngspice/const.h> -#include <ngspice/sperror.h> -#include <ngspice/ifsim.h> -#include <ngspice/suffix.h> +#include "$(module)itf.h" //fixme!!! redundant #define max(x,y) (((x)>(y))?(x):(y)) @@ -4715,6 +4320,10 @@ int $(module)setup (SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int * { register $(module)model *model = ($(module)model*)inModel; register $(module)instance *here; +typedef int FP1(CKTcircuit *ckt, CKTnode **node, IFuid basename, char *suffix); +typedef double * FP2(SMPmatrix *Matrix, int Row, int Col); + FP1*myCKTmkVolt=(FP1*)get_$(module)_info()->DEVunsetup; + FP2*mySMPmakeElt=(FP2*)get_$(module)_info()->DEVfindBranch; /* loop through all the $(module) device models */ for ( ;model != NULL ;model = model->$(module)nextModel ) @@ -4757,11 +4366,9 @@ int $(module)setup (SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int * /* set Sparse Matrix Pointers */ - here->PTR_J_%(#row/name)_%(#column/name)_required=0; + here->PTR_J_%(#row/name)_%(#column/name)_required=1; - $(module)guesstopology(matrix,ckt,model,here); - /* Internal Nodes */ { int error; @@ -4773,7 +4380,7 @@ int $(module)setup (SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int * if(here->%(name)Node == -1) { - error=CKTmkVolt(ckt,&tmp,here->$(module)name,"$info"); + error=myCKTmkVolt(ckt,&tmp,here->$(module)name,"$info"); if(error) return(error); here->%(name)Node = tmp->number; } @@ -4782,7 +4389,7 @@ int $(module)setup (SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int * if(here->PTR_J_%(#row/name)_%(#column/name)_required==1) { - here->PTR_J_%(#row/name)_%(#column/name)=SMPmakeElt(matrix,here->%(#row/name)Node,here->%(#column/name)Node); + here->PTR_J_%(#row/name)_%(#column/name)=mySMPmakeElt(matrix,here->%(#row/name)Node,here->%(#column/name)Node); } @@ -4794,20 +4401,16 @@ int $(module)setup (SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int * - - + - + -#include <ngspice/ngspice.h> -#include "$(module)defs.h" -#include <ngspice/sperror.h> -#include <ngspice/suffix.h> +#include "$(module)itf.h" int $(module)delete(GENmodel *inModel, IFuid name, GENinstance **inInst) @@ -4823,7 +4426,7 @@ int $(module)delete(GENmodel *inModel, IFuid name, GENinstance **inInst) for (here = *prev; here ; here = *prev) { if(here->$(module)name == name || (fast && here==*fast) ) { *prev = here->$(module)nextInstance; - FREE(here); + myFREE(here); return(OK); } @@ -4835,20 +4438,16 @@ int $(module)delete(GENmodel *inModel, IFuid name, GENinstance **inInst) - - + - + -#include <ngspice/ngspice.h> -#include "$(module)defs.h" -#include <ngspice/sperror.h> -#include <ngspice/suffix.h> +#include "$(module)itf.h" int $(module)mDelete(GENmodel **inModel, IFuid modname, GENmodel *kill) @@ -4871,30 +4470,27 @@ int $(module)mDelete(GENmodel **inModel, IFuid modname, GENmodel *kill) delgot: *oldmod = (*model)->$(module)nextModel; /* cut deleted device out of list */ for (here = (*model)->$(module)instances; here; here = here->$(module)nextInstance) - { if(prev) FREE(prev); + { if(prev) myFREE(prev); prev = here; } - if(prev) FREE(prev); - FREE(*model); + if(prev) myFREE(prev); + myFREE(*model); return(OK); } - - + - + -#include <ngspice/ngspice.h> -#include "$(module)defs.h" -#include <ngspice/suffix.h> +#include "$(module)itf.h" void $(module)destroy(GENmodel **inModel) @@ -4906,16 +4502,16 @@ void $(module)destroy(GENmodel **inModel) $(module)model *oldmod = NULL; for ( ; mod ; mod = mod->$(module)nextModel ) { - if (oldmod) FREE(oldmod); + if (oldmod) myFREE(oldmod); oldmod = mod; prev = ($(module)instance *)NULL; for (here = mod->$(module)instances; here ; here = here->$(module)nextInstance) { - if(prev) FREE(prev); + if(prev) myFREE(prev); prev = here; } - if(prev) FREE(prev); + if(prev) myFREE(prev); } - if(oldmod) FREE(oldmod); + if(oldmod) myFREE(oldmod); *model = NULL; return; } @@ -4923,317 +4519,17 @@ void $(module)destroy(GENmodel **inModel) - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#include <ngspice/ngspice.h> -#include <ngspice/cktdefs.h> -#include <ngspice/smpdefs.h> -#include "$(module)defs.h" -#include <ngspice/const.h> -#include <ngspice/sperror.h> -#include <ngspice/ifsim.h> -#include <ngspice/suffix.h> - -#define jacobian(a,b) here->PTR_J_##a##_##b##_required=1; -#define static_jacobian4(p,q,r,s) jacobian(p,r) jacobian(p,s) jacobian(q,r) jacobian(q,s) -#define static_jacobian2s(p,q,r) jacobian(p,r) jacobian(q,r) -#define static_jacobian2p(p,r,s) jacobian(p,r) jacobian(p,s) -#define static_jacobian1(p,r) jacobian(p,r) -#define dynamic_jacobian4(p,q,r,s) jacobian(p,r) jacobian(p,s) jacobian(q,r) jacobian(q,s) -#define dynamic_jacobian2s(p,q,r) jacobian(p,r) jacobian(q,r) -#define dynamic_jacobian2p(p,r,s) jacobian(p,r) jacobian(p,s) -#define dynamic_jacobian1(p,r) jacobian(p,r) -#define whitenoise_jacobian4(p,q,r,s) -#define whitenoise_jacobian2s(p,q,r) -#define whitenoise_jacobian2p(p,r,s) -#define whitenoise_jacobian1(p) -#define flickernoise_jacobian4(p,q,r,s) -#define flickernoise_jacobian2s(p,q,r) -#define flickernoise_jacobian2p(p,r,s) -#define flickernoise_jacobian1(p) - - -int $(module)guesstopology (SMPmatrix *matrix, CKTcircuit *ckt, $(module)model *model, $(module)instance *here) - /* guess topology */ -{ - NG_IGNOREABLE(matrix); - NG_IGNOREABLE(ckt); - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int %(name);\n - double %(name)=0.0/0.0;\n - char* %(name);\n - - - - - return(OK); -} - - - - - - - - - - - - - - - - -#include <ngspice/ngspice.h> -#include <ngspice/devdefs.h> -#include "$(module)defs.h" -#include <ngspice/suffix.h> +#include "$(module)itf.h" @@ -5288,13 +4584,12 @@ int $(module)mSize = sizeof($(module)model); - - + - + /* arithmetics */ #define EXP90 1.220403294317841e+039 @@ -5338,7 +4633,7 @@ int $(module)mSize = sizeof($(module)model); #define m00_log10(v00,x) v00 = log10(x); #define m10_log10(v10,v00,x) v10 = (1.0/x/log(10)); #define m00_sqrt(v00,x) v00 = sqrt(x); -#define m10_sqrt(v10,v00,x) v10 = (0.5/v00); +#define m10_sqrt(v10,v00,x) v10 = (1.0/((v00>0)?(2.0*v00):1.0E+38)); #define m00_fabs(v00,x) v00 = fabs(x); #define m10_fabs(v10,v00,x) v10 = (((x)>=0)?(+1.0):(-1.0)); #define m00_exp(v00,x) v00 = exp(x); @@ -5359,7 +4654,6 @@ int $(module)mSize = sizeof($(module)model); #define pModel model #define pInst here #define mint_get_circuit_tempK() _circuit_temp -#define voltages(n) NP(n) #define _DDT(q) q #define _DDX #define _DERIVATEFORDDX @@ -5498,15 +4792,12 @@ inline double _d1_pow(double x,double y) { return (x==0.0)?0.0:((log(x)/exp(0. - + - + - - - @@ -5534,10 +4825,10 @@ inline double _d1_pow(double x,double y) { return (x==0.0)?0.0:((log(x)/exp(0. - + - + @@ -6136,7 +5427,7 @@ inline double _d1_pow(double x,double y) { return (x==0.0)?0.0:((log(x)/exp(0. - + @@ -6270,7 +5561,7 @@ inline double _d1_pow(double x,double y) { return (x==0.0)?0.0:((log(x)/exp(0. - + @@ -6338,7 +5629,7 @@ inline double _d1_pow(double x,double y) { return (x==0.0)?0.0:((log(x)/exp(0. - + @@ -6672,16 +5963,9 @@ inline double _d1_pow(double x,double y) { return (x==0.0)?0.0:((log(x)/exp(0. - - - - - - - - - - + + + @@ -6728,10 +6012,7 @@ inline double _d1_pow(double x,double y) { return (x==0.0)?0.0:((log(x)/exp(0. - - - - +