devices/asrc, cleanup #2/9, whitespace

This commit is contained in:
rlar 2015-04-11 21:25:22 +02:00
parent df147cd8b8
commit 2cb727476f
18 changed files with 483 additions and 460 deletions

View File

@ -9,6 +9,7 @@ Author: 1987 Kanwar Jit Singh
#include "asrcdefs.h" #include "asrcdefs.h"
#include "ngspice/suffix.h" #include "ngspice/suffix.h"
/* Arbitrary source */ /* Arbitrary source */
IFparm ASRCpTable[] = { /* parameters */ IFparm ASRCpTable[] = { /* parameters */
IP("i", ASRC_CURRENT, IF_PARSETREE, "Current source"), IP("i", ASRC_CURRENT, IF_PARSETREE, "Current source"),
@ -25,11 +26,13 @@ IFparm ASRCpTable[] = { /* parameters */
OP("neg_node", ASRC_NEG_NODE, IF_INTEGER, "Negative Node") OP("neg_node", ASRC_NEG_NODE, IF_INTEGER, "Negative Node")
}; };
char *ASRCnames[] = { char *ASRCnames[] = {
"src+", "src+",
"src-" "src-"
}; };
int ASRCnSize = NUMELEMS(ASRCnames); int ASRCnSize = NUMELEMS(ASRCnames);
int ASRCpTSize = NUMELEMS(ASRCpTable); int ASRCpTSize = NUMELEMS(ASRCpTable);
int ASRCmPTSize = 0; int ASRCmPTSize = 0;

View File

@ -17,7 +17,6 @@ Author: 1988 Kanwar Jit Singh
int int
ASRCacLoad(GENmodel *inModel, CKTcircuit *ckt) ASRCacLoad(GENmodel *inModel, CKTcircuit *ckt)
{ {
/* /*
* Actually load the current voltage value into the * Actually load the current voltage value into the
* sparse matrix previously provided. The values have * sparse matrix previously provided. The values have
@ -35,7 +34,6 @@ ASRCacLoad(GENmodel *inModel, CKTcircuit *ckt)
/* loop through all the Arbitrary source models */ /* 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 */ /* loop through all the instances of the model */
for (here = model->ASRCinstances; here != NULL; for (here = model->ASRCinstances; here != NULL;
here = here->ASRCnextInstance) { here = here->ASRCnextInstance) {
@ -43,6 +41,7 @@ ASRCacLoad(GENmodel *inModel, CKTcircuit *ckt)
difference = (here->ASRCtemp + here->ASRCdtemp) - 300.15; difference = (here->ASRCtemp + here->ASRCdtemp) - 300.15;
factor = 1.0 + (here->ASRCtc1) * difference + factor = 1.0 + (here->ASRCtc1) * difference +
(here->ASRCtc2) * difference * difference; (here->ASRCtc2) * difference * difference;
if (here->ASRCreciproctc == 1) { if (here->ASRCreciproctc == 1) {
factor = 1 / factor; factor = 1 / factor;
} }

View File

@ -9,6 +9,7 @@ Author: 1988 Kanwar Jit Singh
#include "ngspice/sperror.h" #include "ngspice/sperror.h"
#include "ngspice/suffix.h" #include "ngspice/suffix.h"
int int
ASRCconvTest(GENmodel *inModel, CKTcircuit *ckt) ASRCconvTest(GENmodel *inModel, CKTcircuit *ckt)
{ {
@ -51,6 +52,7 @@ ASRCconvTest(GENmodel *inModel, CKTcircuit *ckt)
prev = here->ASRCprev_value; prev = here->ASRCprev_value;
diff = fabs(prev - rhs); diff = fabs(prev - rhs);
if (here->ASRCtype == ASRC_VOLTAGE) { if (here->ASRCtype == ASRC_VOLTAGE) {
tol = ckt->CKTreltol * tol = ckt->CKTreltol *
MAX(fabs(rhs), fabs(prev)) + ckt->CKTvoltTol; MAX(fabs(rhs), fabs(prev)) + ckt->CKTvoltTol;
@ -66,5 +68,6 @@ ASRCconvTest(GENmodel *inModel, CKTcircuit *ckt)
} }
} }
} }
return(OK); return(OK);
} }

View File

@ -10,6 +10,7 @@ Author: 1985 Thomas L. Quarles
#include "ngspice/ifsim.h" #include "ngspice/ifsim.h"
#include "ngspice/complex.h" #include "ngspice/complex.h"
/* /*
* structures to describe Arbitrary sources * structures to describe Arbitrary sources
*/ */
@ -24,9 +25,11 @@ typedef struct sASRCinstance {
int ASRCstates; /* state info */ int ASRCstates; /* state info */
int ASRCposNode; /* number of positive node of source */ int ASRCposNode; /* number of positive node of source */
int ASRCnegNode; /* number of negative node of source */ int ASRCnegNode; /* number of negative node of source */
int ASRCtype; /* Whether source is voltage or current */ int ASRCtype; /* Whether source is voltage or current */
int ASRCbranch; /* number of branch equation added for v source */ int ASRCbranch; /* number of branch equation added for v source */
IFparseTree *ASRCtree; /* The parse tree */ IFparseTree *ASRCtree; /* The parse tree */
double ASRCtemp; /* temperature at which this resistor operates */ double ASRCtemp; /* temperature at which this resistor operates */
double ASRCdtemp; /* delta-temperature of a particular instance */ double ASRCdtemp; /* delta-temperature of a particular instance */
double ASRCtc1; /* first temperature coefficient of resistors */ double ASRCtc1; /* first temperature coefficient of resistors */
@ -37,13 +40,16 @@ typedef struct sASRCinstance {
double ASRCprev_value; /* Previous value for the convergence test */ double ASRCprev_value; /* Previous value for the convergence test */
double *ASRCacValues; /* Store rhs and derivatives for ac anal */ double *ASRCacValues; /* Store rhs and derivatives for ac anal */
int ASRCcont_br; /* Temporary store for controlling current branch */ int ASRCcont_br; /* Temporary store for controlling current branch */
unsigned ASRCtempGiven : 1; /* indicates temperature specified */ unsigned ASRCtempGiven : 1; /* indicates temperature specified */
unsigned ASRCdtempGiven : 1; /* indicates delta-temp specified */ unsigned ASRCdtempGiven : 1; /* indicates delta-temp specified */
unsigned ASRCtc1Given : 1; /* indicates tc1 parameter specified */ unsigned ASRCtc1Given : 1; /* indicates tc1 parameter specified */
unsigned ASRCtc2Given : 1; /* indicates tc2 parameter specified */ unsigned ASRCtc2Given : 1; /* indicates tc2 parameter specified */
unsigned ASRCreciproctcGiven : 1; /* indicates reciproctc flag parameter specified */ unsigned ASRCreciproctcGiven : 1; /* indicates reciproctc flag parameter specified */
} ASRCinstance; } ASRCinstance;
#define ASRCvOld ASRCstates #define ASRCvOld ASRCstates
#define ASRCcontVOld ASRCstates + 1 #define ASRCcontVOld ASRCstates + 1
@ -61,6 +67,7 @@ typedef struct sASRCmodel { /* model structure for a source */
} ASRCmodel; } ASRCmodel;
/* device parameters */ /* device parameters */
#define ASRC_VOLTAGE 1 #define ASRC_VOLTAGE 1
#define ASRC_CURRENT 2 #define ASRC_CURRENT 2
@ -87,4 +94,5 @@ extern int asrc_nvals;
/* model questions */ /* model questions */
#include "asrcext.h" #include "asrcext.h"
#endif /*ASRC*/ #endif /*ASRC*/

