From 1e602edfb65e7d4f3ffeaefdc79c60c9768e0cab Mon Sep 17 00:00:00 2001 From: rlar Date: Sun, 25 Feb 2018 12:02:07 +0100 Subject: [PATCH] fix truncation to work successfully with trunc-1.cir testcase testcase trunc-1.cir working now pretty much perfectly testcase davis-130420.cir works very precise as well number of timesteps going up from 374 to 1296 voltage error 20mV going down to 2 uV currently ckt->CKTdelmin = 1e-11*ckt->CKTmaxStep; is hardwired in traninit.c might make sense making it possible to steer that --- src/spicelib/devices/sw/swtrunc.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/spicelib/devices/sw/swtrunc.c b/src/spicelib/devices/sw/swtrunc.c index c1f51461c..f03012060 100644 --- a/src/spicelib/devices/sw/swtrunc.c +++ b/src/spicelib/devices/sw/swtrunc.c @@ -25,11 +25,10 @@ SWtrunc(GENmodel *inModel, CKTcircuit *ckt, double *timeStep) ckt->CKTstate1[here->SWctrlvalue]; if (ckt->CKTstate0[here->SWswitchstate] < 0) { ref = (model->SWvThreshold + model->SWvHysteresis); - if (ckt->CKTstate0[here->SWctrlvalue] < ref && lastChange > 1e-3) + if (ckt->CKTstate0[here->SWctrlvalue] < ref && lastChange > 0) { maxChange = - (ref - ckt->CKTstate0[here->SWctrlvalue]) * 0.75 - + 0.05; + (ref - ckt->CKTstate0[here->SWctrlvalue]) * 0.75; maxStep = maxChange / lastChange * ckt->CKTdeltaOld[0]; if (maxStep < ckt->CKTdelmin) maxStep = ckt->CKTdelmin; @@ -38,11 +37,10 @@ SWtrunc(GENmodel *inModel, CKTcircuit *ckt, double *timeStep) } } else { ref = model->SWvThreshold - model->SWvHysteresis; - if (ckt->CKTstate0[here->SWctrlvalue] > ref && lastChange < -1e-3) + if (ckt->CKTstate0[here->SWctrlvalue] > ref && lastChange < 0) { maxChange = - (ref - ckt->CKTstate0[here->SWctrlvalue]) * 0.75 - - 0.05; + (ref - ckt->CKTstate0[here->SWctrlvalue]) * 0.75; maxStep = maxChange / lastChange * ckt->CKTdeltaOld[0]; if (maxStep < ckt->CKTdelmin) maxStep = ckt->CKTdelmin;