From b6b76ad035e695f3ce739d18ead8a96bc56019c2 Mon Sep 17 00:00:00 2001 From: rlar Date: Sun, 12 Apr 2015 21:01:44 +0200 Subject: [PATCH] devices/asrc, introduce `ASRCvars' with the indices of the controlling nodes/branches --- src/spicelib/devices/asrc/asrcconv.c | 8 +------- src/spicelib/devices/asrc/asrcdefs.h | 1 + src/spicelib/devices/asrc/asrcdest.c | 2 ++ src/spicelib/devices/asrc/asrcload.c | 8 +------- src/spicelib/devices/asrc/asrcset.c | 3 +++ 5 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/spicelib/devices/asrc/asrcconv.c b/src/spicelib/devices/asrc/asrcconv.c index 781bd261a..05d0ace5a 100644 --- a/src/spicelib/devices/asrc/asrcconv.c +++ b/src/spicelib/devices/asrc/asrcconv.c @@ -36,13 +36,7 @@ ASRCconvTest(GENmodel *inModel, CKTcircuit *ckt) } 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]; - } + asrc_vals[i] = ckt->CKTrhsOld[here->ASRCvars[i]]; if (here->ASRCtree->IFeval(here->ASRCtree, ckt->CKTgmin, &rhs, asrc_vals, asrc_derivs) != OK) diff --git a/src/spicelib/devices/asrc/asrcdefs.h b/src/spicelib/devices/asrc/asrcdefs.h index d402fded4..93bdef553 100644 --- a/src/spicelib/devices/asrc/asrcdefs.h +++ b/src/spicelib/devices/asrc/asrcdefs.h @@ -29,6 +29,7 @@ typedef struct sASRCinstance { int ASRCtype; /* Whether source is voltage or current */ int ASRCbranch; /* number of branch equation added for v source */ IFparseTree *ASRCtree; /* The parse tree */ + int *ASRCvars; /* indices of the controlling nodes/branches */ double ASRCtemp; /* temperature at which this resistor operates */ double ASRCdtemp; /* delta-temperature of a particular instance */ diff --git a/src/spicelib/devices/asrc/asrcdest.c b/src/spicelib/devices/asrc/asrcdest.c index 623858a65..da4f371b5 100644 --- a/src/spicelib/devices/asrc/asrcdest.c +++ b/src/spicelib/devices/asrc/asrcdest.c @@ -25,6 +25,8 @@ ASRCdestroy(GENmodel **model) INPfreeTree(here->ASRCtree); if (here->ASRCposptr) free(here->ASRCposptr); + if (here->ASRCvars) + free(here->ASRCvars); FREE(here); } nextmod = mod->ASRCnextModel; diff --git a/src/spicelib/devices/asrc/asrcload.c b/src/spicelib/devices/asrc/asrcload.c index 8a34bc358..e67f57cc4 100644 --- a/src/spicelib/devices/asrc/asrcload.c +++ b/src/spicelib/devices/asrc/asrcload.c @@ -59,13 +59,7 @@ ASRCload(GENmodel *inModel, CKTcircuit *ckt) * 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]; - } else { - int node_num = (here->ASRCtree->vars[i].nValue) -> number; - asrc_vals[i] = ckt->CKTrhsOld[node_num]; - } + asrc_vals[i] = ckt->CKTrhsOld[here->ASRCvars[i]]; if (here->ASRCtree->IFeval(here->ASRCtree, ckt->CKTgmin, &rhs, asrc_vals, asrc_derivs) != OK) return(E_BADPARM); diff --git a/src/spicelib/devices/asrc/asrcset.c b/src/spicelib/devices/asrc/asrcset.c index fbc64e9cd..6ab88d02f 100644 --- a/src/spicelib/devices/asrc/asrcset.c +++ b/src/spicelib/devices/asrc/asrcset.c @@ -62,6 +62,7 @@ ASRCsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states) } here->ASRCposptr = TMALLOC(double *, j); + here->ASRCvars = TMALLOC(int *, here->ASRCtree->numVars); here->ASRCacValues = TMALLOC(double *, here->ASRCtree->numVars + 1); /* For each controlling variable set the entries @@ -103,6 +104,8 @@ ASRCsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states) return (E_BADPARM); } + here->ASRCvars[i] = column; + if (here->ASRCtype == ASRC_VOLTAGE) { TSTALLOC(ASRCposptr[j++], here->ASRCbranch, column); } else {