View File

@ -14,7 +14,6 @@ Author: 1987 Kanwar Jit Singh
int int
ASRCdelete(GENmodel *model, IFuid name, GENinstance **fast) ASRCdelete(GENmodel *model, IFuid name, GENinstance **fast)
{ {
ASRCinstance **instPtr = (ASRCinstance**) fast; ASRCinstance **instPtr = (ASRCinstance**) fast;
ASRCmodel *modPtr = (ASRCmodel*) model; ASRCmodel *modPtr = (ASRCmodel*) model;
@ -33,5 +32,6 @@ ASRCdelete(GENmodel *model, IFuid name, GENinstance **fast)
prev = &(here->ASRCnextInstance); prev = &(here->ASRCnextInstance);
} }
} }
return(E_NODEV); return(E_NODEV);
} }

View File

@ -8,9 +8,9 @@ Author: 1987 Kanwar Jit Singh
#include "ngspice/suffix.h" #include "ngspice/suffix.h"
#include "ngspice/inpdefs.h" #include "ngspice/inpdefs.h"
void void
ASRCdestroy(GENmodel **model) ASRCdestroy(GENmodel **model)
{ {
ASRCmodel **start = (ASRCmodel**) model; /* starting model */ ASRCmodel **start = (ASRCmodel**) model; /* starting model */
ASRCinstance *here; /* current instance */ ASRCinstance *here; /* current instance */
@ -30,5 +30,6 @@ ASRCdestroy(GENmodel **model)
nextmod = mod->ASRCnextModel; nextmod = mod->ASRCnextModel;
FREE(mod); FREE(mod);
} }
*model = NULL; *model = NULL;
} }

