home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-01-28 | 49.5 KB | 1,777 lines |
- Path: sparky!uunet!ferkel.ucsb.edu!taco!rock!stanford.edu!ames!haven.umd.edu!darwin.sura.net!ukma!cs.widener.edu!dsinc!ub!galileo.cc.rochester.edu!ee.rochester.edu!rbc!al
- From: al@rbc.uucp (Al Davis)
- Newsgroups: alt.sources
- Subject: ACS circuit simulator part 13/20
- Message-ID: <1993Jan27.040819.11609@rbc.uucp>
- Date: 27 Jan 93 04:08:19 GMT
- Sender: al@rbc.uucp (Al Davis)
- Organization: Huh?
- Lines: 1766
-
- #! /bin/sh
- # This is a shell archive, meaning:
- # 1. Remove everything above the #! /bin/sh line.
- # 2. Save the resulting text in a file.
- # 3. Execute the file with /bin/sh (not csh) to create the files:
- # src/d_logic.c
- # src/d_res.c
- # src/d_subckt.c
- # src/d_trln.c
- # src/d_vccs.c
- # src/d_vcvs.c
- # src/d_vs.c
- # This archive created: Tue Jan 26 22:51:03 1993
- export PATH; PATH=/bin:$PATH
- if test -f 'src/d_logic.c'
- then
- echo shar: will not over-write existing file "'src/d_logic.c'"
- else
- cat << \SHAR_EOF > 'src/d_logic.c'
- /* dev_log.c 01/05/93
- * Copyright 1983-1992 Albert Davis
- * logic model.
- */
- #include "ecah.h"
- #include "argparse.h"
- #include "branch.h"
- #include "convstat.h"
- #include "dev.h"
- #include "error.h"
- #include "mode.h"
- #include "nodestat.h"
- #include "options.h"
- #include "status.h"
- #include "types.h"
- #include "d_logic.h"
- #include "d_subckt.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- static branch_t *create_logic(const branch_t*);
- static void parse_logic(branch_t*,const char*,int*);
- static void print_logic(const branch_t*,int,int);
- static branch_t *create_model_logic(const branch_t*);
- static void parse_model_logic(branch_t*,const char*,int*);
- static void print_model_logic(const branch_t*,int,int);
- static void expand_logic(branch_t*);
- static double trprobe_logic(const branch_t*,const char*);
- static int tr_logic(branch_t*);
- static void un_logic(branch_t*);
- static void ac_logic(branch_t*);
- static struct nodestat *tologic(const struct lmod*,node_t);
- static double toanalog(const struct lmod*,node_t);
- static double tr_review_logic(branch_t*);
- /*--------------------------------------------------------------------------*/
- functions_t dev_logic = {
- sizeof(branch_t),
- create_logic,
- parse_logic,
- print_logic,
- expand_logic,
- trprobe_logic,
- (double(*)())NULL,/* acprobe */
- tr_logic,
- un_logic,
- ac_logic,
- (void(*)())NULL, /* trfun1 */
- (void(*)())NULL, /* trfun0 */
- (complex_t(*)())NULL,/* acfun */
- (void(*)())NULL, /* tr_guess */
- (void(*)())NULL, /* tr_advance */
- tr_review_logic
- };
- functions_t model_logic = {
- sizeof(branch_t),
- create_model_logic,
- parse_model_logic,
- print_model_logic,
- (void(*)())NULL, /* expand */
- (double(*)())NULL, /* trprobe */
- (double(*)())NULL,/* acprobe */
- (int(*)())NULL, /* dotr */
- (void(*)())NULL, /* untr */
- (void(*)())NULL, /* doac */
- (void(*)())NULL, /* trfun1 */
- (void(*)())NULL, /* trfun0 */
- (complex_t(*)())NULL,/* acfun */
- (void(*)())NULL, /* tr_guess */
- (void(*)())NULL, /* tr_advance */
- tr_review_logic
- };
- /*--------------------------------------------------------------------------*/
- extern struct nodestat *nstat; /* node status flags */
- extern const int inc_mode; /* make incremental changes */
- extern const int sim_phase;
- extern const double trtime; /* transient analysis time */
- extern const struct options opt;
- extern const struct status stats;
-
- static char *(typename[]) = {"error", "and", "nand", "or", "nor", "xor",
- "inv", ""};
- static struct logic defalt = {(generic_t*)NULL, sizeof(struct logic),
- (struct lmod*)NULL, lDEFAULT_modelname, lDEFAULT_type, INVALIDNODE};
- static struct lmod defaltmodel = {(generic_t*)NULL, sizeof(struct lmod),
- lDEFAULT_delay, lDEFAULT_rise, lDEFAULT_fall, lDEFAULT_rs,
- lDEFAULT_rw, lDEFAULT_th1, lDEFAULT_th0, lDEFAULT_mr, lDEFAULT_mf,
- lDEFAULT_over, lDEFAULT_vmax, lDEFAULT_vmin, lDEFAULT_range};
- static branch_t modellist = {(generic_t*)&defaltmodel, sizeof(branch_t),
- &model_logic, &modellist, &modellist, &modellist, &modellist,
- (branch_t*)NULL, (branch_t*)NULL, lDEFAULT_modelname, /* more */};
- /*--------------------------------------------------------------------------*/
- static branch_t *create_logic(proto)
- const branch_t *proto;
- {
- branch_t *brh;
- struct logic *x;
-
- brh = createbranch(proto,(generic_t*)&defalt,&dev_logic);
- x = (struct logic*)brh->x;
- brh->n = x->n;
- return brh;
- }
- /*--------------------------------------------------------------------------*/
- static void parse_logic(brh,cmd,cnt)
- branch_t *brh;
- const char *cmd;
- int *cnt;
- {
- struct logic *x;
- x = (struct logic*)brh->x;
-
- parselabel(brh,cmd,cnt);
- x->incount = parsenodes(brh,cmd,cnt,PORTSPERGATE);
- (void)ctostr(cmd, cnt, x->modelname, LABELEN);
- if (argparse(cmd,cnt,ONEPASS,
- "AND", aENUM, &x->type, lAND,
- "NAND", aENUM, &x->type, lNAND,
- "OR", aENUM, &x->type, lOR,
- "NOR", aENUM, &x->type, lNOR,
- "XOR", aENUM, &x->type, lXOR,
- "INV", aENUM, &x->type, lINV,
- ""))
- x->incount -= 2;
- else{
- syntax(cmd,cnt,bWARNING);
- }
- }
- /*--------------------------------------------------------------------------*/
- static void print_logic(brh,where,detail)
- const branch_t *brh;
- int where;
- int detail;
- {
- struct logic *x;
- x = (struct logic*)brh->x;
-
- (void)printlabel(brh,where);
- printnodes(brh,where);
- mprintf(where, " %s %s\n", x->modelname, typename[x->type]);
- }
- /*--------------------------------------------------------------------------*/
- static branch_t *create_model_logic(proto)
- const branch_t *proto;
- {
- branch_t *brh;
- struct lmod *m;
-
- brh = createbranch(proto,(generic_t*)&defaltmodel,&model_logic);
- m = (struct lmod*)brh->x;
- brh->stprev = &modellist;
- return brh;
- }
- /*--------------------------------------------------------------------------*/
- static void parse_model_logic(brh,cmd,cnt)
- branch_t *brh;
- const char *cmd;
- int *cnt;
- {
- struct lmod *m;
- m = (struct lmod*)brh->x;
-
- (void)ctostr(cmd, cnt, brh->label, LABELEN);
- skiparg(cmd,cnt); /* skip known "logic" */
- (void)skiplparen(cmd,cnt);
- for (;;){
- if (argparse(cmd,cnt,REPEAT,
- "DElay",aUDOUBLE, &m->delay,
- "RIse", aUDOUBLE, &m->rise,
- "FAll", aUDOUBLE, &m->fall,
- "RS", aUDOUBLE, &m->rs,
- "RW", aUDOUBLE, &m->rw,
- "THH", aDOUBLE, &m->th1,
- "THL", aDOUBLE, &m->th0,
- "MR", aUDOUBLE, &m->mr,
- "MF", aUDOUBLE, &m->mf,
- "OVer", aUDOUBLE, &m->over,
- "VMAx", aDOUBLE, &m->vmax,
- "VMIn", aDOUBLE, &m->vmin,
- ""))
- ;
- else{
- (void)skiprparen(cmd,cnt);
- syntax(cmd,cnt,bWARNING);
- break;
- }
- m->range = m->vmax - m->vmin;
- }
- }
- /*--------------------------------------------------------------------------*/
- static void print_model_logic(brh,where,detail)
- const branch_t *brh;
- int where;
- int detail;
- {
- struct lmod *m;
- m = (struct lmod*)brh->x;
-
- mprintf(where, ".model %s logic (", brh->label);
- mprintf(where, " delay=%s ",ftos(m->delay,"", 7, 0));
- mprintf(where, " rise=%s ", ftos(m->rise, "", 7, 0));
- mprintf(where, " fall=%s ", ftos(m->fall, "", 7, 0));
- mprintf(where, " rs=%s ", ftos(m->rs, "", 7, 0));
- mprintf(where, " rw=%s ", ftos(m->rw, "", 7, 0));
- mprintf(where, " thh=%s ", ftos(m->th1, "", 7, 0));
- mprintf(where, " thl=%s ", ftos(m->th0, "", 7, 0));
- mprintf(where, " mr=%s ", ftos(m->mf, "", 7, 0));
- mprintf(where, " mf=%s ", ftos(m->mr, "", 7, 0));
- mprintf(where, " over=%s ", ftos(m->over, "", 7, 0));
- mprintf(where, " vmax=%s ", ftos(m->vmax, "", 7, 0));
- mprintf(where, " vmin=%s ", ftos(m->vmin, "", 7, 0));
- mprintf(where, ")\n");
- }
- /*--------------------------------------------------------------------------*/
- static void expand_logic(brh)
- branch_t *brh;
- {
- char cktname[BUFLEN];
- struct logic *x;
-
- branch_t *foo;
- foo = brh->subckt;
-
- x = (struct logic*)brh->x;
- sprintf(cktname, "%s%s%u", x->modelname, typename[x->type], x->incount);
- expandgeneric(brh,&modellist);
- brh->subckt = foo;
- expandsubckt(brh,cktname);
- if (!brh->subckt){
- error(bDANGER, "%s: no model, forcing digital\n", printlabel(brh,0));
- }
- brh->tracesubckt = YES;
- }
- /*--------------------------------------------------------------------------*/
- static double trprobe_logic(brh,what)
- const branch_t *brh;
- const char *what;
- {
- struct logic *x;
- double volts;
- int dummy = 0;
-
- x = (struct logic*)brh->x;
- if (!x->m || !brh->subckt)
- error(bERROR, "internal error: %s not expanded\n", printlabel(brh,NO));
-
- volts = tr_volts(brh->n[OUT1],brh->n[OUT2]);
-
- setmatch(what,&dummy);
- if (rematch("V")){
- return volts;
- }else { /* bad parameter */
- return NOT_VALID;
- }
- }
- /*--------------------------------------------------------------------------*/
- static int tr_logic(brh)
- branch_t *brh;
- {
- struct nodestat *n;
- struct logic *x;
- const struct lmod *m;
-
- if (brh->iter == stats.iter[iTOTAL]){
- return brh->status;
- }else{
- brh->iter = stats.iter[iTOTAL];
- }
- x = (struct logic*)brh->x;
- m = x->m;
- n = &(nstat[brh->n[1].m]);
-
- if ((x->gatemode == mANALOG)
- || (opt.mode == mMIXED && sim_phase == pINIT_DC)
- || (opt.mode == mANALOG)){
- x->gatemode = n->nodemode = mANALOG;
- return brh->status = tr_fill_rl(brh->subckt);
- }
-
- /* if it gets here, either opt.mode == mMIXED && quality == qGOOD
- * or opt.mode == mDIGITAL
- */
-
- brh->bypass = YES;
- x->gatemode = n->nodemode = mDIGITAL;
- /* in transition */
- if (trtime >= n->finaltime){ /* time to propagate */
- brh->bypass = NO;
- n->lv0 = n->lv1;
- n->ls0 = n->ls1;
- n->isanalog = NO;
- n->quality = qGOOD;
- n->diter = stats.iter[iTOTAL];
- n->finaltime = BIGBIG;
- n->lastchange = trtime;
- }
-
- if (n->finaltime != BIGBIG || !brh->bypass || !inc_mode){
- trsetup(brh);
- brh->m0.x = 0.;
- brh->y0.x = 0.;
- brh->y0.f1 = -toanalog(m,brh->n[1]);
- brh->y0.f0 = 0.;
- brh->ev = brh->y0.f1;
- brh->m0.f1 = 1./m->rs;
- brh->m0.c0 = brh->y0.f1 / -m->rs;
- trloadpassive(brh);
- }
- return brh->status = cGOOD;
- }
- /*--------------------------------------------------------------------------*/
- static void un_logic(brh)
- branch_t *brh;
- {
- tr_unfill_rl(brh->subckt);
- unloadpassive(brh);
- }
- /*--------------------------------------------------------------------------*/
- static void ac_logic(brh)
- branch_t *brh;
- {
- error(bWARNING, "%s: no logic in AC analysis\n", printlabel(brh,NO));
- }
- /*--------------------------------------------------------------------------*/
- static struct nodestat *tologic(m,node)
- const struct lmod *m;
- node_t node;
- {
- struct nodestat *n;
-
- if (node.m == INVALIDNODE){
- node_t ground;
- ground.e = ground.m = ground.t = 0;
- error(bDANGER, "%u:(%u,%u,%u):internal error: invalid node\n",
- stats.iter[iTOTAL], node.e, node.t, node.m);
- return &(nstat[ground.m]);
- }
-
- n = &(nstat[node.m]);
- if (!m){
- m = n->family;
- }else if (!n->family){
- n->family = m;
- }
-
- if (n->nodemode == mDIGITAL){
- /* nothing */;
- }else{ /* n->nodemode == mANALOG */
- if (n->diter < n->aiter){
- double newv;
- double sv;
- int oldstate;
- node_t ground;
-
- ground.e = ground.m = ground.t = 0;
- newv = tr_volts(node,ground);
- sv = newv / m->range;
-
- n->dt = trtime - n->lastchange;
- oldstate = n->lv0;
-
- if (sv >= m->th1){
- n->lv0 = n->lv1 = YES;
- }else if (sv <= m->th0){
- n->lv0 = n->lv1 = NO;
- }else{ /* transition region */
- int lv1old = n->lv1;
- double oldv = tr_volts_t1(node,ground);
- double oldsv = oldv / m->range;
- double diff = sv - oldsv;
-
- if (diff > opt.abstol){ /* rising */
- n->lv1 = YES;
- if ((n->lv1 == lv1old)
- && (n->lv0 == n->lv1 || diff < n->dt/(m->mr * m->rise))){
- n->quality = qBAD; /* inflection or too slow */
- n->failuremode = "slow rise";
- }
- }else if (diff < -opt.abstol){ /* falling */
- n->lv1 = NO;
- if ((n->lv1 == lv1old)
- && (n->lv0 == n->lv1 || -diff < n->dt/(m->mf * m->fall))){
- n->quality = qBAD; /* inflection or too slow */
- n->failuremode = "slow fall";
- }
- }
- }
- if (sv > 1.+m->over || sv < -m->over){ /* out of range */
- n->quality = qBAD;
- n->failuremode = "out of range";
- }
- if (n->quality != qGOOD && n->lv0 != oldstate){
- ++n->quality;
- }
- n->family = m;
- n->diter = stats.iter[iTOTAL];
- n->lastchange = trtime;
- }else{
- }
- }
- if (m != n->family){
- n->quality = qBAD;
- n->failuremode = "family mismatch";
- }
- return n;
- }
- /*--------------------------------------------------------------------------*/
- static double toanalog(m,node)
- const struct lmod *m;
- node_t node;
- {
- struct nodestat *n;
-
- n = &(nstat[node.m]);
- if (!m){
- m = n->family;
- }else if (!n->family){
- n->family = m;
- }
-
- if (n->lv0 == n->lv1){
- return (n->lv0) ? m->vmax : m->vmin;
- }else if (trtime <= (n->finaltime - ((n->lv0)?(m->fall):(m->rise)))){
- return (n->lv0) ? m->vmax : m->vmin;
- }else if (trtime >= n->finaltime){
- return (n->lv1) ? m->vmax : m->vmin;
- }else{
- double start,end,interp;
- start = (n->lv0) ? m->vmax : m->vmin;
- end = (n->lv1) ? m->vmax : m->vmin;
- interp = (n->finaltime-trtime) / ((n->lv0)?(m->fall):(m->rise));
- return end - (end - start) * interp;
- }
- }
- /*--------------------------------------------------------------------------*/
- static double tr_review_logic(brh)
- branch_t *brh;
- {
- struct nodestat *n[PORTSPERGATE];
- struct logic *x;
- const struct lmod *m;
- int count; /* review */
- int lastchangenode = 0; /* review */
- int lastchangeiter = 0; /* review, once */
- int quality = qGOOD; /* both */
- char* failuremode = "default"; /* review & print */
-
- if (brh->iter == stats.iter[iTOTAL]){
- error(bDANGER, "%s:%u:%g internal error: skip review\n",
- printlabel(brh,0), stats.iter[iTOTAL], trtime);
- return BIGBIG;
- }else{
- brh->iter = stats.iter[iTOTAL];
- }
- x = (struct logic*)brh->x;
- m = x->m;
-
- for (count = 1;
- count < PORTSPERGATE && brh->n[count].e != INVALIDNODE;
- /**/ count++){
- n[count] = tologic(m,brh->n[count]);
- if (quality > n[count]->quality){
- quality = n[count]->quality;
- failuremode = n[count]->failuremode;
- }
- if (n[count]->diter >= lastchangeiter){
- lastchangeiter = n[count]->diter;
- lastchangenode = count;
- }
- }
-
- /* count == number of connections, now const */
- /* if lastchangenode == 1, no new changes, bypass */
-
- if ((opt.mode == mANALOG) || (opt.mode == mMIXED && quality != qGOOD)){
- if (x->gatemode == mDIGITAL){
- error(bTRACE, "%s:%u:%g switch to analog (review), %s\n",
- printlabel(brh,0), stats.iter[iTOTAL], trtime, failuremode);
- unloadpassive(brh);
- }
- x->gatemode = nstat[brh->n[1].m].nodemode = mANALOG;
- return tr_review_rl(brh->subckt);
- }
-
- /* if it gets here, either opt.mode == mMIXED && quality == qGOOD
- * or opt.mode == mDIGITAL
- */
-
- if (x->gatemode == mANALOG){
- error(bTRACE, "%s:%u:%g switch to digital (review)\n",
- printlabel(brh,0), stats.iter[iTOTAL], trtime);
- tr_unfill_rl(brh->subckt);
- }
- x->gatemode = n[1]->nodemode = mDIGITAL;
- brh->bypass = YES;
-
- if (!opt.bypass || lastchangenode!=1 || sim_phase==pINIT_DC){
- struct nodestat new;
- int ii;
- new = *n[1];
- brh->bypass = NO;
- switch (x->type){
- case lAND:
- new.lv1 = YES;
- for (ii = 2; ii < count; ii++)
- new.lv1 &= n[ii]->lv0;
- break;
- case lNAND:
- new.lv1 = YES;
- for (ii = 2; ii < count; ii++)
- new.lv1 &= n[ii]->lv0;
- new.lv1 = !new.lv1;
- break;
- case lOR:
- new.lv1 = NO;
- for (ii = 2; ii < count; ii++)
- new.lv1 |= n[ii]->lv0;
- break;
- case lNOR:
- new.lv1 = NO;
- for (ii = 2; ii < count; ii++)
- new.lv1 |= n[ii]->lv0;
- new.lv1 = !new.lv1;
- break;
- case lXOR:
- new.lv1 = n[2]->lv0 ^ n[3]->lv0;
- break;
- case lINV:
- new.lv1 = !n[2]->lv0;
- break;
- default:
- error(bWARNING,"%s: %s, bad logic type\n",printlabel(brh,NO),x->type);
- break;
- }
- if (new.lv1 != n[1]->lv1){
- if (new.finaltime != BIGBIG){ /* in transition */
- new.quality = qBAD;
- new.failuremode = "race";
- }
- new.diter = stats.iter[iTOTAL];
- new.finaltime = trtime + m->delay;
- error(bTRACE, "%s:%u:%g new event\n",
- printlabel(brh,0), stats.iter[iTOTAL], trtime);
- new_event(new.finaltime);
- new.lastchange = trtime;
- *n[1] = new;
- if (lastchangenode == 1){
- error(bDANGER, "%s:%u:%g non-event state change\n",
- printlabel(brh,0), stats.iter[iTOTAL], trtime);
- }
- }else if (lastchangenode != 1){
- error(bTRACE,"%s:%u:%g null transition\n",
- printlabel(brh,0), stats.iter[iTOTAL], trtime);
- }else{
- error(bTRACE,"%s:%u:%g null evaluation\n",
- printlabel(brh,0), stats.iter[iTOTAL], trtime);
- }
- }
- return BIGBIG;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/d_res.c'
- then
- echo shar: will not over-write existing file "'src/d_res.c'"
- else
- cat << \SHAR_EOF > 'src/d_res.c'
- /* dev_res.c 12/30/92
- * Copyright 1983-1992 Albert Davis
- * functions for resistor.
- * x = amps, y.f0 = volts, ev = y.f1 = ohms
- */
- #include "ecah.h"
- #include "branch.h"
- #include "convstat.h"
- #include "error.h"
- #include "mode.h"
- #include "options.h"
- #include "status.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- static branch_t *create_resistor(const branch_t*);
- static void parse_resistor(branch_t*,const char*,int*);
- static void print_resistor(const branch_t*,int,int);
- static void expand_resistor(branch_t*);
- static double trprobe_resistor(const branch_t*,const char*);
- static double acprobe_resistor(const branch_t*,const char*);
- static int tr_resistor_lin(branch_t*);
- static int tr_resistor_nl(branch_t*);
- static void un_resistor(branch_t*);
- static void ac_resistor_lin(branch_t*);
- static void ac_resistor_nl(branch_t*);
- /*--------------------------------------------------------------------------*/
- functions_t dev_resistor_lin = {
- sizeof(branch_t),
- create_resistor,
- parse_resistor,
- print_resistor,
- expand_resistor,
- trprobe_resistor,
- acprobe_resistor,
- tr_resistor_lin,
- un_resistor,
- ac_resistor_lin,
- (void(*)())NULL, /* trfun1 */
- (void(*)())NULL, /* trfun0 */
- (complex_t(*)())NULL,/* acfun */
- (void(*)())NULL, /* tr_guess */
- (void(*)())NULL, /* tr_advance */
- (double(*)())NULL, /* tr_review */
- };
- functions_t dev_resistor = {
- sizeof(branch_t),
- create_resistor,
- parse_resistor,
- print_resistor,
- expand_resistor,
- trprobe_resistor,
- acprobe_resistor,
- tr_resistor_nl,
- un_resistor,
- ac_resistor_nl,
- trfix1,
- trfix0,
- acfix,
- (void(*)())NULL, /* tr_guess */
- (void(*)())NULL, /* tr_advance */
- (double(*)())NULL /* tr_review */
- };
- /*--------------------------------------------------------------------------*/
- extern const struct options opt;
- extern const struct status stats;
- /*--------------------------------------------------------------------------*/
- static branch_t *create_resistor(proto)
- const branch_t *proto;
- {
- return createbranch(proto,(generic_t*)NULL,&dev_resistor);
- }
- /*--------------------------------------------------------------------------*/
- static void parse_resistor(brh,cmd,cnt)
- branch_t *brh;
- const char *cmd;
- int *cnt;
- {
- parsegeneric(brh,cmd,cnt,2);
- brh->f = &dev_resistor;
- }
- /*--------------------------------------------------------------------------*/
- static void print_resistor(brh,where,detail)
- const branch_t *brh;
- int where;
- int detail;
- {
- printgeneric(brh,where,detail);
- }
- /*--------------------------------------------------------------------------*/
- static void expand_resistor(brh)
- branch_t *brh;
- {
- if (!brh->x){
- brh->f = &dev_resistor_lin;
- if (brh->val == 0.){
- error(bPICKY, "%s: short circuit\n", printlabel(brh,NO));
- brh->ev = opt.shortckt;
- }else{
- brh->ev = brh->val;
- }
- brh->y0.f1 = brh->ev;
- brh->y0.f0 = LINEAR;
-
- brh->m0.f1 = 1./brh->ev;
- brh->m0.c0 = 0.;
- }
- }
- /*--------------------------------------------------------------------------*/
- static double trprobe_resistor(brh,what)
- const branch_t *brh;
- const char *what;
- {
- return trprobegeneric(brh,what);
- }
- /*--------------------------------------------------------------------------*/
- static double acprobe_resistor(brh,what)
- const branch_t *brh;
- const char *what;
- {
- return acprobegeneric(brh,what);
- }
- /*--------------------------------------------------------------------------*/
- static int tr_resistor_lin(brh)
- branch_t *brh;
- {
- if (brh->iter == stats.iter[iTOTAL]){
- return brh->status;
- }else{
- brh->iter = stats.iter[iTOTAL];
- }
- trloadpassive(brh);
- return brh->status = cGOOD;
- }
- /*--------------------------------------------------------------------------*/
- static int tr_resistor_nl(brh)
- branch_t *brh;
- {
- if (brh->iter == stats.iter[iTOTAL]){
- return brh->status;
- }else{
- brh->iter = stats.iter[iTOTAL];
- }
- trsetup(brh);
- brh->m0.x = tr_volts_limited(brh->n[OUT1],brh->n[OUT2]);
- brh->y0.x = brh->m0.c0 + brh->m0.f1 * brh->m0.x;
-
- if (brh->f->trfun1){
- (*brh->f->trfun1)(brh);
- }else{
- brh->y0.f1 = brh->val;
- brh->y0.f0 = LINEAR;
- }
- if (brh->y0.f1 == 0.){
- error(bPICKY, "%s: short circuit\n", printlabel(brh,NO));
- brh->y0.f1 = opt.shortckt;
- }
- brh->ev = brh->y0.f1;
- brh->m0.f1 = 1./brh->y0.f1;
- brh->m0.c0 = brh->y0.x - brh->y0.f0 / brh->y0.f1;
-
- trloadpassive(brh);
- return brh->status = conv_check(brh);
- }
- /*--------------------------------------------------------------------------*/
- static void un_resistor(brh)
- branch_t *brh;
- {
- unloadpassive(brh);
- }
- /*--------------------------------------------------------------------------*/
- static void ac_resistor_lin(brh)
- branch_t *brh;
- {
- brh->acg.x = brh->m0.f1;
- brh->acg.y = 0.;
- acloadpassivereal(brh);
- }
- /*--------------------------------------------------------------------------*/
- static void ac_resistor_nl(brh)
- branch_t *brh;
- {
- double dcvolts;
-
- if (brh->f->acfun){
- dcvolts = dc_volts(brh->n[OUT1],brh->n[OUT2]);
- brh->acbias = brh->m0.c0 + brh->m0.f1*dcvolts;
- brh->acg = (*brh->f->acfun)(brh);
- if (brh->acg.y == 0.){
- if (brh->acg.x == 0.){
- error(bPICKY, "%s: short circuit\n", printlabel(brh,NO));
- brh->acg.x = opt.shortckt;
- }
- brh->acg.x = 1. / brh->acg.x;
- }else{
- brh->acg = cflip(brh->acg);
- }
- acloadpassive(brh);
- }else{
- brh->acg.x = brh->m0.f1; /* == 1/ev */
- brh->acg.y = 0.;
- acloadpassivereal(brh);
- }
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/d_subckt.c'
- then
- echo shar: will not over-write existing file "'src/d_subckt.c'"
- else
- cat << \SHAR_EOF > 'src/d_subckt.c'
- /* dev_subc.c 12/30/92
- * Copyright 1983-1992 Albert Davis
- * subcircuit stuff
- * netlist syntax:
- * device: Xxxxx <nodelist> <subckt-name>
- * model: .subckt <subckt-name> <nodelist>
- * (device cards)
- * .ends <subckt-name>
- */
- #include "ecah.h"
- #include "branch.h"
- #include "dev.h"
- #include "d_subckt.h"
- #include "error.h"
- #include "mode.h"
- #include "status.h"
- #include "types.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void cmd_ends(const char*,int*);
- static branch_t *create_subckt(const branch_t*);
- static void parse_subckt(branch_t*,const char*,int*);
- static void print_subckt(const branch_t*,int,int);
- static branch_t *create_model_subckt(const branch_t*);
- static void parse_model_subckt(branch_t*,const char*,int*);
- static void print_model_subckt(const branch_t*,int,int);
- static void expand_subckt(branch_t*);
- void expandsubckt(branch_t*,const char*);
- static double trprobe_subckt(const branch_t*,const char*);
- static int tr_subckt(branch_t*);
- static void un_subckt(branch_t*);
- static void ac_subckt(branch_t*);
- static double tr_review_subckt(branch_t*);
- /*--------------------------------------------------------------------------*/
- functions_t dev_subckt = {
- sizeof(branch_t),
- create_subckt,
- parse_subckt,
- print_subckt,
- expand_subckt,
- trprobe_subckt,
- (double(*)())NULL,/* acprobe */
- tr_subckt,
- un_subckt,
- ac_subckt,
- (void(*)())NULL, /* trfun1 */
- (void(*)())NULL, /* trfun0 */
- (complex_t(*)())NULL,/* acfun */
- (void(*)())NULL, /* tr_guess */
- (void(*)())NULL, /* tr_advance */
- tr_review_subckt
- };
- functions_t model_subckt = {
- sizeof(branch_t),
- create_model_subckt,
- parse_model_subckt,
- print_model_subckt,
- (void(*)())NULL, /* expand */
- (double(*)())NULL, /* trprobe */
- (double(*)())NULL,/* acprobe */
- (int(*)())NULL, /* dotr */
- (void(*)())NULL, /* untr */
- (void(*)())NULL, /* doac */
- (void(*)())NULL, /* trfun1 */
- (void(*)())NULL, /* trfun0 */
- (complex_t(*)())NULL,/* acfun */
- (void(*)())NULL, /* tr_guess */
- (void(*)())NULL, /* tr_advance */
- (double(*)())NULL /* tr_review */
- };
- /*--------------------------------------------------------------------------*/
- static struct subckt defalt =
- {(generic_t*)NULL, sizeof(struct subckt),
- (generic_t*)NULL, sDEFAULT_modelname, INVALIDNODE};
- static struct smod defaltmodel =
- {(generic_t*)NULL, sizeof(struct smod),
- (generic_t*)NULL, sDEFAULT_modelname, INVALIDNODE};
- static branch_t modellist = {(generic_t*)NULL, sizeof(branch_t), &model_subckt,
- &modellist, &modellist, &modellist, &modellist, (branch_t*)NULL,
- (branch_t*)NULL, sDEFAULT_modelname, /* more */};
- static branch_t *(neststack[RECURSE]);
- static char namestack[LABELEN+1][RECURSE];
- static int nestlevel;
-
- extern branch_t *insertbefore;
- extern const struct status stats;
- extern const char e_int[];
- /*--------------------------------------------------------------------------*/
- void cmd_ends(cmd,cnt)
- const char* cmd;
- int *cnt;
- {
- if (nestlevel == 0)
- error(bWARNING, "ends not in subckt\n");
- else
- nestlevel--;
-
- if (cmd[*cnt]){
- if (!pmatch(cmd, cnt, namestack[nestlevel]))
- error(bERROR, "ends tag [%s] does not match subckt [%s]\n",
- &cmd[*cnt], namestack[nestlevel]);
- }else{
- nestlevel = 0;
- }
- insertbefore = neststack[nestlevel];
- }
- /*--------------------------------------------------------------------------*/
- static branch_t *create_subckt(proto)
- const branch_t *proto;
- {
- branch_t *brh;
- struct subckt *x;
-
- brh = createbranch(proto,(generic_t*)&defalt,&dev_subckt);
- x = (struct subckt*)brh->x;
- brh->n = x->n;
- return brh;
- }
- /*--------------------------------------------------------------------------*/
- static void parse_subckt(brh,cmd,cnt)
- branch_t *brh;
- const char *cmd;
- int *cnt;
- {
- struct subckt *x;
- x = (struct subckt*)brh->x;
-
- parselabel(brh,cmd,cnt);
- (void)parsenodes(brh,cmd,cnt,PORTSPERSUBCKT);
- (void)ctostr(cmd, cnt, x->modelname, LABELEN);
- }
- /*--------------------------------------------------------------------------*/
- static void print_subckt(brh,where,detail)
- const branch_t *brh;
- int where;
- int detail;
- {
- struct subckt *x;
- x = (struct subckt*)brh->x;
-
- (void)printlabel(brh,where);
- printnodes(brh,where);
- mprintf(where, " %s\n", x->modelname);
- }
- /*--------------------------------------------------------------------------*/
- static branch_t *create_model_subckt(proto)
- const branch_t *proto;
- {
- branch_t *brh;
- struct smod *x;
-
- brh = createbranch(proto,(generic_t*)&defaltmodel,&model_subckt);
- x = (struct smod*)brh->x;
- brh->n = x->n;
- brh->stprev = &modellist;
- return brh;
- }
- /*--------------------------------------------------------------------------*/
- static void parse_model_subckt(brh,cmd,cnt)
- branch_t *brh;
- const char *cmd;
- int *cnt;
- {
- struct smod *m;
- m = (struct smod*)brh->x;
-
- if (nestlevel >= RECURSE)
- error(bERROR,"%s: subckt nesting too deep\n", printlabel(brh,NO));
-
- (void)ctostr(cmd, cnt, brh->label, LABELEN);
- (void)parsenodes(brh,cmd,cnt,PORTSPERSUBCKT);
-
- strcpy(namestack[nestlevel], brh->label);
- neststack[nestlevel] = insertbefore;
- nestlevel++;
- brh->subckt = insertbefore =
- insertbranch((*(dev_comment.create))((branch_t*)NULL));
- m->x = (generic_t*)NULL;
- }
- /*--------------------------------------------------------------------------*/
- static void print_model_subckt(brh,where,detail)
- const branch_t *brh;
- int where;
- int detail;
- {
- branch_t *x, *stop;
-
- mprintf(where, ".subckt %s ", brh->label);
- printnodes(brh,where);
- mprintf(where, "\n");
-
- x = stop = brh->subckt;
- if (x){
- do {
- print_branch(x, where, NO);
- } while (x = x->next, x != stop);
- }
- mprintf(where, "*+ends %s\n", brh->label);
- }
- /*--------------------------------------------------------------------------*/
- static void expand_subckt(brh)
- branch_t *brh;
- {
- struct subckt *x;
- x = (struct subckt*)brh->x;
- expandsubckt(brh,x->modelname);
- if (!brh->subckt){
- error(bERROR, "");
- }
- brh->tracesubckt = YES;
- }
- /*--------------------------------------------------------------------------*/
- void expandsubckt(brh,modelname)
- branch_t *brh;
- const char *modelname;
- {
- const branch_t *model;
- /*struct subckt *x;*/
- branch_t *scan;
- branch_t *stop;
- int port, i;
- int map[NODESPERSUBCKT];
-
- /*x = (struct subckt*)brh->x;*/
- model = &modellist; /* search for thing to copy */
- for (;;){
- model = model->stnext;
- if (wmatch(modelname, model->label)){
- break;
- }else if (model == &modellist){
- error(bDANGER, "%s: can't find model: %s\n",
- printlabel(brh,NO), modelname);
- if (brh->subckt){
- error(bERROR, e_int, "subckt exists but has no def\n");
- }else{
- return;
- }
- }
- }
-
- for (i = 0; i < NODESPERSUBCKT; i++) /* initialize: all nodes unused */
- map[i] = UNUSED;
-
- stop = scan = nextbranch_dev(model->subckt);
- do { /* scan elements of subckt */
- int ii; /* mark nodes used */
- for (ii = 0; scan->n[ii].e != INVALIDNODE; ii++){
- if (scan->n[ii].e > NODESPERSUBCKT)
- error(bERROR, "%s: too many internal nodes\n", model->label);
- map[scan->n[ii].e] = USED;
- }
- } while (scan=nextbranch_dev(scan), scan != stop);
-
- map[0] = 0;
- for (port = 0; model->n[port].e != INVALIDNODE; port++){ /* map ports */
- if (model->n[port].e > NODESPERSUBCKT)
- error(bERROR, "internal error: subckt node out of range: %s\n",
- model->label);
- map[model->n[port].e] = brh->n[port].t;
- }
-
- for (i = 0; i < NODESPERSUBCKT; i++){
- if (map[i] == USED){
- map[i] = newnode_subckt(); /* assign number to internal nodes */
- }
- }
-
- if (!brh->subckt){
- error(bTRACE, "%s: expanding\n", printlabel(brh,NO));
- stop = scan = nextbranch_dev(model->subckt);
- do {
- branch_t *scratch; /* copy subckt */
- scratch = create_branch(scan);
- scratch->parent = brh;
- scratch->next = brh->subckt;
- brh->subckt = insertbranch(scratch);
- } while (scan=nextbranch_dev(scan), scan != stop);
- }else{
- error(bTRACE, "%s: re-expanding\n", printlabel(brh,NO));
- }
-
- stop = scan = nextbranch_dev(brh->subckt);
- do { /* patch nodes */
- int ii;
- for (ii = 0; scan->n[ii].e != INVALIDNODE; ii++){
- if (scan->n[ii].e < 0)
- error(bERROR, e_int, "bad node");
- if (map[scan->n[ii].e] < 0)
- error(bERROR, e_int, "node map");
- scan->n[ii].t = map[scan->n[ii].e];
- }
- scan->n[ii].t = INVALIDNODE;
- } while (scan=nextbranch_dev(scan), scan != stop);
- }
- /*--------------------------------------------------------------------------*/
- static double trprobe_subckt(brh,what)
- const branch_t *brh;
- const char *what;
- {
- struct subckt *x;
- int dummy = 0;
-
- x = (struct subckt*)brh->x;
- if (!brh->subckt)
- error(bERROR, "internal error: %s not expanded\n", printlabel(brh,NO));
-
- setmatch(what,&dummy);
- if (rematch("P")){
- branch_t *pb, *stop;
- double power = 0.;
- stop = pb = brh->subckt;
- do {
- power += trprobe_branch(pb,"P");
- } while (pb=nextbranch_dev(pb), pb != stop);
- return power;
- }else{ /* bad parameter */
- return NOT_VALID;
- }
- /*NOTREACHED*/
- }
- /*--------------------------------------------------------------------------*/
- static int tr_subckt(brh)
- branch_t *brh;
- {
- if (brh->iter == stats.iter[iTOTAL]){
- return brh->status;
- }else{
- brh->iter = stats.iter[iTOTAL];
- }
- if (!brh->subckt)
- error(bERROR, "internal error: %s not expanded\n", printlabel(brh,NO));
- return brh->status = tr_fill_rl(brh->subckt);
- }
- /*--------------------------------------------------------------------------*/
- static void un_subckt(brh)
- branch_t *brh;
- {
- tr_unfill_rl(brh->subckt);
- }
- /*--------------------------------------------------------------------------*/
- static void ac_subckt(brh)
- branch_t *brh;
- {
- if (!brh->subckt)
- error(bERROR, "internal error: %s not expanded\n", printlabel(brh,NO));
- ac_fill_rl(brh->subckt);
- }
- /*--------------------------------------------------------------------------*/
- static double tr_review_subckt(brh)
- branch_t *brh;
- {
- return tr_review_rl(brh->subckt);
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/d_trln.c'
- then
- echo shar: will not over-write existing file "'src/d_trln.c'"
- else
- cat << \SHAR_EOF > 'src/d_trln.c'
- /* dev_trln 12/30/92
- * Copyright 1983-1992 Albert Davis
- * Transmission line. (ideal lossless. for now, AC only)
- */
- #include "ecah.h"
- #include "ac.h"
- #include "argparse.h"
- #include "branch.h"
- #include "d_trln.h"
- #include "error.h"
- #include "mode.h"
- #include "status.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- static branch_t *create_trnlin(const branch_t*);
- static void parse_trnlin(branch_t*,const char*,int*);
- static void setinitcond(const char*,int*);
- static void print_trnlin(const branch_t*,int,int);
- static int tr_trnlin(branch_t*);
- static void ac_trnlin(branch_t*);
- /*--------------------------------------------------------------------------*/
- functions_t dev_trnlin = {
- sizeof(branch_t),
- create_trnlin,
- parse_trnlin,
- print_trnlin,
- (void(*)())NULL, /* expand */
- (double(*)())NULL, /* trprobe */
- (double(*)())NULL, /* acprobe */
- tr_trnlin,
- (void(*)())NULL, /* untr */
- ac_trnlin,
- (void(*)())NULL, /* trfun1 */
- (void(*)())NULL, /* trfun0 */
- (complex_t(*)())NULL,/* acfun */
- (void(*)())NULL, /* tr_guess */
- (void(*)())NULL, /* tr_advance */
- (double(*)())NULL /* tr_review */
- };
- /*--------------------------------------------------------------------------*/
- #define LINLENTOL .000001
- extern const ac_t ac;
- extern const struct status stats;
-
- static struct trnlin *x;
- static struct trnlin defalt = {(generic_t*)NULL, sizeof(struct trnlin),
- DEFAULT_Z0, DEFAULT_TD, DEFAULT_F, DEFAULT_NL, {0.,0.,0.,0.}, 0., NO};
- /*--------------------------------------------------------------------------*/
- static branch_t *create_trnlin(proto)
- const branch_t* proto;
- {
- return createbranch(proto,(generic_t*)&defalt,&dev_trnlin);
- }
- /*--------------------------------------------------------------------------*/
- /* parse_trnlin: parse input for transmission line, set up branch structure
- */
- static void parse_trnlin(brh,cmd,cnt)
- branch_t *brh;
- const char *cmd;
- int *cnt;
- {
- x = (struct trnlin*)brh->x;
-
- parselabel(brh,cmd,cnt);
- (void)parsenodes(brh,cmd,cnt,4);
- for (;;){
- if (argparse(cmd,cnt,REPEAT,
- "Z", a2DOUBLE, &x->z0, &x->z0,
- "Freq", aUDOUBLE, &x->f,
- "Nl", aUDOUBLE, &x->nl,
- "Ic", aFUNCTION, setinitcond,
- ""))
- ;
- else{
- syntax(cmd,cnt,bWARNING);
- break;
- }
- }
- if (x->nl == 0.)
- x->nl = DEFAULT_NL;
- x->reson = x->f * (.25 / x->nl);
- }
- /*--------------------------------------------------------------------------*/
- /* setinitcond: set initial conditions
- * called indirectly thru argparse
- * reads NUM_INIT_COND args, put them in static struct x.
- * passed this way because of inability of argparse to return values,
- * and that only cmd and cnt are passed by argparse
- */
- static void setinitcond(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- int i;
- x->icset = YES;
- for (i=0; i<NUM_INIT_COND; i++)
- x->ic[i] = ctof(cmd,cnt);
- }
- /*--------------------------------------------------------------------------*/
- /* print_trnlin: print (to "where") the transmission line data structure
- */
- static void print_trnlin(brh,where,detail)
- const branch_t *brh;
- int where;
- int detail;
- {
- struct trnlin *x;
- (void)printlabel(brh,where);
- printnodes(brh,where);
- x = (struct trnlin*)brh->x;
- mprintf(where, " Z0=%s F=%s NL=%s",
- ftos(x->z0, "", 7, 0),
- ftos(x->f, "", 7, 0),
- ftos(x->nl, "", 7, 0));
- if (x->icset){
- int i;
- mprintf(where, " IC=");
- for (i=0; i<NUM_INIT_COND; i++)
- mprintf(where, "%s ",ftos(x->ic[i],"", 7, 0));
- }
- mputc('\n', where);
- }
- /*--------------------------------------------------------------------------*/
- /* tr_trnlin: transmission line for transient analysis
- * stub: doesn't work
- * always returns failure
- */
- static int tr_trnlin(brh)
- branch_t *brh;
- {
- if (brh->iter == stats.iter[iTOTAL]){
- return brh->status;
- }else{
- brh->iter = stats.iter[iTOTAL];
- }
- error(bWARNING, "%s: no transmission line in dc or transient\n",
- printlabel(brh,NO));
- return brh->status = NO;
- }
- /*--------------------------------------------------------------------------*/
- /* ac_trnlin: transmission line procesing for AC analysis
- */
- static void ac_trnlin(brh)
- branch_t *brh;
- {
- double y11, y12; /* equivalent y parameters (y22, y21 are same) */
- double lenth; /* length, first in quarter waves, then radians */
- double dif; /* difference between actual length and resonance */
- struct trnlin *x;
-
- x = (struct trnlin*)brh->x;
-
- lenth = ac.freq / x->reson;
- dif = lenth - floor(lenth+.5);
- if (fabs(dif) < LINLENTOL){
- error(bPICKY,
- "%s: transmission line too close to resonance\n", printlabel(brh,NO));
- lenth = (dif<0.) ? floor(lenth+.5)-LINLENTOL : floor(lenth+.5)+LINLENTOL;
- }
- lenth *= (PId2); /* now in radians */
-
- y12 = -1 / ( x->z0 * sin(lenth) );
- y11 = tan(lenth/2) / x->z0 + y12;
-
- *im(brh->n[OUT1].m,brh->n[OUT1].m) += y11;
- *im(brh->n[OUT2].m,brh->n[OUT2].m) += y11;
- *im(brh->n[OUT1].m,brh->n[OUT2].m) -= y11;
- *im(brh->n[OUT2].m,brh->n[OUT1].m) -= y11;
-
- *im(brh->n[IN1].m,brh->n[IN1].m) += y11;
- *im(brh->n[IN2].m,brh->n[IN2].m) += y11;
- *im(brh->n[IN1].m,brh->n[IN2].m) -= y11;
- *im(brh->n[IN2].m,brh->n[IN1].m) -= y11;
-
- *im(brh->n[OUT1].m,brh->n[IN1].m) -= y12;
- *im(brh->n[OUT2].m,brh->n[IN2].m) -= y12;
- *im(brh->n[OUT1].m,brh->n[IN2].m) += y12;
- *im(brh->n[OUT2].m,brh->n[IN1].m) += y12;
-
- *im(brh->n[IN1].m,brh->n[OUT1].m) -= y12;
- *im(brh->n[IN2].m,brh->n[OUT2].m) -= y12;
- *im(brh->n[IN1].m,brh->n[OUT2].m) += y12;
- *im(brh->n[IN2].m,brh->n[OUT1].m) += y12;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/d_vccs.c'
- then
- echo shar: will not over-write existing file "'src/d_vccs.c'"
- else
- cat << \SHAR_EOF > 'src/d_vccs.c'
- /* dev_vccs 12/30/92
- * Copyright 1983-1992 Albert Davis
- * functions for vccs
- */
- #include "ecah.h"
- #include "branch.h"
- #include "mode.h"
- #include "status.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- static branch_t *create_vccs(const branch_t*);
- static void parse_vccs(branch_t*,const char*,int*);
- static void print_vccs(const branch_t*,int,int);
- static double trprobe_vccs(const branch_t*,const char*);
- static double acprobe_vccs(const branch_t*,const char*);
- static int tr_vccs(branch_t*);
- static void un_vccs(branch_t*);
- static void ac_vccs(branch_t*);
- /*--------------------------------------------------------------------------*/
- functions_t dev_vccs = {
- sizeof(branch_t),
- create_vccs,
- parse_vccs,
- print_vccs,
- (void(*)())NULL, /* expand */
- trprobe_vccs,
- acprobe_vccs,
- tr_vccs,
- un_vccs,
- ac_vccs,
- trfix1,
- trfix0,
- acfix,
- (void(*)())NULL, /* tr_guess */
- (void(*)())NULL, /* tr_advance */
- (double(*)())NULL /* tr_review */
- };
- /*--------------------------------------------------------------------------*/
- extern const struct status stats;
- /*--------------------------------------------------------------------------*/
- static branch_t *create_vccs(proto)
- const branch_t *proto;
- {
- return createbranch(proto,(generic_t*)NULL,&dev_vccs);
- }
- /*--------------------------------------------------------------------------*/
- static void parse_vccs(brh,cmd,cnt)
- branch_t *brh;
- const char *cmd;
- int *cnt;
- {
- parsegeneric(brh,cmd,cnt,4);
- }
- /*--------------------------------------------------------------------------*/
- static void print_vccs(brh,where,detail)
- const branch_t *brh;
- int where;
- int detail;
- {
- printgeneric(brh,where,detail);
- }
- /*--------------------------------------------------------------------------*/
- static double trprobe_vccs(brh,what)
- const branch_t *brh;
- const char *what;
- {
- return trprobegeneric(brh,what);
- }
- /*--------------------------------------------------------------------------*/
- static double acprobe_vccs(brh,what)
- const branch_t *brh;
- const char *what;
- {
- return acprobegeneric(brh,what);
- }
- /*--------------------------------------------------------------------------*/
- static int tr_vccs(brh)
- branch_t *brh;
- {
- if (brh->iter == stats.iter[iTOTAL]){
- return brh->status;
- }else{
- brh->iter = stats.iter[iTOTAL];
- }
- trsetup(brh);
- brh->m0.x = tr_volts_limited(brh->n[IN1],brh->n[IN2]);
- brh->y0.x = brh->m0.x;
- if (brh->f->trfun1){
- (*brh->f->trfun1)(brh);
- }else{
- brh->y0.f1 = brh->val;
- brh->y0.f0 = LINEAR;
- }
- brh->ev = brh->y0.f1;
- brh->m0.x = brh->y0.x;
- brh->m0.c0 = brh->y0.f0 - brh->y0.x * brh->y0.f1;
- brh->m0.f1 = brh->y0.f1;
- trloadactive(brh);
- return brh->status = conv_check(brh);
- }
- /*--------------------------------------------------------------------------*/
- static void un_vccs(brh)
- branch_t *brh;
- {
- unloadactive(brh);
- }
- /*--------------------------------------------------------------------------*/
- static void ac_vccs(brh)
- branch_t *brh;
- {
- if (brh->f->acfun){
- brh->acbias = dc_volts(brh->n[IN1],brh->n[IN2]);
- brh->acg = (*brh->f->acfun)(brh);
- }else{
- brh->acg.x = brh->ev;
- brh->acg.y = 0.;
- }
- acloadactive(brh);
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/d_vcvs.c'
- then
- echo shar: will not over-write existing file "'src/d_vcvs.c'"
- else
- cat << \SHAR_EOF > 'src/d_vcvs.c'
- /* dev_vcvs 12/30/92
- * Copyright 1983-1992 Albert Davis
- * functions for vcvs
- * temporary kluge: it has resistance
- * BUG: doesn't work in incmode
- */
- #include "ecah.h"
- #include "branch.h"
- #include "mode.h"
- #include "options.h"
- #include "status.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- static branch_t *create_vcvs(const branch_t*);
- static void parse_vcvs(branch_t*,const char*,int*);
- static void print_vcvs(const branch_t*,int,int);
- static double trprobe_vcvs(const branch_t*,const char*);
- static double acprobe_vcvs(const branch_t*,const char*);
- static int tr_vcvs(branch_t*);
- static void un_vcvs(branch_t*);
- static void ac_vcvs(branch_t*);
- /*--------------------------------------------------------------------------*/
- functions_t dev_vcvs = {
- sizeof(branch_t),
- create_vcvs,
- parse_vcvs,
- print_vcvs,
- (void(*)())NULL, /* expand */
- trprobe_vcvs,
- acprobe_vcvs,
- tr_vcvs,
- un_vcvs,
- ac_vcvs,
- trfix1,
- trfix0,
- acfix,
- (void(*)())NULL, /* tr_guess */
- (void(*)())NULL, /* tr_advance */
- (double(*)())NULL /* tr_review */
- };
- /*--------------------------------------------------------------------------*/
- extern const struct options opt;
- extern const struct status stats;
- static branch_t resistor = {(generic_t*)NULL, sizeof(branch_t),
- (functions_t*)NULL, (branch_t*)NULL, (branch_t*)NULL, (branch_t*)NULL,
- (branch_t*)NULL, /*more*/};
- /*--------------------------------------------------------------------------*/
- static branch_t *create_vcvs(proto)
- const branch_t *proto;
- {
- return createbranch(proto,(generic_t*)NULL,&dev_vcvs);
- }
- /*--------------------------------------------------------------------------*/
- static void parse_vcvs(brh,cmd,cnt)
- branch_t *brh;
- const char *cmd;
- int *cnt;
- {
- parsegeneric(brh,cmd,cnt,4);
- }
- /*--------------------------------------------------------------------------*/
- static void print_vcvs(brh,where,detail)
- const branch_t *brh;
- int where;
- int detail;
- {
- printgeneric(brh,where,detail);
- }
- /*--------------------------------------------------------------------------*/
- static double trprobe_vcvs(brh,what)
- const branch_t *brh;
- const char *what;
- {
- return trprobegeneric(brh,what);
- }
- /*--------------------------------------------------------------------------*/
- static double acprobe_vcvs(brh,what)
- const branch_t *brh;
- const char *what;
- {
- return acprobegeneric(brh,what);
- }
- /*--------------------------------------------------------------------------*/
- static int tr_vcvs(brh)
- branch_t *brh;
- {
- if (brh->iter == stats.iter[iTOTAL]){
- return brh->status;
- }else{
- brh->iter = stats.iter[iTOTAL];
- }
- trsetup(brh);
-
- resistor.n = brh->n;
- resistor.loaditer = 0;
- resistor.y0.f1 = 1./opt.shortckt; /* load the resistor */
- resistor.y0.f0 = LINEAR; /* a big fudge */
- resistor.m0.x = resistor.y0.x;
- resistor.m0.c0 = 0.;
- resistor.m0.f1 = resistor.y0.f1;
- trloadpassive(&resistor);
-
- /* then do vccs */
- brh->m0.x = tr_volts_limited(brh->n[IN1],brh->n[IN2]);
- brh->y0.x = brh->m0.x;
- if (brh->f->trfun1){
- (*brh->f->trfun1)(brh);
- }else{
- brh->y0.f1 = brh->val;
- brh->y0.f0 = LINEAR;
- }
- brh->ev = brh->y0.f1;
- brh->m0.f1 = brh->y0.f1 / -opt.shortckt;
- brh->m0.c0 = (brh->y0.f0 - brh->y0.x * brh->y0.f1) / -opt.shortckt;
- trloadactive(brh);
- return brh->status = conv_check(brh);
- }
- /*--------------------------------------------------------------------------*/
- static void un_vcvs(brh)
- branch_t *brh;
- {
- unloadactive(brh);
- }
- /*--------------------------------------------------------------------------*/
- static void ac_vcvs(brh)
- branch_t *brh;
- {
- brh->acg.x = 1./opt.shortckt;
- brh->acg.y = 0.;
- acloadpassivereal(brh);
-
- if (brh->f->acfun){
- brh->acbias = dc_volts(brh->n[IN1],brh->n[IN2]);
- brh->acg = (*brh->f->acfun)(brh);
- brh->acg.x /= -opt.shortckt;
- brh->acg.y /= -opt.shortckt;
- }else{
- brh->acg.x = brh->ev / -opt.shortckt;
- brh->acg.y = 0.;
- }
- acloadactive(brh);
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/d_vs.c'
- then
- echo shar: will not over-write existing file "'src/d_vs.c'"
- else
- cat << \SHAR_EOF > 'src/d_vs.c'
- /* dev_vs.c 12/30/92
- * Copyright 1983-1992 Albert Davis
- * functions for fixed voltage sources
- * temporary kluge: it has resistance
- */
- #include "ecah.h"
- #include "branch.h"
- #include "mode.h"
- #include "options.h"
- #include "status.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- static branch_t *create_vs(const branch_t*);
- static void parse_vs(branch_t*,const char*,int*);
- static void print_vs(const branch_t*,int,int);
- static double trprobe_vs(const branch_t*,const char*);
- static double acprobe_vs(const branch_t*,const char*);
- static int tr_vs(branch_t*);
- static void un_vs(branch_t*);
- static void ac_vs(branch_t*);
- /*--------------------------------------------------------------------------*/
- functions_t dev_vs = {
- sizeof(branch_t),
- create_vs,
- parse_vs,
- print_vs,
- (void(*)())NULL, /* expand */
- trprobe_vs,
- acprobe_vs,
- tr_vs,
- un_vs,
- ac_vs,
- trfix1,
- trfix0,
- acfix,
- (void(*)())NULL, /* tr_guess */
- (void(*)())NULL, /* tr_advance */
- (double(*)())NULL /* tr_review */
- };
- /*--------------------------------------------------------------------------*/
- extern const struct options opt;
- extern const struct status stats;
- /*--------------------------------------------------------------------------*/
- static branch_t *create_vs(proto)
- const branch_t *proto;
- {
- return createbranch(proto,(generic_t*)NULL,&dev_vs);
- }
- /*--------------------------------------------------------------------------*/
- static void parse_vs(brh,cmd,cnt)
- branch_t *brh;
- const char *cmd;
- int *cnt;
- {
- parsegeneric(brh,cmd,cnt,2);
- }
- /*--------------------------------------------------------------------------*/
- static void print_vs(brh,where,detail)
- const branch_t *brh;
- int where;
- int detail;
- {
- printgeneric(brh,where,detail);
- }
- /*--------------------------------------------------------------------------*/
- static double trprobe_vs(brh,what)
- const branch_t *brh;
- const char *what;
- {
- return trprobegeneric(brh,what);
- }
- /*--------------------------------------------------------------------------*/
- static double acprobe_vs(brh,what)
- const branch_t *brh;
- const char *what;
- {
- return acprobegeneric(brh,what);
- }
- /*--------------------------------------------------------------------------*/
- static int tr_vs(brh)
- branch_t *brh;
- {
- if (brh->iter == stats.iter[iTOTAL]){
- return brh->status;
- }else{
- brh->iter = stats.iter[iTOTAL];
- }
- trsetup(brh);
- brh->m0.x = 0.;
- brh->y0.x = 0.;
- if (brh->f->trfun1){
- (*brh->f->trfun1)(brh);
- }else{
- brh->y0.f1 = brh->val;
- brh->y0.f0 = 0.;
- }
- brh->ev = brh->y0.f1;
- brh->m0.f1 = 1./opt.shortckt;
- brh->m0.c0 = brh->y0.f1 / -opt.shortckt;
-
- trloadpassive(brh);
- return brh->status = conv_check(brh);
- }
- /*--------------------------------------------------------------------------*/
- static void un_vs(brh)
- branch_t *brh;
- {
- unloadpassive(brh);
- }
- /*--------------------------------------------------------------------------*/
- static void ac_vs(brh)
- branch_t *brh;
- {
- brh->acg.x = 1./opt.shortckt;
- brh->acg.y = 0.;
- acloadpassivereal(brh);
-
- if (brh->f->acfun){
- brh->acbias = 0.;
- brh->acg = (*brh->f->acfun)(brh);
- brh->acg.x /= -opt.shortckt;
- brh->acg.y /= -opt.shortckt;
- }else{
- brh->acg.x = brh->ev / -opt.shortckt;
- brh->acg.y = 0.;
- }
- acloadsource(brh);
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- # End of shell archive
- exit 0
-