From ea2912551830fe71bc31272272caa8d2f6b7bd64 Mon Sep 17 00:00:00 2001 From: alan Date: Sat, 24 Feb 2018 19:18:09 +0100 Subject: [PATCH] alans proposal #1 for swtrunc.c, trying to avoid timestep too small --- src/spicelib/devices/sw/swtrunc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/spicelib/devices/sw/swtrunc.c b/src/spicelib/devices/sw/swtrunc.c index 2215deae0..453f89d6e 100644 --- a/src/spicelib/devices/sw/swtrunc.c +++ b/src/spicelib/devices/sw/swtrunc.c @@ -25,23 +25,27 @@ SWtrunc(GENmodel *inModel, CKTcircuit *ckt, double *timeStep) ckt->CKTstates[1][here->SWstate + 1]; if (ckt->CKTstates[0][here->SWstate + 0] == 0) { ref = (model->SWvThreshold + model->SWvHysteresis); - if (ckt->CKTstates[0][here->SWstate + 1] < ref && lastChange > 0) + if (ckt->CKTstates[0][here->SWstate + 1] < ref && lastChange > 1e-3) { maxChange = (ref - ckt->CKTstates[0][here->SWstate + 1]) * 0.75 + 0.05; maxStep = maxChange / lastChange * ckt->CKTdeltaOld[0]; + if (maxStep < ckt->CKTdelmin) + maxStep = ckt->CKTdelmin; if (*timeStep > maxStep) *timeStep = maxStep; } } else { ref = model->SWvThreshold - model->SWvHysteresis; - if (ckt->CKTstates[0][here->SWstate + 1] > ref && lastChange < 0) + if (ckt->CKTstates[0][here->SWstate + 1] > ref && lastChange < -1e-3) { maxChange = (ref - ckt->CKTstates[0][here->SWstate + 1]) * 0.75 - 0.05; maxStep = maxChange / lastChange * ckt->CKTdeltaOld[0]; + if (maxStep < ckt->CKTdelmin) + maxStep = ckt->CKTdelmin; if (*timeStep > maxStep) *timeStep = maxStep; }