diff --git a/src/spicelib/devices/csw/cswacld.c b/src/spicelib/devices/csw/cswacld.c index 6bf052d15..e9e21fada 100644 --- a/src/spicelib/devices/csw/cswacld.c +++ b/src/spicelib/devices/csw/cswacld.c @@ -21,7 +21,7 @@ CSWacLoad(GENmodel *inModel, CKTcircuit *ckt) for (; model; model = CSWnextModel(model)) for (here = CSWinstances(model); here; here = CSWnextInstance(here)) { - current_state = (int) ckt->CKTstates[0][here->CSWstate + 0]; + current_state = (int) ckt->CKTstate0[here->CSWswitchstate]; g_now = current_state ? model->CSWonConduct : model->CSWoffConduct; diff --git a/src/spicelib/devices/csw/cswdefs.h b/src/spicelib/devices/csw/cswdefs.h index 3764bc90f..4e97562bd 100644 --- a/src/spicelib/devices/csw/cswdefs.h +++ b/src/spicelib/devices/csw/cswdefs.h @@ -66,6 +66,10 @@ typedef struct sCSWinstance { #define CSW_OFF_CONDUCTANCE ckt->CKTgmin /* default off conductance */ #define CSW_NUM_STATES 2 +#define CSWswitchstate CSWstate+0 +#define CSWctrlvalue CSWstate+1 + + typedef struct sCSWmodel { /* model structure for a switch */ struct GENmodel gen; diff --git a/src/spicelib/devices/csw/cswload.c b/src/spicelib/devices/csw/cswload.c index 23c722294..f77c3a43f 100644 --- a/src/spicelib/devices/csw/cswload.c +++ b/src/spicelib/devices/csw/cswload.c @@ -30,8 +30,8 @@ CSWload(GENmodel *inModel, CKTcircuit *ckt) for (; model; model = CSWnextModel(model)) for (here = CSWinstances(model); here; here = CSWnextInstance(here)) { - old_current_state = ckt->CKTstates[0][here->CSWstate + 0]; - previous_state = ckt->CKTstates[1][here->CSWstate + 0]; + old_current_state = ckt->CKTstate0[here->CSWswitchstate]; + previous_state = ckt->CKTstate1[here->CSWswitchstate]; i_ctrl = ckt->CKTrhsOld[here->CSWcontBranch]; /* decide the state of the switch */ @@ -126,8 +126,8 @@ CSWload(GENmodel *inModel, CKTcircuit *ckt) } } - ckt->CKTstates[0][here->CSWstate + 0] = current_state; - ckt->CKTstates[1][here->CSWstate + 0] = previous_state; + ckt->CKTstate0[here->CSWswitchstate] = current_state; + ckt->CKTstate1[here->CSWswitchstate] = previous_state; if (current_state == REALLY_ON || current_state == HYST_ON) g_now = model->CSWonConduct; diff --git a/src/spicelib/devices/csw/cswnoise.c b/src/spicelib/devices/csw/cswnoise.c index 4e452d891..732383c9a 100644 --- a/src/spicelib/devices/csw/cswnoise.c +++ b/src/spicelib/devices/csw/cswnoise.c @@ -61,7 +61,7 @@ CSWnoise(int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt, Ndata *da switch (mode) { case N_DENS: - current_state = (int) ckt->CKTstates[0][inst->CSWstate + 0]; + current_state = (int) ckt->CKTstate0[inst->CSWswitchstate]; NevalSrc(&noizDens, &lnNdens, ckt, THERMNOISE, inst->CSWposNode, inst->CSWnegNode, current_state ? model->CSWonConduct : model->CSWoffConduct); diff --git a/src/spicelib/devices/csw/cswpzld.c b/src/spicelib/devices/csw/cswpzld.c index 6f7c587c6..065cefec0 100644 --- a/src/spicelib/devices/csw/cswpzld.c +++ b/src/spicelib/devices/csw/cswpzld.c @@ -24,7 +24,7 @@ CSWpzLoad(GENmodel *inModel, CKTcircuit *ckt, SPcomplex *s) for (; model; model = CSWnextModel(model)) for (here = CSWinstances(model); here; here = CSWnextInstance(here)) { - current_state = (int) ckt->CKTstates[0][here->CSWstate + 0]; + current_state = (int) ckt->CKTstate0[here->CSWswitchstate]; g_now = current_state ? model->CSWonConduct : model->CSWoffConduct; diff --git a/src/spicelib/devices/csw/cswtrunc.c b/src/spicelib/devices/csw/cswtrunc.c index 91f4702a5..e7be9559f 100644 --- a/src/spicelib/devices/csw/cswtrunc.c +++ b/src/spicelib/devices/csw/cswtrunc.c @@ -23,13 +23,13 @@ CSWtrunc(GENmodel *inModel, CKTcircuit *ckt, double *timeStep) for (; model; model = CSWnextModel(model)) for (here = CSWinstances(model); here; here = CSWnextInstance(here)) { lastChange = - ckt->CKTstates[0][here->CSWstate + 1] - - ckt->CKTstates[1][here->CSWstate + 1]; - if (ckt->CKTstates[0][here->CSWstate + 0] == 0) { + ckt->CKTstate0[here->CSWctrlvalue] - + ckt->CKTstate1[here->CSWctrlvalue]; + if (ckt->CKTstate0[here->CSWswitchstate] == 0) { ref = model->CSWiThreshold + model->CSWiHysteresis; - if (ckt->CKTstates[0][here->CSWstate + 1] < ref && lastChange > 0) { + if (ckt->CKTstate0[here->CSWctrlvalue] < ref && lastChange > 0) { maxChange = - (ref - ckt->CKTstates[0][here->CSWstate + 1]) * 0.75 + (ref - ckt->CKTstate0[here->CSWctrlvalue]) * 0.75 + 0.00005; maxStep = maxChange / lastChange * ckt->CKTdeltaOld[0]; if (*timeStep > maxStep) @@ -37,9 +37,9 @@ CSWtrunc(GENmodel *inModel, CKTcircuit *ckt, double *timeStep) } } else { ref = model->CSWiThreshold - model->CSWiHysteresis; - if (ckt->CKTstates[0][here->CSWstate + 1] > ref && lastChange < 0) { + if (ckt->CKTstate0[here->CSWctrlvalue] > ref && lastChange < 0) { maxChange = - (ref - ckt->CKTstates[0][here->CSWstate + 1]) * 0.75 + (ref - ckt->CKTstate0[here->CSWctrlvalue]) * 0.75 - 0.00005; maxStep = maxChange / lastChange * ckt->CKTdeltaOld[0]; if (*timeStep > maxStep) diff --git a/src/spicelib/devices/sw/swacload.c b/src/spicelib/devices/sw/swacload.c index a97487d7b..e8b2c03d7 100644 --- a/src/spicelib/devices/sw/swacload.c +++ b/src/spicelib/devices/sw/swacload.c @@ -23,7 +23,7 @@ SWacLoad(GENmodel *inModel, CKTcircuit *ckt) /* In AC analysis, just propogate the state... */ - current_state = (int) ckt->CKTstates[0][here->SWstate + 0]; + current_state = (int) ckt->CKTstate0[here->SWswitchstate]; g_now = current_state ? model->SWonConduct : model->SWoffConduct; diff --git a/src/spicelib/devices/sw/swdefs.h b/src/spicelib/devices/sw/swdefs.h index ee0a245cd..55d6e5c4c 100644 --- a/src/spicelib/devices/sw/swdefs.h +++ b/src/spicelib/devices/sw/swdefs.h @@ -65,6 +65,10 @@ typedef struct sSWinstance { #define SW_OFF_CONDUCTANCE ckt->CKTgmin /* default off conductance */ #define SW_NUM_STATES 2 +#define SWswitchstate SWstate+0 +#define SWctrlvalue SWstate+1 + + typedef struct sSWmodel { /* model structure for a switch */ struct GENmodel gen; diff --git a/src/spicelib/devices/sw/swload.c b/src/spicelib/devices/sw/swload.c index 65a0a2c1f..4150d736f 100644 --- a/src/spicelib/devices/sw/swload.c +++ b/src/spicelib/devices/sw/swload.c @@ -31,8 +31,8 @@ SWload(GENmodel *inModel, CKTcircuit *ckt) for (; model; model = SWnextModel(model)) for (here = SWinstances(model); here; here = SWnextInstance(here)) { - old_current_state = ckt->CKTstates[0][here->SWstate + 0]; - previous_state = ckt->CKTstates[1][here->SWstate + 0]; + old_current_state = ckt->CKTstate0[here->SWswitchstate]; + previous_state = ckt->CKTstate1[here->SWswitchstate]; v_ctrl = ckt->CKTrhsOld[here->SWposCntrlNode] - @@ -129,8 +129,8 @@ SWload(GENmodel *inModel, CKTcircuit *ckt) // After analyzing the transient code, it seems that this is not a problem because state updating // occurs before the convergence loop in transient processing. - ckt->CKTstates[0][here->SWstate + 0] = current_state; - ckt->CKTstates[0][here->SWstate + 1] = v_ctrl; + ckt->CKTstate0[here->SWswitchstate] = current_state; + ckt->CKTstate0[here->SWctrlvalue] = v_ctrl; if (current_state == REALLY_ON || current_state == HYST_ON) g_now = model->SWonConduct; diff --git a/src/spicelib/devices/sw/swnoise.c b/src/spicelib/devices/sw/swnoise.c index 9ec1c46bc..ed0ce79c6 100644 --- a/src/spicelib/devices/sw/swnoise.c +++ b/src/spicelib/devices/sw/swnoise.c @@ -61,7 +61,7 @@ SWnoise(int mode, int operation, GENmodel *genmodel, CKTcircuit *ckt, Ndata *dat switch (mode) { case N_DENS: - current_state = (int) ckt->CKTstates[0][inst->SWstate + 0]; + current_state = (int) ckt->CKTstate0[inst->SWswitchstate]; NevalSrc(&noizDens, &lnNdens, ckt, THERMNOISE, inst->SWposNode, inst->SWnegNode, current_state ? model->SWonConduct : model->SWoffConduct); diff --git a/src/spicelib/devices/sw/swpzload.c b/src/spicelib/devices/sw/swpzload.c index 733936e24..ff23edb16 100644 --- a/src/spicelib/devices/sw/swpzload.c +++ b/src/spicelib/devices/sw/swpzload.c @@ -26,7 +26,7 @@ SWpzLoad(GENmodel *inModel, CKTcircuit *ckt, SPcomplex *s) /* In AC analysis, just propogate the state... */ - current_state = (int) ckt->CKTstates[0][here->SWstate + 0]; + current_state = (int) ckt->CKTstate0[here->SWswitchstate]; g_now = current_state ? model->SWonConduct : model->SWoffConduct; diff --git a/src/spicelib/devices/sw/swtrunc.c b/src/spicelib/devices/sw/swtrunc.c index 53511ee8b..81866e285 100644 --- a/src/spicelib/devices/sw/swtrunc.c +++ b/src/spicelib/devices/sw/swtrunc.c @@ -21,13 +21,13 @@ SWtrunc(GENmodel *inModel, CKTcircuit *ckt, double *timeStep) for (; model; model = SWnextModel(model)) for (here = SWinstances(model); here; here = SWnextInstance(here)) { lastChange = - ckt->CKTstates[0][here->SWstate + 1] - - ckt->CKTstates[1][here->SWstate + 1]; - if (ckt->CKTstates[0][here->SWstate + 0] == 0) { + ckt->CKTstate0[here->SWctrlvalue] - + ckt->CKTstate1[here->SWctrlvalue]; + if (ckt->CKTstate0[here->SWswitchstate] == 0) { ref = model->SWvThreshold + model->SWvHysteresis; - if (ckt->CKTstates[0][here->SWstate + 1] < ref && lastChange > 0) { + if (ckt->CKTstate0[here->SWctrlvalue] < ref && lastChange > 0) { maxChange = - (ref - ckt->CKTstates[0][here->SWstate + 1]) * 0.75 + (ref - ckt->CKTstate0[here->SWctrlvalue]) * 0.75 + 0.05; maxStep = maxChange / lastChange * ckt->CKTdeltaOld[0]; if (*timeStep > maxStep) @@ -35,9 +35,9 @@ SWtrunc(GENmodel *inModel, CKTcircuit *ckt, double *timeStep) } } else { ref = model->SWvThreshold - model->SWvHysteresis; - if (ckt->CKTstates[0][here->SWstate + 1] > ref && lastChange < 0) { + if (ckt->CKTstate0[here->SWctrlvalue] > ref && lastChange < 0) { maxChange = - (ref - ckt->CKTstates[0][here->SWstate + 1]) * 0.75 + (ref - ckt->CKTstate0[here->SWctrlvalue]) * 0.75 - 0.05; maxStep = maxChange / lastChange * ckt->CKTdeltaOld[0]; if (*timeStep > maxStep)