View File

@ -35,5 +35,6 @@ ASRCfindBr(CKTcircuit *ckt, GENmodel *inputModel, IFuid name)
} }
} }
} }
return(0); return(0);
} }

View File

@ -1,6 +1,7 @@
/********** /**********
Copyright 1990 Regents of the University of California. All rights reserved. Copyright 1990 Regents of the University of California. All rights reserved.
**********/ **********/
#ifndef DEV_ASRC #ifndef DEV_ASRC
#define DEV_ASRC #define DEV_ASRC

View File

@ -12,14 +12,15 @@ Author: 1987 Kanwar Jit Singh
#include "ngspice/sperror.h" #include "ngspice/sperror.h"
#include "ngspice/suffix.h" #include "ngspice/suffix.h"
double *asrc_vals, *asrc_derivs; double *asrc_vals, *asrc_derivs;
int asrc_nvals; int asrc_nvals;
/*ARGSUSED*/ /*ARGSUSED*/
int int
ASRCload(GENmodel *inModel, CKTcircuit *ckt) ASRCload(GENmodel *inModel, CKTcircuit *ckt)
{ {
/* actually load the current voltage value into the /* actually load the current voltage value into the
* sparse matrix previously provided * sparse matrix previously provided
*/ */
@ -33,13 +34,14 @@ ASRCload(GENmodel *inModel, CKTcircuit *ckt)
/* loop through all the Arbitrary source models */ /* 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 */ /* loop through all the instances of the model */
for (here = model->ASRCinstances; here != NULL; for (here = model->ASRCinstances; here != NULL;
here=here->ASRCnextInstance) here=here->ASRCnextInstance)
{ {
difference = (here->ASRCtemp + here->ASRCdtemp) - 300.15; difference = (here->ASRCtemp + here->ASRCdtemp) - 300.15;
factor = 1.0 + (here->ASRCtc1) * difference + (here->ASRCtc2) * difference * difference; factor = 1.0 + (here->ASRCtc1) * difference + (here->ASRCtc2) * difference * difference;
if (here->ASRCreciproctc == 1) { if (here->ASRCreciproctc == 1) {
factor = 1 / factor; factor = 1 / factor;
} }
@ -79,7 +81,6 @@ ASRCload(GENmodel *inModel, CKTcircuit *ckt)
here->ASRCprev_value = rhs; here->ASRCprev_value = rhs;
/* The ac load precomputation and storage */ /* The ac load precomputation and storage */
if (ckt->CKTmode & MODEINITSMSIG) { if (ckt->CKTmode & MODEINITSMSIG) {
int size = (here->ASRCtree->numVars) + 1; int size = (here->ASRCtree->numVars) + 1;
here->ASRCacValues = NEWN(double, size); here->ASRCacValues = NEWN(double, size);
@ -108,7 +109,6 @@ ASRCload(GENmodel *inModel, CKTcircuit *ckt)
*(here->ASRCposptr[j++]) -= asrc_derivs[i] * factor; *(here->ASRCposptr[j++]) -= asrc_derivs[i] * factor;
} }
break; break;
case IF_NODE: case IF_NODE:
if (here->ASRCtype == ASRC_VOLTAGE) { if (here->ASRCtype == ASRC_VOLTAGE) {
/* VCVS */ /* VCVS */
@ -119,7 +119,6 @@ ASRCload(GENmodel *inModel, CKTcircuit *ckt)
*(here->ASRCposptr[j++]) -= asrc_derivs[i] * factor; *(here->ASRCposptr[j++]) -= asrc_derivs[i] * factor;
} }
break; break;
default: default:
return(E_BADPARM); return(E_BADPARM);
} }

View File

@ -15,29 +15,32 @@ Author: 1987 Kanwar Jit Singh
int int
ASRCmDelete(GENmodel **modList, IFuid modname, GENmodel *killModel) ASRCmDelete(GENmodel **modList, IFuid modname, GENmodel *killModel)
{ {
ASRCmodel **model = (ASRCmodel**) modList; ASRCmodel **model = (ASRCmodel**) modList;
ASRCmodel *modfast = (ASRCmodel*) killModel; ASRCmodel *modfast = (ASRCmodel*) killModel;
ASRCinstance *here; ASRCinstance *here;
ASRCinstance *prev = NULL; ASRCinstance *prev = NULL;
ASRCmodel **oldmod; ASRCmodel **oldmod;
oldmod = model; oldmod = model;
for (; *model; model = &((*model)->ASRCnextModel)) { for (; *model; model = &((*model)->ASRCnextModel)) {
if ((*model)->ASRCmodName == modname || if ((*model)->ASRCmodName == modname ||
(modfast && *model == modfast)) goto delgot; (modfast && *model == modfast)) goto delgot;
oldmod = model; oldmod = model;
} }
return(E_NOMOD); return(E_NOMOD);
delgot: delgot:
*oldmod = (*model)->ASRCnextModel; /* cut deleted device out of list */ *oldmod = (*model)->ASRCnextModel; /* cut deleted device out of list */
for (here = (*model)->ASRCinstances; here; here = here->ASRCnextInstance) { for (here = (*model)->ASRCinstances; here; here = here->ASRCnextInstance) {
FREE(here->ASRCacValues); FREE(here->ASRCacValues);
if (prev) FREE(prev); if (prev) FREE(prev);
prev = here; prev = here;
} }
if (prev) FREE(prev); if (prev) FREE(prev);
FREE(*model); FREE(*model);
return(OK); return(OK);
} }

View File

@ -45,5 +45,6 @@ ASRCparam(int param, IFvalue *value, GENinstance *fast, IFvalue *select)
default: default:
return(E_BADPARM); return(E_BADPARM);
} }
return(OK); return(OK);
} }

