diff --git a/src/spicelib/devices/asrc/asrc.c b/src/spicelib/devices/asrc/asrc.c index cc13634ff..1ccaeadb5 100644 --- a/src/spicelib/devices/asrc/asrc.c +++ b/src/spicelib/devices/asrc/asrc.c @@ -9,29 +9,32 @@ Author: 1987 Kanwar Jit Singh #include "asrcdefs.h" #include "ngspice/suffix.h" + /* Arbitrary source */ -IFparm ASRCpTable[] = { /* parameters */ - IP( "i", ASRC_CURRENT, IF_PARSETREE, "Current source"), - IP( "v", ASRC_VOLTAGE, IF_PARSETREE, "Voltage source"), - IOPZU( "temp", ASRC_TEMP, IF_REAL, "Instance operating temperature"), - IOPZ( "dtemp", ASRC_DTEMP, IF_REAL, - "Instance temperature difference with the rest of the circuit"), - IOPU( "tc1", ASRC_TC1, IF_REAL, "First order temp. coefficient"), - IOPU( "tc2", ASRC_TC2, IF_REAL, "Second order temp. coefficient"), - IOPU( "reciproctc", ASRC_RTC, IF_INTEGER, "Flag to calculate reciprocal temperature behaviour"), - OP( "i", ASRC_OUTPUTCURRENT, IF_REAL, "Current through source"), - OP( "v", ASRC_OUTPUTVOLTAGE, IF_REAL, "Voltage across source"), - OP( "pos_node", ASRC_POS_NODE, IF_INTEGER, "Positive Node"), - OP( "neg_node", ASRC_NEG_NODE, IF_INTEGER, "Negative Node") +IFparm ASRCpTable[] = { /* parameters */ + IP("i", ASRC_CURRENT, IF_PARSETREE, "Current source"), + IP("v", ASRC_VOLTAGE, IF_PARSETREE, "Voltage source"), + IOPZU("temp", ASRC_TEMP, IF_REAL, "Instance operating temperature"), + IOPZ("dtemp", ASRC_DTEMP, IF_REAL, + "Instance temperature difference with the rest of the circuit"), + IOPU("tc1", ASRC_TC1, IF_REAL, "First order temp. coefficient"), + IOPU("tc2", ASRC_TC2, IF_REAL, "Second order temp. coefficient"), + IOPU("reciproctc", ASRC_RTC, IF_INTEGER, "Flag to calculate reciprocal temperature behaviour"), + OP("i", ASRC_OUTPUTCURRENT, IF_REAL, "Current through source"), + OP("v", ASRC_OUTPUTVOLTAGE, IF_REAL, "Voltage across source"), + OP("pos_node", ASRC_POS_NODE, IF_INTEGER, "Positive Node"), + OP("neg_node", ASRC_NEG_NODE, IF_INTEGER, "Negative Node") }; + char *ASRCnames[] = { "src+", "src-" }; -int ASRCnSize = NUMELEMS(ASRCnames); -int ASRCpTSize = NUMELEMS(ASRCpTable); -int ASRCmPTSize = 0; -int ASRCiSize = sizeof(ASRCinstance); -int ASRCmSize = sizeof(ASRCmodel); + +int ASRCnSize = NUMELEMS(ASRCnames); +int ASRCpTSize = NUMELEMS(ASRCpTable); +int ASRCmPTSize = 0; +int ASRCiSize = sizeof(ASRCinstance); +int ASRCmSize = sizeof(ASRCmodel); diff --git a/src/spicelib/devices/asrc/asrcacld.c b/src/spicelib/devices/asrc/asrcacld.c index 653fe4349..fba568c08 100644 --- a/src/spicelib/devices/asrc/asrcacld.c +++ b/src/spicelib/devices/asrc/asrcacld.c @@ -17,7 +17,6 @@ Author: 1988 Kanwar Jit Singh int ASRCacLoad(GENmodel *inModel, CKTcircuit *ckt) { - /* * Actually load the current voltage value into the * sparse matrix previously provided. The values have @@ -34,63 +33,63 @@ ASRCacLoad(GENmodel *inModel, CKTcircuit *ckt) NG_IGNORE(ckt); /* loop through all the Arbitrary source models */ - for( ; model != NULL; model = model->ASRCnextModel ) { - + for (; model != NULL; model = model->ASRCnextModel) { /* loop through all the instances of the model */ - for (here = model->ASRCinstances; here != NULL ; - here = here->ASRCnextInstance) { + for (here = model->ASRCinstances; here != NULL; + here = here->ASRCnextInstance) { - difference = (here->ASRCtemp + here->ASRCdtemp) - 300.15; - factor = 1.0 + (here->ASRCtc1)*difference + - (here->ASRCtc2)*difference*difference; - if(here->ASRCreciproctc == 1) { - factor = 1/factor; - } + difference = (here->ASRCtemp + here->ASRCdtemp) - 300.15; + factor = 1.0 + (here->ASRCtc1) * difference + + (here->ASRCtc2) * difference * difference; - /* - * Get the function and its derivatives from the - * field in the instance structure. The field is - * an array of doubles holding the rhs, and the - * entries of the jacobian. - */ + if (here->ASRCreciproctc == 1) { + factor = 1 / factor; + } - j=0; - derivs = here->ASRCacValues; + /* + * Get the function and its derivatives from the + * field in the instance structure. The field is + * an array of doubles holding the rhs, and the + * entries of the jacobian. + */ - if( here->ASRCtype == ASRC_VOLTAGE) { + j = 0; + derivs = here->ASRCacValues; + + if (here->ASRCtype == ASRC_VOLTAGE) { *(here->ASRCposptr[j++]) += 1.0; *(here->ASRCposptr[j++]) -= 1.0; *(here->ASRCposptr[j++]) -= 1.0; *(here->ASRCposptr[j++]) += 1.0; } - for(i=0; i < here->ASRCtree->numVars; i++) { - switch(here->ASRCtree->varTypes[i]) { - case IF_INSTANCE: - if( here->ASRCtype == ASRC_VOLTAGE) { - /* CCVS */ - *(here->ASRCposptr[j++]) -= derivs[i] / factor; - } else{ - /* CCCS */ - *(here->ASRCposptr[j++]) += derivs[i] / factor; - *(here->ASRCposptr[j++]) -= derivs[i] / factor; - } - break; - case IF_NODE: - if(here->ASRCtype == ASRC_VOLTAGE) { - /* VCVS */ - *(here->ASRCposptr[j++]) -= derivs[i] / factor; - } else { - /* VCCS */ - *(here->ASRCposptr[j++]) += derivs[i] / factor; - *(here->ASRCposptr[j++]) -= derivs[i] / factor; - } - break; - default: - return(E_BADPARM); - } - } - } + for (i = 0; i < here->ASRCtree->numVars; i++) { + switch (here->ASRCtree->varTypes[i]) { + case IF_INSTANCE: + if (here->ASRCtype == ASRC_VOLTAGE) { + /* CCVS */ + *(here->ASRCposptr[j++]) -= derivs[i] / factor; + } else { + /* CCCS */ + *(here->ASRCposptr[j++]) += derivs[i] / factor; + *(here->ASRCposptr[j++]) -= derivs[i] / factor; + } + break; + case IF_NODE: + if (here->ASRCtype == ASRC_VOLTAGE) { + /* VCVS */ + *(here->ASRCposptr[j++]) -= derivs[i] / factor; + } else { + /* VCCS */ + *(here->ASRCposptr[j++]) += derivs[i] / factor; + *(here->ASRCposptr[j++]) -= derivs[i] / factor; + } + break; + default: + return(E_BADPARM); + } + } + } } return(OK); diff --git a/src/spicelib/devices/asrc/asrcask.c b/src/spicelib/devices/asrc/asrcask.c index 9283503a6..2d5a71e77 100644 --- a/src/spicelib/devices/asrc/asrcask.c +++ b/src/spicelib/devices/asrc/asrcask.c @@ -24,49 +24,49 @@ Author: 1987 Kanwar Jit Singh int ASRCask(CKTcircuit *ckt, GENinstance *instPtr, int which, IFvalue *value, IFvalue *select) { - ASRCinstance *here = (ASRCinstance*)instPtr; + ASRCinstance *here = (ASRCinstance*) instPtr; NG_IGNORE(select); switch(which) { - case ASRC_TEMP: - value->rValue = here->ASRCtemp - CONSTCtoK; - return(OK); - case ASRC_DTEMP: - value->rValue = here->ASRCdtemp; - return(OK); - case ASRC_TC1: - value->rValue = here->ASRCtc1; - return(OK); - case ASRC_TC2: - value->rValue = here->ASRCtc2; - return(OK); - case ASRC_CURRENT: - value->tValue = here->ASRCtype == ASRC_CURRENT ? - here->ASRCtree : NULL; - return (OK); - case ASRC_VOLTAGE: - value->tValue = here->ASRCtype == ASRC_VOLTAGE ? - here->ASRCtree : NULL; - return (OK); - case ASRC_POS_NODE: - value->iValue = here->ASRCposNode; - return (OK); - case ASRC_NEG_NODE: - value->iValue = here->ASRCnegNode; - return (OK); - case ASRC_OUTPUTCURRENT: - if( here->ASRCtype == ASRC_VOLTAGE) - value->rValue = ckt->CKTrhsOld[here->ASRCbranch]; - else - value->rValue = here->ASRCprev_value; - return (OK); - case ASRC_OUTPUTVOLTAGE: - value->rValue = ckt->CKTrhsOld[here->ASRCposNode] - - ckt->CKTrhsOld[here->ASRCnegNode]; - return(OK); - default: - return (E_BADPARM); + case ASRC_TEMP: + value->rValue = here->ASRCtemp - CONSTCtoK; + return(OK); + case ASRC_DTEMP: + value->rValue = here->ASRCdtemp; + return(OK); + case ASRC_TC1: + value->rValue = here->ASRCtc1; + return(OK); + case ASRC_TC2: + value->rValue = here->ASRCtc2; + return(OK); + case ASRC_CURRENT: + value->tValue = here->ASRCtype == ASRC_CURRENT ? + here->ASRCtree : NULL; + return(OK); + case ASRC_VOLTAGE: + value->tValue = here->ASRCtype == ASRC_VOLTAGE ? + here->ASRCtree : NULL; + return(OK); + case ASRC_POS_NODE: + value->iValue = here->ASRCposNode; + return(OK); + case ASRC_NEG_NODE: + value->iValue = here->ASRCnegNode; + return(OK); + case ASRC_OUTPUTCURRENT: + if (here->ASRCtype == ASRC_VOLTAGE) + value->rValue = ckt->CKTrhsOld[here->ASRCbranch]; + else + value->rValue = here->ASRCprev_value; + return(OK); + case ASRC_OUTPUTVOLTAGE: + value->rValue = ckt->CKTrhsOld[here->ASRCposNode] - + ckt->CKTrhsOld[here->ASRCnegNode]; + return(OK); + default: + return(E_BADPARM); } /* NOTREACHED */ } diff --git a/src/spicelib/devices/asrc/asrcconv.c b/src/spicelib/devices/asrc/asrcconv.c index bb1dd4b50..8354181af 100644 --- a/src/spicelib/devices/asrc/asrcconv.c +++ b/src/spicelib/devices/asrc/asrcconv.c @@ -9,10 +9,11 @@ Author: 1988 Kanwar Jit Singh #include "ngspice/sperror.h" #include "ngspice/suffix.h" + int ASRCconvTest(GENmodel *inModel, CKTcircuit *ckt) { - ASRCmodel *model = (ASRCmodel *)inModel; + ASRCmodel *model = (ASRCmodel *) inModel; ASRCinstance *here; int i, node_num, branch; double diff; @@ -20,51 +21,53 @@ ASRCconvTest(GENmodel *inModel, CKTcircuit *ckt) double tol; double rhs; - for( ; model != NULL; model = model->ASRCnextModel) { - for( here = model->ASRCinstances; here != NULL; - here = here->ASRCnextInstance) { + for (; model != NULL; model = model->ASRCnextModel) { + for (here = model->ASRCinstances; here != NULL; + here = here->ASRCnextInstance) { - i = here->ASRCtree->numVars; - if (asrc_nvals < i) { - if (asrc_nvals) { - FREE(asrc_vals); - FREE(asrc_derivs); - } - asrc_nvals = i; - asrc_vals = NEWN(double, i); - asrc_derivs = NEWN(double, i); - } + i = here->ASRCtree->numVars; + if (asrc_nvals < i) { + if (asrc_nvals) { + FREE(asrc_vals); + FREE(asrc_derivs); + } + asrc_nvals = i; + asrc_vals = NEWN(double, i); + asrc_derivs = NEWN(double, i); + } - for( i=0; i < here->ASRCtree->numVars; i++){ - if( here->ASRCtree->varTypes[i] == IF_INSTANCE){ - branch = CKTfndBranch(ckt,here->ASRCtree->vars[i].uValue); - asrc_vals[i] = *(ckt->CKTrhsOld+branch); + for (i = 0; i < here->ASRCtree->numVars; i++) { + if (here->ASRCtree->varTypes[i] == IF_INSTANCE) { + branch = CKTfndBranch(ckt, here->ASRCtree->vars[i].uValue); + asrc_vals[i] = *(ckt->CKTrhsOld + branch); } else { node_num = here->ASRCtree->vars[i].nValue->number; - asrc_vals[i] = *(ckt->CKTrhsOld+node_num); + asrc_vals[i] = *(ckt->CKTrhsOld + node_num); } } - if( here->ASRCtree->IFeval (here->ASRCtree, ckt->CKTgmin, &rhs, - asrc_vals,asrc_derivs) != OK) + if (here->ASRCtree->IFeval(here->ASRCtree, ckt->CKTgmin, &rhs, + asrc_vals, asrc_derivs) != OK) return(E_BADPARM); - prev = here->ASRCprev_value; - diff = fabs( prev - rhs); - if ( here->ASRCtype == ASRC_VOLTAGE){ - tol = ckt->CKTreltol * - MAX(fabs(rhs),fabs(prev)) + ckt->CKTvoltTol; - } else { - tol = ckt->CKTreltol * - MAX(fabs(rhs),fabs(prev)) + ckt->CKTabstol; - } + prev = here->ASRCprev_value; + diff = fabs(prev - rhs); - if ( diff > tol) { - ckt->CKTnoncon++; - ckt->CKTtroubleElt = (GENinstance *) here; - return(OK); - } + if (here->ASRCtype == ASRC_VOLTAGE) { + tol = ckt->CKTreltol * + MAX(fabs(rhs), fabs(prev)) + ckt->CKTvoltTol; + } else { + tol = ckt->CKTreltol * + MAX(fabs(rhs), fabs(prev)) + ckt->CKTabstol; + } + + if (diff > tol) { + ckt->CKTnoncon++; + ckt->CKTtroubleElt = (GENinstance *) here; + return(OK); + } } } + return(OK); } diff --git a/src/spicelib/devices/asrc/asrcdefs.h b/src/spicelib/devices/asrc/asrcdefs.h index b1aa80dcc..c4c617935 100644 --- a/src/spicelib/devices/asrc/asrcdefs.h +++ b/src/spicelib/devices/asrc/asrcdefs.h @@ -10,70 +10,77 @@ Author: 1985 Thomas L. Quarles #include "ngspice/ifsim.h" #include "ngspice/complex.h" + /* * structures to describe Arbitrary sources -*/ + */ /* information to describe a single instance */ typedef struct sASRCinstance { - struct sASRCmodel *ARRCmodPtr; /* backpointer to model */ - struct sASRCinstance *ASRCnextInstance; /* pointer to next instance of - * current model */ - IFuid ASRCname; /* pointer to character string naming this instance */ - int ASRCstates; /* state info */ - int ASRCposNode; /* number of positive node of source */ - int ASRCnegNode; /* number of negative node of source */ - int ASRCtype; /* Whether source is voltage or current */ - int ASRCbranch; /* number of branch equation added for v source */ - IFparseTree *ASRCtree; /* The parse tree */ - double ASRCtemp; /* temperature at which this resistor operates */ - double ASRCdtemp; /* delta-temperature of a particular instance */ - double ASRCtc1; /* first temperature coefficient of resistors */ - double ASRCtc2; /* second temperature coefficient of resistors */ - int ASRCreciproctc; /* Flag to calculate reciprocal temperature behaviour */ - double **ASRCposptr; /* pointer to pointers of the elements - * in the sparce matrix */ - double ASRCprev_value; /* Previous value for the convergence test */ - double *ASRCacValues; /* Store rhs and derivatives for ac anal */ - int ASRCcont_br; /* Temporary store for controlling current branch */ - unsigned ASRCtempGiven : 1; /* indicates temperature specified */ - unsigned ASRCdtempGiven : 1; /* indicates delta-temp specified */ - unsigned ASRCtc1Given : 1; /* indicates tc1 parameter specified */ - unsigned ASRCtc2Given : 1; /* indicates tc2 parameter specified */ - unsigned ASRCreciproctcGiven : 1; /* indicates reciproctc flag parameter specified */ -} ASRCinstance ; + struct sASRCmodel *ARRCmodPtr; /* backpointer to model */ + struct sASRCinstance *ASRCnextInstance; /* pointer to next instance of + * current model */ + IFuid ASRCname; /* pointer to character string naming this instance */ + int ASRCstates; /* state info */ + int ASRCposNode; /* number of positive node of source */ + int ASRCnegNode; /* number of negative node of source */ -#define ASRCvOld ASRCstates -#define ASRCcontVOld ASRCstates + 1 + int ASRCtype; /* Whether source is voltage or current */ + int ASRCbranch; /* number of branch equation added for v source */ + IFparseTree *ASRCtree; /* The parse tree */ + + double ASRCtemp; /* temperature at which this resistor operates */ + double ASRCdtemp; /* delta-temperature of a particular instance */ + double ASRCtc1; /* first temperature coefficient of resistors */ + double ASRCtc2; /* second temperature coefficient of resistors */ + int ASRCreciproctc; /* Flag to calculate reciprocal temperature behaviour */ + double **ASRCposptr; /* pointer to pointers of the elements + * in the sparce matrix */ + double ASRCprev_value; /* Previous value for the convergence test */ + double *ASRCacValues; /* Store rhs and derivatives for ac anal */ + int ASRCcont_br; /* Temporary store for controlling current branch */ + + unsigned ASRCtempGiven : 1; /* indicates temperature specified */ + unsigned ASRCdtempGiven : 1; /* indicates delta-temp specified */ + unsigned ASRCtc1Given : 1; /* indicates tc1 parameter specified */ + unsigned ASRCtc2Given : 1; /* indicates tc2 parameter specified */ + unsigned ASRCreciproctcGiven : 1; /* indicates reciproctc flag parameter specified */ + +} ASRCinstance; + + +#define ASRCvOld ASRCstates +#define ASRCcontVOld ASRCstates + 1 /* per model data */ typedef struct sASRCmodel { /* model structure for a source */ - int ASRCmodType; /* type index of this device */ - struct sASRCmodel *ASRCnextModel; /* pointer to next possible model - *in linked list */ - ASRCinstance * ASRCinstances; /* pointer to list of instances - * that have this model */ - IFuid ASRCmodName; /* pointer to character string naming this model */ + int ASRCmodType; /* type index of this device */ + struct sASRCmodel *ASRCnextModel; /* pointer to next possible model + * in linked list */ + ASRCinstance *ASRCinstances; /* pointer to list of instances + * that have this model */ + IFuid ASRCmodName; /* pointer to character string naming this model */ /* --- end of generic struct GENmodel --- */ } ASRCmodel; + /* device parameters */ -#define ASRC_VOLTAGE 1 -#define ASRC_CURRENT 2 -#define ASRC_POS_NODE 3 -#define ASRC_NEG_NODE 4 -#define ASRC_PARSE_TREE 5 -#define ASRC_OUTPUTVOLTAGE 6 -#define ASRC_OUTPUTCURRENT 7 -#define ASRC_TEMP 8 -#define ASRC_DTEMP 9 -#define ASRC_TC1 10 -#define ASRC_TC2 11 -#define ASRC_RTC 12 +#define ASRC_VOLTAGE 1 +#define ASRC_CURRENT 2 +#define ASRC_POS_NODE 3 +#define ASRC_NEG_NODE 4 +#define ASRC_PARSE_TREE 5 +#define ASRC_OUTPUTVOLTAGE 6 +#define ASRC_OUTPUTCURRENT 7 +#define ASRC_TEMP 8 +#define ASRC_DTEMP 9 +#define ASRC_TC1 10 +#define ASRC_TC2 11 +#define ASRC_RTC 12 /* module-wide variables */ @@ -87,4 +94,5 @@ extern int asrc_nvals; /* model questions */ #include "asrcext.h" + #endif /*ASRC*/ diff --git a/src/spicelib/devices/asrc/asrcdel.c b/src/spicelib/devices/asrc/asrcdel.c index 08be3e573..79e40bf2e 100644 --- a/src/spicelib/devices/asrc/asrcdel.c +++ b/src/spicelib/devices/asrc/asrcdel.c @@ -14,24 +14,24 @@ Author: 1987 Kanwar Jit Singh int ASRCdelete(GENmodel *model, IFuid name, GENinstance **fast) - { - ASRCinstance **instPtr = (ASRCinstance**)fast; - ASRCmodel *modPtr = (ASRCmodel*)model; + ASRCinstance **instPtr = (ASRCinstance**) fast; + ASRCmodel *modPtr = (ASRCmodel*) model; ASRCinstance **prev = NULL; ASRCinstance *here; - for( ; modPtr ; modPtr = modPtr->ASRCnextModel) { + for (; modPtr ; modPtr = modPtr->ASRCnextModel) { prev = &(modPtr->ASRCinstances); - for(here = *prev; here ; here = *prev) { - if(here->ASRCname == name || (instPtr && here==*instPtr) ) { - *prev= here->ASRCnextInstance; + for (here = *prev; here ; here = *prev) { + if (here->ASRCname == name || (instPtr && here == *instPtr)) { + *prev = here->ASRCnextInstance; FREE(here); return(OK); } prev = &(here->ASRCnextInstance); } } + return(E_NODEV); } diff --git a/src/spicelib/devices/asrc/asrcdest.c b/src/spicelib/devices/asrc/asrcdest.c index c90ca427b..623858a65 100644 --- a/src/spicelib/devices/asrc/asrcdest.c +++ b/src/spicelib/devices/asrc/asrcdest.c @@ -8,27 +8,28 @@ Author: 1987 Kanwar Jit Singh #include "ngspice/suffix.h" #include "ngspice/inpdefs.h" + void ASRCdestroy(GENmodel **model) - { - ASRCmodel **start = (ASRCmodel**)model; /* starting model */ + ASRCmodel **start = (ASRCmodel**) model; /* starting model */ ASRCinstance *here; /* current instance */ ASRCinstance *next; ASRCmodel *mod = *start; /* current model */ ASRCmodel *nextmod; - for( ; mod ; mod = nextmod) { - for(here = mod->ASRCinstances ; here ; here = next) { + for (; mod ; mod = nextmod) { + for (here = mod->ASRCinstances; here; here = next) { next = here->ASRCnextInstance; - FREE(here->ASRCacValues); - INPfreeTree(here->ASRCtree); - if(here->ASRCposptr) - free(here->ASRCposptr); + FREE(here->ASRCacValues); + INPfreeTree(here->ASRCtree); + if (here->ASRCposptr) + free(here->ASRCposptr); FREE(here); } nextmod = mod->ASRCnextModel; FREE(mod); } + *model = NULL; } diff --git a/src/spicelib/devices/asrc/asrcext.h b/src/spicelib/devices/asrc/asrcext.h index a0a23f636..14218c685 100644 --- a/src/spicelib/devices/asrc/asrcext.h +++ b/src/spicelib/devices/asrc/asrcext.h @@ -3,16 +3,16 @@ Copyright 1990 Regents of the University of California. All rights reserved. Author: 1985 Thomas L. Quarles **********/ -extern int ASRCask(CKTcircuit*,GENinstance *,int,IFvalue *,IFvalue*); -extern int ASRCconvTest(GENmodel *,CKTcircuit*); -extern int ASRCdelete(GENmodel *,IFuid,GENinstance **); -extern void ASRCdestroy(GENmodel**); -extern int ASRCfindBr(CKTcircuit *,GENmodel *,IFuid); -extern int ASRCload(GENmodel *,CKTcircuit*); -extern int ASRCmDelete(GENmodel**,IFuid,GENmodel*); -extern int ASRCparam(int,IFvalue*,GENinstance*,IFvalue*); -extern int ASRCpzLoad(GENmodel*,CKTcircuit*,SPcomplex*); -extern int ASRCacLoad(GENmodel*,CKTcircuit*); -extern int ASRCsetup(SMPmatrix*,GENmodel*,CKTcircuit*,int*); -extern int ASRCunsetup(GENmodel*,CKTcircuit*); -extern int ASRCtemp(GENmodel*,CKTcircuit*); +extern int ASRCask(CKTcircuit *, GENinstance *, int, IFvalue *, IFvalue*); +extern int ASRCconvTest(GENmodel *, CKTcircuit *); +extern int ASRCdelete(GENmodel *, IFuid, GENinstance **); +extern void ASRCdestroy(GENmodel **); +extern int ASRCfindBr(CKTcircuit *, GENmodel *, IFuid); +extern int ASRCload(GENmodel *, CKTcircuit *); +extern int ASRCmDelete(GENmodel **, IFuid, GENmodel *); +extern int ASRCparam(int, IFvalue *, GENinstance *, IFvalue *); +extern int ASRCpzLoad(GENmodel *, CKTcircuit *, SPcomplex *); +extern int ASRCacLoad(GENmodel *, CKTcircuit *); +extern int ASRCsetup(SMPmatrix *, GENmodel *, CKTcircuit *, int *); +extern int ASRCunsetup(GENmodel *, CKTcircuit *); +extern int ASRCtemp(GENmodel *, CKTcircuit *); diff --git a/src/spicelib/devices/asrc/asrcfbr.c b/src/spicelib/devices/asrc/asrcfbr.c index f451f45d4..0f98063ba 100644 --- a/src/spicelib/devices/asrc/asrcfbr.c +++ b/src/spicelib/devices/asrc/asrcfbr.c @@ -18,22 +18,23 @@ int ASRCfindBr(CKTcircuit *ckt, GENmodel *inputModel, IFuid name) { ASRCinstance *here; - ASRCmodel *model = (ASRCmodel*)inputModel; + ASRCmodel *model = (ASRCmodel*) inputModel; int error; CKTnode *tmp; - for( ; model != NULL; model = model->ASRCnextModel) { + for (; model != NULL; model = model->ASRCnextModel) { for (here = model->ASRCinstances; here != NULL; - here = here->ASRCnextInstance) { - if(here->ASRCname == name) { - if(here->ASRCbranch == 0) { - error = CKTmkCur(ckt,&tmp, here->ASRCname,"branch"); - if(error) return(error); + here = here->ASRCnextInstance) { + if (here->ASRCname == name) { + if (here->ASRCbranch == 0) { + error = CKTmkCur(ckt, &tmp, here->ASRCname, "branch"); + if (error) return(error); here->ASRCbranch = tmp->number; } return(here->ASRCbranch); } } } + return(0); } diff --git a/src/spicelib/devices/asrc/asrcinit.c b/src/spicelib/devices/asrc/asrcinit.c index b38c95e5e..61f379a89 100644 --- a/src/spicelib/devices/asrc/asrcinit.c +++ b/src/spicelib/devices/asrc/asrcinit.c @@ -9,19 +9,19 @@ SPICEdev ASRCinfo = { { - "ASRC", - "Arbitrary Source ", + "ASRC", + "Arbitrary Source ", - &ASRCnSize, - &ASRCnSize, - ASRCnames, + &ASRCnSize, + &ASRCnSize, + ASRCnames, - &ASRCpTSize, - ASRCpTable, + &ASRCpTSize, + ASRCpTable, + + 0, + NULL, - 0, - NULL, - #ifdef XSPICE /*---- Fixed by SDB 5.2.2003 to enable XSPICE/tclspice integration -----*/ NULL, /* This is a SPICE device, it has no MIF info data */ @@ -35,46 +35,46 @@ SPICEdev ASRCinfo = { 0, /* This is a SPICE device, it has no MIF info data */ NULL, /* This is a SPICE device, it has no MIF info data */ /*--------------------------- End of SDB fix -------------------------*/ -#endif +#endif - - DEV_DEFAULT + + DEV_DEFAULT }, - /* DEVparam */ ASRCparam, - /* DEVmodParam */ NULL, - /* DEVload */ ASRCload, - /* DEVsetup */ ASRCsetup, - /* DEVunsetup */ ASRCunsetup, - /* DEVpzSetup */ ASRCsetup, - /* DEVtemperature*/ ASRCtemp, - /* DEVtrunc */ NULL, - /* DEVfindBranch */ ASRCfindBr, - /* DEVacLoad */ ASRCacLoad, /* ac and normal load functions NOT identical */ - /* DEVaccept */ NULL, - /* DEVdestroy */ ASRCdestroy, - /* DEVmodDelete */ ASRCmDelete, - /* DEVdelete */ ASRCdelete, - /* DEVsetic */ NULL, - /* DEVask */ ASRCask, - /* DEVmodAsk */ NULL, - /* DEVpzLoad */ ASRCpzLoad, - /* DEVconvTest */ ASRCconvTest, - /* DEVsenSetup */ NULL, - /* DEVsenLoad */ NULL, - /* DEVsenUpdate */ NULL, - /* DEVsenAcLoad */ NULL, - /* DEVsenPrint */ NULL, - /* DEVsenTrunc */ NULL, - /* DEVdisto */ NULL, /* DISTO */ - /* DEVnoise */ NULL, /* NOISE */ - /* DEVsoaCheck */ NULL, + /* DEVparam */ ASRCparam, + /* DEVmodParam */ NULL, + /* DEVload */ ASRCload, + /* DEVsetup */ ASRCsetup, + /* DEVunsetup */ ASRCunsetup, + /* DEVpzSetup */ ASRCsetup, + /* DEVtemperature*/ ASRCtemp, + /* DEVtrunc */ NULL, + /* DEVfindBranch */ ASRCfindBr, + /* DEVacLoad */ ASRCacLoad, /* ac and normal load functions NOT identical */ + /* DEVaccept */ NULL, + /* DEVdestroy */ ASRCdestroy, + /* DEVmodDelete */ ASRCmDelete, + /* DEVdelete */ ASRCdelete, + /* DEVsetic */ NULL, + /* DEVask */ ASRCask, + /* DEVmodAsk */ NULL, + /* DEVpzLoad */ ASRCpzLoad, + /* DEVconvTest */ ASRCconvTest, + /* DEVsenSetup */ NULL, + /* DEVsenLoad */ NULL, + /* DEVsenUpdate */ NULL, + /* DEVsenAcLoad */ NULL, + /* DEVsenPrint */ NULL, + /* DEVsenTrunc */ NULL, + /* DEVdisto */ NULL, /* DISTO */ + /* DEVnoise */ NULL, /* NOISE */ + /* DEVsoaCheck */ NULL, #ifdef CIDER - /* DEVdump */ NULL, - /* DEVacct */ NULL, -#endif - /* DEVinstSize */ &ASRCiSize, - /* DEVmodSize */ &ASRCmSize + /* DEVdump */ NULL, + /* DEVacct */ NULL, +#endif + /* DEVinstSize */ &ASRCiSize, + /* DEVmodSize */ &ASRCmSize }; diff --git a/src/spicelib/devices/asrc/asrcinit.h b/src/spicelib/devices/asrc/asrcinit.h index ec57e40a5..6e5ea2dab 100644 --- a/src/spicelib/devices/asrc/asrcinit.h +++ b/src/spicelib/devices/asrc/asrcinit.h @@ -1,8 +1,8 @@ #ifndef _ASRCINIT_H #define _ASRCINIT_H -extern IFparm ASRCpTable[ ]; -extern char *ASRCnames[ ]; +extern IFparm ASRCpTable[]; +extern char *ASRCnames[]; extern int ASRCpTSize; extern int ASRCnSize; extern int ASRCiSize; diff --git a/src/spicelib/devices/asrc/asrcitf.h b/src/spicelib/devices/asrc/asrcitf.h index 0f5b12436..ffdef35a5 100644 --- a/src/spicelib/devices/asrc/asrcitf.h +++ b/src/spicelib/devices/asrc/asrcitf.h @@ -1,6 +1,7 @@ /********** Copyright 1990 Regents of the University of California. All rights reserved. **********/ + #ifndef DEV_ASRC #define DEV_ASRC diff --git a/src/spicelib/devices/asrc/asrcload.c b/src/spicelib/devices/asrc/asrcload.c index 9fae882ca..d9db05c17 100644 --- a/src/spicelib/devices/asrc/asrcload.c +++ b/src/spicelib/devices/asrc/asrcload.c @@ -12,14 +12,15 @@ Author: 1987 Kanwar Jit Singh #include "ngspice/sperror.h" #include "ngspice/suffix.h" + double *asrc_vals, *asrc_derivs; int asrc_nvals; + /*ARGSUSED*/ int ASRCload(GENmodel *inModel, CKTcircuit *ckt) { - /* actually load the current voltage value into the * sparse matrix previously provided */ @@ -32,16 +33,17 @@ ASRCload(GENmodel *inModel, CKTcircuit *ckt) double factor; /* loop through all the Arbitrary source models */ - for( ; model != NULL; model = model->ASRCnextModel ) { - + for (; model != NULL; model = model->ASRCnextModel) { /* loop through all the instances of the model */ - for (here = model->ASRCinstances; here != NULL ; + for (here = model->ASRCinstances; here != NULL; here=here->ASRCnextInstance) { + difference = (here->ASRCtemp + here->ASRCdtemp) - 300.15; - factor = 1.0 + (here->ASRCtc1)*difference + (here->ASRCtc2)*difference*difference; - if(here->ASRCreciproctc == 1) { - factor = 1/factor; + factor = 1.0 + (here->ASRCtc1) * difference + (here->ASRCtc2) * difference * difference; + + if (here->ASRCreciproctc == 1) { + factor = 1 / factor; } /* @@ -58,13 +60,13 @@ ASRCload(GENmodel *inModel, CKTcircuit *ckt) asrc_derivs = NEWN(double, i); } - j=0; + j = 0; /* * Fill the vector of values from the previous solution */ - for( i=0; i < here->ASRCtree->numVars; i++) - if( here->ASRCtree->varTypes[i] == IF_INSTANCE) { + for (i = 0; i < here->ASRCtree->numVars; i++) + if (here->ASRCtree->varTypes[i] == IF_INSTANCE) { int branch = CKTfndBranch(ckt, here->ASRCtree->vars[i].uValue); asrc_vals[i] = *(ckt->CKTrhsOld + branch); } else { @@ -72,65 +74,62 @@ ASRCload(GENmodel *inModel, CKTcircuit *ckt) asrc_vals[i] = *(ckt->CKTrhsOld + node_num); } - if (here->ASRCtree->IFeval (here->ASRCtree, ckt->CKTgmin, &rhs, asrc_vals, asrc_derivs) != OK) + if (here->ASRCtree->IFeval(here->ASRCtree, ckt->CKTgmin, &rhs, asrc_vals, asrc_derivs) != OK) return(E_BADPARM); /* The convergence test */ here->ASRCprev_value = rhs; /* The ac load precomputation and storage */ - if (ckt->CKTmode & MODEINITSMSIG) { - int size = (here->ASRCtree->numVars) + 1 ; + int size = (here->ASRCtree->numVars) + 1; here->ASRCacValues = NEWN(double, size); - for ( i = 0; i < here->ASRCtree->numVars; i++) + for (i = 0; i < here->ASRCtree->numVars; i++) here->ASRCacValues[i] = asrc_derivs[i]; } - if( here->ASRCtype == ASRC_VOLTAGE) { + if (here->ASRCtype == ASRC_VOLTAGE) { *(here->ASRCposptr[j++]) += 1.0; *(here->ASRCposptr[j++]) -= 1.0; *(here->ASRCposptr[j++]) -= 1.0; *(here->ASRCposptr[j++]) += 1.0; } - for(i=0; i < here->ASRCtree->numVars; i++) { + for (i = 0; i < here->ASRCtree->numVars; i++) { rhs -= (asrc_vals[i] * asrc_derivs[i]); - switch(here->ASRCtree->varTypes[i]) { - case IF_INSTANCE: - if( here->ASRCtype == ASRC_VOLTAGE) { - /* CCVS */ - *(here->ASRCposptr[j++]) -= asrc_derivs[i] * factor; - } else{ - /* CCCS */ - *(here->ASRCposptr[j++]) += asrc_derivs[i] * factor; - *(here->ASRCposptr[j++]) -= asrc_derivs[i] * factor; - } - break; - - case IF_NODE: - if(here->ASRCtype == ASRC_VOLTAGE) { - /* VCVS */ - *(here->ASRCposptr[j++]) -= asrc_derivs[i] * factor; - } else { - /* VCCS */ - *(here->ASRCposptr[j++]) += asrc_derivs[i] * factor; - *(here->ASRCposptr[j++]) -= asrc_derivs[i] * factor; - } - break; - - default: - return(E_BADPARM); + switch (here->ASRCtree->varTypes[i]) { + case IF_INSTANCE: + if (here->ASRCtype == ASRC_VOLTAGE) { + /* CCVS */ + *(here->ASRCposptr[j++]) -= asrc_derivs[i] * factor; + } else { + /* CCCS */ + *(here->ASRCposptr[j++]) += asrc_derivs[i] * factor; + *(here->ASRCposptr[j++]) -= asrc_derivs[i] * factor; + } + break; + case IF_NODE: + if (here->ASRCtype == ASRC_VOLTAGE) { + /* VCVS */ + *(here->ASRCposptr[j++]) -= asrc_derivs[i] * factor; + } else { + /* VCCS */ + *(here->ASRCposptr[j++]) += asrc_derivs[i] * factor; + *(here->ASRCposptr[j++]) -= asrc_derivs[i] * factor; + } + break; + default: + return(E_BADPARM); } } /* Insert the RHS */ - if( here->ASRCtype == ASRC_VOLTAGE) { - *(ckt->CKTrhs+(here->ASRCbranch)) += factor * rhs; + if (here->ASRCtype == ASRC_VOLTAGE) { + *(ckt->CKTrhs + (here->ASRCbranch)) += factor * rhs; } else { - *(ckt->CKTrhs+(here->ASRCposNode)) -= factor * rhs; - *(ckt->CKTrhs+(here->ASRCnegNode)) += factor * rhs; + *(ckt->CKTrhs + (here->ASRCposNode)) -= factor * rhs; + *(ckt->CKTrhs + (here->ASRCnegNode)) += factor * rhs; } /* Store the rhs for small signal analysis */ diff --git a/src/spicelib/devices/asrc/asrcmdel.c b/src/spicelib/devices/asrc/asrcmdel.c index 2ee344894..e154c8880 100644 --- a/src/spicelib/devices/asrc/asrcmdel.c +++ b/src/spicelib/devices/asrc/asrcmdel.c @@ -15,29 +15,32 @@ Author: 1987 Kanwar Jit Singh int ASRCmDelete(GENmodel **modList, IFuid modname, GENmodel *killModel) { - - ASRCmodel **model = (ASRCmodel**)modList; - ASRCmodel *modfast = (ASRCmodel*)killModel; + ASRCmodel **model = (ASRCmodel**) modList; + ASRCmodel *modfast = (ASRCmodel*) killModel; ASRCinstance *here; ASRCinstance *prev = NULL; ASRCmodel **oldmod; + oldmod = model; - for( ; *model ; model = &((*model)->ASRCnextModel)) { - if( (*model)->ASRCmodName == modname || - (modfast && *model == modfast) ) goto delgot; + for (; *model; model = &((*model)->ASRCnextModel)) { + if ((*model)->ASRCmodName == modname || + (modfast && *model == modfast)) goto delgot; oldmod = model; } + return(E_NOMOD); -delgot: + delgot: + *oldmod = (*model)->ASRCnextModel; /* cut deleted device out of list */ - for(here = (*model)->ASRCinstances ; here ; here = here->ASRCnextInstance) { - FREE(here->ASRCacValues); - if(prev) FREE(prev); + + for (here = (*model)->ASRCinstances; here; here = here->ASRCnextInstance) { + FREE(here->ASRCacValues); + if (prev) FREE(prev); prev = here; } - if(prev) FREE(prev); + + if (prev) FREE(prev); FREE(*model); return(OK); - } diff --git a/src/spicelib/devices/asrc/asrcpar.c b/src/spicelib/devices/asrc/asrcpar.c index 3ac664ecb..292f0a399 100644 --- a/src/spicelib/devices/asrc/asrcpar.c +++ b/src/spicelib/devices/asrc/asrcpar.c @@ -17,33 +17,34 @@ Author: 1987 Kanwar Jit Singh int ASRCparam(int param, IFvalue *value, GENinstance *fast, IFvalue *select) { - ASRCinstance *here = (ASRCinstance*)fast; + ASRCinstance *here = (ASRCinstance*) fast; NG_IGNORE(select); - switch(param) { - case ASRC_VOLTAGE: - here->ASRCtype = ASRC_VOLTAGE; - here->ASRCtree = value->tValue; - break; - case ASRC_CURRENT: - here->ASRCtype = ASRC_CURRENT; - here->ASRCtree = value->tValue; - break; - case ASRC_TC1: - here->ASRCtc1 = value->rValue; - here->ASRCtc1Given = TRUE; - break; - case ASRC_TC2: - here->ASRCtc2 = value->rValue; - here->ASRCtc2Given = TRUE; - break; - case ASRC_RTC: - here->ASRCreciproctc = value->iValue; - here->ASRCreciproctcGiven = TRUE; - break; - default: - return(E_BADPARM); + switch (param) { + case ASRC_VOLTAGE: + here->ASRCtype = ASRC_VOLTAGE; + here->ASRCtree = value->tValue; + break; + case ASRC_CURRENT: + here->ASRCtype = ASRC_CURRENT; + here->ASRCtree = value->tValue; + break; + case ASRC_TC1: + here->ASRCtc1 = value->rValue; + here->ASRCtc1Given = TRUE; + break; + case ASRC_TC2: + here->ASRCtc2 = value->rValue; + here->ASRCtc2Given = TRUE; + break; + case ASRC_RTC: + here->ASRCreciproctc = value->iValue; + here->ASRCreciproctcGiven = TRUE; + break; + default: + return(E_BADPARM); } + return(OK); } diff --git a/src/spicelib/devices/asrc/asrcpzld.c b/src/spicelib/devices/asrc/asrcpzld.c index 695979f1e..28d7d96d2 100644 --- a/src/spicelib/devices/asrc/asrcpzld.c +++ b/src/spicelib/devices/asrc/asrcpzld.c @@ -10,13 +10,13 @@ Author: 1987 Kanwar Jit Singh #include "ngspice/suffix.h" #include "ngspice/complex.h" + /*ARGSUSED*/ int ASRCpzLoad(GENmodel *inModel, CKTcircuit *ckt, SPcomplex *s) - - /* actually load the current voltage value into the - * sparse matrix previously provided - */ +/* actually load the current voltage value into the + * sparse matrix previously provided + */ { ASRCmodel *model = (ASRCmodel*) inModel; ASRCinstance *here; @@ -28,18 +28,19 @@ ASRCpzLoad(GENmodel *inModel, CKTcircuit *ckt, SPcomplex *s) NG_IGNORE(s); /* loop through all the Arbitrary source models */ - for( ; model != NULL; model = model->ASRCnextModel ) { - + for (; model != NULL; model = model->ASRCnextModel) { /* loop through all the instances of the model */ - for (here = model->ASRCinstances; here != NULL ; - here=here->ASRCnextInstance) + for (here = model->ASRCinstances; here != NULL; + here = here->ASRCnextInstance) { - difference = (here->ASRCtemp + here->ASRCdtemp) - 300.15; - factor = 1.0 + (here->ASRCtc1)*difference + - (here->ASRCtc2)*difference*difference; - if(here->ASRCreciproctc == 1) { - factor = 1/factor; - } + + difference = (here->ASRCtemp + here->ASRCdtemp) - 300.15; + factor = 1.0 + (here->ASRCtc1) * difference + + (here->ASRCtc2) * difference * difference; + + if (here->ASRCreciproctc == 1) { + factor = 1 / factor; + } j = 0; @@ -56,30 +57,30 @@ ASRCpzLoad(GENmodel *inModel, CKTcircuit *ckt, SPcomplex *s) } /* Fill the vector of values from the previous solution */ - for( i=0; i < here->ASRCtree->numVars; i++) { - if( here->ASRCtree->varTypes[i] == IF_INSTANCE) { - int branch = CKTfndBranch(ckt,here->ASRCtree->vars[i].uValue); - asrc_vals[i] = *(ckt->CKTrhsOld + branch); + for (i = 0; i < here->ASRCtree->numVars; i++) { + if (here->ASRCtree->varTypes[i] == IF_INSTANCE) { + int branch = CKTfndBranch(ckt, here->ASRCtree->vars[i].uValue); + asrc_vals[i] = *(ckt->CKTrhsOld + branch); } else { int node_num = (here->ASRCtree->vars[i].nValue) -> number; asrc_vals[i] = *(ckt->CKTrhsOld + node_num); } } - if(here->ASRCtree->IFeval (here->ASRCtree, ckt->CKTgmin, &value, asrc_vals, asrc_derivs) != OK) + if (here->ASRCtree->IFeval(here->ASRCtree, ckt->CKTgmin, &value, asrc_vals, asrc_derivs) != OK) return(E_BADPARM); - if( here->ASRCtype == ASRC_VOLTAGE) { + if (here->ASRCtype == ASRC_VOLTAGE) { *(here->ASRCposptr[j++]) += 1.0; *(here->ASRCposptr[j++]) -= 1.0; *(here->ASRCposptr[j++]) -= 1.0; *(here->ASRCposptr[j++]) += 1.0; } - for(i=0; i < here->ASRCtree->numVars; i++) { - switch(here->ASRCtree->varTypes[i]) { + for (i = 0; i < here->ASRCtree->numVars; i++) { + switch (here->ASRCtree->varTypes[i]) { case IF_INSTANCE: - if( here->ASRCtype == ASRC_VOLTAGE) { + if (here->ASRCtype == ASRC_VOLTAGE) { /* CCVS */ *(here->ASRCposptr[j++]) -= asrc_derivs[i] / factor; } else { @@ -89,7 +90,7 @@ ASRCpzLoad(GENmodel *inModel, CKTcircuit *ckt, SPcomplex *s) } break; case IF_NODE: - if(here->ASRCtype == ASRC_VOLTAGE) { + if (here->ASRCtype == ASRC_VOLTAGE) { /* VCVS */ *(here->ASRCposptr[j++]) -= asrc_derivs[i] / factor; } else { diff --git a/src/spicelib/devices/asrc/asrcset.c b/src/spicelib/devices/asrc/asrcset.c index de90f7faf..4af923daa 100644 --- a/src/spicelib/devices/asrc/asrcset.c +++ b/src/spicelib/devices/asrc/asrcset.c @@ -16,13 +16,12 @@ Author: 1987 Kanwar Jit Singh /*ARGSUSED*/ int ASRCsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states) - /* load the voltage source structure with those - * pointers needed later for fast matrix loading - */ - +/* load the voltage source structure with those + * pointers needed later for fast matrix loading + */ { ASRCinstance *here; - ASRCmodel *model = (ASRCmodel*)inModel; + ASRCmodel *model = (ASRCmodel*) inModel; int error, i, j; int v_first; CKTnode *tmp; @@ -30,103 +29,103 @@ ASRCsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states) NG_IGNORE(states); /* loop through all the user models*/ - for( ; model != NULL; model = model->ASRCnextModel ) { - + for (; model != NULL; model = model->ASRCnextModel) { /* loop through all the instances of the model */ - for (here = model->ASRCinstances; here != NULL ; - here=here->ASRCnextInstance) { - - if(!here->ASRCtc1Given) here->ASRCtc1 = 0.0; - if(!here->ASRCtc2Given) here->ASRCtc2 = 0.0; - if(!here->ASRCreciproctcGiven) here->ASRCreciproctc = 0; + for (here = model->ASRCinstances; here != NULL; + here=here->ASRCnextInstance) { + + if (!here->ASRCtc1Given) here->ASRCtc1 = 0.0; + if (!here->ASRCtc2Given) here->ASRCtc2 = 0.0; + if (!here->ASRCreciproctcGiven) here->ASRCreciproctc = 0; here->ASRCposptr = NULL; - j=0; /*strchr of the array holding ptrs to SMP */ + j = 0; /* strchr of the array holding ptrs to SMP */ v_first = 1; - if( here->ASRCtype == ASRC_VOLTAGE){ - if(here->ASRCbranch==0) { - error = CKTmkCur(ckt,&tmp,here->ASRCname,"branch"); - if(error) return(error); + + if (here->ASRCtype == ASRC_VOLTAGE) { + if (here->ASRCbranch == 0) { + error = CKTmkCur(ckt, &tmp, here->ASRCname, "branch"); + if (error) return(error); here->ASRCbranch = tmp->number; } } - /* 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) +#define TSTALLOC(ptr, first, second) \ + do { if ((here->ptr = SMPmakeElt(matrix, here->first, here->second)) == NULL) { \ + return(E_NOMEM); \ + } } while(0) -#define MY_TSTALLOC(ptr,first,second) \ -do { if((here->ptr = SMPmakeElt(matrix, here->first, (second)->number)) == NULL){\ - return(E_NOMEM);\ -} } while(0) +#define MY_TSTALLOC(ptr, first, second) \ + do { if ((here->ptr = SMPmakeElt(matrix, here->first, (second)->number)) == NULL) { \ + return(E_NOMEM); \ + } } while(0) /* For each controlling variable set the entries - in the vector of the positions of the SMP */ + in the vector of the positions of the SMP */ if (!here->ASRCtree) - return E_PARMVAL; + return E_PARMVAL; - if( here->ASRCtype == ASRC_VOLTAGE) { + if (here->ASRCtype == ASRC_VOLTAGE) { - if(here->ASRCposNode == here->ASRCnegNode) { - SPfrontEnd->IFerrorf (ERR_FATAL, - "instance %s is a shorted ASRC", here->ASRCname); + if (here->ASRCposNode == here->ASRCnegNode) { + SPfrontEnd->IFerrorf(ERR_FATAL, + "instance %s is a shorted ASRC", here->ASRCname); return(E_UNSUPP); } - here->ASRCposptr = TREALLOC(double *, here->ASRCposptr, j + 5); - TSTALLOC(ASRCposptr[j++],ASRCposNode,ASRCbranch); - TSTALLOC(ASRCposptr[j++],ASRCnegNode,ASRCbranch); - TSTALLOC(ASRCposptr[j++],ASRCbranch,ASRCnegNode); - TSTALLOC(ASRCposptr[j++],ASRCbranch,ASRCposNode); - } - - for( i=0; i < here->ASRCtree->numVars; i++){ - switch(here->ASRCtree->varTypes[i]){ + here->ASRCposptr = TREALLOC(double *, here->ASRCposptr, j + 5); + + TSTALLOC(ASRCposptr[j++], ASRCposNode, ASRCbranch); + TSTALLOC(ASRCposptr[j++], ASRCnegNode, ASRCbranch); + TSTALLOC(ASRCposptr[j++], ASRCbranch, ASRCnegNode); + TSTALLOC(ASRCposptr[j++], ASRCbranch, ASRCposNode); + } + + for (i = 0; i < here->ASRCtree->numVars; i++) { + switch (here->ASRCtree->varTypes[i]) { case IF_INSTANCE: here->ASRCcont_br = CKTfndBranch(ckt, - here->ASRCtree->vars[i].uValue); - if(here->ASRCcont_br == 0) { + here->ASRCtree->vars[i].uValue); + if (here->ASRCcont_br == 0) { SPfrontEnd->IFerrorf (ERR_FATAL, - "%s: unknown controlling source %s", here->ASRCname, here->ASRCtree->vars[i].uValue); + "%s: unknown controlling source %s", here->ASRCname, here->ASRCtree->vars[i].uValue); return(E_BADPARM); } - if( here->ASRCtype == ASRC_VOLTAGE){ + if (here->ASRCtype == ASRC_VOLTAGE) { /* CCVS */ - if(v_first){ - TSTALLOC(ASRCposptr[j++],ASRCbranch,ASRCcont_br); + if (v_first) { + TSTALLOC(ASRCposptr[j++], ASRCbranch, ASRCcont_br); v_first = 0; - } else{ + } else { here->ASRCposptr = TREALLOC(double *, here->ASRCposptr, j + 1); - TSTALLOC(ASRCposptr[j++],ASRCbranch,ASRCcont_br); + TSTALLOC(ASRCposptr[j++], ASRCbranch, ASRCcont_br); } - } else if(here->ASRCtype == ASRC_CURRENT){ + } else if (here->ASRCtype == ASRC_CURRENT) { /* CCCS */ - here->ASRCposptr = TREALLOC(double *, here->ASRCposptr, j + 2); - TSTALLOC(ASRCposptr[j++],ASRCposNode,ASRCcont_br); - TSTALLOC(ASRCposptr[j++],ASRCnegNode,ASRCcont_br); - } else{ + here->ASRCposptr = TREALLOC(double *, here->ASRCposptr, j + 2); + TSTALLOC(ASRCposptr[j++], ASRCposNode, ASRCcont_br); + TSTALLOC(ASRCposptr[j++], ASRCnegNode, ASRCcont_br); + } else { return (E_BADPARM); } break; case IF_NODE: - if( here->ASRCtype == ASRC_VOLTAGE){ + if (here->ASRCtype == ASRC_VOLTAGE) { /* VCVS */ - if(v_first){ - MY_TSTALLOC(ASRCposptr[j++],ASRCbranch,here->ASRCtree->vars[i].nValue); + if (v_first) { + MY_TSTALLOC(ASRCposptr[j++], ASRCbranch, here->ASRCtree->vars[i].nValue); v_first = 0; - } else{ + } else { here->ASRCposptr = TREALLOC(double *, here->ASRCposptr, j + 1); - MY_TSTALLOC(ASRCposptr[j++],ASRCbranch,here->ASRCtree->vars[i].nValue); + MY_TSTALLOC(ASRCposptr[j++], ASRCbranch, here->ASRCtree->vars[i].nValue); } - } else if(here->ASRCtype == ASRC_CURRENT){ + } else if (here->ASRCtype == ASRC_CURRENT) { /* VCCS */ here->ASRCposptr = TREALLOC(double *, here->ASRCposptr, j + 2); - MY_TSTALLOC(ASRCposptr[j++],ASRCposNode,here->ASRCtree->vars[i].nValue); - MY_TSTALLOC(ASRCposptr[j++],ASRCnegNode,here->ASRCtree->vars[i].nValue); - } else{ + MY_TSTALLOC(ASRCposptr[j++], ASRCposNode, here->ASRCtree->vars[i].nValue); + MY_TSTALLOC(ASRCposptr[j++], ASRCnegNode, here->ASRCtree->vars[i].nValue); + } else { return (E_BADPARM); } break; @@ -136,9 +135,11 @@ do { if((here->ptr = SMPmakeElt(matrix, here->first, (second)->number)) == NULL) } } } + return(OK); } + int ASRCunsetup( GENmodel *inModel, @@ -147,17 +148,18 @@ ASRCunsetup( ASRCmodel *model; ASRCinstance *here; - for (model = (ASRCmodel *)inModel; model != NULL; - model = model->ASRCnextModel) + for (model = (ASRCmodel *) inModel; model != NULL; + model = model->ASRCnextModel) { for (here = model->ASRCinstances; here != NULL; - here=here->ASRCnextInstance) - { - if (here->ASRCbranch) { - CKTdltNNum(ckt, here->ASRCbranch); - here->ASRCbranch = 0; - } - } + here = here->ASRCnextInstance) + { + if (here->ASRCbranch) { + CKTdltNNum(ckt, here->ASRCbranch); + here->ASRCbranch = 0; + } + } } + return OK; } diff --git a/src/spicelib/devices/asrc/asrctemp.c b/src/spicelib/devices/asrc/asrctemp.c index 64a034d8e..fddcd3b8d 100644 --- a/src/spicelib/devices/asrc/asrctemp.c +++ b/src/spicelib/devices/asrc/asrctemp.c @@ -8,31 +8,32 @@ Author: 1985 Thomas L. Quarles #include "asrcdefs.h" #include "ngspice/sperror.h" + int ASRCtemp(GENmodel *inModel, CKTcircuit *ckt) { - ASRCmodel *model = (ASRCmodel *)inModel; + ASRCmodel *model = (ASRCmodel *) inModel; ASRCinstance *here; /* loop through all the source models */ - for( ; model != NULL; model = model->ASRCnextModel ) { - + for (; model != NULL; model = model->ASRCnextModel) { /* loop through all the instances of the model */ - for (here = model->ASRCinstances; here != NULL ; - here=here->ASRCnextInstance) { + for (here = model->ASRCinstances; here != NULL; + here = here->ASRCnextInstance) { /* Default Value Processing for Source Instance */ - if(!here->ASRCtempGiven) { - here->ASRCtemp = ckt->CKTtemp; - if(!here->ASRCdtempGiven) here->ASRCdtemp = 0.0; - } else { /* ASRCtempGiven */ - here->ASRCdtemp = 0.0; - if (here->ASRCdtempGiven) - printf("%s: Instance temperature specified, dtemp ignored\n", here->ASRCname); - } + if (!here->ASRCtempGiven) { + here->ASRCtemp = ckt->CKTtemp; + if (!here->ASRCdtempGiven) here->ASRCdtemp = 0.0; + } else { /* ASRCtempGiven */ + here->ASRCdtemp = 0.0; + if (here->ASRCdtempGiven) + printf("%s: Instance temperature specified, dtemp ignored\n", here->ASRCname); + } } } + return(OK); }