diff --git a/src/spicelib/analysis/cktterr.c b/src/spicelib/analysis/cktterr.c index 9852b2acf..66f56fea7 100644 --- a/src/spicelib/analysis/cktterr.c +++ b/src/spicelib/analysis/cktterr.c @@ -10,68 +10,77 @@ Author: 1985 Thomas L. Quarles void -CKTterr(int qcap, CKTcircuit *ckt, double *timeStep) +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[] = { + double volttol, chargetol, tol, del ; + double diff [8] ; + double deltmp [8] ; + double factor = 0 ; + int i, j ; + static double gearCoeff [] = { .5, .2222222222, .1363636364, .096, .07299270073, .05830903790 - }; - static double trapCoeff[] = { + } ; + 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) ; - 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 = ckt->CKTorder + 1 ; i >= 0 ; i--) + { + diff [i] = ckt->CKTstates[i] [qcap] ; } - for(i=0 ; i <= ckt->CKTorder ; i++) { - deltmp[i] = ckt->CKTdeltaOld[i]; + 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]; + 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]; + + if (--j < 0) + break ; + + for (i = 0 ; i <= j ; i++) + { + deltmp [i] = deltmp [i + 1] + ckt->CKTdeltaOld [i] ; } } - switch(ckt->CKTintegrateMethod) { + switch (ckt->CKTintegrateMethod) + { case GEAR: - factor = gearCoeff[ckt->CKTorder-1]; - break; + factor = gearCoeff [ckt->CKTorder - 1] ; + break ; case TRAPEZOIDAL: - factor = trapCoeff[ckt->CKTorder - 1] ; - break; + factor = trapCoeff [ckt->CKTorder - 1] ; + break ; } - del = ckt->CKTtrtol * tol/MAX(ckt->CKTabstol,factor * fabs(diff[0])); - if(ckt->CKTorder == 2) { - del = sqrt(del); + 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); + del = exp (log (del) / ckt->CKTorder) ; } - *timeStep = MIN(*timeStep,del); - return; + + *timeStep = MIN (*timeStep, del) ; + + return ; } diff --git a/src/spicelib/analysis/ckttrunc.c b/src/spicelib/analysis/ckttrunc.c index cbf57dcc5..a139dc363 100644 --- a/src/spicelib/analysis/ckttrunc.c +++ b/src/spicelib/analysis/ckttrunc.c @@ -17,43 +17,51 @@ Author: 1985 Thomas L. Quarles int -CKTtrunc(CKTcircuit *ckt, double *timeStep) +CKTtrunc (CKTcircuit *ckt, double *timeStep) { #ifndef NEWTRUNC - int i; - double timetemp; -#ifdef STEPDEBUG - double debugtemp; -#endif /* STEPDEBUG */ - double startTime; - int error = OK; + int i ; + double timetemp ; - startTime = SPfrontEnd->IFseconds(); - - timetemp = HUGE; - for (i=0;iDEVtrunc && ckt->CKThead[i]) { #ifdef STEPDEBUG - debugtemp = timetemp; + double debugtemp ; #endif /* STEPDEBUG */ - error = DEVices[i]->DEVtrunc (ckt->CKThead[i], ckt, &timetemp); - if(error) { - ckt->CKTstat->STATtranTruncTime += SPfrontEnd->IFseconds() - - startTime; - return(error); + + double startTime ; + int error = OK ; + + startTime = SPfrontEnd->IFseconds () ; + + timetemp = HUGE ; + for (i = 0 ; i < DEVmaxnum ; i++) + { + if (DEVices[i] && DEVices[i]->DEVtrunc && ckt->CKThead[i]) + { + +#ifdef STEPDEBUG + debugtemp = timetemp ; +#endif /* STEPDEBUG */ + + error = DEVices[i]->DEVtrunc (ckt->CKThead[i], ckt, &timetemp) ; + if (error) + { + ckt->CKTstat->STATtranTruncTime += SPfrontEnd->IFseconds () - startTime ; + return (error) ; } + #ifdef STEPDEBUG - if(debugtemp != timetemp) { - printf("timestep cut by device type %s from %g to %g\n", - DEVices[i]->DEVpublic.name, debugtemp, timetemp); + if (debugtemp != timetemp) + { + printf ("timestep cut by device type %s from %g to %g\n", DEVices[i]->DEVpublic.name, debugtemp, timetemp) ; } #endif /* STEPDEBUG */ + } } - *timeStep = MIN(2 * *timeStep,timetemp); + *timeStep = MIN (2 * *timeStep, timetemp) ; - ckt->CKTstat->STATtranTruncTime += SPfrontEnd->IFseconds() - startTime; - return(OK); + ckt->CKTstat->STATtranTruncTime += SPfrontEnd->IFseconds () - startTime ; + return (OK) ; #else /* NEWTRUNC */ int i; CKTnode *node; diff --git a/src/spicelib/devices/bsim4v7/b4v7trunc.c b/src/spicelib/devices/bsim4v7/b4v7trunc.c index 9aea00696..b30061b79 100644 --- a/src/spicelib/devices/bsim4v7/b4v7trunc.c +++ b/src/spicelib/devices/bsim4v7/b4v7trunc.c @@ -18,43 +18,44 @@ int -BSIM4v7trunc( -GENmodel *inModel, -CKTcircuit *ckt, -double *timeStep) +BSIM4v7trunc (GENmodel *inModel, CKTcircuit *ckt, double *timeStep) { -BSIM4v7model *model = (BSIM4v7model*)inModel; -BSIM4v7instance *here; + BSIM4v7model *model = (BSIM4v7model*)inModel; + BSIM4v7instance *here; #ifdef STEPDEBUG double debugtemp; -#endif /* STEPDEBUG */ +#endif + + for (; model; model = BSIM4v7nextModel(model)) + for (here = BSIM4v7instances(model); here; here = BSIM4v7nextInstance(here)) { - for (; model != NULL; model = BSIM4v7nextModel(model)) - { for (here = BSIM4v7instances(model); here != NULL; - here = BSIM4v7nextInstance(here)) - { #ifdef STEPDEBUG debugtemp = *timeStep; -#endif /* STEPDEBUG */ - CKTterr(here->BSIM4v7qb,ckt,timeStep); - CKTterr(here->BSIM4v7qg,ckt,timeStep); - CKTterr(here->BSIM4v7qd,ckt,timeStep); +#endif + + CKTterr(here->BSIM4v7qb, ckt, timeStep); + CKTterr(here->BSIM4v7qg, ckt, timeStep); + CKTterr(here->BSIM4v7qd, ckt, timeStep); + if (here->BSIM4v7trnqsMod) - CKTterr(here->BSIM4v7qcdump,ckt,timeStep); + CKTterr(here->BSIM4v7qcdump, ckt, timeStep); + if (here->BSIM4v7rbodyMod) - { CKTterr(here->BSIM4v7qbs,ckt,timeStep); - CKTterr(here->BSIM4v7qbd,ckt,timeStep); - } - if (here->BSIM4v7rgateMod == 3) - CKTterr(here->BSIM4v7qgmid,ckt,timeStep); -#ifdef STEPDEBUG - if(debugtemp != *timeStep) - { printf("device %s reduces step from %g to %g\n", - here->BSIM4v7name,debugtemp,*timeStep); + { + CKTterr(here->BSIM4v7qbs, ckt, timeStep); + CKTterr(here->BSIM4v7qbd, ckt, timeStep); } -#endif /* STEPDEBUG */ + + if (here->BSIM4v7rgateMod == 3) + CKTterr(here->BSIM4v7qgmid, ckt, timeStep); + +#ifdef STEPDEBUG + if (debugtemp != *timeStep) + printf("device %s reduces step from %g to %g\n", here->BSIM4v7name, debugtemp, *timeStep); +#endif + } - } - return(OK); + + return OK; } diff --git a/src/spicelib/devices/cap/captrunc.c b/src/spicelib/devices/cap/captrunc.c index b6903591a..9f7548ba2 100644 --- a/src/spicelib/devices/cap/captrunc.c +++ b/src/spicelib/devices/cap/captrunc.c @@ -14,17 +14,18 @@ Modified: September 2003 Paolo Nenzi int -CAPtrunc(GENmodel *inModel, CKTcircuit *ckt, double *timeStep) +CAPtrunc (GENmodel *inModel, CKTcircuit *ckt, double *timeStep) { - CAPmodel *model = (CAPmodel*)inModel; - CAPinstance *here; + CAPmodel *model = (CAPmodel*)inModel ; + CAPinstance *here ; - for( ; model!= NULL; model = CAPnextModel(model)) { - for(here = CAPinstances(model); here != NULL ; - here = CAPnextInstance(here)) { - - CKTterr(here->CAPqcap,ckt,timeStep); + for ( ; model != NULL ; model = CAPnextModel(model)) + { + for (here = CAPinstances(model); here != NULL ; here = CAPnextInstance(here)) + { + CKTterr (here->CAPqcap, ckt, timeStep) ; } } - return(OK); + + return (OK) ; } diff --git a/src/spicelib/devices/ind/indtrunc.c b/src/spicelib/devices/ind/indtrunc.c index 3d57c1f56..60df50eb1 100644 --- a/src/spicelib/devices/ind/indtrunc.c +++ b/src/spicelib/devices/ind/indtrunc.c @@ -13,16 +13,17 @@ Author: 1985 Thomas L. Quarles int -INDtrunc(GENmodel *inModel, CKTcircuit *ckt, double *timeStep) +INDtrunc (GENmodel *inModel, CKTcircuit *ckt, double *timeStep) { - INDmodel *model = (INDmodel*)inModel; - INDinstance *here; - for( ; model!= NULL; model = INDnextModel(model)) { - for(here = INDinstances(model); here != NULL ; - here = INDnextInstance(here)) { - - CKTterr(here->INDflux,ckt,timeStep); + INDmodel *model = (INDmodel*)inModel ; + INDinstance *here ; + for ( ; model!= NULL ; model = INDnextModel(model)) + { + for (here = INDinstances(model); here != NULL ; here = INDnextInstance(here)) + { + CKTterr (here->INDflux, ckt, timeStep) ; } } - return(OK); + + return (OK) ; }