View File

@ -10,10 +10,10 @@ Author: 1987 Kanwar Jit Singh
#include "ngspice/suffix.h" #include "ngspice/suffix.h"
#include "ngspice/complex.h" #include "ngspice/complex.h"
/*ARGSUSED*/ /*ARGSUSED*/
int int
ASRCpzLoad(GENmodel *inModel, CKTcircuit *ckt, SPcomplex *s) ASRCpzLoad(GENmodel *inModel, CKTcircuit *ckt, SPcomplex *s)
/* actually load the current voltage value into the /* actually load the current voltage value into the
* sparse matrix previously provided * sparse matrix previously provided
*/ */
@ -29,14 +29,15 @@ ASRCpzLoad(GENmodel *inModel, CKTcircuit *ckt, SPcomplex *s)
/* loop through all the Arbitrary source models */ /* 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 */ /* loop through all the instances of the model */
for (here = model->ASRCinstances; here != NULL; for (here = model->ASRCinstances; here != NULL;
here = here->ASRCnextInstance) here = here->ASRCnextInstance)
{ {
difference = (here->ASRCtemp + here->ASRCdtemp) - 300.15; difference = (here->ASRCtemp + here->ASRCdtemp) - 300.15;
factor = 1.0 + (here->ASRCtc1) * difference + factor = 1.0 + (here->ASRCtc1) * difference +
(here->ASRCtc2) * difference * difference; (here->ASRCtc2) * difference * difference;
if (here->ASRCreciproctc == 1) { if (here->ASRCreciproctc == 1) {
factor = 1 / factor; factor = 1 / factor;
} }

View File

@ -19,7 +19,6 @@ ASRCsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states)
/* load the voltage source structure with those /* load the voltage source structure with those
* pointers needed later for fast matrix loading * pointers needed later for fast matrix loading
*/ */
{ {
ASRCinstance *here; ASRCinstance *here;
ASRCmodel *model = (ASRCmodel*) inModel; ASRCmodel *model = (ASRCmodel*) inModel;
@ -31,7 +30,6 @@ ASRCsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states)
/* loop through all the user models*/ /* 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 */ /* loop through all the instances of the model */
for (here = model->ASRCinstances; here != NULL; for (here = model->ASRCinstances; here != NULL;
here=here->ASRCnextInstance) { here=here->ASRCnextInstance) {
@ -43,6 +41,7 @@ ASRCsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states)
here->ASRCposptr = NULL; 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; v_first = 1;
if (here->ASRCtype == ASRC_VOLTAGE) { if (here->ASRCtype == ASRC_VOLTAGE) {
if (here->ASRCbranch == 0) { if (here->ASRCbranch == 0) {
error = CKTmkCur(ckt, &tmp, here->ASRCname, "branch"); error = CKTmkCur(ckt, &tmp, here->ASRCname, "branch");
@ -51,7 +50,6 @@ ASRCsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states)
} }
} }
/* macro to make elements with built in test for out of memory */ /* macro to make elements with built in test for out of memory */
#define TSTALLOC(ptr, first, second) \ #define TSTALLOC(ptr, first, second) \
do { if ((here->ptr = SMPmakeElt(matrix, here->first, here->second)) == NULL) { \ do { if ((here->ptr = SMPmakeElt(matrix, here->first, here->second)) == NULL) { \
@ -77,6 +75,7 @@ do { if((here->ptr = SMPmakeElt(matrix, here->first, (second)->number)) == NULL)
} }
here->ASRCposptr = TREALLOC(double *, here->ASRCposptr, j + 5); here->ASRCposptr = TREALLOC(double *, here->ASRCposptr, j + 5);
TSTALLOC(ASRCposptr[j++], ASRCposNode, ASRCbranch); TSTALLOC(ASRCposptr[j++], ASRCposNode, ASRCbranch);
TSTALLOC(ASRCposptr[j++], ASRCnegNode, ASRCbranch); TSTALLOC(ASRCposptr[j++], ASRCnegNode, ASRCbranch);
TSTALLOC(ASRCposptr[j++], ASRCbranch, ASRCnegNode); TSTALLOC(ASRCposptr[j++], ASRCbranch, ASRCnegNode);
@ -136,9 +135,11 @@ do { if((here->ptr = SMPmakeElt(matrix, here->first, (second)->number)) == NULL)
} }
} }
} }
return(OK); return(OK);
} }
int int
ASRCunsetup( ASRCunsetup(
GENmodel *inModel, GENmodel *inModel,
@ -159,5 +160,6 @@ ASRCunsetup(
} }
} }
} }
return OK; return OK;
} }

View File

@ -8,6 +8,7 @@ Author: 1985 Thomas L. Quarles
#include "asrcdefs.h" #include "asrcdefs.h"
#include "ngspice/sperror.h" #include "ngspice/sperror.h"
int int
ASRCtemp(GENmodel *inModel, CKTcircuit *ckt) ASRCtemp(GENmodel *inModel, CKTcircuit *ckt)
{ {
@ -16,7 +17,6 @@ ASRCtemp(GENmodel *inModel, CKTcircuit *ckt)
/* loop through all the source models */ /* 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 */ /* loop through all the instances of the model */
for (here = model->ASRCinstances; here != NULL; for (here = model->ASRCinstances; here != NULL;
here = here->ASRCnextInstance) { here = here->ASRCnextInstance) {
@ -34,5 +34,6 @@ ASRCtemp(GENmodel *inModel, CKTcircuit *ckt)
} }
} }
return(OK); return(OK);
} }